Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Grammar.cs
Go to the documentation of this file.
1 #region License
2 /* **********************************************************************************
3  * Copyright (c) Roman Ivantsov
4  * This source code is subject to terms and conditions of the MIT License
5  * for Irony. A copy of the license can be found in the License.txt file
6  * at the root of this distribution.
7  * By using this source code in any fashion, you are agreeing to be bound by the terms of the
8  * MIT License.
9  * You must not remove this notice from this software.
10  * **********************************************************************************/
11 #endregion
12 
13 using System;
14 using System.Collections.Generic;
15 using System.Globalization;
16 using System.Text;
17 
18 namespace Irony.Parsing {
19 
20  public partial class Grammar {
21 
22  #region properties
23  /// <summary>
24  /// Gets case sensitivity of the grammar. Read-only, true by default.
25  /// Can be set to false only through a parameter to grammar constructor.
26  /// </summary>
27  public readonly bool CaseSensitive = true;
28  public readonly StringComparer LanguageStringComparer;
29 
30  //List of chars that unambigously identify the start of new token.
31  //used in scanner error recovery, and in quick parse path in NumberLiterals, Identifiers
32  public string Delimiters = null;
33 
34  public string WhitespaceChars = " \t\r\n\v";
35 
36  //Used for line counting in source file
37  public string LineTerminators = "\n\r\v";
38 
39  #region Language Flags
40  public LanguageFlags LanguageFlags = LanguageFlags.Default;
41 
42  public bool FlagIsSet(LanguageFlags flag) {
43  return (LanguageFlags & flag) != 0;
44  }
45 
46  public TermReportGroupList TermReportGroups = new TermReportGroupList();
47  #endregion
48 
49  //Terminals not present in grammar expressions and not reachable from the Root
50  // (Comment terminal is usually one of them)
51  // Tokens produced by these terminals will be ignored by parser input.
52  public readonly TerminalSet NonGrammarTerminals = new TerminalSet();
53 
54  //Terminals that either don't have explicitly declared Firsts symbols, or can start with chars not covered by these Firsts
55  // For ex., identifier in c# can start with a Unicode char in one of several Unicode classes, not necessarily latin letter.
56  // Whenever terminals with explicit Firsts() cannot produce a token, the Scanner would call terminals from this fallback
57  // collection to see if they can produce it.
58  // Note that IdentifierTerminal automatically add itself to this collection if its StartCharCategories list is not empty,
59  // so programmer does not need to do this explicitly
60  public readonly TerminalSet FallbackTerminals = new TerminalSet();
61 
62  public Type DefaultNodeType;
63 
64 
65  /// <summary>
66  /// The main root entry for the grammar.
67  /// </summary>
68  public NonTerminal Root;
69 
70  public Func<Scanner> ScannerBuilder;
71 
72  /// <summary>
73  /// Alternative roots for parsing code snippets.
74  /// </summary>
75  public NonTerminalSet SnippetRoots = new NonTerminalSet();
76 
77  public string GrammarComments; //shown in Grammar info tab
78 
79  public CultureInfo DefaultCulture = CultureInfo.InvariantCulture;
80 
81  //Console-related properties, initialized in grammar constructor
82  public string ConsoleTitle;
83  public string ConsoleGreeting;
84  public string ConsolePrompt; //default prompt
85  public string ConsolePromptMoreInput; //prompt to show when more input is expected
86 
87  #endregion
88 
89  #region constructors
90 
92  {
93  return new LanguageData(this);
94  }
95 
96  public Grammar() : this(true) { } //case sensitive by default
97 
98  public Grammar(bool caseSensitive) {
99  _currentGrammar = this;
100  this.CaseSensitive = caseSensitive;
101  bool ignoreCase = !this.CaseSensitive;
102  LanguageStringComparer = StringComparer.Create(System.Globalization.CultureInfo.InvariantCulture, ignoreCase);
103  KeyTerms = new KeyTermTable(LanguageStringComparer);
104  //Initialize console attributes
105  ConsoleTitle = Resources.MsgDefaultConsoleTitle;
106  ConsoleGreeting = string.Format(Resources.MsgDefaultConsoleGreeting, this.GetType().Name);
107  ConsolePrompt = ">";
108  ConsolePromptMoreInput = ".";
109  }
110  #endregion
111 
112  #region Reserved words handling
113  //Reserved words handling
114  public void MarkReservedWords(params string[] reservedWords) {
115  foreach (var word in reservedWords) {
116  var wdTerm = ToTerm(word);
117  wdTerm.SetFlag(TermFlags.IsReservedWord);
118  }
119  }
120  #endregion
121 
122  #region Register/Mark methods
123  public void RegisterOperators(int precedence, params string[] opSymbols) {
124  RegisterOperators(precedence, Associativity.Left, opSymbols);
125  }
126 
127  public void RegisterOperators(int precedence, Associativity associativity, params string[] opSymbols) {
128  foreach (string op in opSymbols) {
129  KeyTerm opSymbol = ToTerm(op);
130  opSymbol.SetFlag(TermFlags.IsOperator);
131  opSymbol.Precedence = precedence;
132  opSymbol.Associativity = associativity;
133  }
134  }//method
135 
136  public void RegisterOperators(int precedence, params BnfTerm[] opTerms) {
137  RegisterOperators(precedence, Associativity.Left, opTerms);
138  }
139  public void RegisterOperators(int precedence, Associativity associativity, params BnfTerm[] opTerms) {
140  foreach (var term in opTerms) {
141  term.SetFlag(TermFlags.IsOperator);
142  term.Precedence = precedence;
143  term.Associativity = associativity;
144  }
145  }
146 
147  public void RegisterBracePair(string openBrace, string closeBrace) {
148  KeyTerm openS = ToTerm(openBrace);
149  KeyTerm closeS = ToTerm(closeBrace);
150  openS.SetFlag(TermFlags.IsOpenBrace);
151  openS.IsPairFor = closeS;
152  closeS.SetFlag(TermFlags.IsCloseBrace);
153  closeS.IsPairFor = openS;
154  }
155 
156  public void MarkPunctuation(params string[] symbols) {
157  foreach (string symbol in symbols) {
158  KeyTerm term = ToTerm(symbol);
159  term.SetFlag(TermFlags.IsPunctuation|TermFlags.NoAstNode);
160  }
161  }
162 
163  public void MarkPunctuation(params BnfTerm[] terms) {
164  foreach (BnfTerm term in terms)
165  term.SetFlag(TermFlags.IsPunctuation|TermFlags.NoAstNode);
166  }
167 
168 
169  public void MarkTransient(params NonTerminal[] nonTerminals) {
170  foreach (NonTerminal nt in nonTerminals)
171  nt.Flags |= TermFlags.IsTransient | TermFlags.NoAstNode;
172  }
173  //MemberSelect are symbols invoking member list dropdowns in editor; for ex: . (dot), ::
174  public void MarkMemberSelect(params string[] symbols) {
175  foreach (var symbol in symbols)
176  ToTerm(symbol).SetFlag(TermFlags.IsMemberSelect);
177  }
178  //Sets IsNotReported flag on terminals. As a result the terminal wouldn't appear in expected terminal list
179  // in syntax error messages
180  public void MarkNotReported(params BnfTerm[] terms) {
181  foreach (var term in terms)
182  term.SetFlag(TermFlags.IsNotReported);
183  }
184  public void MarkNotReported(params string[] symbols) {
185  foreach (var symbol in symbols)
186  ToTerm(symbol).SetFlag(TermFlags.IsNotReported);
187  }
188 
189  #endregion
190 
191  #region virtual methods: TryMatch, CreateNode, CreateRuntime, RunSample
192  public virtual void CreateTokenFilters(LanguageData language, TokenFilterList filters) {
193  }
194 
195  //This method is called if Scanner fails to produce a token; it offers custom method a chance to produce the token
196  public virtual Token TryMatch(ParsingContext context, ISourceStream source) {
197  return null;
198  }
199 
200  //Gives a way to customize parse tree nodes captions in the tree view.
201  public virtual string GetParseNodeCaption(ParseTreeNode node) {
202  if (node.IsError)
203  return node.Term.Name + " (Syntax error)";
204  if (node.Token != null)
205  return node.Token.ToString();
206  if(node.Term == null) //special case for initial node pushed into the stack at parser start
207  return (node.State != null ? string.Empty : "(State " + node.State.Name + ")"); // Resources.LabelInitialState;
208  var ntTerm = node.Term as NonTerminal;
209  if(ntTerm != null && !string.IsNullOrEmpty(ntTerm.NodeCaptionTemplate))
210  return ntTerm.GetNodeCaption(node);
211  return node.Term.Name;
212  }
213 
214  //Gives a chance of custom AST node creation at Grammar level
215  // by default calls Term's method
216  public virtual void CreateAstNode(ParsingContext context, ParseTreeNode nodeInfo) {
217  nodeInfo.Term.CreateAstNode(context, nodeInfo);
218  }
219 
220  /// <summary>
221  /// Override this method to help scanner select a terminal to create token when there are more than one candidates
222  /// for an input char. Context.CurrentTerminals contains candidate terminals; leave a single terminal in this list
223  /// as the one to use.
224  /// </summary>
225  public virtual void OnScannerSelectTerminal(ParsingContext context) { }
226 
227  /// <summary>
228  /// Override this method to provide custom conflict resolution; for example, custom code may decide proper shift or reduce
229  /// action based on preview of tokens ahead.
230  /// </summary>
231  public virtual void OnResolvingConflict(ConflictResolutionArgs args) {
232  //args.Result is Shift by default
233  }
234 
235  //The method is called after GrammarData is constructed
236  public virtual void OnGrammarDataConstructed(LanguageData language) {
237  }
238 
239  public virtual void OnLanguageDataConstructed(LanguageData language) {
240  }
241 
242 
243  //Constructs the error message in situation when parser has no available action for current input.
244  // override this method if you want to change this message
245  public virtual string ConstructParserErrorMessage(ParsingContext context, StringSet expectedTerms) {
246  return string.Format(Resources.ErrParserUnexpInput, expectedTerms.ToString(" "));
247  }
248 
249  // Override this method to perform custom error processing
250  public virtual void ReportParseError(ParsingContext context) {
251  string error = null;
252  if (context.CurrentParserInput.Term == this.SyntaxError)
253  error = context.CurrentParserInput.Token.Value as string; //scanner error
254  else if (context.CurrentParserInput.Term == this.Indent)
255  error = Resources.ErrUnexpIndent;
256  else if (context.CurrentParserInput.Term == this.Eof && context.OpenBraces.Count > 0) {
257  //report unclosed braces/parenthesis
258  var openBrace = context.OpenBraces.Peek();
259  error = string.Format(Resources.ErrNoClosingBrace, openBrace.Text);
260  } else {
261  var expectedTerms = context.GetExpectedTermSet();
262  if (expectedTerms.Count > 0)
263  error = ConstructParserErrorMessage(context, expectedTerms);
264  //error = string.Format(Resources.ErrParserUnexpInput, expectedTerms.ToString(" ")
265  else
266  error = Resources.ErrUnexpEof;
267  }
268  context.AddParserError(error);
269  }//method
270 
271  #endregion
272 
273  #region MakePlusRule, MakeStarRule methods
274  public static BnfExpression MakePlusRule(NonTerminal listNonTerminal, BnfTerm listMember) {
275  return MakePlusRule(listNonTerminal, null, listMember);
276  }
277 
278  public static BnfExpression MakePlusRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember, TermListOptions options) {
279  bool allowTrailingDelimiter = (options & TermListOptions.AllowTrailingDelimiter) != 0;
280  if (delimiter == null || !allowTrailingDelimiter)
281  return MakePlusRule(listNonTerminal, delimiter, listMember);
282  //create plus list
283  var plusList = new NonTerminal(listMember.Name + "+");
284  plusList.Rule = MakePlusRule(listNonTerminal, delimiter, listMember);
285  listNonTerminal.Rule = plusList | plusList + delimiter;
286  listNonTerminal.SetFlag(TermFlags.IsListContainer);
287  return listNonTerminal.Rule;
288  }
289 
290  public static BnfExpression MakePlusRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember) {
291  if (delimiter == null)
292  listNonTerminal.Rule = listMember | listNonTerminal + listMember;
293  else
294  listNonTerminal.Rule = listMember | listNonTerminal + delimiter + listMember;
295  listNonTerminal.SetFlag(TermFlags.IsList);
296  return listNonTerminal.Rule;
297  }
298 
299  public static BnfExpression MakeStarRule(NonTerminal listNonTerminal, BnfTerm listMember) {
300  return MakeStarRule(listNonTerminal, null, listMember, TermListOptions.None);
301  }
302 
303  public static BnfExpression MakeStarRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember) {
304  return MakeStarRule(listNonTerminal, delimiter, listMember, TermListOptions.None);
305  }
306 
307  public static BnfExpression MakeStarRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember, TermListOptions options) {
308  bool allowTrailingDelimiter = (options & TermListOptions.AllowTrailingDelimiter) != 0;
309  if (delimiter == null) {
310  //it is much simpler case
311  listNonTerminal.SetFlag(TermFlags.IsList);
312  listNonTerminal.Rule = _currentGrammar.Empty | listNonTerminal + listMember;
313  return listNonTerminal.Rule;
314  }
315  //Note that deceptively simple version of the star-rule
316  // Elem* -> Empty | Elem | Elem* + delim + Elem
317  // does not work when you have delimiters. This simple version allows lists starting with delimiters -
318  // which is wrong. The correct formula is to first define "Elem+"-list, and then define "Elem*" list
319  // as "Elem* -> Empty|Elem+"
320  NonTerminal plusList = new NonTerminal(listMember.Name + "+");
321  plusList.Rule = MakePlusRule(plusList, delimiter, listMember);
322  plusList.SetFlag(TermFlags.NoAstNode); //to allow it to have AstNodeType not assigned
323  if (allowTrailingDelimiter)
324  listNonTerminal.Rule = _currentGrammar.Empty | plusList | plusList + delimiter;
325  else
326  listNonTerminal.Rule = _currentGrammar.Empty | plusList;
327  listNonTerminal.SetFlag(TermFlags.IsListContainer);
328  return listNonTerminal.Rule;
329  }
330  #endregion
331 
332  #region Hint utilities
334  return new GrammarHint(HintType.ResolveToShift, null);
335  }
336  protected GrammarHint ReduceHere() {
337  return new GrammarHint(HintType.ResolveToReduce, null);
338  }
340  return new GrammarHint(HintType.ResolveInCode, null);
341  }
342  protected TokenPreviewHint ReduceIf(string symbol) {
343  return new TokenPreviewHint(ParserActionType.Reduce, symbol);
344  }
345  protected TokenPreviewHint ShiftIf(string symbol) {
346  return new TokenPreviewHint(ParserActionType.Shift, symbol);
347  }
348  protected GrammarHint ImplyPrecedenceHere(int precedence) {
349  return ImplyPrecedenceHere(precedence, Associativity.Left);
350  }
351  protected GrammarHint ImplyPrecedenceHere(int precedence, Associativity associativity) {
352  var hint = new GrammarHint(HintType.Precedence, null);
353  hint.Precedence = precedence;
354  hint.Associativity = associativity;
355  return hint;
356  }
357 
358  #endregion
359 
360  #region Term report group methods
361  /// <summary>
362  /// Creates a terminal reporting group, so all terminals in the group will be reported as a single "alias" in syntex error messages like
363  /// "Syntax error, expected: [list of terms]"
364  /// </summary>
365  /// <param name="alias">An alias for all terminals in the group.</param>
366  /// <param name="symbols">Symbols to be included into the group.</param>
367  protected void AddTermsReportGroup(string alias, params string[] symbols) {
368  TermReportGroups.Add(new TermReportGroup(alias, TermReportGroupType.Normal, SymbolsToTerms(symbols)));
369  }
370  /// <summary>
371  /// Creates a terminal reporting group, so all terminals in the group will be reported as a single "alias" in syntex error messages like
372  /// "Syntax error, expected: [list of terms]"
373  /// </summary>
374  /// <param name="alias">An alias for all terminals in the group.</param>
375  /// <param name="terminals">Terminals to be included into the group.</param>
376  protected void AddTermsReportGroup(string alias, params Terminal[] terminals) {
377  TermReportGroups.Add(new TermReportGroup(alias, TermReportGroupType.Normal, terminals));
378  }
379  /// <summary>
380  /// Adds symbols to a group with no-report type, so symbols will not be shown in expected lists in syntax error messages.
381  /// </summary>
382  /// <param name="symbols">Symbols to exclude.</param>
383  protected void AddToNoReportGroup(params string[] symbols) {
384  TermReportGroups.Add(new TermReportGroup(string.Empty, TermReportGroupType.Normal, SymbolsToTerms(symbols)));
385  }
386  /// <summary>
387  /// Adds symbols to a group with no-report type, so symbols will not be shown in expected lists in syntax error messages.
388  /// </summary>
389  /// <param name="symbols">Symbols to exclude.</param>
390  protected void AddToNoReportGroup(params Terminal[] terminals) {
391  TermReportGroups.Add(new TermReportGroup(string.Empty, TermReportGroupType.Normal, terminals));
392  }
393  /// <summary>
394  /// Adds a group and an alias for all operator symbols used in the grammar.
395  /// </summary>
396  /// <param name="alias">An alias for operator symbols.</param>
397  protected void AddOperatorReportGroup(string alias) {
398  TermReportGroups.Add(new TermReportGroup(alias, TermReportGroupType.Operator, null)); //operators will be filled later
399  }
400 
401  private IEnumerable<Terminal> SymbolsToTerms(IEnumerable<string> symbols) {
402  var termList = new TerminalList();
403  foreach(var symbol in symbols)
404  termList.Add(ToTerm(symbol));
405  return termList;
406  }
407  #endregion
408 
409  #region Standard terminals: EOF, Empty, NewLine, Indent, Dedent
410  // Empty object is used to identify optional element:
411  // term.Rule = term1 | Empty;
412  public readonly Terminal Empty = new Terminal("EMPTY");
413  // The following terminals are used in indent-sensitive languages like Python;
414  // they are not produced by scanner but are produced by CodeOutlineFilter after scanning
415  public readonly Terminal NewLine = new Terminal("LF");
416  public readonly Terminal Indent = new Terminal("INDENT", TokenCategory.Outline, TermFlags.IsNonScanner);
417  public readonly Terminal Dedent = new Terminal("DEDENT", TokenCategory.Outline, TermFlags.IsNonScanner);
418  //End-of-Statement terminal - used in indentation-sensitive language to signal end-of-statement;
419  // it is not always synced with CRLF chars, and CodeOutlineFilter carefully produces Eos tokens
420  // (as well as Indent and Dedent) based on line/col information in incoming content tokens.
421  public readonly Terminal Eos = new Terminal("EOS", Resources.LabelEosLabel, TokenCategory.Outline, TermFlags.IsNonScanner);
422  // Identifies end of file
423  // Note: using Eof in grammar rules is optional. Parser automatically adds this symbol
424  // as a lookahead to Root non-terminal
425  public readonly Terminal Eof = new Terminal("EOF", TokenCategory.Outline);
426 
427  //Used for error tokens
428  public readonly Terminal LineStartTerminal = new Terminal("LINE_START", TokenCategory.Outline);
429 
430  //Used for error tokens
431  public readonly Terminal SyntaxError = new Terminal("SYNTAX_ERROR", TokenCategory.Error, TermFlags.IsNonScanner);
432 
433  public NonTerminal NewLinePlus {
434  get {
435  if(_newLinePlus == null) {
436  _newLinePlus = new NonTerminal("LF+");
437  MarkPunctuation(_newLinePlus);
438  _newLinePlus.Rule = MakePlusRule(_newLinePlus, NewLine);
439  }
440  return _newLinePlus;
441  }
442  } NonTerminal _newLinePlus;
443 
444  public NonTerminal NewLineStar {
445  get {
446  if(_newLineStar == null) {
447  _newLineStar = new NonTerminal("LF*");
448  MarkPunctuation(_newLineStar);
449  _newLineStar.Rule = MakeStarRule(_newLineStar, NewLine);
450  }
451  return _newLineStar;
452  }
453  } NonTerminal _newLineStar;
454 
455  #endregion
456 
457  #region KeyTerms (keywords + special symbols)
459 
460  public KeyTerm ToTerm(string text) {
461  return ToTerm(text, text);
462  }
463  public KeyTerm ToTerm(string text, string name) {
464  KeyTerm term;
465  if (KeyTerms.TryGetValue(text, out term)) {
466  //update name if it was specified now and not before
467  if (string.IsNullOrEmpty(term.Name) && !string.IsNullOrEmpty(name))
468  term.Name = name;
469  return term;
470  }
471  //create new term
472  if (!CaseSensitive)
473  text = text.ToLower();
474  string.Intern(text);
475  term = new KeyTerm(text, name);
476  KeyTerms[text] = term;
477  return term;
478  }
479 
480  #endregion
481 
482  #region CurrentGrammar static field
483  //Static per-thread instance; Grammar constructor sets it to self (this).
484  // This field/property is used by operator overloads (which are static) to access Grammar's predefined terminals like Empty,
485  // and SymbolTerms dictionary to convert string literals to symbol terminals and add them to the SymbolTerms dictionary
486  [ThreadStatic]
487  private static Grammar _currentGrammar;
488  public static Grammar CurrentGrammar {
489  get { return _currentGrammar; }
490  }
491  internal static void ClearCurrentGrammar() {
492  _currentGrammar = null;
493  }
494  #endregion
495 
496  }//class
497 
498 }//namespace
TokenCategory
Token category.
Definition: Token.cs:29
virtual void CreateTokenFilters(LanguageData language, TokenFilterList filters)
Definition: Grammar.cs:192
string ConsolePromptMoreInput
Definition: Grammar.cs:85
void AddTermsReportGroup(string alias, params string[] symbols)
Creates a terminal reporting group, so all terminals in the group will be reported as a single "alias...
Definition: Grammar.cs:367
virtual LanguageData CreateLanguageData()
Definition: Grammar.cs:91
void MarkPunctuation(params string[] symbols)
Definition: Grammar.cs:156
static BnfExpression MakeStarRule(NonTerminal listNonTerminal, BnfTerm listMember)
Definition: Grammar.cs:299
virtual Token TryMatch(ParsingContext context, ISourceStream source)
Definition: Grammar.cs:196
bool FlagIsSet(LanguageFlags flag)
Definition: Grammar.cs:42
KeyTerm ToTerm(string text)
Definition: Grammar.cs:460
virtual void OnLanguageDataConstructed(LanguageData language)
Definition: Grammar.cs:239
virtual void OnGrammarDataConstructed(LanguageData language)
Definition: Grammar.cs:236
A strongly-typed resource class, for looking up localized strings, etc.
void MarkNotReported(params BnfTerm[] terms)
Definition: Grammar.cs:180
void AddOperatorReportGroup(string alias)
Adds a group and an alias for all operator symbols used in the grammar.
Definition: Grammar.cs:397
virtual void ReportParseError(ParsingContext context)
Definition: Grammar.cs:250
string ConsolePrompt
Definition: Grammar.cs:84
static string ErrUnexpEof
Looks up a localized string similar to Unexpected end of file..
virtual void OnScannerSelectTerminal(ParsingContext context)
Override this method to help scanner select a terminal to create token when there are more than one c...
Definition: Grammar.cs:225
GrammarHint PreferShiftHere()
Definition: Grammar.cs:333
void MarkTransient(params NonTerminal[] nonTerminals)
Definition: Grammar.cs:169
KeyTermTable KeyTerms
Definition: Grammar.cs:458
static BnfExpression MakeStarRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember, TermListOptions options)
Definition: Grammar.cs:307
TokenPreviewHint ReduceIf(string symbol)
Definition: Grammar.cs:342
GrammarHint ReduceHere()
Definition: Grammar.cs:336
static string ErrUnexpIndent
Looks up a localized string similar to Unexpected indentation..
void RegisterOperators(int precedence, Associativity associativity, params string[] opSymbols)
Definition: Grammar.cs:127
Interface for Terminals to access the source stream and produce tokens.
KeyTerm ToTerm(string text, string name)
Definition: Grammar.cs:463
static string LabelEosLabel
Looks up a localized string similar to [end-of-statement].
readonly string Name
Definition: ParserData.cs:39
static BnfExpression MakePlusRule(NonTerminal listNonTerminal, BnfTerm listMember)
Definition: Grammar.cs:274
The class provides arguments for custom conflict resolution grammar method.
Definition: ParserData.cs:178
static string MsgDefaultConsoleGreeting
Looks up a localized string similar to {0} Console. Ctrl-C to exit the program. . ...
void MarkMemberSelect(params string[] symbols)
Definition: Grammar.cs:174
void AddToNoReportGroup(params string[] symbols)
Adds symbols to a group with no-report type, so symbols will not be shown in expected lists in syntax...
Definition: Grammar.cs:383
virtual void CreateAstNode(ParsingContext context, ParseTreeNode nodeInfo)
Definition: Grammar.cs:216
void RegisterOperators(int precedence, params string[] opSymbols)
Definition: Grammar.cs:123
readonly StringComparer LanguageStringComparer
Definition: Grammar.cs:28
Describes a language.
Definition: LanguageData.cs:23
string GrammarComments
Definition: Grammar.cs:77
TokenPreviewHint ShiftIf(string symbol)
Definition: Grammar.cs:345
GrammarHint ResolveInCode()
Definition: Grammar.cs:339
static BnfExpression MakePlusRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember)
Definition: Grammar.cs:290
void MarkNotReported(params string[] symbols)
Definition: Grammar.cs:184
Func< Scanner > ScannerBuilder
Definition: Grammar.cs:70
void AddToNoReportGroup(params Terminal[] terminals)
Adds symbols to a group with no-report type, so symbols will not be shown in expected lists in syntax...
Definition: Grammar.cs:390
virtual string ConstructParserErrorMessage(ParsingContext context, StringSet expectedTerms)
Definition: Grammar.cs:245
static string MsgDefaultConsoleTitle
Looks up a localized string similar to Console.
readonly TokenStack OpenBraces
string GetNodeCaption(ParseTreeNode node)
Definition: NonTerminal.cs:123
void MarkReservedWords(params string[] reservedWords)
Definition: Grammar.cs:114
void RegisterOperators(int precedence, Associativity associativity, params BnfTerm[] opTerms)
Definition: Grammar.cs:139
NonTerminal Root
The main root entry for the grammar.
Definition: Grammar.cs:68
static BnfExpression MakeStarRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember)
Definition: Grammar.cs:303
static string ErrParserUnexpInput
Looks up a localized string similar to Syntax error, expected: {0}.
virtual void OnResolvingConflict(ConflictResolutionArgs args)
Override this method to provide custom conflict resolution; for example, custom code may decide prope...
Definition: Grammar.cs:231
void MarkPunctuation(params BnfTerm[] terms)
Definition: Grammar.cs:163
Tokens are produced by scanner and fed to parser, optionally passing through Token filters in between...
Definition: Token.cs:74
virtual string GetParseNodeCaption(ParseTreeNode node)
Definition: Grammar.cs:201
static string ErrNoClosingBrace
Looks up a localized string similar to No closing pair for opening symbol {0}.
GrammarHint ImplyPrecedenceHere(int precedence)
Definition: Grammar.cs:348
void RegisterOperators(int precedence, params BnfTerm[] opTerms)
Definition: Grammar.cs:136
string ConsoleGreeting
Definition: Grammar.cs:83
void RegisterBracePair(string openBrace, string closeBrace)
Definition: Grammar.cs:147
GrammarHint ImplyPrecedenceHere(int precedence, Associativity associativity)
Definition: Grammar.cs:351
Grammar(bool caseSensitive)
Definition: Grammar.cs:98
static BnfExpression MakePlusRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember, TermListOptions options)
Definition: Grammar.cs:278
void AddTermsReportGroup(string alias, params Terminal[] terminals)
Creates a terminal reporting group, so all terminals in the group will be reported as a single "alias...
Definition: Grammar.cs:376