Пример #1
0
        protected void MemorizeReference(ReferenceExp exp)
        {
            RefParseInfo pi = (RefParseInfo)refParseInfos[exp];

            if (pi == null)
            {
                refParseInfos[exp] = pi = new RefParseInfo();
            }
            pi.MemorizeReference(reader);
        }
Пример #2
0
        protected virtual ReferenceExp Define()
        {
            string combine = GetAttribute("combine");
            string name    = GetAttribute("name");

            if (name == null)
            {
                // error: missing attribute
                ReportError(ERR_MISSING_ATTRIBUTE, reader.Name, "name");
                reader.Skip();
                return(null);
            }
            Expression body = Group();          // parse the body.

            ReferenceExp exp = grammar.GetOrCreate(name);

            CombineReferenceExp(exp, body, combine);
            return(exp);
        }
Пример #3
0
        protected virtual Expression ParentRef()
        {
            string name = GetRequiredAttribute("name");

            EmptyContent();
            if (name == null)
            {
                // error: missing attribute
                return(Expression.NotAllowed);
            }

            if (grammar == null || grammar.Parent == null)
            {
                // error: no-enclosing grammar
                ReportError(ERR_NO_GRAMMAR);
                return(Expression.NotAllowed);
            }
            ReferenceExp exp = grammar.Parent.GetOrCreate(name);

            MemorizeReference(exp);
            return(exp);
        }
Пример #4
0
        protected virtual void CombineReferenceExp(
            ReferenceExp r, Expression body, string combine)
        {
            if (redefiningRefExps.ContainsKey(r))
            {
                // this pattern is currently being redefined.
                redefiningRefExps[r] = true;
                return;         // ignore the value
            }

            RefParseInfo pi = (RefParseInfo)refParseInfos[r];

            if (pi == null)
            {
                refParseInfos[r] = pi = new RefParseInfo();
            }

            if (pi.Combine != null && combine != null && pi.Combine != combine)
            {
                // error: inconsistent combine method
                ReportError(ERR_INCONSISTENT_COMBINE, r.name);
                pi.Combine = null;
                return;
            }
            if (combine == null)
            {
                if (pi.HeadDefined)
                {
                    // error: multiple heads
                    ReportError(ERR_MULTIPLE_HEADS, r.name);
                }
                pi.HeadDefined = true;
                combine        = pi.Combine;
            }
            else
            {
                pi.Combine = combine;
            }

            if (r.exp == null)
            {
                r.exp = body;
            }
            else
            {
                if (combine == "interleave")
                {
                    r.exp = Builder.CreateInterleave(r.exp, body);
                }
                else
                if (combine == "choice")
                {
                    r.exp = Builder.CreateChoice(r.exp, body);
                }
                else
                {
                    // error: invalid combine value
                    ReportError(ERR_INVALID_COMBINE, combine);
                }
            }
        }
 public virtual Expression OnRef(ReferenceExp exp)
 {
     return(exp.exp.Visit(this));
 }
 public void OnRef(ReferenceExp exp)
 {
     exp.exp.Visit(this);
 }