radare2/shlr/radare2-shell-parser
2020-04-23 16:32:53 +02:00
..
corpus Add support for >? help_command (#16699) 2020-04-23 16:32:53 +02:00
src Add support for >? help_command (#16699) 2020-04-23 16:32:53 +02:00
.gitignore Compile new shell parser by default (#16660) 2020-04-21 13:44:30 +02:00
binding.gyp Compile new shell parser by default (#16660) 2020-04-21 13:44:30 +02:00
grammar.js Handle 'q' to interrumpt prompt in newshell ##newshell (#16681) 2020-04-22 21:48:43 +02:00
index.js Compile new shell parser by default (#16660) 2020-04-21 13:44:30 +02:00
package-lock.json Compile new shell parser by default (#16660) 2020-04-21 13:44:30 +02:00
package.json Compile new shell parser by default (#16660) 2020-04-21 13:44:30 +02:00
README.md Compile new shell parser by default (#16660) 2020-04-21 13:44:30 +02:00

radare2-shell-parser

This is the parser for radare2 shell language. See https://tree-sitter.github.io/tree-sitter/creating-parsers for more info on how to create a parser with tree-sitter.

Sources

  • grammar.js: defines the basic grammar
  • src/scanner.c: external scanner used to scan some tokens that cannot be parsed with the regular js grammar, as that includes only the context-free part of the language.
  • src/parser.c: this file is auto-generated by tree-sitter based on grammar.js
  • corpus/*: list of test files used to ensure the grammar works well

How to update grammar

When you update something in grammar.js or src/scanner.c you have to re-generate the parser. The process works as follows:

  1. Do changes as needed to grammar.js and/or src/scanner.c
  2. Install npm dependencies with: cd shlr/radare2-shell-parser ; npm install
  3. Make sure tree-sitter is in PATH: export PATH=$PATH:./node_modules/.bin
  4. Re-generate the parser files: tree-sitter generate
  5. Check tests still pass: tree-sitter test. Use tree-sitter parse ./example-file if you want to see the syntax tree of a custom input provided in ./example-file
  6. Commit auto-generated files and modified grammar.js and src/scanner.c into git.