pegjs icon indicating copy to clipboard operation
pegjs copied to clipboard

Using same rule in pattern

Open jcubic opened this issue 2 years ago • 2 comments

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:

jcubic avatar Oct 15 '21 07:10 jcubic

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

jarble avatar Mar 11 '22 03:03 jarble

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

jcubic avatar Mar 11 '22 07:03 jcubic