Skip to content

Using same rule in pattern #670

Description

@jcubic

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions