question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to define a rule to match with a pattern multiple times in PEG.js?

See original GitHub issue

Issue 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:closed
  • Created 4 years ago
  • Comments:22 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
lukas-vlcekcommented, Feb 4, 2020

@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.

1reaction
StoneCyphercommented, Feb 4, 2020

When I said “do not give this advice again,” I also really meant it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found