ch.akuhn.fame.parser
Class Scanner
java.lang.Object
ch.akuhn.fame.parser.Scanner
- All Implemented Interfaces:
- Iterable<Token>, Iterator<Token>
public class Scanner
- extends Object
- implements Iterator<Token>, Iterable<Token>
Breaks input-stream into tokens. Accepts the following grammar
Tokens
OPEN ::= "("
CLOSE ::= ")"
ID ::= "id:"
REF ::= "ref:"
KEYWORD ::= "@" NamePart
NAME ::= NamePart ( "." NamePart )*
STRING ::= ( "'" [ˆ']* "'" )+
BOOLEAN ::= "true" | "false"
UNDEFINED ::= "nil"
NUMBER ::= "-"? Digit+ ( "." Digit+ )? ( "e" ( "-"? Digit+ ))?
Terminals and Intermediates
NamePart ::= Letter ( Letter | Digit )*
Digit ::= [0-9]
Letter ::= [a-zA-Z_]
Whitespace
Whitespace ::= \s+
Comment ::= "\"" [ˆ"]* "\""
In order to provide more user friendly error messages, this implementation
imposed the following constraint upon the sequence of tokens: Name
must be followed by whitespace; String, Undefined,
Boolean, and Number must be followed by Open,
Close or whitespace.
If the input source is in Smalltalk compatibility mode, the grammar is
extended as follows
Unlimited ::= "*"
Keyword ::= ... | Letter+ ":"
Scanner
public Scanner(CharSequence string)
Scanner
public Scanner(InputSource in)
hasNext
public boolean hasNext()
- Specified by:
hasNext in interface Iterator<Token>
iterator
public Iterator<Token> iterator()
- Specified by:
iterator in interface Iterable<Token>
next
public Token next()
- Specified by:
next in interface Iterator<Token>
nextOrEOF
public Token nextOrEOF()
pos
public final Position pos()
remove
public void remove()
- Specified by:
remove in interface Iterator<Token>