protected void captureFeature(int c) { switch(c) { case '\n': lineBuffer.append((char) c); case -1: captureFeatureNewline(); break; default: lineBuffer.append((char) c); break; } }
private void escaped(RubyYaccLexer lexer, Encoding encoding, LexerSource src, ByteList buffer) throws java.io.IOException { int c; switch (c = src.read()) { case '\\': parseEscapeIntoBuffer(lexer, encoding, src, buffer); break; case RubyYaccLexer.EOF: throw new SyntaxException(PID.INVALID_ESCAPE_SYNTAX, src.getPosition(), src.getCurrentLine(), "Invalid escape character syntax"); default: buffer.append(c); } }
public ISourcePosition getPosition() { if (lastPosition.getStartLine() == source.getVirtualLine()) return lastPosition; lastPosition = new SimpleSourcePosition(source.getFilename(), source.getVirtualLine()); return lastPosition; } }
private void syntaxError(LexerSource src) { throw new SyntaxException(PID.STRING_MARKER_MISSING, src.getPosition(), src.getCurrentLine(), "can't find string \"" + marker + "\" anywhere before EOF", marker); } }
if (src.peek(RubyYaccLexer.EOF)) syntaxError(src); if (src.lastWasBeginOfLine() && src.matchMarker(marker, indent, true)) { ISourcePosition position = lexer.getPosition(); src.unreadMany(lastLine); str.append(src.readLineBytes()); str.append('\n'); if (src.peek(RubyYaccLexer.EOF)) syntaxError(src); position = lexer.getPosition(); } while (!src.matchMarker(marker, indent, true)); } else { int c = src.read(); if (c == '#') { switch (c = src.read()) { case '$': case '@': src.unread(c); lexer.setValue(new Token("#" + c, lexer.getPosition())); return Tokens.tSTRING_DVAR; src.unread(c); str.append(src.read()); if (src.peek(RubyYaccLexer.EOF)) syntaxError(src); position = lexer.getPosition(); } while (!src.matchMarker(marker, indent, true));
if (token == 0 && src.getLine() == 0) detectUTF8BOM(); c = src.read(); switch(c) { case '\000': /* NUL */ while((c = src.read()) == '\n') {} } else { switch (lex_state) { c = src.read(); continue; case '.': { if ((c = src.read()) != '.') { src.unread(c); src.unread('.'); src.unread(c); getPosition(); if (src.wasBeginOfLine()) { if (src.matchMarker(BEGIN_DOC_MARKER, false, false)) { c = src.read(); src.unread(c); for (;;) { c = src.read();
switch (c = src.read()) { case '\n': break; /* just ignore */ buffer.append(c); for (int i = 0; i < 2; i++) { c = src.read(); if (c == RubyYaccLexer.EOF) { throw new SyntaxException(PID.INVALID_ESCAPE_SYNTAX, src.getPosition(), src.getCurrentLine(), "Invalid escape character syntax"); src.unread(c); break; buffer.append('\\'); buffer.append(c); c = src.read(); if (!RubyYaccLexer.isHexChar(c)) { throw new SyntaxException(PID.INVALID_ESCAPE_SYNTAX, src.getPosition(), src.getCurrentLine(), "Invalid escape character syntax"); c = src.read(); if (RubyYaccLexer.isHexChar(c)) { buffer.append(c); } else { src.unread(c); if ((c = src.read()) != '-') { throw new SyntaxException(PID.INVALID_ESCAPE_SYNTAX, src.getPosition(),
/** * 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'); }
StringBuilder unknownFlags = new StringBuilder(10); for (c = src.read(); c != RubyYaccLexer.EOF && Character.isLetter(c); c = src.read()) { switch (c) { case 'i': src.unread(c); if (unknownFlags.length() != 0) { throw new SyntaxException(PID.REGEXP_UNKNOWN_OPTION, src.getPosition(), "unknown regexp option" + (unknownFlags.length() > 1 ? "s" : "") + " - " + unknownFlags.toString(), unknownFlags.toString());
runtime.setVerbose(runtime.getNil()); try { runtime.defineGlobalConstant("DATA", new RubyFile(runtime, file, lexerSource.getRemainingAsStream())); } catch (IOException e) { // Not sure how to handle suddenly closed IO here? runtime.defineGlobalConstant("DATA", runtime.getNil()); totalBytes += lexerSource.getOffset();
/** * Get position information for Token/Node that follows node represented by startPosition * and current lexer location. * * @param startPosition previous node/token * @param inclusive include previous node into position information of current node * @return a new position */ public ISourcePosition getPosition(ISourcePosition startPosition) { return src.getPosition(startPosition); }
@SuppressWarnings("unchecked") public Node parse(String file, byte[] content, DynamicScope blockScope, ParserConfiguration configuration) { RubyArray list = getLines(configuration, runtime, file); LexerSource lexerSource = LexerSource.getSource(file, content, list, configuration); return parse(file, lexerSource, blockScope, configuration); }
public SimplePositionFactory(LexerSource source, int line) { this.source = source; lastPosition = new SimpleSourcePosition(source.getFilename(), line); }
public String getCurrentLine() { return src.getCurrentLine(); }
if (src.peek(RubyYaccLexer.EOF)) syntaxError(src); if (src.lastWasBeginOfLine() && src.matchMarker(marker, indent, true)) { ISourcePosition position = lexer.getPosition(); src.unreadMany(lastLine); str.append(src.readLineBytes()); str.append('\n'); if (src.peek(RubyYaccLexer.EOF)) syntaxError(src); position = lexer.getPosition(); } while (!src.matchMarker(marker, indent, true)); } else { int c = src.read(); if (c == '#') { switch (c = src.read()) { case '$': case '@': src.unread(c); lexer.setValue(new Token("#" + c, lexer.getPosition())); return Tokens.tSTRING_DVAR; src.unread(c); str.append(src.read()); if (src.peek(RubyYaccLexer.EOF)) syntaxError(src); position = lexer.getPosition(); } while (!src.matchMarker(marker, indent, true));
if (token == 0 && src.getLine() == 0) detectUTF8BOM(); c = src.read(); switch(c) { case '\000': /* NUL */ while((c = src.read()) == '\n') {} } else { switch (lex_state) { c = src.read(); continue; case '.': { if ((c = src.read()) != '.') { src.unread(c); src.unread('.'); src.unread(c); getPosition(); if (src.wasBeginOfLine()) { if (src.matchMarker(BEGIN_DOC_MARKER, false, false)) { c = src.read(); src.unread(c); for (;;) { c = src.read();
switch (c = src.read()) { case '\n': break; /* just ignore */ buffer.append(c); for (int i = 0; i < 2; i++) { c = src.read(); if (c == RubyYaccLexer.EOF) { throw new SyntaxException(PID.INVALID_ESCAPE_SYNTAX, src.getPosition(), src.getCurrentLine(), "Invalid escape character syntax"); src.unread(c); break; buffer.append('\\'); buffer.append(c); c = src.read(); if (!RubyYaccLexer.isHexChar(c)) { throw new SyntaxException(PID.INVALID_ESCAPE_SYNTAX, src.getPosition(), src.getCurrentLine(), "Invalid escape character syntax"); c = src.read(); if (RubyYaccLexer.isHexChar(c)) { buffer.append(c); } else { src.unread(c); if ((c = src.read()) != '-') { throw new SyntaxException(PID.INVALID_ESCAPE_SYNTAX, src.getPosition(),
/** * 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'); }
StringBuilder unknownFlags = new StringBuilder(10); for (c = src.read(); c != RubyYaccLexer.EOF && Character.isLetter(c); c = src.read()) { switch (c) { case 'i': src.unread(c); if (unknownFlags.length() != 0) { throw new SyntaxException(PID.REGEXP_UNKNOWN_OPTION, src.getPosition(), "unknown regexp option" + (unknownFlags.length() > 1 ? "s" : "") + " - " + unknownFlags.toString(), unknownFlags.toString());
private void syntaxError(LexerSource src) { throw new SyntaxException(PID.STRING_MARKER_MISSING, src.getPosition(), src.getCurrentLine(), "can't find string \"" + marker + "\" anywhere before EOF", marker); } }