Lexer for EC# source code.
- See also
- ILexer<Token>, TokensToTree
|
| Les2Lexer (UString text, IMessageSink errorSink) |
|
| Les2Lexer (ICharSource text, string fileName, IMessageSink sink, int startPosition=0) |
|
override void | Reset (ICharSource source, string fileName="", int inputPosition=0, bool newSourceFile=true) |
|
Les2Lexer | Clone () |
|
override Maybe< Token > | NextToken () |
| Scans the next token and returns information about it. More...
|
|
bool | TDQStringLine () |
|
bool | TSQStringLine () |
|
bool | MLCommentLine (ref int nested) |
|
override void | Reset (CharSrc source, string fileName="", int inputPosition=0, bool newSourceFile=true) |
| Reinitializes the object. This method is called by the constructor. More...
|
|
ILineColumnFile | IndexToLine (int index) |
| Returns the position in a source file of the specified index. More...
|
|
T | Clone () |
|
|
static string | UnescapeQuotedString (ref UString sourceText, Action< int, string > onError, UString indentation=default(UString), bool les3TQIndents=false) |
| Parses a normal or triple-quoted string that still includes the quotes. Supports quote types '\'', '"' and '`'. More...
|
|
static void | UnescapeQuotedString (ref UString sourceText, Action< int, string > onError, StringBuilder sb, UString indentation=default(UString), bool les3TQIndents=false) |
| Parses a normal or triple-quoted string that still includes the quotes (see documentation of the first overload) into a StringBuilder. More...
|
|
static bool | UnescapeString (ref UString sourceText, char quoteType, bool isTripleQuoted, Action< int, string > onError, StringBuilder sb, UString indentation=default(UString), bool les3TQIndents=false) |
| Parses a normal or triple-quoted string whose starting quotes have been stripped out. If triple-quote parsing was requested, stops parsing at three quote marks; otherwise, stops parsing at a single end-quote or newline. More...
|
|
static string | ParseIdentifier (ref UString source, Action< int, string > onError, out bool checkForNamedLiteral) |
| Parses an LES-style identifier such as foo , @foo , <tt>foo or –punctuation– . More...
|
|
static object | ParseNumberCore (UString source, bool isNegative, int numberBase, bool isFloat, Symbol typeSuffix, out string error) |
| Parses the digits of a literal (integer or floating-point), not including the radix prefix (0x, 0b) or type suffix (F, D, L, etc.) More...
|
|
|
override void | Error (int lookaheadIndex, string message, params object[] args) |
|
UString | Text () |
|
sealed override void | AfterNewline () |
|
override bool | SupportDotIndents () |
| The LES and EC# languages support "dot indents", which are lines that start with a dot (.) followed by a tab or spaces. If you overload this method to return true, then AfterNewline() and Reset will count dot indents as part of the indentation at the beginning of each line; otherwise, only spaces and tabs will be counted. More...
|
|
object | ParseSQStringValue () |
|
Symbol | ParseBQStringValue () |
|
object | ParseStringValue (bool isTripleQuoted, bool les3TQIndents=false) |
|
string | ParseStringCore (bool isTripleQuoted, bool les3TQindents=false) |
|
object | ParseIdValue (bool isFancy) |
|
object | ParseSymbolValue (bool lesv3=false) |
|
Symbol | IdToSymbol (UString ustr) |
|
object | ParseNumberValue (int numberEndPosition) |
|
object | ParseNormalOp () |
|
| BaseILexer (CharSrc charSrc, string fileName="", int inputPosition=0) |
|
override void | AfterNewline () |
| The lexer must call this method exactly once after it advances past each newline, even inside comments and strings. This method keeps the BaseLexer<C>.LineNumber, BaseLexer<C>.LineStartAt, IndentString and IndentLevel properties updated. More...
|
|
void | AfterNewline (bool ignoreIndent, bool skipIndent) |
|
void | ScanIndent (bool skipSpaces=true) |
| Scans indentation at the beginning of a line and updates the IndentLevel and IndentString properties. This function is called automatically by AfterNewline(), but should be called manually on the very first line of the file. More...
|
|
override bool Loyc.Syntax.Les.Les2Lexer.SupportDotIndents |
( |
| ) |
|
|
inlineprotectedvirtual |
The LES and EC# languages support "dot indents", which are lines that start with a dot (.) followed by a tab or spaces. If you overload this method to return true, then AfterNewline() and Reset will count dot indents as part of the indentation at the beginning of each line; otherwise, only spaces and tabs will be counted.
A dot indent has the syntax ('.' ('\t' | ' '+))*
. This indentation style is recognized only if a dot is the first character on a line. Each pair of dot+(tab/spaces) prior to the first non-space token is counted the same way as a tab character (\t). Dot indents are useful for posting source code on "bad" blog software or forums that do not preseve indentation.
Reimplemented from Loyc.Syntax.Lexing.BaseILexer< ICharSource, Token >.
static string Loyc.Syntax.Les.Les2Lexer.UnescapeQuotedString |
( |
ref UString |
sourceText, |
|
|
Action< int, string > |
onError, |
|
|
UString |
indentation = default(UString) , |
|
|
bool |
les3TQIndents = false |
|
) |
| |
|
inlinestatic |
Parses a normal or triple-quoted string that still includes the quotes. Supports quote types '\'', '"' and '`'.
- Parameters
-
sourceText | input text |
onError | Called in case of parsing error (unknown escape sequence or missing end quotes) |
indentation | Inside a triple-quoted string, any text following a newline is ignored as long as it matches this string. For example, if the text following a newline is "\t\t Foo" and this string is "\t\t\t", the tabs are ignored and " Foo" is kept. |
les3TQIndents | Enable EC# triple-quoted string indent rules, which allow an additional one tab or three spaces of indent. (I'm leaning toward also supporting this in LES; switched on in v3) |
- Returns
- The decoded string
This method recognizes LES and EC#-style string syntax. Firstly, it recognizes triple-quoted strings (''' """ ```). These strings enjoy special newline handling: the newline is always interpreted as
regardless of the actual kind of newline (\r and \r
newlines come out as
), and indentation following the newline can be stripped out. Triple-quoted strings can have escape sequences that use both kinds of slash, like so:
/ \r/ \'/ "/ \0/
. However, there are no unicode escapes (\u1234/ is NOT supported).
Secondly, it recognizes normal strings (' " `). These strings stop parsing (with an error) at a newline, and can contain C-style escape sequences:
\r \' " \0
etc. C#-style verbatim strings are NOT supported.
static bool Loyc.Syntax.Les.Les2Lexer.UnescapeString |
( |
ref UString |
sourceText, |
|
|
char |
quoteType, |
|
|
bool |
isTripleQuoted, |
|
|
Action< int, string > |
onError, |
|
|
StringBuilder |
sb, |
|
|
UString |
indentation = default(UString) , |
|
|
bool |
les3TQIndents = false |
|
) |
| |
|
inlinestatic |