{"id":13520432,"url":"https://github.com/RokuRoad/bright","last_synced_at":"2025-03-31T16:31:27.631Z","repository":{"id":95851531,"uuid":"136671649","full_name":"RokuRoad/bright","owner":"RokuRoad","description":"Blazing fast parser for BrightScript that gives you ESTree like AST","archived":false,"fork":false,"pushed_at":"2020-12-17T21:44:55.000Z","size":1185,"stargazers_count":29,"open_issues_count":14,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-18T23:30:17.834Z","etag":null,"topics":["ast","brightscript","cst","parser","roku","source","syntax-tree","tree-structure"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RokuRoad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-06-08T22:32:19.000Z","updated_at":"2023-09-08T17:41:31.000Z","dependencies_parsed_at":"2023-03-13T16:44:47.848Z","dependency_job_id":null,"html_url":"https://github.com/RokuRoad/bright","commit_stats":{"total_commits":85,"total_committers":6,"mean_commits":"14.166666666666666","dds":"0.44705882352941173","last_synced_commit":"3b5a75c1a40fde9649a728253a9f3fceb207a570"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RokuRoad%2Fbright","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RokuRoad%2Fbright/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RokuRoad%2Fbright/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RokuRoad%2Fbright/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RokuRoad","download_url":"https://codeload.github.com/RokuRoad/bright/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222670691,"owners_count":17020513,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","brightscript","cst","parser","roku","source","syntax-tree","tree-structure"],"created_at":"2024-08-01T05:02:20.504Z","updated_at":"2024-11-02T03:31:33.156Z","avatar_url":"https://github.com/RokuRoad.png","language":"TypeScript","funding_links":[],"categories":["HarmonyOS","TypeScript"],"sub_categories":["Windows Manager"],"readme":"# Bright\n\n[![npm version](https://img.shields.io/npm/v/@roku-road/bright.svg)](https://www.npmjs.com/package/@roku-road/bright)\n[![Downloads/month](https://img.shields.io/npm/dm/@roku-road/bright.svg)](http://www.npmtrends.com/@roku-road/bright)\n[![Build Status](https://travis-ci.com/RokuRoad/bright.svg?branch=master)](https://travis-ci.com/RokuRoad/bright)\n[![CircleCI](https://img.shields.io/circleci/project/github/RokuRoad/bright.svg?style=for-the-badge)](https://circleci.com/gh/RokuRoad/bright)\n[![Coverage Status](https://codecov.io/gh/RokuRoad/bright/branch/master/graph/badge.svg)](https://codecov.io/gh/RokuRoad/bright)\n[![Dependency Status](https://david-dm.org/RokuRoad/bright.svg)](https://david-dm.org/RokuRoad/bright) [![Greenkeeper badge](https://badges.greenkeeper.io/RokuRoad/bright.svg)](https://greenkeeper.io/)\n[![CodeFactor](https://www.codefactor.io/repository/github/RokuRoad/bright/badge)](https://www.codefactor.io/repository/github/RokuRoad/bright)\n## What is Bright?\n\nBlazing 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.\n\nThis project uses awesome https://github.com/SAP/chevrotain parser engine, performance tests : https://sap.github.io/chevrotain/performance/\n\n\n### Performance\n\nWhile there is no official metrics yet, during development it continuesly got tested on ~800 random open source project files from Github.\n\n![Tokei](https://github.com/RokuRoad/bright/blob/master/docs/tokei.png)\n\nThanks, [Tokei](https://github.com/Aaronepower/tokei)\n\n![Tests](https://github.com/RokuRoad/bright/blob/master/docs/tests.png)\n\nProject is written in TypeScript and compiles to JS\n\n## Installation\n\n```yarn```\n\n\n## Usage\n\n```typescript\nimport { ast, parse } from '@roku-road/bright'\n\nexport const scanSource = (source: string, type = 'Program') =\u003e {\n  const { value, lexErrors, tokens, parseErrors } = parse(source, type)\n\n  //...\n\n  return ast(value)\n}\n```\n\n\n## Example\n``` brightscript\nLibrary \"ads\"\n```\n\nWill produce\n\n#### Tokens\n``` javascript\n [ { loc: { start: { column: 1, line: 1 }, end: { column: 7, line: 1 } },\n           range: [ 0, 6 ],\n           type: 'LIBRARY',\n           value: 'Library' },\n         { loc: { start: { column: 9, line: 1 }, end: { column: 13, line: 1 } },\n           range: [ 8, 12 ],\n           type: 'STRING_LITERAL',\n           value: '\"ads\"' } ]\n```\nand value\n```javascript\n    { value:\n       { name: 'Program',\n         children:\n          { Declaration:\n             [ { name: 'LibraryStatement',\n                 children:\n                  { LIBRARY:\n                     [ { image: 'Library',\n                         startOffset: 0,\n                         endOffset: 6,\n                         startLine: 1,\n                         endLine: 1,\n                         startColumn: 1,\n                         endColumn: 7,\n                         tokenTypeIdx: 39 } ],\n                    path:\n                     [ { image: '\"ads\"',\n                         startOffset: 8,\n                         endOffset: 12,\n                         startLine: 1,\n                         endLine: 1,\n                         startColumn: 9,\n                         endColumn: 13,\n                         tokenTypeIdx: 79\n                           ],\n                            tokenTypeIdx: 79,\n                            categoryMatches: [],\n                            categoryMatchesMap: {},\n                            tokenName: 'STRING_LITERAL',\n                            isParent: false } } ] } } ],\n            EOF:\n             [ { image: '',\n                 startOffset: NaN,\n                 endOffset: NaN,\n                 startLine: NaN,\n                 endLine: NaN,\n                 startColumn: NaN,\n                 endColumn: NaN,\n                 tokenTypeIdx: 1,\n                 } ] } } }\n```\n\n### Errors\nLets say we forget to put a new line after function signature declaration\n\n```brightscript\nfunction a end function\n```\n\n```javascript\n[ Error {\n           name: 'MismatchedTokenException',\n           message: 'Expecting token of type --\u003e TERMINATOR \u003c-- but found --\u003e \\'end function\\' \u003c--',\n           token:\n            { image: 'end function',\n              startOffset: 11,\n              endOffset: 22,\n              startLine: 1,\n              endLine: 1,\n              startColumn: 12,\n              endColumn: 23,\n              tokenTypeIdx: 29,\n              tokenType:\n               { PATTERN: [Function: pattern],\n                 tokenTypeIdx: 29,\n                 CATEGORIES: [],\n                 categoryMatches: [],\n                 categoryMatchesMap: {},\n                 tokenName: 'END_FUNCTION',\n                 isParent: false,\n                 LONGER_ALT:\n                  { PATTERN: /([A-Za-z_]+[A-Za-z0-9_]*)/,\n                    tokenTypeIdx: 3,\n                    CATEGORIES: [],\n                    categoryMatches: [],\n                    categoryMatchesMap: {},\n                    tokenName: 'IDENTIFIER',\n                    isParent: false },\n                 START_CHARS_HINT: [ 'E', 'e' ] } },\n           resyncedTokens: [],\n           context:\n            { ruleStack: [ 'Program', 'FunctionDeclaration', 'EndOfStatement' ],\n              ruleOccurrenceStack: [ 0, 0, 0 ] } } ]\n```\n\n##### Rendered as\n\n```\n    \u003e 1 | function a end function\n        |            ^^^^^^^^^^^ Expecting token of type --\u003e TERMINATOR \u003c-- but found --\u003e 'end function' \u003c--\n```\n\n\nBright consists of Tokens, Parser and Visitors. Please see *Chevrotain* project for details\n\n| Element       | Description |\n| ---           | ---         |\n| RokuBRSParser | Heart of the project, defined structure of nodes |\n| ASTVisitor    | Visitor that walks parsed CST and produce AST for other tools |\n| ALL_TOKENS    | Map of the tokens, literals, punctuation etc |\n| parse         | API function to get parsed value, lexer and parser errors |\n| ast           | API function to get AST tree value, lexer and parser errors |\n| visitorKeys   | Map for walking though the tree (to avoid blind iteration) |\n\n## Grammar\nPlease check generated https://github.com/RokuRoad/bright/blob/master/diagram/index.html for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRokuRoad%2Fbright","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRokuRoad%2Fbright","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRokuRoad%2Fbright/lists"}