java.lang.Object
com.maroontress.clione.impl.DefaultLexicalParser
- All Implemented Interfaces:
LexicalParser,AutoCloseable
The default implementation of
LexicalParser.-
Constructor Summary
ConstructorsConstructorDescriptionDefaultLexicalParser(Reader reader, String filename, Collection<String> reservedWords) Creates a new instance. -
Method Summary
-
Constructor Details
-
DefaultLexicalParser
Creates a new instance.- Parameters:
reader- The reader that provides the stream of the source file.filename- The filename.reservedWords- The collection that contains reserved keywords. Note that the constructor copies the collection, so changes to the collection do not affect this instance.
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceLexicalParser- Throws:
IOException
-
getEof
Returns the character representing EOF.Note that there is no need for this method in most cases. If you want to detect when the line concatenation (a backslash followed by a newline character) is immediately followed by EOF, you can do so as follows:
void parse(LexicalParser parser) { for (;;) { var maybeToken = parser.next(); if (maybeToken.isEmpty()) { var maybeEof = parser.getEof(); assert(maybeEof.isPresent()); var eof = maybeEof.get(); assert(eof.isEof()); var list = eof.getChildren(); if (list.size() > 0) { var m = "backslash-newline at end of file"; System.err.println(eof.getSpan() + ": warning: " + m); } break; } ... } }- Specified by:
getEofin interfaceLexicalParser- Returns:
- The character representing EOF. Or
Optional.empty()if this parser has not yet reached EOF. - Throws:
IOException- If an I/O error occurs.
-
getLocation
Returns the current location of the source file.- Specified by:
getLocationin interfaceLexicalParser- Returns:
- The current location.
-
getFilename
Returns the filename.- Specified by:
getFilenamein interfaceLexicalParser- Returns:
- The filename. Or
nullif no filename is specified.
-
next
Returns the next token.- Specified by:
nextin interfaceLexicalParser- Returns:
- The next token. Or
Optional.empty()if this parser reaches EOF. - Throws:
IOException- If an I/O error occurs.
-
getReservedWords
Returns the unmodifiableSetcontaining the reserved words that this parser uses.- Specified by:
getReservedWordsin interfaceLexicalParser- Returns:
- The unmodifiable
Setcontaining the reserved words.
-