Skip to main content

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

Metadata

Release files for tree-sitter-netlinx 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tree-sitter-netlinx 1.0.4
File Size Uploaded
tree_sitter_netlinx-1.0.4.tar.gz 1.5 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for tree-sitter-netlinx 1.0.4
File
tree_sitter_netlinx-1.0.4-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details
tree_sitter_netlinx-1.0.4-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
tree_sitter_netlinx-1.0.4-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
tree_sitter_netlinx-1.0.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
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 CPython 3.10 abi3 Linux glibc 2.5+ x86-64, Linux glibc 2.17+ x86-64 Details
tree_sitter_netlinx-1.0.4-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
tree_sitter_netlinx-1.0.4-cp310-abi3-macosx_10_9_x86_64.whl CPython 3.10 abi3 macOS 10.9+ x86-64 Details

Total release size: 3.0 MB

Release files / tree_sitter_netlinx-1.0.4.tar.gz

Download URL tree_sitter_netlinx-1.0.4.tar.gz
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
bc5b4e12c0fb682f476b01d507381524ff37df2afd8e4682b3a3ec02401e260e
BLAKE2b-256 checksum
How to use checksums
e31ecb096ab41bfb4b53e9c78e00acaf4dcf638df39b6057c4ecf77ec8e29649
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / tree_sitter_netlinx-1.0.4-cp310-abi3-win_arm64.whl

Download URL tree_sitter_netlinx-1.0.4-cp310-abi3-win_arm64.whl
Size 184.2 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
76975b7433669760822fb2b054caa82d91365ccc533dfa2696e28dd22e120cc8
BLAKE2b-256 checksum
How to use checksums
86f900e8eff2dbc6ac1dbc3090deca4db6cc58508a0a5ab009c426ac5ebe3c3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / tree_sitter_netlinx-1.0.4-cp310-abi3-win_amd64.whl

Download URL tree_sitter_netlinx-1.0.4-cp310-abi3-win_amd64.whl
Size 193.0 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
c97dec8676d2fe82a260a503872ef63fc69b9518da4fefabb5e952b33ae082f4
BLAKE2b-256 checksum
How to use checksums
3725e6333f01a52ec56f31e2b83a1efb3cb09086b0b2a0fb7c9ed5b6702e6229
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / tree_sitter_netlinx-1.0.4-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL tree_sitter_netlinx-1.0.4-cp310-abi3-musllinux_1_2_x86_64.whl
Size 214.5 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
f9b9df9d9f331b25d58f900a6125e85be65c4777f9e5487ea95c88551671b1a2
BLAKE2b-256 checksum
How to use checksums
9a15ad9bc52ecdef03b6c42d4ed6d1bd7af84626d8971ebdb59c1b9ebe86f7ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / tree_sitter_netlinx-1.0.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL tree_sitter_netlinx-1.0.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 303.7 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
2ffaa8dcd2ca16bc22c55e9426bc7ee1b08fca235b1cf63d02c4199241b228d4
BLAKE2b-256 checksum
How to use checksums
ce9a7f1837ee6f045869e1d69a26e2f5966666aad31676e5b52eb2d67da896a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / 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

Download URL 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
Size 231.2 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 Linux glibc 2.5+ x86-64 abi3
SHA-256 checksum
How to use checksums
56e67aeb7b88d8ad0546d76616bf5154cb270e998cb608d74f2d2723f62a9f0a
BLAKE2b-256 checksum
How to use checksums
6cedd375c88c334898ddca1b9e1f81279bb779c8f2b503fd066e1024f45cf7b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / tree_sitter_netlinx-1.0.4-cp310-abi3-macosx_11_0_arm64.whl

Download URL tree_sitter_netlinx-1.0.4-cp310-abi3-macosx_11_0_arm64.whl
Size 207.8 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c884bb75171502c4b8a23eee8b26342d4da0af9be589cf2af93e8176e3267e58
BLAKE2b-256 checksum
How to use checksums
2405f888da4d8c976430636d484d257af026a44fde319882053d7815b31d1551
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / tree_sitter_netlinx-1.0.4-cp310-abi3-macosx_10_9_x86_64.whl

Download URL tree_sitter_netlinx-1.0.4-cp310-abi3-macosx_10_9_x86_64.whl
Size 186.2 kB
Tags CPython 3.10 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
d9963bf30c434a2ff04ca7f9e6eef22a09c3659cdbf47df812082a6e15af0ca9
BLAKE2b-256 checksum
How to use checksums
36df3f0c9985259e23c9cc5ca3cdb3ac59821eb78a0ff964ab67c0a4f5b6121d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

1.0.4 This release

8 release files

1.0.3

8 release files

1.0.1

8 release files

1.0.0

8 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page