|
|||||||||
Home >> All >> jpicedt >> graphic >> io >> [ parser overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: ![]() ![]() ![]() |
DETAIL: FIELD | CONSTR | METHOD |
jpicedt.graphic.io.parser
Class Context

java.lang.Objectjpicedt.graphic.io.parser.Context
- All Implemented Interfaces:
- ExpressionConstants
- public class Context
- extends java.lang.Object
- implements ExpressionConstants
- extends java.lang.Object
A class that stores context information about the parsing process, like : current line number, current parsed substring, block markers, stack for markers...
By convention, end markers (EOF, EndOfBlocks, ...) always refer to a position one character ahead of the last character (e.g. of the block), so that String.substring() works properly w/o adding 1 to the end-index.
Field Summary | |
private int |
beginBlockMarker
|
private java.util.Stack |
blockMarkersStack
|
private java.lang.String |
buffer
|
private int |
caret
|
private int |
endBlockMarker
|
private int[] |
lineBreaks
|
private int |
marker
|
private int |
stackLevel
|
Fields inherited from interface jpicedt.graphic.io.parser.ExpressionConstants |
ANY_CHAR, ANY_CHAR_EOL, ANY_SIGN, AT_LEAST, AT_MOST, DEBUG, DOUBLE, EOL, EXACTLY, INTEGER, NEGATIVE, NON_NULL, POSITIVE, STRICTLY_NEGATIVE, STRICTLY_POSITIVE, WHITE_SPACES, WHITE_SPACES_OR_EOL |
Constructor Summary | |
Context(java.io.Reader reader)
build a new Context fed by the given reader |
Method Summary | |
void |
enterBlock(int blockEnd)
save current markers in the stack, and set new block borders : new endBlockMarker is set to the given position new beginBlockMarker is set to the current caret position convenience marker is saved, and a new one is initialized to the beginning of the (new) current block. |
void |
exitBlock()
restore old markers (and forget current value), then move caret to the end of the block we just went out. |
int |
getBeginningOfBlock()
|
java.lang.String |
getBlockContent()
Return the content of the current block. |
int |
getBOL()
Returns the position of the beginning of the current line, or the beginning of the current block if the caret is located b/w the B.of.Block and the first CR inside the current block. |
java.lang.String |
getBuffer()
Return the entire buffer |
int |
getCaretPosition()
|
java.lang.Character |
getCharAt(int index)
Return the character at the given position, or null if index is negative, or past EOF |
java.lang.String |
getCurrentLine()
|
int |
getEndOfBlock()
|
int |
getEOF()
|
int |
getEOL()
Returns the position of the end of the current line, i.e. |
int |
getLineNumber()
|
gnu.regexp.REMatch |
getMatch(gnu.regexp.RE re)
match the given RE on the current block, starting at the caret position, then move the caret past the matched string if found. |
int |
indexOf(java.lang.String s)
Return the index of the first occurence of the given String, starting from the current caret position. |
int |
indexOf(java.lang.String s,
int fromIndex)
Return the index of the first occurence of the given String in the current block, starting from the given position |
int |
indexOfBeforeEOL(java.lang.String s)
Return the index of the first occurence of the given String, starting from the current caret position, ending at getEndOfBlock() (not included!). |
boolean |
isAtBeginningOfBlock()
Return true if the caret is located at the beginning of the current block |
boolean |
isAtEndOfBlock()
Return true if the caret is located at the end of the current block |
boolean |
isAtEOF()
Return true if the caret is located at the end of the entire buffer |
boolean |
lineFeed()
Move cursor to the beginning of the next line, EVEN if we aren't at an EOL |
static void |
main(java.lang.String[] arg)
context standalone test |
void |
mark()
Set the convenience marker to the current caret position. |
boolean |
matchAndMove(java.lang.String s)
Test if the string at the caret position starts with the given string, and in case of success moves the caret past this string ; return false otherwise. |
boolean |
moveCaretBy(int increment)
Move cursor position forward by the given increment, possibly proceeding to linefeeds. |
boolean |
moveCaretTo(int newPos)
Move cursor position forward to the given position, possibly proceeding to linefeeds. |
boolean |
pushBack()
After a read(), pushes back the char that has been read |
java.lang.Character |
read()
read a character, and increment the caret position by one, if this is possible. |
java.lang.String |
read(int n)
read the given number of character, wrapped in a String, and move the caret past the String being returned. |
java.lang.String |
readTo(int pos)
|
java.lang.String |
readToEOL()
Returns the remaining substring up to the end of the current line, EOL NOT INCLUDED ! Doesn't proceed to any linefeed, i.e. |
static java.lang.String |
removeLineFeeds(java.lang.String s)
Remove '\n' and '\r' from a given string, and return a new string. |
static java.lang.String |
removeRedundantWhiteSpaces(java.lang.String s)
Replace " " (double-space) or tabs by ' ' ; always return a new String. |
void |
reset()
reset caret position to the convenience marker position, or to the beginning of the current block if no marker has been set. |
boolean |
startsWith(java.lang.String s)
Return whether the string at the caret position starts with the given string or not. |
java.lang.String |
toString()
Convert this Object to a human-readable String. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
buffer
private java.lang.String buffer
caret
private int caret
marker
private int marker
beginBlockMarker
private int beginBlockMarker
endBlockMarker
private int endBlockMarker
lineBreaks
private int[] lineBreaks
blockMarkersStack
private java.util.Stack blockMarkersStack
stackLevel
private int stackLevel
Constructor Detail |
Context
public Context(java.io.Reader reader) throws ParserException.EOF
- build a new Context fed by the given reader
Method Detail |
toString
public java.lang.String toString()
- Description copied from class:
java.lang.Object
- Convert this Object to a human-readable String.
There are no limits placed on how long this String
should be or what it should contain. We suggest you
make it as intuitive as possible to be able to place
it into System.out.println() 55
and such.
It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.
This method will be called when performing string concatenation with this object. If the result is
null
, string concatenation will instead use"null"
.The default implementation returns
getClass().getName() + "@" + Integer.toHexString(hashCode())
.
getLineNumber
public int getLineNumber()
getCaretPosition
public int getCaretPosition()
getBOL
public int getBOL()
- Returns the position of the beginning of the current line, or the beginning of the current block
if the caret is located b/w the B.of.Block and the first CR inside the current block.
getEOL
public int getEOL()
- Returns the position of the end of the current line, i.e. the location of the "\n" character,
OR the end of the current block, if the caret is located b/w the E.of.Block and the last CR
inside the block.
isAtEOF
public boolean isAtEOF()
- Return true if the caret is located at the end of the entire buffer
getEOF
public int getEOF()
moveCaretBy
public boolean moveCaretBy(int increment) throws ParserException.EOF
- Move cursor position forward by the given increment, possibly proceeding to linefeeds.
moveCaretTo
public boolean moveCaretTo(int newPos) throws ParserException.EOF
- Move cursor position forward to the given position, possibly proceeding to linefeeds.
In any case, caret CAN'T move out of the current block.
lineFeed
public boolean lineFeed() throws ParserException.EOF
- Move cursor to the beginning of the next line, EVEN if we aren't at an EOL
mark
public void mark()
- Set the convenience marker to the current caret position.
reset
public void reset()
- reset caret position to the convenience marker position, or to the beginning of the
current block if no marker has been set.
There's one convenience marker per block, i.e. marker defaults to beginning-of-block when entering a block.
getBuffer
public java.lang.String getBuffer()
- Return the entire buffer
getCharAt
public java.lang.Character getCharAt(int index)
- Return the character at the given position, or null if index is negative, or past EOF
getCurrentLine
public java.lang.String getCurrentLine()
read
public java.lang.Character read() throws ParserException.EOF
- read a character, and increment the caret position by one, if this is possible.
pushBack
public boolean pushBack() throws ParserException.EOF
- After a read(), pushes back the char that has been read
read
public java.lang.String read(int n) throws ParserException.EOF
- read the given number of character, wrapped in a String, and move the caret past the String
being returned. May return "" if we're inside a block, and end-of-block has been reached.
readToEOL
public java.lang.String readToEOL() throws ParserException.EOF
- Returns the remaining substring up to the end of the current line, EOL NOT INCLUDED !
Doesn't proceed to any linefeed, i.e. simply move the caret to EOL
!!! If we're inside a block, and current EOL is greater than getEndOfBlock(), getEndOfBlock() is taken as the EOL (see getEOL())
readTo
public java.lang.String readTo(int pos) throws ParserException.EOF
matchAndMove
public boolean matchAndMove(java.lang.String s) throws ParserException.EOF
- Test if the string at the caret position starts with the given string, and in case of success
moves the caret past this string ; return false otherwise.
indexOf
public int indexOf(java.lang.String s)
- Return the index of the first occurence of the given String, starting from the current
caret position.
indexOf
public int indexOf(java.lang.String s, int fromIndex)
- Return the index of the first occurence of the given String in the current block,
starting from the given position
indexOfBeforeEOL
public int indexOfBeforeEOL(java.lang.String s)
- Return the index of the first occurence of the given String, starting from the current
caret position, ending at getEndOfBlock() (not included!).
startsWith
public boolean startsWith(java.lang.String s)
- Return whether the string at the caret position starts with the given string or not.
removeLineFeeds
public static java.lang.String removeLineFeeds(java.lang.String s)
- Remove '\n' and '\r' from a given string, and return a new string.
removeRedundantWhiteSpaces
public static java.lang.String removeRedundantWhiteSpaces(java.lang.String s)
- Replace " " (double-space) or tabs by ' ' ; always return a new String.
getMatch
public gnu.regexp.REMatch getMatch(gnu.regexp.RE re)
- match the given RE on the current block, starting at the caret position, then move the caret
past the matched string if found.
getBeginningOfBlock
public int getBeginningOfBlock()
getEndOfBlock
public int getEndOfBlock()
isAtBeginningOfBlock
public boolean isAtBeginningOfBlock()
- Return true if the caret is located at the beginning of the current block
isAtEndOfBlock
public boolean isAtEndOfBlock()
- Return true if the caret is located at the end of the current block
getBlockContent
public java.lang.String getBlockContent()
- Return the content of the current block. Note : this is an expensive operation since
it creates a new String.
enterBlock
public void enterBlock(int blockEnd)
- save current markers in the stack, and set new block borders :
- new endBlockMarker is set to the given position
- new beginBlockMarker is set to the current caret position
- convenience marker is saved, and a new one is initialized to the beginning of the (new) current block.
exitBlock
public void exitBlock()
- restore old markers (and forget current value), then move caret to the end of the block we just went out.
main
public static void main(java.lang.String[] arg)
- context standalone test
|
|||||||||
Home >> All >> jpicedt >> graphic >> io >> [ parser overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: ![]() ![]() ![]() |
DETAIL: FIELD | CONSTR | METHOD |