Ejemplo n.º 1
0
 public Signature(String name, Access access, IParseFunction func, Boolean isMemoized)
 {
     this.Name       = name;
     this.Access     = access;
     this.Func       = func;
     this.IsMemoized = isMemoized;
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
            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);
            }
Ejemplo n.º 5
0
 private void AddInvoker(IParseFunction target, Invoker invoker)
 {
     this.invokers[target] = invoker;
 }
Ejemplo n.º 6
0
 public SequenceStep(IParseFunction parseFunction, MatchAction matchAction)
 {
     this.Function    = parseFunction;
     this.MatchAction = matchAction;
 }
Ejemplo n.º 7
0
 public Series(IParseFunction repeatedToken, IParseFunction delimiterToken, InterfaceMethod interfaceMethod)
 {
     this.RepeatedToken   = repeatedToken;
     this.DelimiterToken  = delimiterToken;
     this.InterfaceMethod = interfaceMethod;
 }
Ejemplo n.º 8
0
 public Repetition(IParseFunction innerParseFunction, Cardinality cardinality, InterfaceMethod interfaceMethod)
 {
     this.InnerParseFunction = innerParseFunction;
     this.Cardinality        = cardinality;
     this.InterfaceMethod    = interfaceMethod;
 }
Ejemplo n.º 9
0
 public SelectionStep(IParseFunction parseFunction, InterfaceMethod interfaceMethod)
 {
     this.Function        = parseFunction;
     this.InterfaceMethod = interfaceMethod;
 }
Ejemplo n.º 10
0
 public static Rule WithParseFunction(this Rule rule, IParseFunction func) => new Rule(rule.RuleIdentifier, rule.ReturnType, func);
Ejemplo n.º 11
0
 public Rule(String ruleIdentifier, INodeType returnType, IParseFunction parseFunction)
 {
     this.RuleIdentifier = ruleIdentifier;
     this.ReturnType     = returnType;
     this.ParseFunction  = parseFunction;
 }