I am working on a language that transpiles to javascript and has a similar syntax. However I want to include some new type of block statements. For syntax purposes they are the same as an IfStatement. How can I get esprima or acorn to parse this program MyStatement {a=1;} without throwing an error? Its fine if it calls it an IfStatement. I would prefer not to fork esprima.
How to add keyword to acorn or esprima parser
684 Views Asked by bruceceng At
1
There are 1 best solutions below
Related Questions in JAVASCRIPT
- Using Puppeteer to scrape a public API only when the data changes
- inline SVG text (js)
- An array of images and a for loop display the buttons. How to assign each button to open its own block by name?
- Storing the preferred font-size in localStorage
- Simple movie API request not showing up in the console log
- Authenticate Flask rest API
- Deploying sveltekit app with gunjs on vercel throws cannot find module './lib/text-encoding'
- How to request administrator rights?
- mp4 embedded videos within github pages website not loading
- Scrimba tutorial was working, suddenly stopped even trying the default
- In Datatables, start value resets to 0, when column sorting
- How do I link two models in mongoose?
- parameter values only being sent to certain columns in google sheet?
- Run main several times of wasm in browser
- Variable inside a Variable, not updating
Related Questions in PARSING
- TypeScript: Type checking while parsing an arbitrary JSON that is typed/
- How to have fixed options using Option.Applicative in haskell?
- How to convert mathematical expression to lambda function in C++?
- JsonObject throws an exception: JSONObject["employer_website"] is not a string (class org.json.JSONObject$Null : null)
- Trying to fix my c++ code for it to read the right amount of nodes from a file
- Selenium get page after "loading" page
- Parse tag in html via Google Sheets (importxml)
- FluentD / Fluent-Bit: Concatenate multiple lines of log files and generate one JSON record for all key-value from each line
- Editing non-String values in JComboBox
- Handling multiple errors in Bison parser
- Which is the most idiomatic way to parse an i32 from ascii in Rust
- I got this error from a JSON Validator - what does this mean?
- Conflict between lexer rules in ANTLR4 for Fortran grammar
- mqtt message parsing problem in a node.js
- How to print error code from URL response in swift
Related Questions in ESPRIMA
- escodegen's verbatim option
- How can I add a new semantics on esprima parser?
- Why does escodegen and esprima generate a parenthesis wrapper on my source code?
- EOENT esprima esparse Windows symlinks invalid directory file not found
- Esprima error 404 Not Found in npm install
- What characters can be operators in JavaScript using Esprima?
- ES6 Module export default syntax
- How can I know when the scope changes within an abstract syntax tree?
- transpiler battle: breaking out of nested function, with vs without throw
- why esprima works fine in online browser demo, but failed locally
- How to generate all the leaf to leaf path in an AST?
- extracting specific function calls from javascript
- Error generating code with escodegen after node removal
- Cannot set property 'esprima' of undefined at webpackUniversalModuleDefinition
- Ignore error while generating JS AST using ESPIRMA
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
It turns out, that the plugin capabilities of acorn are not really documented. It seems like forking acorn would be the easiest route. In this case, it is as simple as searching for occurances of
_ifand following a similar pattern for_MyStatement.However it is possible to write a plugin to accomplish what I was trying to do. It seems a bit of a hack, but here is the code. The basic steps are:
To exend
Parseand add to the list of keywords that will be recognized by the first passCreate a TokenType for the new keyword and add it to the
Parser.acorn.keywordTypes, extendparseStatementso that it processes the new TokenTypeCreate a handler for the new TokenType which will add information to the Abstract Syntax Tree as required by the keyword functionality and also consume tokens using commands like
this.expect(tt.parenR)to eat a '(' orthis.parseExpression()to process an entire expression.Here is the code: