Beispiel #1
0
        public virtual LNode CallRule(RuleRef rref, bool recognizerMode)
        {
            Rule target  = rref.Rule;
            var  @params = rref.Params;

            if (recognizerMode)
            {
                target = target.GetOrMakeRecognizerVersion();

                // Allow recognizers to take fewer arguments than the normal rule
                // by truncating argument(s) at the call site.
                int maxArgCount = target.Basis.CallsMin(S.Fn, 3) ? target.Basis.Args[2].ArgCount : 0;
                if (@params.Count > maxArgCount)
                {
                    @params = @params.Initial(maxArgCount);
                }
            }
            LNode call = F.Call(target.Name, @params);

            if (recognizerMode)
            {
                return(F.Call(S.If, F.Call(S.Not, call), F.Call(S.Return, F.@false)));
            }
            else
            {
                return(rref.AutoSaveResult(call));
            }
        }
Beispiel #2
0
        public virtual LNode CallTryRecognizer(RuleRef rref, int lookahead)
        {
            Rule target = rref.Rule;

            target = target.GetOrMakeRecognizerVersion();
            LNode name    = target.TryWrapperName;
            var   @params = rref.Params;

            return(F.Call(name, @params.Insert(0, F.Literal(lookahead))));
        }