Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 1.04 KB

File metadata and controls

27 lines (20 loc) · 1.04 KB

Parser Generator Backend: JavaScript

This backend outputs a parser as JavaScript source code. See parser generator backends for what every generated parser does and scanner generator backend: JavaScript for the scanner side.

The output is an ES module and needs nothing beyond the language itself.

--backend-javascript-scanner-module sets the module specifier the token constants are imported from, which defaults to ./scanner.js.

Parser.parse takes a scanner and returns a result holding the tree and the errors, and can be called again with another scanner. The tree is null when the parse could not be finished. Lexemes are a Uint8Array viewing into the source rather than a copy of it.

Example

examples/calculator/javascript/ is a calculator built on this backend. Its parser was generated with:

golr parser \
  --frontend golr \
  --frontend-file-path calculator.golr \
  --backend javascript \
  --backend-file-path parser/parser.js