/** * Read a comment up to end of line. * * @return something or eof value */ protected int readComment() throws IOException { // 1.9 - first line comment handling ByteList commentLine; if (!isOneEight() && src.getLine() == 0 && token == 0) { // Skip first line if it is a shebang line? // (not the same as MRI:parser_prepare/comment_at_top) if (src.peek('!')) { int c = src.skipUntil('\n'); // TODO: Eat whitespace if (!src.peek('#')) return c; // Next line better also be a comment } commentLine = src.readUntil('\n'); if (commentLine != null) { boolean handledMagicComment = parseMagicComment(commentLine); if (!handledMagicComment) { handleFileEncodingComment(commentLine); } } return 0; } return src.skipUntil('\n'); }
/** * Read a comment up to end of line. * * @return something or eof value */ protected int readComment() throws IOException { // 1.9 - first line comment handling ByteList commentLine; if (!isOneEight() && src.getLine() == 0 && token == 0) { // Skip first line if it is a shebang line? // (not the same as MRI:parser_prepare/comment_at_top) if (src.peek('!')) { int c = src.skipUntil('\n'); // TODO: Eat whitespace if (!src.peek('#')) return c; // Next line better also be a comment } commentLine = src.readUntil('\n'); if (commentLine != null) { boolean handledMagicComment = parseMagicComment(commentLine); if (!handledMagicComment) { handleFileEncodingComment(commentLine); } } return 0; } return src.skipUntil('\n'); }
public int readUTFEscape(ByteList buffer, boolean stringLiteral, boolean symbolLiteral) throws IOException { int codepoint; int c; if (src.peek('{')) { // handle \\u{...} do { src.read(); // Eat curly or whitespace codepoint = scanHex(6, false, "invalid Unicode escape"); if (codepoint > 0x10ffff) { throw new SyntaxException(PID.INVALID_ESCAPE_SYNTAX, getPosition(), getCurrentLine(), "invalid Unicode codepoint (too large)"); } if (buffer != null) readUTF8EscapeIntoBuffer(codepoint, buffer, stringLiteral); } while (src.peek(' ') || src.peek('\t')); c = src.read(); if (c != '}') { throw new SyntaxException(PID.INVALID_ESCAPE_SYNTAX, getPosition(), getCurrentLine(), "unterminated Unicode escape"); } } else { // handle \\uxxxx codepoint = scanHex(4, true, "Invalid Unicode escape"); if (buffer != null) readUTF8EscapeIntoBuffer(codepoint, buffer, stringLiteral); } return codepoint; }
public int readUTFEscape(ByteList buffer, boolean stringLiteral, boolean symbolLiteral) throws IOException { int codepoint; int c; if (src.peek('{')) { // handle \\u{...} do { src.read(); // Eat curly or whitespace codepoint = scanHex(6, false, "invalid Unicode escape"); if (codepoint > 0x10ffff) { throw new SyntaxException(PID.INVALID_ESCAPE_SYNTAX, getPosition(), getCurrentLine(), "invalid Unicode codepoint (too large)"); } if (buffer != null) readUTF8EscapeIntoBuffer(codepoint, buffer, stringLiteral); } while (src.peek(' ') || src.peek('\t')); c = src.read(); if (c != '}') { throw new SyntaxException(PID.INVALID_ESCAPE_SYNTAX, getPosition(), getCurrentLine(), "unterminated Unicode escape"); } } else { // handle \\uxxxx codepoint = scanHex(4, true, "Invalid Unicode escape"); if (buffer != null) readUTF8EscapeIntoBuffer(codepoint, buffer, stringLiteral); } return codepoint; }
public void readUTFEscapeRegexpLiteral(ByteList buffer) throws IOException { buffer.append('\\'); buffer.append('u'); if (src.peek('{')) { // handle \\u{...} do { buffer.append(src.read()); if (scanHexLiteral(buffer, 6, false, "invalid Unicode escape") > 0x10ffff) { throw new SyntaxException(PID.INVALID_ESCAPE_SYNTAX, getPosition(), getCurrentLine(), "invalid Unicode codepoint (too large)"); } } while (src.peek(' ') || src.peek('\t')); int c = src.read(); if (c != '}') { throw new SyntaxException(PID.INVALID_ESCAPE_SYNTAX, getPosition(), getCurrentLine(), "unterminated Unicode escape"); } buffer.append((char) c); } else { // handle \\uxxxx scanHexLiteral(buffer, 4, true, "Invalid Unicode escape"); } }
public void readUTFEscapeRegexpLiteral(ByteList buffer) throws IOException { buffer.append('\\'); buffer.append('u'); if (src.peek('{')) { // handle \\u{...} do { buffer.append(src.read()); if (scanHexLiteral(buffer, 6, false, "invalid Unicode escape") > 0x10ffff) { throw new SyntaxException(PID.INVALID_ESCAPE_SYNTAX, getPosition(), getCurrentLine(), "invalid Unicode codepoint (too large)"); } } while (src.peek(' ') || src.peek('\t')); int c = src.read(); if (c != '}') { throw new SyntaxException(PID.INVALID_ESCAPE_SYNTAX, getPosition(), getCurrentLine(), "unterminated Unicode escape"); } buffer.append((char) c); } else { // handle \\uxxxx scanHexLiteral(buffer, 4, true, "Invalid Unicode escape"); } }
private int leftBracket(boolean spaceSeen) throws IOException { parenNest++; int c = '['; if (lex_state == LexState.EXPR_FNAME || lex_state == LexState.EXPR_DOT) { setState(LexState.EXPR_ARG); if ((c = src.read()) == ']') { if (src.peek('=')) { src.read(); yaccValue = new Token("[]=", getPosition()); return Tokens.tASET; } yaccValue = new Token("[]", getPosition()); return Tokens.tAREF; } src.unread(c); yaccValue = new Token("[", getPosition()); return '['; } else if (isBEG() || (isARG() && spaceSeen)) { c = Tokens.tLBRACK; } setState(LexState.EXPR_BEG); conditionState.stop(); cmdArgumentState.stop(); yaccValue = new Token("[", getPosition()); return c; }
public int parseString(RubyYaccLexer lexer, LexerSource src) throws java.io.IOException { boolean indent = (flags & RubyYaccLexer.STR_FUNC_INDENT) != 0; if (src.peek(RubyYaccLexer.EOF)) syntaxError(src); str.append(src.readLineBytes()); str.append('\n'); if (src.peek(RubyYaccLexer.EOF)) syntaxError(src); position = lexer.getPosition(); } while (!src.matchMarker(marker, indent, true)); if (src.peek(RubyYaccLexer.EOF)) syntaxError(src); position = lexer.getPosition(); } while (!src.matchMarker(marker, indent, true));
private int leftBracket(boolean spaceSeen) throws IOException { parenNest++; int c = '['; if (lex_state == LexState.EXPR_FNAME || lex_state == LexState.EXPR_DOT) { setState(LexState.EXPR_ARG); if ((c = src.read()) == ']') { if (src.peek('=')) { src.read(); yaccValue = new Token("[]=", getPosition()); return Tokens.tASET; } yaccValue = new Token("[]", getPosition()); return Tokens.tAREF; } src.unread(c); yaccValue = new Token("[", getPosition()); return '['; } else if (isBEG() || (isARG() && spaceSeen)) { c = Tokens.tLBRACK; } setState(LexState.EXPR_BEG); conditionState.stop(); cmdArgumentState.stop(); yaccValue = new Token("[", getPosition()); return c; }
public int parseString(RubyYaccLexer lexer, LexerSource src) throws java.io.IOException { boolean indent = (flags & RubyYaccLexer.STR_FUNC_INDENT) != 0; if (src.peek(RubyYaccLexer.EOF)) syntaxError(src); str.append(src.readLineBytes()); str.append('\n'); if (src.peek(RubyYaccLexer.EOF)) syntaxError(src); position = lexer.getPosition(); } while (!src.matchMarker(marker, indent, true)); if (src.peek(RubyYaccLexer.EOF)) syntaxError(src); position = lexer.getPosition(); } while (!src.matchMarker(marker, indent, true));
} else if (expand && c == '#' && !src.peek('\n')) { int c2 = src.read();
} else if (expand && c == '#' && !src.peek('\n')) { int c2 = src.read();