Add Instantations to Grammar
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -22,7 +22,7 @@ export default grammar({
|
|||||||
name: 'p4',
|
name: 'p4',
|
||||||
rules: {
|
rules: {
|
||||||
// Start symbol
|
// Start symbol
|
||||||
p4program: $ => optional(repeat($.declaration)),
|
p4program: $ => optional(repeat(seq(choice($.declaration, $.instantiation), $.semicolon))),
|
||||||
|
|
||||||
// Common
|
// Common
|
||||||
|
|
||||||
@@ -59,8 +59,11 @@ export default grammar({
|
|||||||
annotation: $ => choice(seq('@', "[a-z]+")),// seq('@', "[a-z]+", '(', /* empty for now*/ ')'), seq('@', "[a-z]+", '[', /* empty for now */ ']')),
|
annotation: $ => choice(seq('@', "[a-z]+")),// seq('@', "[a-z]+", '(', /* empty for now*/ ')'), seq('@', "[a-z]+", '[', /* empty for now */ ']')),
|
||||||
|
|
||||||
|
|
||||||
|
// Instantiation
|
||||||
|
instantiation: $ => seq($.typeRef, '(', optional($.parameterList), ')', $.identifier),
|
||||||
|
|
||||||
// Declarations
|
// Declarations
|
||||||
declaration: $ => seq(choice($.parserDeclaration, $.parserTypeDeclaration), $.semicolon),
|
declaration: $ => seq(choice($.parserDeclaration, $.parserTypeDeclaration)),
|
||||||
|
|
||||||
// Make separate productions for the parser type and the parser type declaration because the latter can have type parameters.
|
// Make separate productions for the parser type and the parser type declaration because the latter can have type parameters.
|
||||||
parserTypeDeclaration: $ => seq(optional($.annotations), $.parser, field('parser_name', $.identifier), optional($.typeParameters), '(', optional($.parameterList), ')'),
|
parserTypeDeclaration: $ => seq(optional($.annotations), $.parser, field('parser_name', $.identifier), optional($.typeParameters), '(', optional($.parameterList), ')'),
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
parser simple() {
|
||||||
|
state start {
|
||||||
|
bool l;
|
||||||
|
transition accept;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -43,8 +43,8 @@ parser simple() {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(semicolon)
|
|
||||||
)
|
)
|
||||||
|
(semicolon)
|
||||||
)
|
)
|
||||||
|
|
||||||
=========================
|
=========================
|
||||||
@@ -92,8 +92,8 @@ parser simple() {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(semicolon)
|
|
||||||
)
|
)
|
||||||
|
(semicolon)
|
||||||
)
|
)
|
||||||
|
|
||||||
=========================
|
=========================
|
||||||
@@ -141,8 +141,8 @@ parser simple() {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(semicolon)
|
|
||||||
)
|
)
|
||||||
|
(semicolon)
|
||||||
)
|
)
|
||||||
|
|
||||||
=========================
|
=========================
|
||||||
@@ -194,7 +194,7 @@ parser simple() {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
(semicolon)
|
(semicolon)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
=========================
|
||||||
|
Simple Instantiation
|
||||||
|
=========================
|
||||||
|
bool() main;
|
||||||
|
---
|
||||||
|
(p4program
|
||||||
|
(instantiation
|
||||||
|
(typeRef
|
||||||
|
(baseType
|
||||||
|
(bool)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(identifier)
|
||||||
|
)
|
||||||
|
(semicolon)
|
||||||
|
)
|
||||||
|
|
||||||
@@ -29,8 +29,8 @@ parser simple() {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(semicolon)
|
|
||||||
)
|
)
|
||||||
|
(semicolon)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -75,6 +75,6 @@ parser imple(bool pname) {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
(semicolon)
|
(semicolon)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ parser simple() {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(semicolon)
|
|
||||||
)
|
)
|
||||||
|
(semicolon)
|
||||||
)
|
)
|
||||||
|
|
||||||
=========================
|
=========================
|
||||||
@@ -101,8 +101,8 @@ parser simple() {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(semicolon)
|
|
||||||
)
|
)
|
||||||
|
(semicolon)
|
||||||
)
|
)
|
||||||
|
|
||||||
=========================
|
=========================
|
||||||
@@ -181,7 +181,7 @@ parser simple() {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
(semicolon)
|
(semicolon)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ parser simple() {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(semicolon)
|
|
||||||
)
|
)
|
||||||
|
(semicolon)
|
||||||
)
|
)
|
||||||
|
|
||||||
=========================
|
=========================
|
||||||
@@ -83,6 +83,6 @@ parser simple() {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
(semicolon)
|
(semicolon)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user