java.lang.Object
com.maroontress.clione.impl.DefaultLexicalParser
- All Implemented Interfaces:
LexicalParser
,AutoCloseable
The default implementation of
LexicalParser
.-
Constructor Summary
ConstructorDescriptionDefaultLexicalParser
(Reader reader) Creates a new instance.DefaultLexicalParser
(Reader reader, Collection<String> reservedWords) Creates a new instance. -
Method Summary
-
Constructor Details
-
DefaultLexicalParser
Creates a new instance.The instance considers
Keywords.C11
as reserved words.- Parameters:
reader
- The reader that provides the stream of the source file.
-
DefaultLexicalParser
Creates a new instance.- Parameters:
reader
- The reader that provides the stream of the source file.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:
close
in interfaceAutoCloseable
- Specified by:
close
in 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:
getEof
in 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:
getLocation
in interfaceLexicalParser
- Returns:
- The current location.
-
next
Returns the next token.- Specified by:
next
in interfaceLexicalParser
- Returns:
- The next token. Or
Optional.empty()
if this parser reaches EOF. - Throws:
IOException
- If an I/O error occurs.
-