public static UnparseControl Create_NoUnparse(Grammar grammar) { return(new UnparseControl(grammar) { ExpressionToParenthesesHasBeenSet = false }); }
/// <summary> /// Create a multiparser which consists of multiple parsers, each of them can parse a specific nonterminal of the grammar. /// Nonterminals are specified by grammar.SnippetRoots, which may be extended regarding the value of <paramref name="makeParsableEveryNonTerminal"/> /// </summary> /// <param name="grammar"> /// The grammar which will drive the multiparser. /// </param> /// <param name="makeParsableEveryNonTerminal"> /// If true then gather all nonterminals from grammar (going down from root recursively), and add them to SnippetRoots if needed. /// If false then SnippetRoots will not be changed. /// </param> internal MultiParser(Grammar grammar, bool makeParsableEveryNonTerminal = makeParsableEveryNonTerminalDefault) { grammar.SetDecimalSeparatorOnNumberLiterals(); // it works with Irony.Grammar as well, not just with Sarcasm.Grammar // NOTE: grammar.SnippetRoots should be extended before creating LanguageData if (makeParsableEveryNonTerminal) { foreach (NonTerminal nonTerminal in GrammarHelper.GetDescendantBnfTermsExcludingSelf(grammar.Root).OfType <NonTerminal>()) { if (!grammar.SnippetRoots.Contains(nonTerminal)) { grammar.SnippetRoots.Add(nonTerminal); } } } this.grammar = grammar; this.language = new LanguageData(grammar); if (this.language.ErrorLevel >= GrammarErrorLevel.Conflict && grammar.ErrorHandling == ErrorHandling.ThrowException) { GrammarHelper.ThrowGrammarErrorException(this.language.ErrorLevel, string.Join("\n", this.language.Errors)); } this.mainParser = new Parser(language); foreach (NonTerminal nonTerminal in grammar.SnippetRoots) { this.rootToParser.Add(nonTerminal, new Parser(language, nonTerminal)); } }
public static UnparseControl Create(Grammar grammar, Formatter defaultFormatter, params ParenthesizedExpression[] parenthesizedExpressionsForPrecedenceBasedUnparse) { return new UnparseControl(grammar) { ExpressionToParenthesesHasBeenSet = true, DefaultFormatter = defaultFormatter, expressionToParentheses = parenthesizedExpressionsForPrecedenceBasedUnparse.ToDictionary(parenthesizedExpression => parenthesizedExpression.Expression) }; }
public static UnparseControl Create(Grammar grammar, Formatter defaultFormatter, params ParenthesizedExpression[] parenthesizedExpressionsForPrecedenceBasedUnparse) { return(new UnparseControl(grammar) { ExpressionToParenthesesHasBeenSet = true, DefaultFormatter = defaultFormatter, expressionToParentheses = parenthesizedExpressionsForPrecedenceBasedUnparse.ToDictionary(parenthesizedExpression => parenthesizedExpression.Expression) }); }
public static UnparseControl Create(Grammar grammar, params ParenthesizedExpression[] parenthesizedExpressionsForPrecedenceBasedUnparse) { return Create(grammar, new Formatter(grammar), parenthesizedExpressionsForPrecedenceBasedUnparse); }
public static UnparseControl Create_NoUnparse(Grammar grammar) { return new UnparseControl(grammar) { ExpressionToParenthesesHasBeenSet = false }; }
private UnparseControl(Grammar grammar) { this.grammar = grammar; }
public static MultiParser <TMainRoot> Create <TMainRoot>(Grammar <TMainRoot> grammar, bool makeParsableEveryNonTerminal = makeParsableEveryNonTerminalDefault) { return(new MultiParser <TMainRoot>(grammar, makeParsableEveryNonTerminal)); }
public static MultiParser Create(Grammar grammar, bool makeParsableEveryNonTerminal = makeParsableEveryNonTerminalDefault) { return(new MultiParser(grammar, makeParsableEveryNonTerminal)); }
public Formatter(Grammar grammar) : this(grammar.DefaultCulture) { this.attachedParsers = new List<Parser>(); }
public Formatter(Grammar grammar) : this(grammar.DefaultCulture) { this.attachedParsers = new List <Parser>(); }
public static UnparseControl Create(Grammar grammar, params ParenthesizedExpression[] parenthesizedExpressionsForPrecedenceBasedUnparse) { return(Create(grammar, new Formatter(grammar), parenthesizedExpressionsForPrecedenceBasedUnparse)); }