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

[Question] Parsing comments with two characters limits #48

Closed
mantielero opened this issue Nov 24, 2022 · 2 comments
Closed

[Question] Parsing comments with two characters limits #48

mantielero opened this issue Nov 24, 2022 · 2 comments

Comments

@mantielero
Copy link

I am trying to parse comments with limits: (* and *).

I am trying the following without success:

import npeg

type
  Comment = string

let tmp = "(*This is a comment*)"  # Nested comments are not allowed

let parser = peg("comment", d: Comment):
  commentStart <- "(*"
  commentEnd <- "*)"
  #content <- *(1-commentEnd) 
  #comment <- commentStart * >content * commentEnd:
  comment <- "(*" * >(1-"*)") * "*)":
    d = $1


var comm:Comment
#assert parser.match(tmp, comm).ok
echo parser.match(tmp, comm).captures

#echo comm

The sort of comments I could expect are like:

(* This is an exmaple *)
(* This is 
 * an example
 *)
(********)
(* Ok   *)
(********)
(*
  enum_v1 : enum_type00;
*)
@zevv
Copy link
Owner

zevv commented Nov 24, 2022

import npeg

let tmp = "(*This is a comment*)"  # Nested comments are not allowed
                                                                    
let parser = peg "comment":
  comment <- "(*" * >*(1-"*)") * "*)"              
                                     
echo parser.match(tmp).captures                    

output:

@["This is a comment"]

@mantielero
Copy link
Author

Thanks a lot

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