| Crates.io | tree-sitter-netlinx |
| lib.rs | tree-sitter-netlinx |
| version | 1.0.4 |
| created_at | 2025-04-07 08:52:06.080777+00 |
| updated_at | 2025-05-11 10:49:00.341986+00 |
| description | NetLinx grammar for tree-sitter |
| homepage | |
| repository | https://github.com/norgate-av/tree-sitter-netlinx |
| max_upload_size | |
| id | 1623828 |
| size | 25,179,600 |
NetLinx grammar for tree-sitter.
band, bor, bxor, bnot, lshift, rshift)and, or, xor, not)0:first_local_port+1:1, dvPort.NUMBER:dvPort.PORT:dvPort.SYSTEM)__file__, __line__, __date__, __time__, etc)day, date, ldate, time, etc)true, false, etc)NetLinx.axi)NetLinx.axi)ON, OFF, TO, MIN_TO, PULSE, etc)DEFINE_CALL functions)'')/* */)(* *))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:
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
#IF_DEFINED BAR
(foo && baz && foobar)
#ELSE
(foo && foobar)
#END_IF
For JavaScript/Node.js projects:
npm install tree-sitter-netlinx
# or
yarn add tree-sitter-netlinx
# or
pnpm add tree-sitter-netlinx
For Rust projects:
cargo add tree-sitter-netlinx
For Python projects:
pip install tree-sitter-netlinx
For Nix, NixOS and Home Manager reference:
pkgs.tree-sitter.withPlugins (plugins: with plugins; [
tree-sitter-netlinx
# ...
])
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
The grammar is designed to be as accurate as possible, while also being as flexible as possible.
The grammar is intentionally permissive, allowing it to parse syntactically valid but semantically questionable code. This approach enables:
As a parsing tool, tree-sitter focuses on syntactic structure rather than semantic validity:
The parser will accept patterns that the NetLinx compiler might reject:
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.
This project is maintained by the following person(s) and a bunch of awesome contributors.
Damien Butt |
Thanks go to these awesome people (emoji key):
~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.