Skip to content

Commit

Permalink
feat: add expr, fix conn reference
Browse files Browse the repository at this point in the history
  • Loading branch information
ravsii committed Oct 1, 2024
1 parent 28bd56e commit 7da87e5
Show file tree
Hide file tree
Showing 8 changed files with 1,255 additions and 4,056 deletions.
38 changes: 25 additions & 13 deletions grammar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const PREC = {
connection: 100,
conn_identifier: 90,
identifier: 50,
};

const newline = /\n/;
Expand All @@ -27,17 +28,20 @@ module.exports = grammar({
),

declaration: $ => seq(
optional("("),
choice(
$.connection_refference,
$.expr,
),
repeat(field("label", $.label)),
terminator,
),

expr: $ => seq(
field("identifier", $.identifier),
rseq(
field("connection", $.connection),
field("identifier", $.identifier),
),
optional(")"),
optional(field("conn_identifier", $.connection_identifier)),
repeat(field("field", seq(".", $.field))),
repeat(field("label", $.label)),
terminator,
),

connection: _ => token(prec(PREC.connection, choice(
Expand All @@ -46,16 +50,24 @@ module.exports = grammar({
/-+>/,
/--+/,
))),
connection_identifier: _ => token(seq(
"[", /\d+/, "]",
)),
label: _ => seq(":", /.*/),

identifier: $ => $._ident,
field: $ => $._ident,
connection_refference: $ => seq(
"(",
$.expr,
")",
field("connection_identifier", $.connection_identifier),
optional($._fields),
),
connection_identifier: _ => token(seq("[", /\d+/, "]",)),

_ident: $ => seq($._ident_base, rseq(/[\s\-]+/, $._ident_base)),
_ident_base: _ => /[\p{L}\d\'_]+/,
identifier: $ => prec.left(-1, seq(
$._ident,
optional($._fields),
)),
_fields: $ => r1seq(".", field("field", $.identifier)),
_ident: $ => seq($._ident_base, rseq(/[\s\-\'_]+/, $._ident_base)),
_ident_base: _ => /[\p{L}\d]+/,

comment: _ => token(seq('#', /.*/)),
}
Expand Down
230 changes: 131 additions & 99 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 7da87e5

Please sign in to comment.