GetMethodSignature() public method

Returns Basis if it's a method signature; otherwise constructs a default signature.
public GetMethodSignature ( ) : LNode
return LNode
Beispiel #1
0
        /// <summary>Creates the default method definition wrapped around the body
        /// of the rule, which was generated by the caller. Returns <see cref="Basis"/>
        /// with the specified new method body. If Basis is null, a simple default
        /// method signature is used, e.g. <c>public void R() {...}</c> where R is
        /// the rule name.</summary>
        /// <param name="methodBody">The parsing code that was generated for this rule.</param>
        /// <returns>A method.</returns>
        public virtual LNode CreateRuleMethod(Rule rule, LNodeList methodBody)
        {
            LNode method = rule.GetMethodSignature();
            var   parts  = method.Args.ToWList();

            if (parts[0].IsIdNamed(S.Missing))
            {
                parts[0] = F.Id(rule.Name);
            }
            Debug.Assert(parts.Count == 3);
            if (rule.IsRecognizer)
            {
                methodBody.Add(F.Call(S.Return, F.True));
            }
            parts.Add(F.OnNewLine(F.Braces(methodBody)));
            return(method.WithArgs(parts.ToLNodeList()));
        }
Beispiel #2
0
        /// <summary>See <see cref="IPGCodeGenHelper.CreateTryWrapperForRecognizer"/> for more information.</summary>
        public LNode CreateTryWrapperForRecognizer(Rule rule)
        {
            Debug.Assert(rule.TryWrapperName != null);

            LNode         method = rule.GetMethodSignature();
            LNode         retType = method.Args[0], name = method.Args[1], args = method.Args[2];
            VList <LNode> forwardedArgs = ForwardedArgList(args);

            LNode lookahead = F.Id("lookaheadAmt");

            Debug.Assert(args.Calls(S.AltList));
            args = args.WithArgs(args.Args.Insert(0, F.Var(F.Int32, lookahead)));

            LNode savePosition = ApiType(F.Id(SavePosition));
            LNode @this        = InputSource ?? F.@this;
            LNode body         = F.Braces(
                F.Call(S.UsingStmt, F.Call(S.New, F.Call(savePosition, @this, lookahead)),
                       F.Call(S.Return, F.Call(name, forwardedArgs)))
                );

            return(method.WithArgs(retType, rule.TryWrapperName, args, body));
        }
Beispiel #3
0
		/// <summary>See <see cref="IPGCodeGenHelper.CreateTryWrapperForRecognizer"/> for more information.</summary>
		public LNode CreateTryWrapperForRecognizer(Rule rule)
		{
			Debug.Assert(rule.TryWrapperName != null);

			LNode method = rule.GetMethodSignature();
			LNode retType = method.Args[0], name = method.Args[1], args = method.Args[2];
			RVList<LNode> forwardedArgs = ForwardedArgList(args);
			
			LNode lookahead = F.Id("lookaheadAmt");
			Debug.Assert(args.Calls(S.List));
			args = args.WithArgs(args.Args.Insert(0, F.Var(F.Int32, lookahead)));

			LNode savePosition = ApiType(F.Id(SavePosition));
			LNode @this = InputSource ?? F.@this;
			LNode body = F.Braces(
				F.Call(S.UsingStmt, F.Call(S.New, F.Call(savePosition, @this, lookahead)), 
					F.Call(S.Return, F.Call(name, forwardedArgs)))
			);
			return method.WithArgs(retType, rule.TryWrapperName, args, body);
		}