Parsing System (v0.6)
|
class Lexer
module goldie.lexer
The tokens that resulted from the last lexing.
The lexical errors encountered during the last lexing.
string source
The original source that was last lexed.
uint[] lineIndicies
Indicies into source where each line starts. For example, lineIndicies[0] is the index where the first line starts (always 0), lineIndicies[1] is the index where the second line starts, etc. See the example in lineAtIndex below. uint lineAtIndex(uint index)
Returns the line number (zero-indexed) of a given index into the source that was lexed. As per Goldie conventions, this value should be increased by one whenever it's displayed to the user. Example: string src = "ABC DEF HIJ"; auto lexerUsed = someLanguage.lexCodeX(src); auto numLines = lexerUsed.lineIndicies.length; // Get everything from start of second line, to start of third line auto secondLine = src[ lexerUsed.lineIndicies[1] .. lexerUsed.lineIndicies[2] ] writeln("Number of lines: ", numLines); writeln("Second line: ", secondLine); writefln("src[9] is '%s' and is on line #%s", src[9], 1 + lexerUsed.lineAtIndex(9)); // Output: // Number of lines: 3 // Second line: DEF // // src[9] is 'I' and is on line #3 string filename
The filename (if available) of the last source lexed. uint srcIndex
uint line Internal lexer state. Access is provided to these for diagnostic purposes. If an exception is thrown during lexing, then these can be inspected to check the lexer's internal state at the time of the exception. This is probably only useful for debugging Goldie. Lexes (ie, tokenizes) a source. Throws a LexException if the source contains an error. Normally, you would use one of the Language.parse or Language.lex functions instead of calling this directly, but this direct access is provided in case you'd rather re-use the same lexer instead of instantiating a new one every time. The filename from which the source originated can be provided so error messages can report the appropriate filename. module {user-specified package}.lexer
{languageName} = Name of static-style language
This is the static-style counterpart to Lexer, and is generated by the StaticLang tool. If the name of a language is, for example, foo, then the name of this class will be Lexer_foo. The interface is the same as Lexer. |