/// <summary>Parses an LES2-style identifier such as <c>foo</c>, <c>@foo</c>, /// <c>@`foo`</c> or <c>@--punctuation--</c>. /// </summary> /// <param name="source">Text to parse. On return, the range has been /// decreased by the length of the token; this method also stops if this /// range becomes empty.</param> /// <param name="onError">A method to call on error</param> /// <param name="checkForNamedLiteral">This is set to true when the input /// starts with @ but doesn't use backquotes, which could indicate that /// it is an LES named literal such as @false or @null.</param> /// <returns>The parsed version of the identifier.</returns> public static string ParseIdentifier(ref UString source, Action <int, string> onError, out bool checkForNamedLiteral) { checkForNamedLiteral = false; StringBuilder parsed = TempSB(); UString start = source; bool fail; int c = source.PopFirst(out fail); if (c == '@') { // expecting: (BQString | Star(Set("[0-9a-zA-Z_'#~!%^&*-+=|<>/?:.@$]") | IdExtLetter)) c = source.PopFirst(out fail); if (c == '`') { Les3Lexer.UnescapeString(ref source, (char)c, false, onError, parsed); } else { while (SpecialIdSet.Contains(c) || c >= 128 && char.IsLetter((char)c)) { parsed.Append((char)c); c = source.PopFirst(out fail); } checkForNamedLiteral = true; } } else if (IsIdStartChar(c)) { parsed.Append(c); for (;;) { c = source.PopFirst(out fail); if (!IsIdContChar(c)) { break; } parsed.Append((char)c); } } return(parsed.ToString()); }
public static bool UnescapeString(ref UString sourceText, char quoteType, bool isTripleQuoted, Action <int, string> onError, StringBuilder sb, UString indentation = default(UString), bool les3TQIndents = false) => Les3Lexer.UnescapeString(ref sourceText, quoteType, isTripleQuoted, onError, sb, indentation, les3TQIndents);