org.jrubyparser.lexer
Class LexerSource

java.lang.Object
  extended by org.jrubyparser.lexer.LexerSource
Direct Known Subclasses:
ReaderLexerSource

public abstract class LexerSource
extends Object

This class is what feeds the lexer. It is primarily a wrapper around a Reader that can unread() data back onto the source. Originally, I thought about using the PushBackReader to handle read/unread, but I realized that some extremely pathological case could overflow the pushback buffer. Better safe than sorry. I could have combined this implementation with a PushbackBuffer, but the added complexity did not seem worth it.


Field Summary
protected  int line
           
protected  int offset
           
 
Constructor Summary
protected LexerSource(String sourceName, int line)
          Create our food-source for the lexer
 
Method Summary
abstract  int chompReadAhead()
           
 String getFilename()
          What file are we lexing?
 int getLine()
          What line are we at?
 int getOffset()
          The location of the last byte we read from the source.
 SourcePosition getPosition()
          Where is the reader within the source {filename,row}
 SourcePosition getPosition(SourcePosition startPosition, boolean inclusive)
          Where is the reader within the source {filename,row}
static LexerSource getSource(String name, Reader content, ParserConfiguration configuration)
          Create a source.
abstract  boolean isANewLine()
           
abstract  boolean lastWasBeginOfLine()
           
abstract  boolean matchMarker(String marker, boolean indent, boolean withNewline)
          Match marker against input consumering lexer source as it goes...Unless it does not match then it reverts lexer source back to point when this method was invoked.
abstract  boolean peek(int c)
           
abstract  int read()
           
abstract  String readLineBytes()
           
abstract  String readUntil(char c)
           
abstract  void setIsANewLine(boolean nextCharIsOnANewLine)
           
abstract  void setOffset(int offset)
           
abstract  int skipUntil(int c)
           
abstract  void unread(int c)
           
abstract  void unreadMany(CharSequence line)
           
abstract  boolean wasBeginOfLine()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

line

protected int line

offset

protected int offset
Constructor Detail

LexerSource

protected LexerSource(String sourceName,
                      int line)
Create our food-source for the lexer

Parameters:
sourceName - is the file we are reading
line - starting line number for source (used by eval)
Method Detail

getFilename

public String getFilename()
What file are we lexing?

Returns:
the files name

getLine

public int getLine()
What line are we at?

Returns:
the line number 0...line_size-1

getOffset

public int getOffset()
The location of the last byte we read from the source.

Returns:
current location of source

getPosition

public SourcePosition getPosition(SourcePosition startPosition,
                                  boolean inclusive)
Where is the reader within the source {filename,row}

Returns:
the current position

getPosition

public SourcePosition getPosition()
Where is the reader within the source {filename,row}

Returns:
the current position

getSource

public static LexerSource getSource(String name,
                                    Reader content,
                                    ParserConfiguration configuration)
Create a source.

Parameters:
name - the name of the source (e.g a filename: foo.rb)
content - the data of the source
Returns:
the new source

matchMarker

public abstract boolean matchMarker(String marker,
                                    boolean indent,
                                    boolean withNewline)
                             throws IOException
Match marker against input consumering lexer source as it goes...Unless it does not match then it reverts lexer source back to point when this method was invoked.

Parameters:
marker - to match against
indent - eat any leading whitespace
withNewline - includes a check that marker is followed by newline or EOF
Returns:
true if marker matches...false otherwise
Throws:
IOException - if an error occurred reading from underlying IO source

read

public abstract int read()
                  throws IOException
Throws:
IOException

readUntil

public abstract String readUntil(char c)
                          throws IOException
Throws:
IOException

readLineBytes

public abstract String readLineBytes()
                              throws IOException
Throws:
IOException

skipUntil

public abstract int skipUntil(int c)
                       throws IOException
Throws:
IOException

unread

public abstract void unread(int c)

unreadMany

public abstract void unreadMany(CharSequence line)

peek

public abstract boolean peek(int c)
                      throws IOException
Throws:
IOException

lastWasBeginOfLine

public abstract boolean lastWasBeginOfLine()

wasBeginOfLine

public abstract boolean wasBeginOfLine()

chompReadAhead

public abstract int chompReadAhead()

isANewLine

public abstract boolean isANewLine()

setIsANewLine

public abstract void setIsANewLine(boolean nextCharIsOnANewLine)

setOffset

public abstract void setOffset(int offset)


Copyright © 2013. All Rights Reserved.