static string UnescapeQuotedString(ref UString source, bool isVerbatim, Action <int, string> onError, UString indentation) { Debug.Assert(source.Length >= 1); if (isVerbatim) { bool fail; char stringType = (char)source.PopFirst(out fail); StringBuilder sb = new StringBuilder(); int c; for (;;) { c = source.PopFirst(out fail); if (fail) { break; } if (c == stringType) { if ((c = source.PopFirst(out fail)) != stringType) { break; } } sb.Append((char)c); } return(sb.ToString()); } else { // triple-quoted or normal string: let LES lexer handle it return(Les2Lexer.UnescapeQuotedString(ref source, onError, indentation, true)); } }
void ParseNumberValue() { int start = _startPosition; if (_numberBase != 10) { start += 2; } int stop = InputPosition; if (_typeSuffix != null) { stop -= _typeSuffix.Name.Length; } UString digits = CharSource.Slice(start, stop - start); string error; if ((_value = Les2Lexer.ParseNumberCore(digits, false, _numberBase, _isFloat, _typeSuffix, out error)) == null) { _value = 0; } else if (_value == CodeSymbols.Sub) { InputPosition = _startPosition + 1; _type = TT.Sub; } if (error != null) { Error(_startPosition - InputPosition, error); } }
List <Token> Lex(string input, bool skipWS = true) { var lexer = new Les2Lexer(input, TraceMessageSink.Value); var lexer2 = new TokensToTree(lexer, skipWS); var list = new List <Token>(); Maybe <Token> token; while ((token = lexer2.NextToken()).HasValue) { list.Add(token.Value); } return(list); }