Exemplo n.º 1
0
        public IRuleRef <TNode> Create <TNode>(IGrammarBuilder <TNode> grammar)
        {
            _grammarBuilderAdapter = new GrammarBuilderAdapter(rule => grammar.DefineRule(rule.Name, rule), name => grammar.Ref(name));

            ArgAssert.NotNull(nameof(Factory), Factory);
            var rule    = Factory(this);
            var ruleRef = grammar.DefineRule(rule.Name, rule);

            _grammarBuilderAdapter = null;

            if (RefName != null)
            {
                ruleRef.As(RefName);
            }

            return(ruleRef);
        }
Exemplo n.º 2
0
 private void DefineReferencedRulesAsDummies(IGrammarBuilder <INode> grammar, ProtoRule rule, HashSet <string> defined)
 {
     foreach (var child in rule.Children)
     {
         if (child.DisplayText == "Ref" && child.RuleName != null && !defined.Contains(child.RuleName))
         {
             defined.Add(child.RuleName);
             grammar.DefineRule(child.RuleName, new MockRule(child.RuleName));
         }
         DefineReferencedRulesAsDummies(grammar, child, defined);
     }
 }
 public static IRuleRef <TNode> Not <TNode>(this IGrammarBuilder <TNode> grammar, string?name, IRuleRef target)
 {
     return(grammar.DefineRule(name, new Not(name, target)));
 }
 public static IRuleRef <TNode> Any <TNode>(this IGrammarBuilder <TNode> grammar, string?name)
 {
     return(grammar.DefineRule(name, new AnyTerminal(name)));
 }
 public static IRuleRef <TNode> Optional <TNode>(this IGrammarBuilder <TNode> grammar, string?name, IRuleRef rule)
 {
     return(grammar.DefineRule(name, new Repeat(name, rule, 0, 1)));
 }
 public static IRuleRef <TNode> OneOrMore <TNode>(this IGrammarBuilder <TNode> grammar, string?name, IRuleRef rule)
 {
     return(grammar.DefineRule(name, new Repeat(name, rule, 1, -1)));
 }
 public static IRuleRef <TNode> Repeat <TNode>(this IGrammarBuilder <TNode> grammar, string?name, IRuleRef rule, int min = 0, int max = -1)
 {
     return(grammar.DefineRule(name, new Repeat(name, rule, min, max)));
 }
 public static IRuleRef <TNode> Choice <TNode>(this IGrammarBuilder <TNode> grammar, string?name, IEnumerable <IRuleRef> rules)
 {
     return(grammar.DefineRule(name, new Choice(name, rules)));
 }
 public static IRuleRef <TNode> Choice <TNode>(this IGrammarBuilder <TNode> grammar, string?name, params IRuleRef[] rules)
 {
     return(grammar.DefineRule(name, new Choice(name, rules)));
 }
 public static IRuleRef <TNode> TerminalValue <TNode>(this IGrammarBuilder <TNode> grammar, string value, string?name = null)
 {
     return(grammar.DefineRule(name, new Terminal(name, new TokenValueMatcher(value))));
 }
 public static IRuleRef <TNode> TerminalType <TNode>(this IGrammarBuilder <TNode> grammar, string tokenType, string?name = null)
 {
     return(grammar.DefineRule(name, new Terminal(name, tokenType)));
 }
 public static IRuleRef <TNode> Terminal <TNode, TEnum>(this IGrammarBuilder <TNode> grammar, TEnum tokenType, string?name = null)
     where TEnum : System.Enum
 {
     return(grammar.DefineRule(name, new Terminal(name, tokenType.ToString())));
 }
 public static IRuleRef <TNode> Terminal <TNode>(this IGrammarBuilder <TNode> grammar, ITokenMatcher matcher, string?name = null)
 {
     return(grammar.DefineRule(name, new Terminal(name, matcher)));
 }