1

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!

SuperJMN
  • 13,110
  • 16
  • 86
  • 185
  • It is not a real answer but you can look into [Kaxaml](https://github.com/thinkpixellab/kaxaml) for inspiration. Kaxaml is a free open source XAML editor. – aloisdg Apr 20 '15 at 08:39
  • Oh, thanks, but Kaxaml uses the XAML reading features that WPF provides, so it doesn't provide a pull parser: it uses the existing one, that is closed (in System.Xaml) :( – SuperJMN Apr 20 '15 at 08:43
  • Ok sorry. Good luck. – aloisdg Apr 20 '15 at 09:43
  • You could maybe look at the Perspex project. On the `xaml` branch they're working on their own xaml parser: https://github.com/SuperJMN/Perspex/tree/xaml – Tamás Deme Apr 20 '15 at 11:13
  • Haha, but... hey! I'm the creator! I mean, I'm SuperJMN, the one that is creating the XAML parser :) In fact, I already have one, but I don't really like it. I would like to make a better one using Monadic Parser Combinators. I mentioned Sprache because it's the one I have already used, but any parser framework is welcome if it's as elegant. Thanks for the answer! – SuperJMN Apr 20 '15 at 11:25

0 Answers0