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

Using same rule in pattern #670

Open
jcubic opened this issue Oct 15, 2021 · 2 comments
Open

Using same rule in pattern #670

jcubic opened this issue Oct 15, 2021 · 2 comments

Comments

@jcubic
Copy link

jcubic commented Oct 15, 2021

Issue type

  • Bug Report: no
  • Feature Request: yes
  • Question: no
  • Not an issue: no

Prerequisites

  • Can you reproduce the issue?: yes
  • Did you search the repository issues?: yes
  • Did you check the forums?: yes
  • Did you perform a web search (google, yahoo, etc)?: yes

Description

There should be a way to reference pattern that was defined before in the rule. like in regex /(foo)\1/:

Steps to Reproduce

An example is a rule that matches any XML tag.

start = "<" tag:[\w]+ ">" text:[\s\S]* "</" tag ">" {
   return {
     tag: tag.join(''),
     text: text.join('')
  };
}

my actual use case is adding heredocs:

heredoc = "<<<" marker:[\w]+ "\n" text:[\s\S]+ "\n" marker {
	return text.join('');
}

Expected behavior:

I expect to be able to use tag pattern that was defined in the same rule.

Actual behavior:

got error Line 1, column 40: Rule "tag" is not defined.

Software

  • PEG.js: 0.10.0
  • Node.js: v16.4.2
  • NPM or Yarn: 7.18.1
  • Browser:
  • OS: Fedora GNU/Linux
  • Editor:
@jarble
Copy link

jarble commented Mar 11, 2022

peg.js has been abandoned, so this feature probably won't be implemented.

@jcubic
Copy link
Author

jcubic commented Mar 11, 2022

@jarble I know, see discussion on a maintained fork - peggyjs/peggy#194

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