@maniascript/parser
TypeScript icon, indicating that this package has built-in type declarations

12.2.0 • Public • Published

Maniascript parser

Parse a Maniascript string and generate an ANTLR 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.

import { parse } from '@maniascript/parser'

const result = parse(`
main() {
  declare Integer Test = 0;
}
`)

result will have the following properties after a successful parsing

{
  success: true,
  errors: [],
  tree: { ... },
  ast: { ... }
}

result will have the following properties after a failed parsing

{
  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.

/@maniascript/parser/

    Package Sidebar

    Install

    npm i @maniascript/parser

    Weekly Downloads

    3

    Version

    12.2.0

    License

    LGPL-3.0-or-later

    Unpacked Size

    793 kB

    Total Files

    23

    Last publish

    Collaborators

    • aessi