New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
advice on parsing + state regexp lexer prototype #70
Comments
You're hitting the lack of sub-lexers here. A single token can't be parsed by a sub-node. See solution in #25.
This is an open issue. My current idea is to support sub-lexers, see #25
Yeah that's not good. Do you have the panic stack trace? |
You'll often get a I'd be interested in improving this, what specifically did you have in mind? |
Hi @alecthomas, looking at the time stamp of this reply we have a big timeshift I'm located in France GMT+2. It may be tricky to have a spare time at the same period. |
It's 4pm here (Sydney), I'll be online until around 10pm. |
I'm not sure to understand the point here. I'm not yet familiar to all participle concepts, I may also lack some vocabulary or code knowledge. In #25 you mention
I also splited my comment in #25.
I opened a separate issue about it: #71 |
Ok, I've continued on my experimentation. I now completed my grammar with rules for parsing Here is an input ended by an extra dot ".", it will complexify my grammar if I try to parse this corner
My actual lexer is extracting it as expected:
My idea here, is to remove the The regexp from legacy docoopt parser is: reDefault := regexp.MustCompile(`(?i)\[default: (.*)\]`) How I'm supposed to extract the Is it a job for |
It's tempting to put more and more logic into lexing/parsing, but I would keep it simple and do something like this:
|
Hi,
I discovered participle by looking for grammar parser in Go.
Good job! Participle looks funny and powerful.
Sorry a very long message for all I collected about using participle. May I can split it in multiple issue?
docopt context
Here's follow some of my context.
I'm the maintainer of the project
docopts
note the final "S", which is an analogy togetopts
.docopts
is a CLI parser for bash, implementing the docopt language.I'm currently using the Go docopt library to parse docopt. This library is almost a translation word to word from the original Python docopt parser.
I would like to write a new parser from scratch to re-parse, and next enhance, the docopt language which seems at a standstill. Notably issuing helpful parser error or warning during docopt parsing.
I'm just beginning with
participle
and I'm looking for some advises.The docopt language is line based, and is composed of sections, each section is parsed differently.
Here is a valid docopt example which describes the docopt own language:
https://github.com/docopt/docopts/blob/dev-participle/grammar/docopt_language.docopt
I modified
docopts
in the branch, so it will parse the above example using the actual parser written in Go:testing participle
I first wrote a simple regexp lexer and a top grammar for splitting by section, then I was thinking about to parse each section with a different lexer + section parser.
Now I changed my mind and finished writing a PoC of a state lexer, like GNU flex, based on your lexer/regexp.
https://github.com/docopt/docopts/blob/dev-participle/grammar/lexer_state/lexer_state.go
The idea is that the lexer uses a different set of regexp depending of token it extracts, as I used in GNU/flex.
The following docopt grammar becomes parsable, as some token are only recognized in some defined section of the language.
I wrote a prototype with participle, which should be able to parse a grammar that looks like, the definition may not exactly reflect the real code (#1 would be great for posting issue too 😉)
My questions
Why negative rune for token?
Why not matching array index for token?
Capture without using @@ own type : Usage_first: structs can only be parsed with @@ or by implementing the Capture interface
I first encounter the error:
Capture without using @@ own type : Usage_first: structs can only be parsed with @@ or by implementing the Capture interface
I did not manage to implement a
Capture
interface nor for the parent node, neither for the child node.When I was trying to assign a token to an array. (I did reproduce it like that but it may be an invalid grammar)
So I ended to write the single line case that way:
I would have preferred to be able to have an array with one or many
Usage_line
here.lexer state
Is it a good way to delegate more on lexer state?
Comparing about having a top level grammar controlling multiples lexer + sub-parser
Capital parser struct definition panic error
Forgetting a Capital letter in a parser struct definition gives =>
panic : panic: reflect: reflect.Copy using value obtained using unexported field
This message is a bit cryptic
Error handling reporting
My main goal by refactoring docopt parser is to produce good and nice error handling during docopt parsing. How do I customize and handle parse error in participle?
Thanks for reading. 😄
The text was updated successfully, but these errors were encountered: