14 using System.Collections.Generic;
35 private char[] _stopChars;
40 Terminators.UnionWith(terminators);
41 base.SetFlag(TermFlags.IsLiteral);
46 result.AddRange(Firsts);
50 base.Init(grammarData);
52 foreach (var key
in Escapes.Keys)
53 stopChars.Add(key[0]);
54 foreach (var t
in Terminators)
56 _stopChars = stopChars.ToArray();
60 string tokenText = string.Empty;
63 var newPos = source.Text.IndexOfAny(_stopChars, source.PreviewPosition);
66 source.PreviewPosition = source.Text.Length;
67 return source.CreateToken(this.OutputTerminal);
71 tokenText += source.Text.Substring(source.PreviewPosition, newPos - source.PreviewPosition);
72 source.PreviewPosition = newPos;
74 if (CheckEscape(source, ref tokenText))
77 if (CheckTerminators(source, ref tokenText))
80 return source.CreateToken(this.OutputTerminal, tokenText);
83 private bool CheckEscape(
ISourceStream source, ref
string tokenText) {
84 foreach (var dictEntry
in Escapes) {
86 source.PreviewPosition += dictEntry.Key.Length;
87 tokenText += dictEntry.Value;
94 private bool CheckTerminators(ISourceStream source, ref
string tokenText) {
95 foreach(var term
in Terminators)
96 if(source.MatchSymbol(term, !Grammar.CaseSensitive)) {
100 source.PreviewPosition += term.
Length;
FreeTextOptions FreeTextOptions
Interface for Terminals to access the source stream and produce tokens.
override void Init(GrammarData grammarData)
Flags
Enumeration of the new Assimp's flags.
readonly bool CaseSensitive
Gets case sensitivity of the grammar. Read-only, true by default. Can be set to false only through a ...
override Token TryMatch(ParsingContext context, ISourceStream source)
FreeTextLiteral(string name, params string[] terminators)
override IList< string > GetFirsts()
FreeTextLiteral(string name, FreeTextOptions freeTextOptions, params string[] terminators)
Tokens are produced by scanner and fed to parser, optionally passing through Token filters in between...
bool MatchSymbol(string symbol, bool ignoreCase)
Tries to match the symbol with the text at current preview position.
int Length
Gets the length.