This is a vscode extension for P4 for Programming Protocol-independent Packet Processors.
Most common syntax and semantic highlights are supported for now!
- simple syntax highlight
- relative complete semantic highlight based on ANTLR4
- install npm, node-typescript and node_modules
sudo apt-get install npm
sudo apt-get install node-typescript
npm install
- generate antlr lexer and parser
npm run antlr4ts
- then simply press
F5
in vscode, then you can debug for it.
You can refer to this official document for more help! Have fun!😃
- This folder contains all of the files necessary for your extension.
package.json
- this is the manifest file in which you declare your language support and define the location of the grammar file that has been copied into your extension.syntaxes/p4.tmLanguage.json
- this is the Text mate grammar file that is used for tokenization.language-configuration.json
- this is the language configuration, defining the tokens that are used for comments and brackets.src/main.ts
- contains all visitors for semantic highlightsrc/grammar/*
- contains all P4 language grammar specification (with a bit modification).
- I only deal with some simple things in syntax, which means, without a semantic highlight, this extension might be a bit useless.
- TODO: provide a
TypeDefinitionProvider
- TODO: deal with
macro
s. For now I just skip all macro lines. But when it comes to#ifdef
,#else
sequences, something could go wrong.
The ANTLR4 grammar file is based on fattaholmanan/p4-vscode-extension's. Thanks to their publication.