picoe / Eto.Parse

Recursive descent LL(k) parser for .NET with Fluent API, BNF, EBNF and Gold Grammars
MIT License
148 stars 30 forks source link

Create an AST builder #18

Closed furesoft closed 3 years ago

furesoft commented 9 years ago

how can i build a abstract syntax tree with eto.parse?

cwensley commented 9 years ago

There's no built-in way of creating an AST with Eto.Parse right now, but you can do this relatively easily using the visitor pattern on matches. This is done for things like the EbnfGrammar, which turns a grammar parsed using Eto.Parse into the Parser objects (the AST).

I've been thinking of a way to map matches to an AST more automatically, however doing it manually is certainly the most flexible (and not too painful) way as your grammar won't have to match the AST exactly.

ArsenShnurkov commented 8 years ago

as for me, My ultimate goal is not to build AST, but to build objects of my domain model. To do that, I need to navigate existing structure. It would be convinient for me to navigate with XPath-like API (because it is well documented standart).

see https://github.com/picoe/Eto.Parse/issues/27 and https://github.com/picoe/Eto.Parse/issues/28

cwensley commented 3 years ago

Now done with #58! 🎉

Not really documented, but hopefully the samples help. There's a json > tokens sample, and a json >.concrete object sample. More samples could be made as questions arise.