Skip to content

Latest commit

 

History

History
25 lines (19 loc) · 1.04 KB

File metadata and controls

25 lines (19 loc) · 1.04 KB

Scanner Generator Backend: TypeScript

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

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

The scanner is Scanner and its tokens are the frozen Token object together with the Token type, with tokenToString and isSkipped alongside them. TokenSkipper wraps a scanner to drop the tokens marked for skipping. Both implement the TokenSource interface, which is what a parser reads its tokens through. Lexemes are a Uint8Array viewing into the source rather than a copy of it.

Example

examples/calculator/typescript/ is a calculator built on this backend. Its scanner was generated with:

golr scanner \
  --frontend golr \
  --frontend-file-path calculator.golr \
  --backend typescript \
  --backend-file-path parser/scanner.ts