parent 12 attr="q" { childA 34 childB 56 } lastTag
The ParserEvent sequence emitted for that SDL document would be as follows (indented for readability):
TagStartEvent (parent) ValueEvent (12) AttributeEvent (attr, "q") TagStartEvent (childA) ValueEvent (34) TagEndEvent TagStartEvent (childB) ValueEvent (56) TagEndEvent TagEndEvent TagStartEvent (lastTag) TagEndEvent
t { // stuff.sdl immutable stuffSdl = ` name "sdlang-d" description "An SDL (Simple Declarative Language) library for D." homepage "http://github.com/Abscissa/SDLang-D" configuration "library" { targetType "library" } `; import std.stdio; foreach(event; pullParseSource(stuffSdl)) final switch(event.kind) { case ParserEvent.Kind.tagStart: auto e = cast(TagStartEvent) event; writeln("TagStartEvent: ", e.namespace, ":", e.name, " @ ", e.location); break; case ParserEvent.Kind.tagEnd: auto e = cast(TagEndEvent) event; writeln("TagEndEvent"); break; case ParserEvent.Kind.value: auto e = cast(ValueEvent) event; writeln("ValueEvent: ", e.value); break; case ParserEvent.Kind.attribute: auto e = cast(AttributeEvent) event; writeln("AttributeEvent: ", e.namespace, ":", e.name, "=", e.value); break;
Parses an SDL document using StAX/Pull-style. Returns an InputRange with element type ParserEvent.
The pullParseFile version reads a file and parses it, while pullParseSource parses a string passed in. The optional filename parameter in pullParseSource can be included so that the SDLang document's filename (if any) can be displayed with any syntax error messages.
Note: The old FileStartEvent and FileEndEvent events were deemed unnessecary and removed as of SDLang-D v0.10.0.
Note: Previously, in SDLang-D v0.9.x, ParserEvent was a std.variant.Algebraic. As of SDLang-D v0.10.0, it is now a TaggedAlgebraic, so usage has changed somewhat.