3 using System.Collections.Generic;
11 var symbols = startSymbols.Where(
s => !IsNullOrWhiteSpace(s)).ToArray();
13 if (StartSymbols.Count == 0)
14 StartSymbols.AddRange(_defaultStartSymbols);
15 Priority = Terminal.HighestPriority;
19 private string _startSymbolsFirsts = String.Concat(_defaultStartSymbols);
20 static string[] _defaultStartSymbols =
new[] {
"\\",
"_" };
21 public string LineTerminators =
"\n\r\v";
26 base.Init(grammarData);
29 _startSymbolsFirsts =
new String(StartSymbols.Select(
s =>
s.First()).ToArray());
31 if (this.EditorInfo == null) {
38 var lookAhead = source.PreviewChar;
39 var startIndex = _startSymbolsFirsts.IndexOf(lookAhead);
44 if (!BeginMatch(source, startIndex, lookAhead))
48 var result = CompleteMatch(source);
56 private bool BeginMatch(
ISourceStream source,
int startFrom,
char lookAhead) {
57 foreach (var startSymbol
in StartSymbols.Skip(startFrom)) {
58 if (startSymbol[0] != lookAhead)
61 source.PreviewPosition += startSymbol.Length;
68 private Token CompleteMatch(ISourceStream source) {
74 var lookAhead = source.PreviewChar;
75 if (LineTerminators.IndexOf(lookAhead) >= 0)
77 source.PreviewPosition++;
79 if (!source.EOF() && lookAhead ==
'\r' && source.PreviewChar ==
'\n')
80 source.PreviewPosition++;
85 if (GrammarData.Grammar.WhitespaceChars.IndexOf(lookAhead) >= 0)
87 source.PreviewPosition++;
94 while (!source.EOF());
97 return source.CreateToken(this.OutputTerminal);
106 private static bool IsNullOrWhiteSpace(
string s) {
108 if (
String.IsNullOrEmpty(s))
110 return s.Trim().Length == 0;
112 return String.IsNullOrWhiteSpace(
s);
TokenCategory
Token category.
LineContinuationTerminal(string name, params string[] startSymbols)
override Token TryMatch(ParsingContext context, ISourceStream source)
Interface for Terminals to access the source stream and produce tokens.
readonly bool CaseSensitive
Gets case sensitivity of the grammar. Read-only, true by default. Can be set to false only through a ...
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.
override IList< string > GetFirsts()
static string ErrNewLineExpected
Looks up a localized string similar to NewLine expected..
override void Init(GrammarData grammarData)