🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Parsing baby steps.

Published July 07, 2007
Advertisement
Just a few additions so far, as I've been busy:

Simple parsers for EOF, a variable character, a variable string literal.
And a slightly more complex parser designed to vary upon type and parse out a token which can be deserialized into the type.

As such a slightly more complex example:
        enum Animal {            Cow,            sheep,            dog        }        // SNIP!            ParseTo IntoAnimal = ParseTo.CommonEnum();            Parser AnimalParser = (IntoAnimal + Whitespace.Common.ZeroOrMore).OneOrMore;            IndexTree AnimalRslt = AnimalParser.Parse("Cow 2 dog DOGdog");            foreach (string s in AnimalRslt.ViewTree("Cow 2 dog DOGdog")) {                Console.WriteLine(s);            }            foreach (IndexTree ParsedAnimal in AnimalRslt.Select(IntoAnimal)) {                Console.WriteLine("Animal!:  {0}", IntoAnimal.ParseToObj("Cow 2 dog DOGdog".Substring(ParsedAnimal.Start, ParsedAnimal.Length)));            }


and the output:

rms.Support.Parsing.Series  0:10 - Cow 2 dog  rms.Support.Parsing.Sequence  0:4 - Cow    rms.Support.Parsing.ParseTo`1[ParserTest.Program+Animal]  0:3 - Cow      rms.Support.Parsing.Series  0:3 - Cow        rms.Support.Parsing.DifferenceParser  0:1 - C        rms.Support.Parsing.DifferenceParser  1:2 - o        rms.Support.Parsing.DifferenceParser  2:3 - w    rms.Support.Parsing.Series  3:4 -      rms.Support.Parsing.Whitespace  3:4 -  rms.Support.Parsing.Sequence  4:6 - 2    rms.Support.Parsing.ParseTo`1[ParserTest.Program+Animal]  4:5 - 2      rms.Support.Parsing.Series  4:5 - 2        rms.Support.Parsing.DifferenceParser  4:5 - 2    rms.Support.Parsing.Series  5:6 -      rms.Support.Parsing.Whitespace  5:6 -  rms.Support.Parsing.Sequence  6:10 - dog    rms.Support.Parsing.ParseTo`1[ParserTest.Program+Animal]  6:9 - dog      rms.Support.Parsing.Series  6:9 - dog        rms.Support.Parsing.DifferenceParser  6:7 - d        rms.Support.Parsing.DifferenceParser  7:8 - o        rms.Support.Parsing.DifferenceParser  8:9 - g    rms.Support.Parsing.Series  9:10 -      rms.Support.Parsing.Whitespace  9:10 -Animal!:  CowAnimal!:  dogAnimal!:  dog
Previous Entry Fireworks!
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement