org.jruby.lexer.yacc
Class LexerSource

java.lang.Object
  extended by org.jruby.lexer.yacc.LexerSource

public class LexerSource
extends java.lang.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.

Author:
enebo

Constructor Summary
LexerSource(java.lang.String sourceName, java.io.Reader reader, int line, boolean extraPositionInformation)
          Create our food-source for the lexer
 
Method Summary
 char getCharAt(int anOffset)
          Get character ahead of current position by offset positions.
 int getColumn()
          Are we at beggining of line?
 java.lang.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.
 ISourcePosition getPosition()
          Where is the reader within the source {filename,row}
 ISourcePosition getPosition(ISourcePosition startPosition, boolean inclusive)
          Where is the reader within the source {filename,row}
 ISourcePositionFactory getPositionFactory()
           
static LexerSource getSource(java.lang.String name, java.io.Reader content, int line, boolean extraPositionInformation)
          Create a source.
 boolean matchString(java.lang.String match, boolean indent)
           
 boolean peek(char to)
           
 char read()
          Read next character from this source
 char readEscape()
           
 java.lang.String readLine()
           
 ByteList readLineBytes()
           
 java.lang.String toString()
           
 void unread(char c)
          Pushes char back onto this source.
 void unreadMany(java.lang.CharSequence buffer)
           
 boolean wasBeginOfLine()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LexerSource

public LexerSource(java.lang.String sourceName,
                   java.io.Reader reader,
                   int line,
                   boolean extraPositionInformation)
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 char read()
          throws java.io.IOException
Read next character from this source

Returns:
next character to viewed by the source
Throws:
java.io.IOException

unread

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

Parameters:
c - to be put back onto the source

peek

public boolean peek(char to)
             throws java.io.IOException
Throws:
java.io.IOException

getFilename

public java.lang.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

getColumn

public int getColumn()
Are we at beggining of line?

Returns:
the column (0..x)

getOffset

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

Returns:
current location of source

getPosition

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

Returns:
the current position

getPosition

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

Returns:
the current position

getPositionFactory

public ISourcePositionFactory getPositionFactory()

getSource

public static LexerSource getSource(java.lang.String name,
                                    java.io.Reader content,
                                    int line,
                                    boolean extraPositionInformation)
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

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Throws:
java.io.IOException

readLineBytes

public ByteList readLineBytes()
                       throws java.io.IOException
Throws:
java.io.IOException

unreadMany

public void unreadMany(java.lang.CharSequence buffer)

matchString

public boolean matchString(java.lang.String match,
                           boolean indent)
                    throws java.io.IOException
Throws:
java.io.IOException

wasBeginOfLine

public boolean wasBeginOfLine()

readEscape

public char readEscape()
                throws java.io.IOException
Throws:
java.io.IOException

getCharAt

public char getCharAt(int anOffset)
               throws java.io.IOException
Get character ahead of current position by offset positions.

Parameters:
anOffset - is location past current position to get char at
Returns:
character index positions ahead of source location or EOF
Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2002-2007 JRuby Team. All Rights Reserved.