1

I am tying to create a treetop grammar. I have created the rules to match sections in the file that are of interest to me.

grammar Sexp

  rule bodies
    body+
  end

  rule body
    commentPortString (ifdef_blocks / interface)+ (!newLine)
  end
...
end

How do I run this on a file to extract out the bodies and ignore other sections that I dont care about, or do I need to end up writing rules for those sections also?

Thanks in advance

justrajdeep
  • 855
  • 3
  • 12
  • 29

1 Answers1

1

It's a common idiom in PEG grammars to repeatedly match any character . that isn't part of a rule !body. Something like this:

rule bodies
  ((!body .)* body)+ (!body .)*
end
Josh Voigts
  • 4,114
  • 1
  • 18
  • 43
  • Thanks works. But it slows down the parser significantly. – justrajdeep Aug 02 '18 at 21:32
  • It might help performance-wise to do `((!commentPortString .)* body)+ (!commentPortString .)*` instead, or to not match spaces inside `commentPortString` (I mean move it outside the rule). Just some ideas. – Josh Voigts Aug 03 '18 at 16:47