Beispiel #1
0
        void CheckIsComplexIdentifier(bool?result, LNode expr)
        {
            _testNum++;
            var isCI = EcsValidators.IsComplexIdentifier(expr, ICI.Default, EcsValidators.Pedantics.Strict);

            if (result == null && !isCI)
            {
                return;
            }
            else if (result == isCI)
            {
                return;
            }

            Assert.Fail(string.Format(
                            "IsComplexIdentifier: fail on test #{0} '{1}'. Expected {2}, got {3}",
                            _testNum, expr.ToString(), result, isCI));
        }
Beispiel #2
0
        void CheckIsComplexIdentifier(bool?result, LNode expr)
        {
            var np = new EcsNodePrinter(expr, null);

            _testNum++;
            var isCI = EcsValidators.IsComplexIdentifier(expr);

            if (result == null && !isCI)
            {
                return;
            }
            else if (result == isCI)
            {
                return;
            }

            Assert.Fail(string.Format(
                            "IsComplexIdentifier: fail on test #{0} '{1}'. Expected {2}, got {3}",
                            _testNum, expr.ToString(), result, isCI));
        }
Beispiel #3
0
        public static LNode rule(LNode node, IMacroContext context)
        {
            bool isToken;

            if ((isToken = node.Calls(_token, 2)) || node.Calls(_rule, 2))
            {
                node = context.PreProcessChildren();
                LNode sig = node.Args[0];
                // Ugh. Because the rule has been macro-processed, "rule X::Y ..."
                // has become "rule #var(Y,X) ...". We must allow this, because in
                // case of something like "rule X(arg::int)::Y" we actually do want
                // the argument to become `#var(int, arg)`; so just reverse the
                // transform that we didn't want.
                if (sig.Calls(S.Var, 2))
                {
                    sig = F.Call(S.ColonColon, sig.Args[1], sig.Args[0]);
                }

                LNode name = sig, returnType = F.Void;
                if (sig.Calls(S.ColonColon, 2))
                {
                    returnType = sig.Args[1];
                    name       = sig.Args[0];
                }
                if (EcsValidators.IsComplexIdentifier(name))
                {
                    name = F.Call(name);                     // def requires an argument list
                }
                LNodeList args = name.Args;
                name = name.Target;

                LNode newBody = ParseRuleBody(node.Args[1], context);
                if (newBody != null)
                {
                    return(node.With(isToken ? _hash_token : _hash_rule,
                                     returnType, name, F.AltList(args), newBody));
                }
            }
            return(null);
        }