Skip to content
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

comments for #lang peg #6

Closed
rain-1 opened this issue Feb 28, 2018 · 8 comments
Closed

comments for #lang peg #6

rain-1 opened this issue Feb 28, 2018 · 8 comments

Comments

@rain-1
Copy link
Owner

rain-1 commented Feb 28, 2018

We would like // comments.

@petrolifero
Copy link
Contributor

change main.rkt, on the peg-port->scheme function, to :

"
(define (peg-port->scheme in)
(peg->scheme (car
(peg-result->object (peg (and peg (! (any-char))) (regexp-replace* "//[^\n]*" (port->string in) ""))))))
"

well, just put out the comments before processing. This will resolve, right?

@rain-1
Copy link
Owner Author

rain-1 commented Jun 11, 2018

It would be slightly incorrect to strip comments this way, for example if // occured inside a string literal it would be treated as a comment.

For the optimal solution comment support needs to be added to https://github.com/rain-1/racket-peg/blob/master/peg-in-peg.rkt

@rain-1
Copy link
Owner Author

rain-1 commented Jun 16, 2018

To achieve this I believe we would need to update the SP < [ \t\n]* ; rule to support the // comments.

After editing peg-in-peg.rkt the file https://github.com/rain-1/racket-peg/blob/master/peg-in-peg-expanded.rkt must be manually created by using the racket macro expander.

@petrolifero
Copy link
Contributor

#lang peg

nt-char <- [a-zA-Z0-9_\-] ;
nonterminal <-- nt-char+ !nt-char SP ;
SP < [ \t\n]* ;

literal <-- SQ (BS ['\\] / !['\\] .)* SQ SP ;
SQ < ['] ;
BS < [\\] ;

charclass <-- LB '^'? (cc-range / cc-escape / cc-single)+ RB SP ;
cc-range <-- cc-char DASH cc-char ;
cc-escape <-- BS . ;
cc-single <-- cc-char ;
cc-char <- !cc-escape-char . ;
cc-escape-char <- '[' / ']' / '-' / '^' / '\\' / 'n' / 't' ;
LB < '[' ;
RB < ']' ;
DASH < '-' ;

peg <-- out grammar+ ;
grammar <-- (nonterminal ('<--' / '<-' / '<') SP pattern) ';' out ;
pattern <-- alternative (SLASH SP alternative)* ;
alternative <-- expression+ ;
expression <-- [!]? SP primary ([*+?] SP)? ;
primary <-- '(' SP pattern ')' SP / '.' SP / literal / charclass / nonterminal ;
SLASH < '/' ;



_ < ' ' / [\t] / [\n] ;
comment < '//' [^\n]* ;

out < (comment / _)* ;

I tested this and work. Can put comments in the end of a rule or between rules

//some comment
peg <-- a ; //another comment

//between

a < 'h' ; //end

//after

@petrolifero
Copy link
Contributor

as a problem, I can't remove 'out' of the formed struct, probably because a misunderstanding of relation between < <- and <-- in diferente rules.

@rain-1
Copy link
Owner Author

rain-1 commented Jul 19, 2018

Great! I've integrated this into the code, I added it to SP instead of creating out. It seems to be working but we should add a some comments to the examples to serve as tests.

3b41028
34bfe34

Thanks for contributing!

@rain-1
Copy link
Owner Author

rain-1 commented Jul 19, 2018

  • gotta add the new peg grammar to the docs

@rain-1
Copy link
Owner Author

rain-1 commented Jul 21, 2018

f286257 make test working

1efda98 docs updated!

done!

@rain-1 rain-1 closed this as completed Jul 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants