cpp-peglib icon indicating copy to clipboard operation
cpp-peglib copied to clipboard

I wrote a page about cpp-peglib

Open berthubert opened this issue 1 year ago • 2 comments

Hi! I am so happy with cpp-peglib that I thought more people should hear about it. https://berthub.eu/articles/posts/practical-peg-parsing/ has the post, and I hope I got it all right. It is highly likely that people better versed in PEG and cpp-peglib have suggestions, and if so, I'd love to hear about it!

And maybe once we get it right, it could be an idea to link to this page from the README.

Thank you for cpp-peglib!

berthubert avatar Apr 22 '24 14:04 berthubert

@berthubert thanks for the excellent and beautiful article! I really enjoyed reading it. I wanted to write such a user friendly and enjoyable guide, but my ability as a document writer prevented me from doing it. :)

Please let me know when you write another article on cpp-peglib. I'll also like to it. Thanks a lot!

yhirose avatar Apr 23 '24 22:04 yhirose

I'm looking through the link and found that the first example probably can be improved to accept only valid numbers:

Vector      <- '(' Number ( ',' Number )* ')'
Number      <- [+-]?([0-9]*[.][0-9]+/[0-9]+[.]?)
%whitespace <- [\t ]*

Based on a translation that can be viewed here https://mingodad.github.io/parsertl-playground/playground/ :

%token Number

%%

Vector      : '(' Number ( ',' Number )* ')';

%%

%%
[ \t\r\n]+	skip()

"("	'('
")"	')'
","	','

[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)	Number

%%

Input :

(0.123, -.987, 2.4, 3, .98, 4.)

mingodad avatar May 01 '24 14:05 mingodad