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

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.

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):

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.3.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.3-cp310-abi3-win_arm64.whl (183.7 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_netlinx-1.0.3-cp310-abi3-win_amd64.whl (192.4 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_netlinx-1.0.3-cp310-abi3-musllinux_1_2_x86_64.whl (213.9 kB view details)

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

tree_sitter_netlinx-1.0.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (303.1 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tree_sitter_netlinx-1.0.3-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (230.6 kB view details)

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

tree_sitter_netlinx-1.0.3-cp310-abi3-macosx_11_0_arm64.whl (207.2 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_netlinx-1.0.3-cp310-abi3-macosx_10_9_x86_64.whl (185.7 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: tree_sitter_netlinx-1.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 575b9b295cb7fc96f3e76861512bf704bbf8748002d0b4d0e58a8ba9e73c299a
MD5 2ad3081574129cd2aec9405470422f91
BLAKE2b-256 c80b2250072cf855ce1abb17fd76b7b7aa73494b0c3d22981dd5a59f28f8834f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_netlinx-1.0.3-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 9591cdaa01bfbc09b23dc6e86df43231e4de84a7e68e384d57425ab2b7f6c5b1
MD5 487b36d7f5f25b40144ea0268056ccb9
BLAKE2b-256 4e68aefb3c78f5453e432fa8d2fba6eca49c86ddfe22d0145f959727e6448974

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_netlinx-1.0.3-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2ddde82b1c8ae5ec8f6a0264bd69b8bba30d03cac5c715dc2909718b4a20a79a
MD5 a381e5b062f67ff5e7502d50b2445ab8
BLAKE2b-256 2ed867c6135a272d36eafb50898e1ef6880f74b8555fa642eadcdd031cb6f225

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_netlinx-1.0.3-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1b244aba0a749788a52ce738e4c49a1653e6cdc006333003638a55b91137881b
MD5 fa4d349c7f94220fb07ce679cfc4e222
BLAKE2b-256 15e44a4b2263f2ca8be062e3858cb6cd44371b193ac9c9bc36eea3607d62d799

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_netlinx-1.0.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 564a4cee63605d314f078c81a159b3054882092ee7acddd994306c91c9dee6e1
MD5 3287e561e5ab7c1c199376b141ea2ac3
BLAKE2b-256 26f2f8f3f26cbb8ed5bdc277366851b426d927b1610d748a652dcb495f8fa9e5

See more details on using hashes here.

File details

Details for the file tree_sitter_netlinx-1.0.3-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.3-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9e72201aa3b7350b4953e7b0ba63b86456c5c7d70afc73d1cd9e1db91bcdfd17
MD5 73399fc41bc9a4c3f6ed7cca7f8b3947
BLAKE2b-256 54ded4755beae74c7633dd7f70b1ad9ea692424a7e4965e2e939edfc748fabba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_netlinx-1.0.3-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 32ffe4fb8f49abb38014bf83fea034d82e4d888225d068344a41b7de018704ce
MD5 9d0fda313352c18b526c5d6efe5988ec
BLAKE2b-256 0651e0a8f093382f42740b7bde5b104064130d5dfb12f67502e80b6b458defcc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_netlinx-1.0.3-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1256e66237cd17c1c83693f143ed77232c5747c276fe1ff4cfc161ba7e425855
MD5 ec0e0702120172f5d26bc0736096392a
BLAKE2b-256 7b6bfc768fd2ce81a143ed6d625759dc354365e6ba0b2edc1a089a2b9c5b36e3

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