pointlander / peg

Peg, Parsing Expression Grammar, is an implementation of a Packrat parser generator.
BSD 3-Clause "New" or "Revised" License
1.02k stars 120 forks source link

Interest in a GoCode Element? #97

Closed rwxrob closed 4 years ago

rwxrob commented 4 years ago

As I've been working on the vim-gopeg plugin (which has a notion of regions) I noticed that the peg.peg only really looks for package and import as keywords and doesn't really consider everything before the grammar as a sort of pre-amble (which would have helped earlier had I known I could not use standard import () syntax because of that).

What I'm proposing for discussion is a new peg.peg that separates the the grammar into two main components, or perhaps just an initial component Preamble (or whatever) followed but what is there now.

Then, the Preamble would be set to contain exactly the same syntax GoCode with modification to support things like # for comments and such. The Go AST and parser is readily available to derive that grammar. (By the way, why the Java, C and other grammer pegs and not one for Go itself? wink).

One side-effect is that we could change ActionBody (which I think has a bug) to be GoCode or something like that.

In fact, if we do this we get full Go syntax checking as well as PEG grammar checking.

It would also make the vim-gopeg plugin a lot easier to do because this stuff is very similar.

Please let me know if this is a path worse pursuing and if so I wouldn't mind working on it.