Example #1
0
        public static IParser Integer(
            bool allowLeadingZero = false,
            bool allowNegative    = true,
            string name           = "Integer")
        {
            var parser = allowLeadingZero
                ? ParserBuilder.OneOrMore(ParserBuilder.Class("0-9"))
                : ParserBuilder.Choice(
                ParserBuilder.T("0"),
                ParserBuilder.Sequence(
                    ParserBuilder.Class("1-9"),
                    ParserBuilder.ZeroOrMore(ParserBuilder.Class("0-9"))
                    )
                );

            if (allowNegative)
            {
                parser = ParserBuilder.Sequence(
                    ParserBuilder.Optional(ParserBuilder.T("-")),
                    parser
                    );
            }

            return(AddName(parser, name));
        }
Example #2
0
        public static IParser Identifier(
            string name = "Identifier")
        {
            var parser = ParserBuilder.Sequence(
                ParserBuilder.Choice(
                    ParserBuilder.T('_'),
                    ParserBuilder.Letter
                    ),
                ParserBuilder.ZeroOrMore(ParserBuilder.Choice(
                                             ParserBuilder.T('_'),
                                             ParserBuilder.LetterOrDigit
                                             ))
                );

            return(AddName(parser, name));
        }