예제 #1
0
        public override bool ExpectIt(ref IWordWalker ww, object additionalParam = null)
        {
            var headExpector = new CExactWordExpector("hex(");

            if (!headExpector.ExpectIt(ref ww))
            {
                error = headExpector.error;
                return(false);
            }

            List <string> stringBytes           = new List <string>();
            var           hexDigitExpector      = new CHexDigitExpector();
            var           spaceSkipper          = new CWhiteSpaceSkipper();
            var           closedBracketExpector = new CExactWordExpector(")");

            while (!closedBracketExpector.ExpectItLockable(ref ww))
            {
                spaceSkipper.ExpectIt(ref ww);

                var currentByte = "";

                for (int i = 0; i < 2; i++)
                {
                    if (!hexDigitExpector.ExpectIt(ref ww))
                    {
                        error = hexDigitExpector.error;
                        return(false);
                    }

                    currentByte += hexDigitExpector.result;
                }

                stringBytes.Add(currentByte);
                spaceSkipper.ExpectIt(ref ww);
            }

            var tailExpector = new CExactWordExpector(");");

            if (!tailExpector.ExpectIt(ref ww))
            {
                error = tailExpector.error;
                return(false);
            }

            result = stringBytes.Select(x => Convert.ToByte(x, 16)).ToArray();
            return(true);
        }
예제 #2
0
        public override bool ExpectIt(ref IWordWalker ww, object additionalParam = null)
        {
            List <SingaState> metaSigs = new List <SingaState>();

            var sigExpector         = new CSingleSigExpector();
            var spaceSkipper        = new CWhiteSpaceSkipper();
            var closedBraceExpector = new CExactWordExpector("}");

            while (!closedBraceExpector.ExpectItLockable(ref ww))
            {
                if (!sigExpector.ExpectIt(ref ww))
                {
                    error = sigExpector.error;
                    return(false);
                }

                metaSigs.Add(sigExpector.result);
                spaceSkipper.ExpectIt(ref ww);
            }

            result = metaSigs;
            return(true);
        }
예제 #3
0
        public override bool ExpectIt(ref IWordWalker ww, object additionalParam = null)
        {
            if (additionalParam is null)
            {
                throw new ArgumentNullException();
            }

            result = (SingaRule)additionalParam;

            var metaStringExpector = new CExactWordExpector("meta");

            if (!metaStringExpector.ExpectIt(ref ww))
            {
                error = metaStringExpector.error;
                return(false);
            }

            var spaceSkipper = new CWhiteSpaceSkipper();

            spaceSkipper.ExpectIt(ref ww);

            var openBraceExpector = new CExactWordExpector("{");

            if (!openBraceExpector.ExpectIt(ref ww))
            {
                error = openBraceExpector.error;
                return(false);
            }

            spaceSkipper.ExpectIt(ref ww);

            var metaExpector = new CMetaExpector();

            if (!metaExpector.ExpectIt(ref ww))
            {
                error = metaExpector.error;
                return(false);
            }
            result.meta = metaExpector.result.ToDictionary(x => x.Name, x => (SingaSig)x);

            spaceSkipper.ExpectIt(ref ww);

            var closeBraceExpector = new CExactWordExpector("}");

            if (!closeBraceExpector.ExpectIt(ref ww))
            {
                error = closeBraceExpector.error;
                return(false);
            }

            spaceSkipper.ExpectIt(ref ww);

            var sigsStringExpector = new CExactWordExpector("sigs");

            if (!sigsStringExpector.ExpectIt(ref ww))
            {
                error = sigsStringExpector.error;
                return(false);
            }

            spaceSkipper.ExpectIt(ref ww);

            if (!openBraceExpector.ExpectIt(ref ww))
            {
                error = openBraceExpector.error;
                return(false);
            }

            spaceSkipper.ExpectIt(ref ww);

            var sigsExpector = new CSigsExpector();

            if (!sigsExpector.ExpectIt(ref ww))
            {
                error = sigsExpector.error;
                return(false);
            }
            result.sigs = sigsExpector.result.ToDictionary(x => x.Name, x => x);

            spaceSkipper.ExpectIt(ref ww);

            if (!closeBraceExpector.ExpectIt(ref ww))
            {
                error = closeBraceExpector.error;
                return(false);
            }

            spaceSkipper.ExpectIt(ref ww);

            var condStringExpector = new CExactWordExpector("cond");

            if (!condStringExpector.ExpectIt(ref ww))
            {
                error = condStringExpector.error;
                return(false);
            }

            spaceSkipper.ExpectIt(ref ww);

            if (!openBraceExpector.ExpectIt(ref ww))
            {
                error = openBraceExpector.error;
                return(false);
            }

            spaceSkipper.ExpectIt(ref ww);

            var conditionExpector = new CConditionExpector();

            if (!conditionExpector.ExpectIt(ref ww, result))
            {
                error = conditionExpector.error;
                return(false);
            }
            result.condition = conditionExpector.result;

            spaceSkipper.ExpectIt(ref ww);

            if (!closeBraceExpector.ExpectIt(ref ww))
            {
                error = closeBraceExpector.error;
                return(false);
            }

            return(true);
        }
예제 #4
0
        public override bool ExpectIt(ref IWordWalker ww, object additionalParam = null)
        {
            result = new SingaRule();

            var spaceSkipper = new CWhiteSpaceSkipper();

            spaceSkipper.ExpectIt(ref ww);

            var rExpector = new CExactWordExpector("r");

            if (!rExpector.ExpectIt(ref ww))
            {
                error = rExpector.error;
                return(false);
            }

            spaceSkipper.ExpectIt(ref ww);

            var genericNameExpector = new CNameExpector();

            if (!genericNameExpector.ExpectIt(ref ww))
            {
                error = genericNameExpector.error;
                return(false);
            }
            result.name = genericNameExpector.result.ToString();

            spaceSkipper.ExpectIt(ref ww);

            var openBraceExpector = new CExactWordExpector("{");

            if (!openBraceExpector.ExpectIt(ref ww))
            {
                error = openBraceExpector.error;
                return(false);
            }

            spaceSkipper.ExpectIt(ref ww);

            var ruleExpector = new CRuleExpector();

            if (!ruleExpector.ExpectIt(ref ww, result))
            {
                error = ruleExpector.error;
                return(false);
            }
            result = ruleExpector.result;

            spaceSkipper.ExpectIt(ref ww);

            var closeBraceExpector = new CExactWordExpector("}");

            if (!closeBraceExpector.ExpectIt(ref ww))
            {
                error = closeBraceExpector.error;
                return(false);
            }

            spaceSkipper.ExpectIt(ref ww);

            var eofExpector = new CEOFExpector();

            if (!eofExpector.ExpectIt(ref ww))
            {
                error = closeBraceExpector.error;
                return(false);
            }

            return(true);
        }