{"id":26616469,"url":"https://github.com/norgate-av/tree-sitter-netlinx","last_synced_at":"2026-04-30T00:34:53.584Z","repository":{"id":281551270,"uuid":"867317030","full_name":"Norgate-AV/tree-sitter-netlinx","owner":"Norgate-AV","description":"NetLinx grammar for tree-sitter","archived":false,"fork":false,"pushed_at":"2025-03-23T22:28:45.000Z","size":7642,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-23T22:32:23.373Z","etag":null,"topics":["amx","grammar","harman","netlinx","parser","tree-sitter"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/Norgate-AV.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-03T20:45:14.000Z","updated_at":"2025-03-23T22:28:49.000Z","dependencies_parsed_at":"2025-03-23T22:26:14.132Z","dependency_job_id":"632f3770-d6dc-4f94-86ea-3763efdb9658","html_url":"https://github.com/Norgate-AV/tree-sitter-netlinx","commit_stats":null,"previous_names":["norgate-av/tree-sitter-netlinx"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Norgate-AV%2Ftree-sitter-netlinx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Norgate-AV%2Ftree-sitter-netlinx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Norgate-AV%2Ftree-sitter-netlinx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Norgate-AV%2Ftree-sitter-netlinx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Norgate-AV","download_url":"https://codeload.github.com/Norgate-AV/tree-sitter-netlinx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245225230,"owners_count":20580502,"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":["amx","grammar","harman","netlinx","parser","tree-sitter"],"created_at":"2025-03-24T07:23:15.851Z","updated_at":"2026-04-30T00:34:53.578Z","avatar_url":"https://github.com/Norgate-AV.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tree-sitter-netlinx\n\n\u003cdiv align=\"center\"\u003e\n    \u003cimg align=\"center\" style=\"margin-right: 10px;\" src=\"./assets/img/Tree-sitter1.png\" alt=\"tree-sitter-logo\" width=\"150\" hspace=\"10\" /\u003e\n    \u003c!-- \u003cspan\u003e-----\u003c/span\u003e --\u003e\n    \u003cimg align=\"center\" style=\"margin-left: 10px;\" src=\"./assets/img/NetLinx1.png\" alt=\"netlinx-logo\" width=\"150\" hspace=\"10\"/\u003e\n\u003c/div\u003e\n\n---\n\n[![CI][ci]](https://github.com/Norgate-AV/tree-sitter-netlinx/actions/workflows/ci.yml)\n[![GitHub Release](https://img.shields.io/github/v/release/Norgate-AV/tree-sitter-netlinx)](https://github.com/Norgate-AV/tree-sitter-netlinx/releases)\n[![crates][crates]](https://crates.io/crates/tree-sitter-netlinx)\n[![npm][npm]](https://www.npmjs.com/package/tree-sitter-netlinx)\n[![pypi][pypi]](https://pypi.org/project/tree-sitter-netlinx)\n[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits\u0026logoColor=white)](https://conventionalcommits.org)\n[![GitHub contributors](https://img.shields.io/github/contributors/Norgate-AV/tree-sitter-netlinx)](https://github.com/Norgate-AV/tree-sitter-netlinx/graphs/contributors)\n[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)\n\n[NetLinx](https://pldb.io/concepts/netlinx.html) grammar for [tree-sitter](https://tree-sitter.github.io).\n\n[ci]: https://img.shields.io/github/actions/workflow/status/Norgate-AV/tree-sitter-netlinx/ci.yml?logo=github\u0026label=CI\n[npm]: https://img.shields.io/npm/v/tree-sitter-netlinx?logo=npm\n[crates]: https://img.shields.io/crates/v/tree-sitter-netlinx?logo=rust\n[pypi]: https://img.shields.io/pypi/v/tree-sitter-netlinx?logo=pypi\u0026logoColor=ffd242\n\n## Contents :book:\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n- [What's Working :white_check_mark:](#whats-working-white_check_mark)\n- [Known Limitations :warning:](#known-limitations-warning)\n    - [Preprocessor Directives in Expressions](#preprocessor-directives-in-expressions)\n- [Install :zap:](#install-zap)\n    - [Node.js (npm)](#nodejs-npm)\n    - [Rust (Cargo)](#rust-cargo)\n    - [Python (pip)](#python-pip)\n    - [Nix](#nix)\n    - [Manual Installation](#manual-installation)\n- [Design :art:](#design-art)\n    - [Permissive Parsing](#permissive-parsing)\n    - [Syntax vs. Semantics](#syntax-vs-semantics)\n    - [Examples of Accepted Patterns](#examples-of-accepted-patterns)\n    - [Flexibility Over Semantic Correctness](#flexibility-over-semantic-correctness)\n- [References :book:](#references-book)\n- [Team :soccer:](#team-soccer)\n- [Contributors :sparkles:](#contributors-sparkles)\n- [LICENSE :balance_scale:](#license-balance_scale)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## What's Working :white_check_mark:\n\n- Expressions\n    - :white_check_mark: Binary Expressions\n    - :white_check_mark: Bitwise Expressions\n    - :white_check_mark: Bitwise Word Expressions (`band`, `bor`, `bxor`, `bnot`, `lshift`, `rshift`)\n    - :white_check_mark: Unary Expressions\n    - :white_check_mark: Update Expressions\n    - :white_check_mark: Assignment Expressions\n    - :white_check_mark: Devchan Expressions\n    - :white_check_mark: Devchan Range Expressions\n    - :white_check_mark: Comparison Expressions\n    - :white_check_mark: Logical Expressions\n    - :white_check_mark: Logical Word Expressions (`and`, `or`, `xor`, `not`)\n    - :white_check_mark: String Expressions\n    - :white_check_mark: Function Call Expressions\n    - :white_check_mark: Device Expressions (`0:first_local_port+1:1`, `dvPort.NUMBER:dvPort.PORT:dvPort.SYSTEM`)\n    - :white_check_mark: Parenthesized Expressions\n    - :white_check_mark: Subscript Expressions\n    - :white_check_mark: Comma Expressions\n    - :white_check_mark: Compiler Variables (`__file__`, `__line__`, `__date__`, `__time__`, etc)\n    - :white_check_mark: System Variables (`day`, `date`, `ldate`, `time`, etc)\n    - :white_check_mark: System Constants (`true`, `false`, etc)\n    - :white_check_mark: System Functions (all functions defined in `NetLinx.axi`)\n    - :white_check_mark: System Types (all types defined in `NetLinx.axi`)\n- Statements\n    - :white_check_mark: Expression Statements\n    - :white_check_mark: Compound Statements\n    - :white_check_mark: Return Statements\n    - :white_check_mark: Break Statements\n    - :white_check_mark: Continue Statements\n    - :white_check_mark: If Statements\n    - :white_check_mark: While Loops\n    - :white_check_mark: For Loops\n    - :white_check_mark: Switch/Case Statements\n    - :white_check_mark: Select/Active Statements\n    - :white_check_mark: Create Buffer Statements\n    - :white_check_mark: Create Multi Buffer Statements\n    - :white_check_mark: Clear Buffer Statements\n    - :white_check_mark: Wait Statements\n    - :white_check_mark: Wait Until Statements\n    - :white_check_mark: Cancel Wait Statements\n    - :white_check_mark: Cancel Wait Until Statements\n    - :white_check_mark: Cancel All Wait Statements\n    - :white_check_mark: Cancel All Wait Until Statements\n    - :white_check_mark: Break Statements\n    - :white_check_mark: Section Statements\n    - :white_check_mark: Program Name\n    - :white_check_mark: Module Name\n    - :white_check_mark: Send String Statements\n    - :white_check_mark: Send Command Statements\n    - :white_check_mark: Send Level Statements\n    - :white_check_mark: Devchan Operation Statements (`ON`, `OFF`, `TO`, `MIN_TO`, `PULSE`, etc)\n    - :white_check_mark: Call Statements (for legacy `DEFINE_CALL` functions)\n    - :white_check_mark: System Call Statements\n- Declarations\n    - :white_check_mark: Define Function Definitions\n    - :white_check_mark: Define Library Function Declarations\n    - :white_check_mark: Define Call Definitions\n    - :white_check_mark: Variable Declarations\n    - :white_check_mark: Constants Declarations\n    - :white_check_mark: Type Declarations\n    - :white_check_mark: Module Definitions\n    - :white_check_mark: Combine Definitions\n    - :white_check_mark: Connect Level Definitions\n    - :white_check_mark: Toggling Definitions\n    - :white_check_mark: Mutually Exclusive Definitions\n- Events\n    - :white_check_mark: Button Events\n    - :white_check_mark: Channel Events\n    - :white_check_mark: Level Events\n    - :white_check_mark: Data Events\n    - :white_check_mark: Timeline Events\n    - :white_check_mark: Custom Events\n    - :white_check_mark: Legacy Push\n    - :white_check_mark: Legacy Release\n- Literals\n    - :white_check_mark: String Literals\n        - :white_check_mark: Single Quoted String Literals\n        - :white_check_mark: Escape Sequence for Single Quotes (`''`)\n    - :white_check_mark: Number Literals\n        - :white_check_mark: Decimal\n        - :white_check_mark: Hexadecimal\n        - :white_check_mark: Floating Point\n    - :white_check_mark: Device Literals\n- Comments\n    - :white_check_mark: Single Line Comments\n    - :white_check_mark: Multi Line Comments (C Style `/* */`)\n    - :white_check_mark: Pascal Comments (`(* *)`)\n- Preprocessor\n    - :white_check_mark: Define\n    - :white_check_mark: Include\n    - :white_check_mark: Warn\n    - :white_check_mark: Disable Warning\n    - :white_check_mark: If Defined\n    - :white_check_mark: If Not Defined\n\n## Known Limitations :warning:\n\n### Preprocessor Directives in Expressions\n\nThe NetLinx language allows preprocessor directives to be used within expressions, like:\n\n```netlinx\n(foo #IF_DEFINED BAR \u0026\u0026 baz #END_IF \u0026\u0026 foobar)\n```\n\nWhile this is valid NetLinx code that compiles correctly, tree-sitter has limitations when parsing these constructs due to the nature of preprocessor directives operating at a different level than normal syntax.\n\nWhen encountering preprocessor directives within expressions, the parser will:\n\n1. **Maintain the overall expression structure** - The parenthesized expression remains intact\n2. **Generate some error nodes** - The preprocessor directives are marked as errors\n3. **Preserve correct syntax highlighting** - Despite the errors, tokens are still correctly identified\n4. **Keep all identifiers and operators** - Variable names and operators remain properly connected\n\n**Example Parse Tree**\n\n```\n(source_file\n  (expression_statement\n    (parenthesized_expression\n      (ERROR\n        (identifier) // \u003c- foo\n        (preproc_if_defined_keyword))\n      (binary_expression\n        left: (binary_expression\n          left: (identifier) // \u003c- BAR\n          right: (identifier))  // \u003c- baz\n        (ERROR\n          (preproc_end_if_keyword))\n        right: (identifier))))) // \u003c- foobar\n```\n\n**Implications**\n\n- **Editor Experience**: Syntax highlighting and code navigation should work normally\n- **Error Reports**: Your editor may show these areas as errors, which can be safely ignored\n- **Alternative Approach**: For cleaner parsing, consider restructuring complex conditional expressions to avoid embedding preprocessor directives within expressions, like:\n    ```\n    #IF_DEFINED BAR\n      (foo \u0026\u0026 baz \u0026\u0026 foobar)\n    #ELSE\n      (foo \u0026\u0026 foobar)\n    #END_IF\n    ```\n\n## Install :zap:\n\n### Node.js (npm)\n\nFor JavaScript/Node.js projects:\n\n```sh\nnpm install tree-sitter-netlinx\n\n# or\n\nyarn add tree-sitter-netlinx\n\n# or\n\npnpm add tree-sitter-netlinx\n```\n\n### Rust (Cargo)\n\nFor Rust projects:\n\n```sh\ncargo add tree-sitter-netlinx\n```\n\n### Python (pip)\n\nFor Python projects:\n\n```sh\npip install tree-sitter-netlinx\n```\n\n### Nix\n\nFor Nix, NixOS and Home Manager reference:\n\n```nix\npkgs.tree-sitter.withPlugins (plugins: with plugins; [\n  tree-sitter-netlinx\n  # ...\n])\n```\n\n### Manual Installation\n\nIf you want to install the grammar manually, you can clone the repository and build it yourself:\n\n```sh\ngit clone https://github.com/Norgate-AV/tree-sitter-netlinx\ncd tree-sitter-netlinx\nnpm install\nnpx tree-sitter generate\n```\n\n## Design :art:\n\nThe grammar is designed to be as accurate as possible, while also being as flexible as possible.\n\n### Permissive Parsing\n\nThe grammar is intentionally permissive, allowing it to parse syntactically valid but semantically questionable code. This approach enables:\n\n- Better error recovery during editing\n- A more forgiving experience during development\n- The ability to parse incomplete or incorrect code\n- Better syntax highlighting and code navigation\n\n### Syntax vs. Semantics\n\nAs a parsing tool, tree-sitter focuses on syntactic structure rather than semantic validity:\n\n- The parser will accept constructs that are syntactically correct but might fail during compilation\n- Semantic validation should be handled by the NetLinx compiler or separate analysis tools\n- This separation allows the grammar to be more stable and maintainable\n\n### Examples of Accepted Patterns\n\nThe parser will accept patterns that the NetLinx compiler might reject:\n\n- Declarations with inconsistent or incomplete type specifiers\n- Mixed implicit and explicit typings\n- Unusual combinations of modifiers\n- Devchan range expressions used with devchan operations\n\n### Flexibility Over Semantic Correctness\n\nThe parser deliberately prioritizes syntactic flexibility over strict semantic validation:\n\n- **Section-Independent Parsing**: Declarations can appear anywhere in the code, even outside their semantically correct sections. The parser doesn't enforce section-specific constraints that the NetLinx compiler would apply.\n\n- **Context-Free Analysis**: Device definitions, constants, and variables are parsed based on their syntactic structure rather than their semantic context. For example, device definitions in a `DEFINE_DEVICE` section are parsed as standard assignment expressions.\n\n- **Support for Implicit Typing**: The parser accommodates NetLinx's implicit typing behaviors. In NetLinx, when type declarations are omitted, the compiler applies implicit types—`INTEGER` for regular variables and `CHAR` for array variables.\n\n**Examples:**\n\n```netlinx\nDEFINE_CONSTANT\nFOO = 1  // Parsed as an assignment expression rather than a specialized constant declaration\n\nDEFINE_VARIABLE\nbar = 1  // Parsed as an assignment expression\n         // NetLinx compiler would implicitly type this as INTEGER\n\nbaz[10]  // Parsed as an identifier with subscript\n         // NetLinx compiler would implicitly type this as CHAR array\n```\n\nThis approach enables more resilient parsing during code editing and provides better syntax highlighting and tooling support, even for incomplete or semantically imperfect code. Semantic validation is intentionally left to the NetLinx compiler or separate analysis tools.\n\n## References :book:\n\n- [NetLinx Language Reference Guide](https://www.amx.com/en/site_elements/amx-language-reference-guide-netlinx-programming-language)\n- [NetLinx Style Guide](https://www.amx.com/vn/site_elements/style-guide-netlinx-studio-v-4)\n\n## Team :soccer:\n\nThis project is maintained by the following person(s) and a bunch of [awesome contributors](https://github.com/Norgate-AV/tree-sitter-netlinx/graphs/contributors).\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/damienbutt\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/damienbutt?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDamien Butt\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n## Contributors :sparkles:\n\n\u003c!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --\u003e\n\n[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)\n\n\u003c!-- ALL-CONTRIBUTORS-BADGE:END --\u003e\n\nThanks go to these awesome people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://simple.industries/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/843652?v=4?s=100\" width=\"100px;\" alt=\"~kb\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003e~kb\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Norgate-AV/tree-sitter-netlinx/commits?author=kimburgess\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"https://github.com/Norgate-AV/tree-sitter-netlinx/issues?q=author%3Akimburgess\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"https://github.com/Norgate-AV/tree-sitter-netlinx/commits?author=kimburgess\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/Norgate-AV/tree-sitter-netlinx/commits?author=kimburgess\" title=\"Tests\"\u003e⚠️\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://allcontributors.org) specification.\n\nContributions are welcome! Please fork and open a pull request if you have any suggestions or improvements.\n\nAny help would be greatly appreciated.\n\n## LICENSE :balance_scale:\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnorgate-av%2Ftree-sitter-netlinx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnorgate-av%2Ftree-sitter-netlinx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnorgate-av%2Ftree-sitter-netlinx/lists"}