コード例 #1
0
 public static UnparseControl Create_NoUnparse(Grammar grammar)
 {
     return(new UnparseControl(grammar)
     {
         ExpressionToParenthesesHasBeenSet = false
     });
 }
コード例 #2
0
        /// <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));
            }
        }
コード例 #3
0
ファイル: UnparseControl.cs プロジェクト: davidnemeti/Sarcasm
 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)
     };
 }
コード例 #4
0
 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)
     });
 }
コード例 #5
0
ファイル: UnparseControl.cs プロジェクト: davidnemeti/Sarcasm
 public static UnparseControl Create(Grammar grammar, params ParenthesizedExpression[] parenthesizedExpressionsForPrecedenceBasedUnparse)
 {
     return Create(grammar, new Formatter(grammar), parenthesizedExpressionsForPrecedenceBasedUnparse);
 }
コード例 #6
0
ファイル: UnparseControl.cs プロジェクト: davidnemeti/Sarcasm
 public static UnparseControl Create_NoUnparse(Grammar grammar)
 {
     return new UnparseControl(grammar) { ExpressionToParenthesesHasBeenSet = false };
 }
コード例 #7
0
ファイル: UnparseControl.cs プロジェクト: davidnemeti/Sarcasm
 private UnparseControl(Grammar grammar)
 {
     this.grammar = grammar;
 }
コード例 #8
0
 public static MultiParser <TMainRoot> Create <TMainRoot>(Grammar <TMainRoot> grammar, bool makeParsableEveryNonTerminal = makeParsableEveryNonTerminalDefault)
 {
     return(new MultiParser <TMainRoot>(grammar, makeParsableEveryNonTerminal));
 }
コード例 #9
0
 public static MultiParser Create(Grammar grammar, bool makeParsableEveryNonTerminal = makeParsableEveryNonTerminalDefault)
 {
     return(new MultiParser(grammar, makeParsableEveryNonTerminal));
 }
コード例 #10
0
ファイル: Formatter.cs プロジェクト: davidnemeti/Sarcasm
 public Formatter(Grammar grammar)
     : this(grammar.DefaultCulture)
 {
     this.attachedParsers = new List<Parser>();
 }
コード例 #11
0
ファイル: Formatter.cs プロジェクト: kevlyons/Sarcasm
 public Formatter(Grammar grammar)
     : this(grammar.DefaultCulture)
 {
     this.attachedParsers = new List <Parser>();
 }
コード例 #12
0
 public static UnparseControl Create(Grammar grammar, params ParenthesizedExpression[] parenthesizedExpressionsForPrecedenceBasedUnparse)
 {
     return(Create(grammar, new Formatter(grammar), parenthesizedExpressionsForPrecedenceBasedUnparse));
 }
コード例 #13
0
 private UnparseControl(Grammar grammar)
 {
     this.grammar = grammar;
 }