org.jrubyparser.lexer
Class ReaderLexerSource

java.lang.Object
  extended by org.jrubyparser.lexer.LexerSource
      extended by org.jrubyparser.lexer.ReaderLexerSource

public class ReaderLexerSource
extends LexerSource


Field Summary
 
Fields inherited from class org.jrubyparser.lexer.LexerSource
line, offset
 
Constructor Summary
ReaderLexerSource(String sourceName, Reader in, int line)
          Create our food-source for the lexer
 
Method Summary
 int chompReadAhead()
           
static LexerSource getSource(String name, Reader content, ParserConfiguration configuration)
          Create a source.
 boolean isANewLine()
           
 boolean lastWasBeginOfLine()
           
 boolean matchMarker(String match, boolean indent, boolean checkNewline)
          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.
 boolean peek(int to)
          Is the next character equal to 'to'
 int read()
          Read next character from this source
 String readLineBytes()
           
 String readUntil(char marker)
           
 void setIsANewLine(boolean nextCharIsOnANewLine)
           
 void setOffset(int offset)
           
 int skipUntil(int c)
           
 String toString()
           
 void unread(int c)
          Pushes char back onto this source.
 void unreadMany(CharSequence buffer)
           
 boolean wasBeginOfLine()
          Was the last character read from the stream the first character on a line
 
Methods inherited from class org.jrubyparser.lexer.LexerSource
getFilename, getLine, getOffset, getPosition, getPosition
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ReaderLexerSource

public ReaderLexerSource(String sourceName,
                         Reader in,
                         int line)
Create our food-source for the lexer

Parameters:
sourceName - is the file we are reading
reader - is what represents the contents of file sourceName
line - starting line number for source (used by eval)
extraPositionInformation - will gives us extra information that an IDE may want
Method Detail

read

public int read()
         throws IOException
Read next character from this source

Specified by:
read in class LexerSource
Returns:
next character to viewed by the source
Throws:
IOException

unread

public void unread(int c)
Pushes char back onto this source. Note, this also allows us to push whatever is passes back into the source.

Specified by:
unread in class LexerSource
Parameters:
to - be put back onto the source

peek

public boolean peek(int to)
             throws IOException
Is the next character equal to 'to'

Specified by:
peek in class LexerSource
Parameters:
to - character to compare against
Returns:
true if the same
Throws:
IOException

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

readLineBytes

public String readLineBytes()
                     throws IOException
Specified by:
readLineBytes in class LexerSource
Throws:
IOException

skipUntil

public int skipUntil(int c)
              throws IOException
Specified by:
skipUntil in class LexerSource
Throws:
IOException

unreadMany

public void unreadMany(CharSequence buffer)
Specified by:
unreadMany in class LexerSource

matchMarker

public boolean matchMarker(String match,
                           boolean indent,
                           boolean checkNewline)
                    throws IOException
Description copied from class: LexerSource
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.

Specified by:
matchMarker in class LexerSource
Parameters:
match - to match against
indent - eat any leading whitespace
checkNewline - 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

wasBeginOfLine

public boolean wasBeginOfLine()
Was the last character read from the stream the first character on a line

Specified by:
wasBeginOfLine in class LexerSource
Returns:
true if so

lastWasBeginOfLine

public boolean lastWasBeginOfLine()
Specified by:
lastWasBeginOfLine in class LexerSource

toString

public String toString()
Overrides:
toString in class Object

readUntil

public String readUntil(char marker)
                 throws IOException
Specified by:
readUntil in class LexerSource
Throws:
IOException

chompReadAhead

public int chompReadAhead()
Specified by:
chompReadAhead in class LexerSource

isANewLine

public boolean isANewLine()
Specified by:
isANewLine in class LexerSource

setIsANewLine

public void setIsANewLine(boolean nextCharIsOnANewLine)
Specified by:
setIsANewLine in class LexerSource

setOffset

public void setOffset(int offset)
Specified by:
setOffset in class LexerSource


Copyright © 2013. All Rights Reserved.