• entries
    359
  • comments
    237
  • views
    188206

Parsing baby steps.

Sign in to follow this  
Telastyn

39 views

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!: Cow
Animal!: dog
Animal!: dog


Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now