How to define a rule to match with a pattern multiple times in PEG.js?
See original GitHub issueIssue type
- Bug Report:
- Feature Request:
- Question: yes
- Not an issue:
Prerequisites
- Can you reproduce the issue?: yes
- Did you search the repository issues?: to an extend
- Did you check the forums?: no
- Did you perform a web search (google, yahoo, etc)?: yes
Description
I’m trying to parse a file where the pattern might be seen multiple times:
G04 hello world*
G04 foo bar*
The corresponding PEG.js grammar is:
Comment
= "G04" _ content:String* _ EOL
{
return content
}
_ "whitespace"
= [ \t\n\r]*
String
= value:[a-zA-Z0-9.(): _-]+
{
return value.join('')
}
EOL
= [*] _
Expected behavior:
I would expect PEG.js to produce a 2 item array for each G04 line.
Actual behavior:
The following error is thrown:
Line 2, column 1: Expected end of input but “G” found.
Software
- PEG.js: online version
- Node.js:
- NPM or Yarn:
- Browser:
- OS:
- Editor:
Issue Analytics
- State:
- Created 4 years ago
- Comments:22 (1 by maintainers)
Top Results From Across the Web
How to define a rule to match with a pattern multiple times ...
Line 2, column 1: Expected end of input but "G" found. How do I make this Comment rule to match multiple times? peg....
Read more >Ability to specify repetition count (like in regexps) · Issue #30
I will not implement this feature. The main reason is that there is no room in the PEG.js grammar for the {m,n} syntax...
Read more >Documentation » PEG.js – Parser Generator for JavaScript
Match one or more repetitions of the expression and return their match results in an array. The matching is greedy, i.e. the parser...
Read more >PEG Parsers: sometimes more appropriate than Regex
... regex for pattern, PEG.js only allows much simpler pattern matches, I'm going to define two rules, one for integers, and one for...
Read more >Create a custom parser like a PRO with PEGJS
If the parser fails to chain the AND operator it will fallback to the ConditionStatement rule explained below. Notice the Javascript expression at...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@StoneCypher I like you energy 😃 I used to be using pegjs in the past (in dmajda’s times) and I liked it a lot.
Just fork it and do not fight. Things can and will settle down later. If community follows you then you do not need to care about existing “key holder” or anything like that. Building reputation takes time but is necessary. Do not waste time on arguing anymore.
Eight your fork will make it “back into the origin” at some point in the future or it will have its own life. Both options are valid and fine IMO.
When I said “do not give this advice again,” I also really meant it.