https://github.com/duskmoon314/tree-sitter-p4
Try vibe tree-sitter-p4 and related editor support
https://github.com/duskmoon314/tree-sitter-p4
p4 tree-sitter vibe-coded
Last synced: 14 days ago
JSON representation
Try vibe tree-sitter-p4 and related editor support
- Host: GitHub
- URL: https://github.com/duskmoon314/tree-sitter-p4
- Owner: duskmoon314
- License: mit
- Created: 2026-04-23T11:45:05.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2026-05-09T02:50:35.000Z (about 2 months ago)
- Last Synced: 2026-06-12T23:35:03.301Z (14 days ago)
- Topics: p4, tree-sitter, vibe-coded
- Language: JavaScript
- Homepage:
- Size: 304 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tree-sitter-p4
A [tree-sitter](https://tree-sitter.github.io/tree-sitter/) grammar for [P4-16](https://p4.org/specs/) (Programming Protocol-independent Packet Processors).
## Features
- Full P4-16 grammar coverage: types, expressions, statements, parsers, controls, tables, actions, externs, packages, annotations
- 13-level operator precedence for expressions
- Multi-line preprocessor directive handling
- 98.3% parse success rate on official Tofino example programs (119/121 files)
## Usage
```bash
# Generate the parser and run grammar checks
pnpm run check
# Parse a P4 file
tree-sitter parse example.p4
```
## Editor Support
### VS Code
A VS Code extension is available at [`editors/vscode/`](editors/vscode/) providing semantic syntax highlighting, code folding, and smart selection. To build and install:
```bash
tree-sitter build --wasm
cd editors/vscode
pnpm install
pnpm run build
pnpm run package # produces a .vsix file
code --install-extension tree-sitter-p4-*.vsix
```
## Bindings
- **Rust**: `cargo test`
- **C**: `make && make test`
## Known Limitations
- Files using complex C preprocessor macros (token pasting with `##`) may not parse correctly
- Preprocessor directives are skipped rather than expanded
## License
MIT