I’ve created a pull parser as part of my OmniXaml project. It reads an XML file and transforms it into an enumerable of XAML Nodes. But I'm not happy with the result, so I decided to try to build another in a more elegant way.
This is why I tried to make the parser using Sprache.
The thing is that I don’t even know how to start. XAML parsing heavily relies on context, so if you want to yield one Xaml Node, you might have to look-ahead and process the following nodes. I currently use an XmlReader to read the XAML.
Here I'm listing some EXAMPLES of inputs/outputs for you to figure out what I want to do. The input is a XAML code, and the output is a list of XAML nodes. XAML nodes are a structure in which I hold the data that is required to recreate the objects represented in the XAML. They are like instructions of a CPU.
EXAMPLE 1
Input (XAML):
<DummyClass xmlns="root" SampleProperty="Property!">
</DummyClass>
Output (list of XAML Nodes)
- Namespace Declaration of "root" with prefix: ""
- Start of Object of type DummyClass
- Start of Member "SampleProperty" from type "DummyClass"
- Value Node: "Property!"
- End Of Member
- None
- End of Object
EXAMPLE 2
Input:
<DummyClass xmlns="root">
<DummyClass.Child>
<ChildClass></ChildClass>
</DummyClass.Child>
</DummyClass>
Output:
- Namespace Declaration of "root" with prefix: ""
- Start of Object of type DummyClass
- None
- Start of Member "Child" from type "DummyClass"
- Start of Object of type "ChildClass"
- None
- End of Object
- End of Member
- End of Object
EXAMPLE 3
Input:
<DummyClass xmlns="root">
<DummyClass.Items>
<Item/>
<Item/>
<Item/>
</DummyClass.Items>
</DummyClass>
Output:
- Namespace Declaration of "root" with prefix: ""
- Start of Object of type DummyClass
- None
- Start of Member “Items” from type “DummyClass”
- [Get Object] Directive
- [Start of Items] Directive
- Start of Object of type “Item”
- None
- End of Object
- Start of Object of type “Item”
- None
- End of Object
- Start of Object of type “Item”
- None
- End of Object
- End of Member
- End of Object
- End of Member
- End of Object
The question: How to start with this?
Could you provide me with some samples/guidelines? Thanks!