zevv / npeg

PEGs for Nim, another take
MIT License
330 stars 22 forks source link

PEG section in the Nim book #41

Closed StefanSalewski closed 2 years ago

StefanSalewski commented 2 years ago

Dear Sir,

I have just shipped the first draft of the PEG section for the Nim book, see

http://ssalewski.de/nimprogramming.html#_parsing_expression_grammars

That section have not yet been checked by native English proof readers, so there may be still some grammar or spelling errors. Please let me know if my explanations are wrong or still unclear.

I have the hope that this section will make it a bit easier for kids and beginners to start with PEGs.

Some notes to your NPeg README text:

data up to the match; if his is

Plain typo, should be "this".

NPeg provides various prefix, infix and suffix operators.

I still wonder if there are really suffix operators.

even if the match is part of a pattern that fails and is later backtracked.

That full sentence is displayed in italics -- is that intended?

The syntax for defining a generic grammar is as follows:

peg(name, identifier: Type)

The phrase "generic grammar" sounds strange here, as you are not talking about grammar, but about passing an additional variable to the peg() macro.

Best regards, Stefan Salewski

zevv commented 2 years ago

Hi Stefan,

Quoting StefanSalewski (2022-02-17 16:23:26)

I have just shipped the first draft of the PEG section for the Nim book, see

http://ssalewski.de/nimprogramming.html#_parsing_expression_grammars

Nice work!

That section have not yet been checked by native English proof readers, so there may be still some grammar or spelling errors. Please let me know if my explanations are wrong or still unclear.

Sure, I'll take some time to go over it, and will get back to you if I have any comments.

Some notes to your NPeg README text:

data up to the match; if his is

Plain typo, should be "this".

Right, fixed.

NPeg provides various prefix, infix and suffix operators.

I still wonder if there are really suffix operators.

Very true, also fixed.

even if the match is part of a pattern that fails and is later backtracked.

That full sentence is displayed in italics -- is that intended?

Yes - I could probably also make it bold or add a "note" icon, but it's ment to stand out: the fact that npeg matches these patterns even if they are later backtracked is a big gotcha, and actually the root cause for a number of github issues that have been reported over time. This is one of the "rough edges" of Npeg that still have not been ironed out for various reasons.

The syntax for defining a generic grammar is as follows:

peg(name, identifier: Type)

The phrase "generic grammar" sounds strange here, as you are not talking about grammar, but about passing an additional variable to the peg() macro.

Hmm, I see what you mean. I think i ment to use 'generic' here as in 'generics', but it's indeed misplaced in this context. I will reword this.

Thanks for the review & comments!

Best regards, Stefan Salewski

zevv commented 2 years ago

Closing this during spring cleaning - feel free to reopen if needed!