An open API service indexing awesome lists of open source software.

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

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