Skip to main content

NetLinx grammar for tree-sitter

Project description

tree-sitter-netlinx

tree-sitter-logo netlinx-logo

CI GitHub Release crates npm pypi Conventional Commits GitHub contributors MIT license

NetLinx grammar for tree-sitter.

Contents :book:

What's Working :white_check_mark:

  • Expressions
    • :white_check_mark: Binary Expressions
    • :white_check_mark: Bitwise Expressions
    • :white_check_mark: Bitwise Word Expressions (band, bor, bxor, bnot, lshift, rshift)
    • :white_check_mark: Unary Expressions
    • :white_check_mark: Update Expressions
    • :white_check_mark: Assignment Expressions
    • :white_check_mark: Devchan Expressions
    • :white_check_mark: Devchan Range Expressions
    • :white_check_mark: Comparison Expressions
    • :white_check_mark: Logical Expressions
    • :white_check_mark: Logical Word Expressions (and, or, xor, not)
    • :white_check_mark: String Expressions
    • :white_check_mark: Function Call Expressions
    • :white_check_mark: Device Expressions (0:first_local_port+1:1, dvPort.NUMBER:dvPort.PORT:dvPort.SYSTEM)
    • :white_check_mark: Parenthesized Expressions
    • :white_check_mark: Subscript Expressions
    • :white_check_mark: Comma Expressions
    • :white_check_mark: Compiler Variables (__file__, __line__, __date__, __time__, etc)
    • :white_check_mark: System Variables (day, date, ldate, time, etc)
    • :white_check_mark: System Constants (true, false, etc)
    • :white_check_mark: System Functions (all functions defined in NetLinx.axi)
    • :white_check_mark: System Types (all types defined in NetLinx.axi)
  • Statements
    • :white_check_mark: Expression Statements
    • :white_check_mark: Compound Statements
    • :white_check_mark: Return Statements
    • :white_check_mark: Break Statements
    • :white_check_mark: Continue Statements
    • :white_check_mark: If Statements
    • :white_check_mark: While Loops
    • :white_check_mark: For Loops
    • :white_check_mark: Switch/Case Statements
    • :white_check_mark: Select/Active Statements
    • :white_check_mark: Create Buffer Statements
    • :white_check_mark: Create Multi Buffer Statements
    • :white_check_mark: Clear Buffer Statements
    • :white_check_mark: Wait Statements
    • :white_check_mark: Wait Until Statements
    • :white_check_mark: Cancel Wait Statements
    • :white_check_mark: Cancel Wait Until Statements
    • :white_check_mark: Cancel All Wait Statements
    • :white_check_mark: Cancel All Wait Until Statements
    • :white_check_mark: Break Statements
    • :white_check_mark: Section Statements
    • :white_check_mark: Program Name
    • :white_check_mark: Module Name
    • :white_check_mark: Send String Statements
    • :white_check_mark: Send Command Statements
    • :white_check_mark: Send Level Statements
    • :white_check_mark: Devchan Operation Statements (ON, OFF, TO, MIN_TO, PULSE, etc)
    • :white_check_mark: Call Statements (for legacy DEFINE_CALL functions)
    • :white_check_mark: System Call Statements
  • Declarations
    • :white_check_mark: Define Function Definitions
    • :white_check_mark: Define Library Function Declarations
    • :white_check_mark: Define Call Definitions
    • :white_check_mark: Variable Declarations
    • :white_check_mark: Constants Declarations
    • :white_check_mark: Type Declarations
    • :white_check_mark: Module Definitions
    • :white_check_mark: Combine Definitions
    • :white_check_mark: Connect Level Definitions
    • :white_check_mark: Toggling Definitions
    • :white_check_mark: Mutually Exclusive Definitions
  • Events
    • :white_check_mark: Button Events
    • :white_check_mark: Channel Events
    • :white_check_mark: Level Events
    • :white_check_mark: Data Events
    • :white_check_mark: Timeline Events
    • :white_check_mark: Custom Events
    • :white_check_mark: Legacy Push
    • :white_check_mark: Legacy Release
  • Literals
    • :white_check_mark: String Literals
      • :white_check_mark: Single Quoted String Literals
      • :white_check_mark: Escape Sequence for Single Quotes ('')
    • :white_check_mark: Number Literals
      • :white_check_mark: Decimal
      • :white_check_mark: Hexadecimal
      • :white_check_mark: Floating Point
    • :white_check_mark: Device Literals
  • Comments
    • :white_check_mark: Single Line Comments
    • :white_check_mark: Multi Line Comments (C Style /* */)
    • :white_check_mark: Pascal Comments ((* *))
  • Preprocessor
    • :white_check_mark: Define
    • :white_check_mark: Include
    • :white_check_mark: Warn
    • :white_check_mark: Disable Warning
    • :white_check_mark: If Defined
    • :white_check_mark: If Not Defined

Known Limitations :warning:

Preprocessor Directives in Expressions

The NetLinx language allows preprocessor directives to be used within expressions, like:

(foo #IF_DEFINED BAR && baz #END_IF && foobar)

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

When encountering preprocessor directives within expressions, the parser will:

  1. Maintain the overall expression structure - The parenthesized expression remains intact
  2. Generate some error nodes - The preprocessor directives are marked as errors
  3. Preserve correct syntax highlighting - Despite the errors, tokens are still correctly identified
  4. Keep all identifiers and operators - Variable names and operators remain properly connected

Example Parse Tree

(source_file
  (expression_statement
    (parenthesized_expression
      (ERROR
        (identifier) // <- foo
        (preproc_if_defined_keyword))
      (binary_expression
        left: (binary_expression
          left: (identifier) // <- BAR
          right: (identifier))  // <- baz
        (ERROR
          (preproc_end_if_keyword))
        right: (identifier))))) // <- foobar

Implications

  • Editor Experience: Syntax highlighting and code navigation should work normally
  • Error Reports: Your editor may show these areas as errors, which can be safely ignored
  • Alternative Approach: For cleaner parsing, consider restructuring complex conditional expressions to avoid embedding preprocessor directives within expressions, like:
    #IF_DEFINED BAR
      (foo && baz && foobar)
    #ELSE
      (foo && foobar)
    #END_IF
    

Install :zap:

Node.js (npm)

For JavaScript/Node.js projects:

npm install tree-sitter-netlinx

# or

yarn add tree-sitter-netlinx

# or

pnpm add tree-sitter-netlinx

Rust (Cargo)

For Rust projects:

cargo add tree-sitter-netlinx

Python (pip)

For Python projects:

pip install tree-sitter-netlinx

Nix

For Nix, NixOS and Home Manager reference:

pkgs.tree-sitter.withPlugins (plugins: with plugins; [
  tree-sitter-netlinx
  # ...
])

Manual Installation

If you want to install the grammar manually, you can clone the repository and build it yourself:

git clone https://github.com/Norgate-AV/tree-sitter-netlinx
cd tree-sitter-netlinx
npm install
npx tree-sitter generate

Design :art:

The grammar is designed to be as accurate as possible, while also being as flexible as possible.

Permissive Parsing

The grammar is intentionally permissive, allowing it to parse syntactically valid but semantically questionable code. This approach enables:

  • Better error recovery during editing
  • A more forgiving experience during development
  • The ability to parse incomplete or incorrect code
  • Better syntax highlighting and code navigation

Syntax vs. Semantics

As a parsing tool, tree-sitter focuses on syntactic structure rather than semantic validity:

  • The parser will accept constructs that are syntactically correct but might fail during compilation
  • Semantic validation should be handled by the NetLinx compiler or separate analysis tools
  • This separation allows the grammar to be more stable and maintainable

Examples of Accepted Patterns

The parser will accept patterns that the NetLinx compiler might reject:

  • Declarations with inconsistent or incomplete type specifiers
  • Mixed implicit and explicit typings
  • Unusual combinations of modifiers
  • Devchan range expressions used with devchan operations

Flexibility Over Semantic Correctness

The parser deliberately prioritizes syntactic flexibility over strict semantic validation:

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

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

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

Examples:

DEFINE_CONSTANT
FOO = 1  // Parsed as an assignment expression rather than a specialized constant declaration

DEFINE_VARIABLE
bar = 1  // Parsed as an assignment expression
         // NetLinx compiler would implicitly type this as INTEGER

baz[10]  // Parsed as an identifier with subscript
         // NetLinx compiler would implicitly type this as CHAR array

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

References :book:

Team :soccer:

This project is maintained by the following person(s) and a bunch of awesome contributors.


Damien Butt

Contributors :sparkles:

All Contributors

Thanks go to these awesome people (emoji key):

~kb
~kb

📖 🐛 💻 ⚠️

This project follows the all-contributors specification.

Contributions are welcome! Please fork and open a pull request if you have any suggestions or improvements.

Any help would be greatly appreciated.

LICENSE :balance_scale:

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tree_sitter_netlinx-1.0.4.tar.gz (1.5 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tree_sitter_netlinx-1.0.4-cp310-abi3-win_arm64.whl (184.2 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_netlinx-1.0.4-cp310-abi3-win_amd64.whl (193.0 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_netlinx-1.0.4-cp310-abi3-musllinux_1_2_x86_64.whl (214.5 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

tree_sitter_netlinx-1.0.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (303.7 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tree_sitter_netlinx-1.0.4-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (231.2 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

tree_sitter_netlinx-1.0.4-cp310-abi3-macosx_11_0_arm64.whl (207.8 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_netlinx-1.0.4-cp310-abi3-macosx_10_9_x86_64.whl (186.2 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

Details for the file tree_sitter_netlinx-1.0.4.tar.gz.

File metadata

  • Download URL: tree_sitter_netlinx-1.0.4.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for tree_sitter_netlinx-1.0.4.tar.gz
Algorithm Hash digest
SHA256 bc5b4e12c0fb682f476b01d507381524ff37df2afd8e4682b3a3ec02401e260e
MD5 b6e3e0db687af635c3ca20be08f7e18d
BLAKE2b-256 e31ecb096ab41bfb4b53e9c78e00acaf4dcf638df39b6057c4ecf77ec8e29649

See more details on using hashes here.

File details

Details for the file tree_sitter_netlinx-1.0.4-cp310-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_netlinx-1.0.4-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 76975b7433669760822fb2b054caa82d91365ccc533dfa2696e28dd22e120cc8
MD5 efebe72717745eb90352a3f0e5aacfbf
BLAKE2b-256 86f900e8eff2dbc6ac1dbc3090deca4db6cc58508a0a5ab009c426ac5ebe3c3a

See more details on using hashes here.

File details

Details for the file tree_sitter_netlinx-1.0.4-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_netlinx-1.0.4-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c97dec8676d2fe82a260a503872ef63fc69b9518da4fefabb5e952b33ae082f4
MD5 b5d542207599007c1e2b72e83b43ada2
BLAKE2b-256 3725e6333f01a52ec56f31e2b83a1efb3cb09086b0b2a0fb7c9ed5b6702e6229

See more details on using hashes here.

File details

Details for the file tree_sitter_netlinx-1.0.4-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_netlinx-1.0.4-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f9b9df9d9f331b25d58f900a6125e85be65c4777f9e5487ea95c88551671b1a2
MD5 e8f5c3b9a759a63eaecbfc5188c7c3db
BLAKE2b-256 9a15ad9bc52ecdef03b6c42d4ed6d1bd7af84626d8971ebdb59c1b9ebe86f7ec

See more details on using hashes here.

File details

Details for the file tree_sitter_netlinx-1.0.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_netlinx-1.0.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2ffaa8dcd2ca16bc22c55e9426bc7ee1b08fca235b1cf63d02c4199241b228d4
MD5 cc93b1a2608b3f4edba586e8c22c29c1
BLAKE2b-256 ce9a7f1837ee6f045869e1d69a26e2f5966666aad31676e5b52eb2d67da896a6

See more details on using hashes here.

File details

Details for the file tree_sitter_netlinx-1.0.4-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_netlinx-1.0.4-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 56e67aeb7b88d8ad0546d76616bf5154cb270e998cb608d74f2d2723f62a9f0a
MD5 81afa4739ee948e0fb390dacdcd7947a
BLAKE2b-256 6cedd375c88c334898ddca1b9e1f81279bb779c8f2b503fd066e1024f45cf7b8

See more details on using hashes here.

File details

Details for the file tree_sitter_netlinx-1.0.4-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_netlinx-1.0.4-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c884bb75171502c4b8a23eee8b26342d4da0af9be589cf2af93e8176e3267e58
MD5 6be8752a59803e124bdc150618a64598
BLAKE2b-256 2405f888da4d8c976430636d484d257af026a44fde319882053d7815b31d1551

See more details on using hashes here.

File details

Details for the file tree_sitter_netlinx-1.0.4-cp310-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_netlinx-1.0.4-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d9963bf30c434a2ff04ca7f9e6eef22a09c3659cdbf47df812082a6e15af0ca9
MD5 a4f9758571d86c5172b9b536e00b80cc
BLAKE2b-256 36df3f0c9985259e23c9cc5ca3cdb3ac59821eb78a0ff964ab67c0a4f5b6121d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page