Package com.blackrook.rookscript.struct
Class PreprocessorLexer
java.lang.Object
com.blackrook.rookscript.struct.Lexer
com.blackrook.rookscript.struct.PreprocessorLexer
- Direct Known Subclasses:
ScriptLexer
A lexer that scans for specific directives and affects the stream.
#include "file path"- Pushes a file onto the stream stack.#define MACRO ...tokens...- Defines a macro and the string to replace them with. Defines are case-insensitive.#undefine MACRO- Undefines a macro.#ifdef MACRO- Includes the next set of lines (until#endif) if the provided macro is defined.#ifndef MACRO- Includes the next set of lines (until#endif) if the provided macro is NOT defined.#endif- Ends an "if" directive block.#else- Block that is used if an "if" block does not succeed.
- Author:
- Matthew Tropiano
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDefault includer to use when none specified.static interfaceAn interface that allows the user to resolve a resource by path when the PreprocessorLexer parses it.static classThrown on preprocessor error.static interfaceLambda interface that returns a string.Nested classes/interfaces inherited from class com.blackrook.rookscript.struct.Lexer
Lexer.Kernel, Lexer.Parser, Lexer.ReaderStack, Lexer.Token -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PreprocessorLexer.DefaultIncluderThe singular instance for the default includer.static final StringPreprocessor directive - Bang.static final StringPreprocessor directive - Define.static final StringPreprocessor directive - Else.static final StringPreprocessor directive - End If.static final StringPreprocessor directive - If Defined.static final StringPreprocessor directive - If Undefined.static final StringPreprocessor directive - Include.static final StringPreprocessor directive - Undefine.Fields inherited from class com.blackrook.rookscript.struct.Lexer
DEBUG, END_OF_LEXER, END_OF_STREAM, NEWLINE -
Constructor Summary
ConstructorsConstructorDescriptionPreprocessorLexer(Lexer.Kernel kernel, Reader in) Creates a new preprocessor lexer around a reader.PreprocessorLexer(Lexer.Kernel kernel, String in) Creates a new preprocessor lexer around a String, that will be wrapped into a StringReader.PreprocessorLexer(Lexer.Kernel kernel, String name, Reader in) Creates a new preprocessor lexer around a reader.PreprocessorLexer(Lexer.Kernel kernel, String name, String in) Creates a new preprocessor lexer around a String, that will be wrapped into a StringReader. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDefine(String macro, PreprocessorLexer.StringProvider tokenProvider) Adds a define macro to this lexer.voidAdds a define macro to this lexer.protected StringgetInfoLine(String streamName, int lineNumber, String token, String message) Gets the next token.protected voidprotected voidprocessDirectiveLine(String streamName, int lineNumber, String directiveLine) Called when a full directive is read and needs to be processed.protected charreadChar()Reads a character from the stream.voidsetIncluder(PreprocessorLexer.Includer includer) Sets the primary includer to use for resolving included streams.Methods inherited from class com.blackrook.rookscript.struct.Lexer
clearCurrentLexeme, getCurrentLexeme, getCurrentLineNumber, getCurrentStream, getCurrentStreamName, getRawStringEnd, getState, getStringEnd, isCommentEndDelimiterStart, isDelimiterStart, isDigit, isExponent, isExponentSign, isHexDigit, isLetter, isLexerEnd, isNewline, isPoint, isRawStringStart, isSpace, isStreamEnd, isStringEnd, isStringEscape, isStringStart, isTab, isUnderscore, isWhitespace, modifyType, pushStream, saveChar, setDelimBreak, setMultilineStringStartAndEnd, setState, setStringStartAndEnd
-
Field Details
-
DIRECTIVE_BANG
Preprocessor directive - Bang.- See Also:
-
DIRECTIVE_INCLUDE
Preprocessor directive - Include.- See Also:
-
DIRECTIVE_DEFINE
Preprocessor directive - Define.- See Also:
-
DIRECTIVE_UNDEFINE
Preprocessor directive - Undefine.- See Also:
-
DIRECTIVE_IFDEF
Preprocessor directive - If Defined.- See Also:
-
DIRECTIVE_IFNDEF
Preprocessor directive - If Undefined.- See Also:
-
DIRECTIVE_ENDIF
Preprocessor directive - End If.- See Also:
-
DIRECTIVE_ELSE
Preprocessor directive - Else.- See Also:
-
DEFAULT_INCLUDER
The singular instance for the default includer.
-
-
Constructor Details
-
PreprocessorLexer
Creates a new preprocessor lexer around a String, that will be wrapped into a StringReader. This will also assign this lexer a default name.- Parameters:
kernel- the lexer kernel to use for defining how to parse the input text.in- the string to read from.
-
PreprocessorLexer
Creates a new preprocessor lexer around a String, that will be wrapped into a StringReader.- Parameters:
kernel- the lexer kernel to use for defining how to parse the input text.name- the name of this lexer.in- the reader to read from.
-
PreprocessorLexer
Creates a new preprocessor lexer around a reader. This will also assign this lexer a default name.- Parameters:
kernel- the kernel to use for this lexer.in- the reader to read from.
-
PreprocessorLexer
Creates a new preprocessor lexer around a reader.- Parameters:
kernel- the kernel to use for this lexer.name- the name of this lexer.in- the reader to read from.
-
-
Method Details
-
setIncluder
Sets the primary includer to use for resolving included streams.- Parameters:
includer- the includer to use.
-
addDefine
Adds a define macro to this lexer.- Parameters:
macro- the macro identifier.tokenString- the string to push onto the lexer.
-
addDefine
Adds a define macro to this lexer.- Parameters:
macro- the macro identifier.tokenProvider- a string-producing lambda function.
-
nextToken
Description copied from class:LexerGets the next token. If there are no tokens left to read, this will return null. This method is NOT thread-safe!- Overrides:
nextTokenin classLexer- Returns:
- the next token, or null if no more tokens to read.
- Throws:
IOException- if a token cannot be read by the underlying Reader.
-
getInfoLine
-
readChar
Description copied from class:LexerReads a character from the stream.- Overrides:
readCharin classLexer- Returns:
- the character read, or
Lexer.END_OF_LEXERif no more characters, orLexer.END_OF_STREAMif end of current stream. - Throws:
IOException- if a character cannot be read.
-
preprocess
- Throws:
IOException
-
processDirectiveLine
Called when a full directive is read and needs to be processed.- Parameters:
streamName- the stream name.lineNumber- the line number.directiveLine- the directive line to process.
-