0

I'm writing a JS macro preprocessor, and refer to the ECMA-262 specification for some guide to parse js code.

I use the code parser to determine where to do macro replace in a standard/precise way, which will distinguish some environments like:

macro(); // valid
foo = /macro()/; // invalid
foo = `macro()`; // invalid
foo = `some text ${macro()}`; // valid

When handling the source code tokenizing procedure, I encountered something called the goal symbol. I made some effort to understand them with some articles from V8 blog and another question.

However, I still can't understand how to determine the goal symbol in a standard way, I searched the specification and didn't find anything about this.

TBA
  • 1,921
  • 4
  • 13
  • 26
Lane Sun
  • 13
  • 4
  • Based on the question, you'd be much better off modifying an existing parser. There are some open-source, high-quality JavaScript parsers out there, such as the ones used by Babel and various bundlers. Writing this from scratch requires a fair bit of parsing knowledge. – T.J. Crowder Nov 18 '21 at 08:32
  • thanks for you answer, I will check it out later, I want to learn to write parsers by myself, and reading other one's source code may be helpful :) – Lane Sun Nov 18 '21 at 09:20

0 Answers0