UNPKG

@maniascript/parser

Version:
76 lines (48 loc) 1.87 kB
# Maniascript parser Parse a Maniascript string and generate an [ANTLR](https://www.antlr.org) parse tree and an AST. ## Installation Install with npm: `npm install @maniascript/parser`. ## Import ### parse `import { parse } from '@maniascript/parser'` or `const { parse } = require('@maniascript/parser')` `parse` is a function that takes a Maniascript string as input, parses it and returns the result. ```ts import { parse } from '@maniascript/parser' const result = parse(` main() { declare Integer Test = 0; } `) ``` `result` will have the following properties after a successful parsing ```ts { success: true, errors: [], tree: { ... }, ast: { ... } } ``` `result` will have the following properties after a failed parsing ```ts { success: false, errors: [{ line: 1, column: 1, message: 'There is an error' }], tree: { ... }, ast: { ... } } ``` ### ManiaScriptLexer `import { ManiaScriptLexer } from '@maniascript/parser'` or `const { ManiaScriptLexer } = require('@maniascript/parser')` `ManiaScriptLexer` is the ANTLR lexer class. ### ManiaScriptParser `import { ManiaScriptParser } from '@maniascript/parser'` or `const { ManiaScriptParser } = require('@maniascript/parser')` `ManiaScriptParser` is the ANTLR parser class. ### ManiaScriptListener `import { ManiaScriptListener } from '@maniascript/parser'` or `const { ManiaScriptListener } = require('@maniascript/parser')` `ManiaScriptListener` is the listenener generated by ANTLR to walk through the parse tree. ### ManiaScriptVisitor `import { ManiaScriptVisitor } from '@maniascript/parser'` or `const { ManiaScriptVisitor } = require('@maniascript/parser')` `ManiaScriptVisitor` is the visitor generated by ANTLR to walk through the parse tree. ## AST The documentation for the abstract syntax tree generated by the parser is available [here](doc/ast.md).