예제 #1
0
 public Signature(String name, Access access, IParseFunction func, Boolean isMemoized)
 {
     this.Name       = name;
     this.Access     = access;
     this.Func       = func;
     this.IsMemoized = isMemoized;
 }
예제 #2
0
        private static Invoker CreateStatelessInvoker(String baseName) => (i, p, s, f) => $"{baseName}({i}, {p})";         // Invocation

        private Boolean AddSignature(IParseFunction target, Access access, Boolean requiresGeneration)
        {
            if (requiresGeneration || this.mustAddSignature)
            {
                this.signatures.Add(new Signature(baseName, access, target, isMemoized));
                return(true);
            }

            return(false);
        }
예제 #3
0
        private void BasicTargetWithInterfaceMethod(IParseFunction target, InterfaceMethod interfaceMethod, Signature signature)
        {
            var resultName = "r";
            var nodeName   = $"{resultName}.Node";
            var invoker    = this.invokers[target];

            writer.VarAssign(resultName, invoker("input", "inputPosition", "states", "factory"));             // Invocation
            writer.IfNullReturnNull(resultName);

            var decl = new Decl(target.ReturnType, nodeName);

            var returnExpression = GetReturnExpression(target.ReturnType, new[] { decl }, $"{resultName}.Advanced", "factory", interfaceMethod);

            if (signature.IsMemoized)
            {
                var memField = NameGen.MemoizedFieldName(signature.Name);
                returnExpression = $"states[inputPosition].{memField} = {returnExpression}";
            }
            writer.Return(returnExpression);
        }
            public (IParseFunction, IReadOnlyList <InterfaceMethod>) Visit(Selection target, INodeType input)
            {
                var interfaceMethods = new List <InterfaceMethod>();
                var newSteps         = new List <SelectionStep>();

                foreach (var step in target.Steps)
                {
                    IParseFunction func           = step.Function;
                    INodeType      funcReturnType = func.ReturnType;

                    InterfaceMethod interfaceMethod = null;
                    if (input != EmptyNodeType.Instance)
                    {
                        var name = $"{interfaceMethodName}{++count}";
                        interfaceMethod = new InterfaceMethod(input, name, GetParameterTypesFromReturnType(funcReturnType));
                        interfaceMethods.Add(interfaceMethod);
                    }

                    var newStep = new SelectionStep(func, interfaceMethod);
                    newSteps.Add(newStep);
                }

                return(new Selection(newSteps), interfaceMethods);
            }
예제 #5
0
 private void AddInvoker(IParseFunction target, Invoker invoker)
 {
     this.invokers[target] = invoker;
 }
예제 #6
0
 public SequenceStep(IParseFunction parseFunction, MatchAction matchAction)
 {
     this.Function    = parseFunction;
     this.MatchAction = matchAction;
 }
예제 #7
0
 public Series(IParseFunction repeatedToken, IParseFunction delimiterToken, InterfaceMethod interfaceMethod)
 {
     this.RepeatedToken   = repeatedToken;
     this.DelimiterToken  = delimiterToken;
     this.InterfaceMethod = interfaceMethod;
 }
예제 #8
0
 public Repetition(IParseFunction innerParseFunction, Cardinality cardinality, InterfaceMethod interfaceMethod)
 {
     this.InnerParseFunction = innerParseFunction;
     this.Cardinality        = cardinality;
     this.InterfaceMethod    = interfaceMethod;
 }
예제 #9
0
 public SelectionStep(IParseFunction parseFunction, InterfaceMethod interfaceMethod)
 {
     this.Function        = parseFunction;
     this.InterfaceMethod = interfaceMethod;
 }
예제 #10
0
 public static Rule WithParseFunction(this Rule rule, IParseFunction func) => new Rule(rule.RuleIdentifier, rule.ReturnType, func);
예제 #11
0
 public Rule(String ruleIdentifier, INodeType returnType, IParseFunction parseFunction)
 {
     this.RuleIdentifier = ruleIdentifier;
     this.ReturnType     = returnType;
     this.ParseFunction  = parseFunction;
 }