Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
zeeshanlakhani committed Dec 10, 2024
1 parent 19c9051 commit 4ee5998
Show file tree
Hide file tree
Showing 6 changed files with 15,287 additions and 18,109 deletions.
1 change: 0 additions & 1 deletion examples/dynamic_router.p4
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ control local(
is_local = true;
}
}

}

control router(
Expand Down
43 changes: 30 additions & 13 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ module.exports = grammar({
),
),

direction: (_) => choice("in", "out", "inout", "packet_in", "packet_out"),
direction: (_) => choice("in", "out", "inout"),

field: ($) =>
seq(
Expand All @@ -422,6 +422,8 @@ module.exports = grammar({
"int",
"bit",
"varbit",
"packet_in",
"packet_out",
$.bit_type,
$.varbit_type,
$.tuple_type,
Expand All @@ -437,9 +439,9 @@ module.exports = grammar({
repeat(seq(",", choice($._type, $.type_identifier))),
),

type_identifier: ($) => prec(2, $.identifier),
type_identifier: ($) => prec(1, $.identifier),

method_identifier: ($) => prec(1, $.identifier),
method_identifier: ($) => $.identifier,

selection_case: ($) =>
choice(
Expand All @@ -449,7 +451,7 @@ module.exports = grammar({
),

identifier: (_) => /[a-zA-Z_][a-zA-Z0-9_]*/,
identifier_preproc: (_) => /[A-Z][A-Z_]*/,
identifier_preproc: (_) => /[A-Z][A-Z0-9_]*/,

bool: (_) => choice("true", "false"),

Expand Down Expand Up @@ -484,35 +486,50 @@ module.exports = grammar({
),
),

line_continuation: (_) => /s*\\?s*/,
line_continuation: (_) => /\s*\\\s*/,

preproc: ($) =>
choice(
seq("#define", $.identifier_preproc, $.number),
seq(
"#define",
$.identifier,
optional($.line_continuation),
choice(
seq("{", optional($.line_continuation), repeat($.field), "}"),
seq($.identifier_preproc, $.number),
seq(
$.identifier_preproc,
"{",
$.line_continuation,
repeat($.field),
"}",
),
seq(
/[a-zA-Z_]*[a-z][a-zA-Z]*/,
"(",
repeat(seq($.identifier, optional(","))),
")",
"(",
$.expr,
")",
),
seq(
$.identifier_preproc,
$.line_continuation,
repeat(
seq(
optional("("),
optional(choice($._type, $.type_identifier)),
optional(")"),
choice($.method_identifier, $.lval),
$.lval,
",",
optional($.line_continuation),
$.line_continuation,
),
),
seq(
optional("("),
optional(choice($._type, $.type_identifier)),
optional(")"),
$.expr,
/\s/,
$.lval,
),
/\s/,
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"_" @keyword
"true" @constant
"false" @constant
(direction) @constant
(direction) @keyword
(number) @number
(bit_type) @type
(varbit_type) @type
Expand Down
184 changes: 100 additions & 84 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4ee5998

Please sign in to comment.