All Projects → RokuRoad → bright

RokuRoad / bright

Licence: MIT License
Blazing fast parser for BrightScript that gives you ESTree like AST

Programming Languages

typescript
32286 projects
HTML
75241 projects
Brightscript
28 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to bright

Unified
☔️ interface for parsing, inspecting, transforming, and serializing content through syntax trees
Stars: ✭ 3,036 (+10742.86%)
Mutual labels:  ast, cst, syntax-tree
ukor
A Roku build tool with support for build flavors
Stars: ✭ 45 (+60.71%)
Mutual labels:  roku, brightscript
crash-course
This course is intended to quickly get you up to speed on Roku SceneGraph. It's aimed at an audience of developers who are familiar with streaming video applications but are unfamiliar with Roku.
Stars: ✭ 118 (+321.43%)
Mutual labels:  roku, brightscript
MarkdownSyntax
☄️ A Type-safe Markdown parser in Swift.
Stars: ✭ 65 (+132.14%)
Mutual labels:  ast, syntax-tree
Escaya
An blazing fast 100% spec compliant, incremental javascript parser written in Typescript
Stars: ✭ 217 (+675%)
Mutual labels:  ast, syntax-tree
sast
Parse CSS, Sass, SCSS, and Less into a unist syntax tree
Stars: ✭ 51 (+82.14%)
Mutual labels:  ast, syntax-tree
codeparser
Parse Wolfram Language source code as abstract syntax trees (ASTs) or concrete syntax trees (CSTs)
Stars: ✭ 84 (+200%)
Mutual labels:  ast, cst
Libdparse
Library for lexing and parsing D source code
Stars: ✭ 91 (+225%)
Mutual labels:  ast, syntax-tree
c-compiler
A compiler that accepts any valid program written in C. It is made using Lex and Yacc. Returns a symbol table, parse tree, annotated syntax tree and intermediate code.
Stars: ✭ 37 (+32.14%)
Mutual labels:  ast, syntax-tree
code summarization public
source code for 'Improving automatic source code summarization via deep reinforcement learning'
Stars: ✭ 71 (+153.57%)
Mutual labels:  ast, tree-structure
abstract-syntax-tree
A library for working with abstract syntax trees.
Stars: ✭ 77 (+175%)
Mutual labels:  ast, syntax-tree
Retext
natural language processor powered by plugins part of the @unifiedjs collective
Stars: ✭ 2,119 (+7467.86%)
Mutual labels:  ast, cst
Nlcst
Natural Language Concrete Syntax Tree format
Stars: ✭ 116 (+314.29%)
Mutual labels:  ast, syntax-tree
Astviewer
Python Abstract Syntax Tree viewer in Qt
Stars: ✭ 101 (+260.71%)
Mutual labels:  ast, syntax-tree
astutils
Bare essentials for building abstract syntax trees, and skeleton classes for PLY lexers and parsers.
Stars: ✭ 13 (-53.57%)
Mutual labels:  ast, syntax-tree
roku-libs
Compilation of utilities for Roku development
Stars: ✭ 47 (+67.86%)
Mutual labels:  roku, brightscript
Metric Parser
📜 AST-based advanced mathematical parser written by Typescript.
Stars: ✭ 26 (-7.14%)
Mutual labels:  ast, syntax-tree
Astexplorer.app
https://astexplorer.net with ES Modules support and Hot Reloading
Stars: ✭ 65 (+132.14%)
Mutual labels:  ast, syntax-tree
eslint-plugin-roku
ESLint plugin to parse and lint BrightScript files
Stars: ✭ 44 (+57.14%)
Mutual labels:  roku, brightscript
kataw
An 100% spec compliant ES2022 JavaScript toolchain
Stars: ✭ 303 (+982.14%)
Mutual labels:  ast, cst

Bright

npm version Downloads/month Build Status CircleCI Coverage Status Dependency Status Greenkeeper badge CodeFactor

What is Bright?

Blazing fast parser for BrightScript that gives you ESTree like AST. Sort of. The motivation behind this project is to build solid platform and base for other development tools in Roku world. This parser takes .brs files and builds AST in form of ESTree like structure that could be used with ESLint, Prettier or other tools for linting, refactoring and formatting.

This project uses awesome https://github.com/SAP/chevrotain parser engine, performance tests : https://sap.github.io/chevrotain/performance/

Performance

While there is no official metrics yet, during development it continuesly got tested on ~800 random open source project files from Github.

Tokei

Thanks, Tokei

Tests

Project is written in TypeScript and compiles to JS

Installation

yarn

Usage

import { ast, parse } from '@roku-road/bright'

export const scanSource = (source: string, type = 'Program') => {
  const { value, lexErrors, tokens, parseErrors } = parse(source, type)

  //...

  return ast(value)
}

Example

Library "ads"

Will produce

Tokens

 [ { loc: { start: { column: 1, line: 1 }, end: { column: 7, line: 1 } },
           range: [ 0, 6 ],
           type: 'LIBRARY',
           value: 'Library' },
         { loc: { start: { column: 9, line: 1 }, end: { column: 13, line: 1 } },
           range: [ 8, 12 ],
           type: 'STRING_LITERAL',
           value: '"ads"' } ]

and value

    { value:
       { name: 'Program',
         children:
          { Declaration:
             [ { name: 'LibraryStatement',
                 children:
                  { LIBRARY:
                     [ { image: 'Library',
                         startOffset: 0,
                         endOffset: 6,
                         startLine: 1,
                         endLine: 1,
                         startColumn: 1,
                         endColumn: 7,
                         tokenTypeIdx: 39 } ],
                    path:
                     [ { image: '"ads"',
                         startOffset: 8,
                         endOffset: 12,
                         startLine: 1,
                         endLine: 1,
                         startColumn: 9,
                         endColumn: 13,
                         tokenTypeIdx: 79
                           ],
                            tokenTypeIdx: 79,
                            categoryMatches: [],
                            categoryMatchesMap: {},
                            tokenName: 'STRING_LITERAL',
                            isParent: false } } ] } } ],
            EOF:
             [ { image: '',
                 startOffset: NaN,
                 endOffset: NaN,
                 startLine: NaN,
                 endLine: NaN,
                 startColumn: NaN,
                 endColumn: NaN,
                 tokenTypeIdx: 1,
                 } ] } } }

Errors

Lets say we forget to put a new line after function signature declaration

function a end function
[ Error {
           name: 'MismatchedTokenException',
           message: 'Expecting token of type --> TERMINATOR <-- but found --> \'end function\' <--',
           token:
            { image: 'end function',
              startOffset: 11,
              endOffset: 22,
              startLine: 1,
              endLine: 1,
              startColumn: 12,
              endColumn: 23,
              tokenTypeIdx: 29,
              tokenType:
               { PATTERN: [Function: pattern],
                 tokenTypeIdx: 29,
                 CATEGORIES: [],
                 categoryMatches: [],
                 categoryMatchesMap: {},
                 tokenName: 'END_FUNCTION',
                 isParent: false,
                 LONGER_ALT:
                  { PATTERN: /([A-Za-z_]+[A-Za-z0-9_]*)/,
                    tokenTypeIdx: 3,
                    CATEGORIES: [],
                    categoryMatches: [],
                    categoryMatchesMap: {},
                    tokenName: 'IDENTIFIER',
                    isParent: false },
                 START_CHARS_HINT: [ 'E', 'e' ] } },
           resyncedTokens: [],
           context:
            { ruleStack: [ 'Program', 'FunctionDeclaration', 'EndOfStatement' ],
              ruleOccurrenceStack: [ 0, 0, 0 ] } } ]
Rendered as
    > 1 | function a end function
        |            ^^^^^^^^^^^ Expecting token of type --> TERMINATOR <-- but found --> 'end function' <--

Bright consists of Tokens, Parser and Visitors. Please see Chevrotain project for details

Element Description
RokuBRSParser Heart of the project, defined structure of nodes
ASTVisitor Visitor that walks parsed CST and produce AST for other tools
ALL_TOKENS Map of the tokens, literals, punctuation etc
parse API function to get parsed value, lexer and parser errors
ast API function to get AST tree value, lexer and parser errors
visitorKeys Map for walking though the tree (to avoid blind iteration)

Grammar

Please check generated https://github.com/RokuRoad/bright/blob/master/diagram/index.html for details

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].