Loyc.LLParserGenerator.Rule.GetMethodSignature C# (CSharp) Method

GetMethodSignature() public method

Returns Basis if it's a method signature; otherwise constructs a default signature.
public GetMethodSignature ( ) : LNode
return LNode
		public LNode GetMethodSignature()
		{
			if (Basis != null && Basis.Calls(S.Fn) && Basis.ArgCount.IsInRange(3, 4)) {
				var parts = Basis.Args;
				if (parts.Count == 4)
					parts.RemoveAt(3);
				if (IsRecognizer)
					parts[0] = F.Bool;
				parts[1] = F.Id(Name);
				// remove OneLiner style to avoid suppresing newlines in output for one-line rules
				return Basis.WithArgs(parts).SetStyle(Basis.Style & ~NodeStyle.OneLiner);
			} else {
				var method = F.Fn(IsRecognizer ? F.Bool : F.Void, F.Id(Name), F.List());
				if (IsPrivate == true)
					method = F.Attr(F.Id(S.Private), method);
				else if (IsStartingRule | IsToken)
					method = F.Attr(F.Id(S.Public), method);
				return method;
			}
		}

Usage Example

Ejemplo n.º 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()));
        }
All Usage Examples Of Loyc.LLParserGenerator.Rule::GetMethodSignature