|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.quasiliteral.syntax.BaseLexer
Untamed: To be replaced with a lexer based on Antlr.
Abstracts out common elements of lexers usable within the E quasi-parsing framework.
Field Summary | |
protected AstroBuilder |
myBuilder
|
protected char |
myChar
the candidate character, or EOFCHAR for end-of-file. |
protected int |
myContinueCount
Should the next line get extra indentation as a continuation line? |
protected boolean |
myDelayedNextChar
Is there a nextChar() that's been delayed? |
private short |
myEolTok
|
private short |
myEotluTok
|
protected Indenter |
myIndenter
Keeps track of indentation level |
private LineFeeder |
myInput
contains all lines after the current line |
char[] |
myLData
Enabled: the string part, but as an array for speed |
Twine |
myLTwine
Enabled: the current line, or null at end-of-file |
protected boolean |
myNoTabsFlag
Should tabs be rejected as valid whitespace? |
protected int |
myOptStartPos
Where on the current line does the current token start? If the token starts before the current line, or if there is no current token, this is -1. |
protected Twine |
myOptStartText
Accumulates all text of the current token from lines before the current line, or null if no current token or if the current token starts on the current line. |
private boolean |
myPartialFlag
|
protected int |
myPos
position in current line of candidate character |
protected boolean |
myQuasiFlag
Should doubled '@', and '$' in literals be collapsed to singles? |
Fields inherited from interface org.quasiliteral.syntax.LexerFace |
EOFCHAR, EOFTOK |
Fields inherited from interface org.erights.e.elib.serial.PassByProxy |
HONORARY, HONORED_NAMES |
Constructor Summary | |
protected |
BaseLexer(LineFeeder optLineFeeder,
short eolTok,
short eotluTok,
boolean partialFlag,
boolean quasiFlag,
boolean noTabsFlag,
AstroBuilder builder)
|
Method Summary | |
protected int |
charConstant()
Used to eat the encoding of a single character as it would appear inside a quoted character or string constant. |
private int |
charConstantInternal()
Leaves myChar at the last character instead of the next one. |
protected Astro |
charLiteral()
Assumes that myChar is the first single quote. |
protected Astro |
closeBracket()
|
Astro |
composite(short tagCode,
Object data,
SourceSpan optSpan)
Enabled: |
private boolean |
digits(int radix)
If myChar isDigitStart(char, int) in base radix, then eat a
sequence of isDigitPart(char, int) s in base radix. |
protected Astro |
docComment(short tagCode)
Assumes the initial '/**' has already been eaten. |
protected SourceSpan |
endSpan()
|
protected Twine |
endToken()
|
protected abstract Astro |
getNextToken()
|
private boolean |
isDigitPart(char c,
int radix)
Is c either a digit in base
radix or an '_'? |
private boolean |
isDigitStart(char c,
int radix)
Is c a digit in base
radix? |
boolean |
isEndOfFile()
Enabled: |
static boolean |
isJavaIdPart(char c)
Enabled: Like java.lang.Character#isJavaIdentifierPart(char) but
rejects EOFCHAR, which happens to be a '\0', which isJavaIdentifierPart
accepts as an "ignorable control character". |
static boolean |
isJavaIdStart(char c)
Enabled: Like java.lang.Character#isJavaIdentifierStart(char) |
protected boolean |
isRestBlank(int start)
Starting at start, is the rest of the current line "blank"? |
protected boolean |
isWhite(int start,
int bound)
Are all the characters on the current line from start inclusive to bound exclusive whitespace characters? |
protected Astro |
leafEOL()
Output either an EOL or, if we're at top level, an EOTLU |
protected Astro |
leafTag(short tagCode,
SourceSpan optSpan)
|
void |
needMore(String msg)
Enabled: |
protected void |
nextChar()
|
private void |
nextLine()
|
Astro |
nextToken()
Enabled: |
Astro[] |
nextTopLevelUnit()
Enabled: |
protected Astro |
numberLiteral()
Note that E never calls this with a leading minus sign, prefering instead to treat the minus as an operator. |
protected Astro |
openBracket(char closer)
|
protected Astro |
openBracket(short tagCode,
Twine openner,
char closer)
|
protected char |
peekChar()
XXX Get rid of peekChar/0 or make it work |
protected boolean |
peekChar(char c)
Is the next character c? |
void |
reset()
Enabled: |
void |
setSource(Twine newSource)
Enabled: |
protected void |
skipLine()
Skip the rest of this line. |
protected void |
skipWhiteSpace()
Skips whitespace characters
except for newlines. |
protected void |
startToken()
|
protected void |
stopToken()
Cancels a started token |
protected Astro |
stringLiteral()
Assumes that myChar is the first double quote. |
void |
syntaxError(String msg)
Enabled: |
String |
toString()
Suppressed: |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private LineFeeder myInput
public Twine myLTwine
public char[] myLData
protected int myPos
protected char myChar
protected int myOptStartPos
protected Twine myOptStartText
protected boolean myDelayedNextChar
private final short myEolTok
private final short myEotluTok
private final boolean myPartialFlag
protected final boolean myQuasiFlag
protected final boolean myNoTabsFlag
protected Indenter myIndenter
protected int myContinueCount
If not, -1. If so, the number of spaces to indent.
protected final AstroBuilder myBuilder
Constructor Detail |
protected BaseLexer(LineFeeder optLineFeeder, short eolTok, short eotluTok, boolean partialFlag, boolean quasiFlag, boolean noTabsFlag, AstroBuilder builder) throws IOException
optLineFeeder
- eolTok
- "End Of Line"eotluTok
- "End Of Top Level Unit"partialFlag
- quasiFlag
- noTabsFlag
- builder
-
IOException
Method Detail |
public String toString()
toString
in class Object
public void setSource(Twine newSource)
setSource
in interface LexerFace
public void reset()
reset
in interface LexerFace
private void nextLine() throws IOException
IOException
protected void nextChar() throws IOException
IOException
public Astro[] nextTopLevelUnit() throws IOException, SyntaxException
nextTopLevelUnit
in interface LexerFace
IOException
SyntaxException
public Astro nextToken() throws IOException, SyntaxException
nextToken
in interface LexerFace
IOException
SyntaxException
public void syntaxError(String msg) throws SyntaxException
syntaxError
in interface LexerFace
SyntaxException
public void needMore(String msg) throws NeedMoreException, SyntaxException
needMore
in interface LexerFace
NeedMoreException
SyntaxException
private boolean isDigitStart(char c, int radix)
digit
in base
radix?
private boolean isDigitPart(char c, int radix)
digit
in base
radix or an '_'?
private boolean digits(int radix) throws IOException
isDigitStart(char, int)
in base radix, then eat a
sequence of isDigitPart(char, int)
s in base radix.
<digits(n)> ::= <digitStart(n)
> <digitPart(n)
>*
IOException
protected void skipWhiteSpace() throws IOException
whitespace
characters
except for newlines.
IOException
protected boolean isWhite(int start, int bound)
protected boolean isRestBlank(int start)
This just defaults to isWhite(start,myLData.length), but should be overridden by subclasses to also consider the remainder of a line blank if the only thing it contains is a rest-of-line comment (such as a "#" or "//" comment in E).
public static boolean isJavaIdStart(char c)
java.lang.Character#isJavaIdentifierStart(char)
public static boolean isJavaIdPart(char c)
java.lang.Character#isJavaIdentifierPart(char)
but
rejects EOFCHAR, which happens to be a '\0', which isJavaIdentifierPart
accepts as an "ignorable control character".
protected Astro leafTag(short tagCode, SourceSpan optSpan)
protected Astro leafEOL()
public Astro composite(short tagCode, Object data, SourceSpan optSpan)
composite
in interface LexerFace
protected abstract Astro getNextToken() throws IOException, SyntaxException
IOException
SyntaxException
protected Astro openBracket(char closer) throws IOException
IOException
protected Astro openBracket(short tagCode, Twine openner, char closer)
protected Astro closeBracket() throws IOException
IOException
private int charConstantInternal() throws IOException, SyntaxException
IOException
SyntaxException
protected int charConstant() throws IOException, SyntaxException
Backslash escapes are interpreted according to the Java standard, except that escaped character codes are not yet implemented.
If we're quasi-parsing, then any literal '$' or '@' characters must appear doubled, in which case a single such character will be included in the literal.
IOException
SyntaxException
protected Astro charLiteral() throws IOException, SyntaxException
<charLiteral> ::= "'" <charConstant()
> "'"
IOException
SyntaxException
protected Astro stringLiteral() throws IOException, SyntaxException
<stringLiteral> ::= '"' <charConstant()
>* '"'
IOException
SyntaxException
protected Astro docComment(short tagCode) throws IOException, SyntaxException
The docComment syntax is as documented in the Java Language Specification.
IOException
SyntaxException
protected Astro numberLiteral() throws IOException, SyntaxException
<numberLiteral> ::= "-"? "0x" <A floating point number must have at least a "." or a ("e"|"E"). A leading "0" on a floating point number doesn't affect the base. A leading "0" on an integer means octal (base 8).digits(16)
> | "-"? "0" <digitPart(8)
>* | "-"? <digits(10)
> ("." <digits(10)
>)? (("e"|"E") "-"? <digits(10)
>)?
IOException
SyntaxException
protected char peekChar()
protected boolean peekChar(char c)
protected void skipLine()
protected void startToken()
protected void stopToken()
protected Twine endToken()
protected SourceSpan endSpan()
public boolean isEndOfFile()
isEndOfFile
in interface LexerFace
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |