Skip to content

Commit

Permalink
feat: finished text&code code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ravsii committed Nov 4, 2024
1 parent fdf4c4d commit f55ef42
Show file tree
Hide file tree
Showing 5 changed files with 1,857 additions and 1,066 deletions.
18 changes: 12 additions & 6 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const PREC = {
conn_identifier: 90,

block: 20,

label: 10,
};

const terminator = token(prec(PREC.term,
choice(/\n/, ';', '\0')));
const terminator = token(prec(PREC.term, choice(/\n/, ';', '\0')));

const opseq = (...x) => optional(seq(...x))
const opfield = (...x) => optional(field(...x))
Expand Down Expand Up @@ -63,15 +63,21 @@ module.exports = grammar({

block: $ => seq("{", repeat($.declaration), "}"),
label: $ => choice(
$._label_codeblock,
$.label_codeblock,
repeat1($._label_base),
token(seq('"', /.*/, '"')),
),

_label_codeblock: _ => choice(
seq(repeat1("|"), /[^\|]+/, repeat1("|")),
label_codeblock: $ => choice(
seq("|`", $._label_codeblock_lang, /[^`]*/, "`|"),
seq("|||", $._label_codeblock_lang, $._label_codeblock_body, "|||"),
seq("||", $._label_codeblock_lang, $._label_codeblock_body, "||"),
seq("|", $._label_codeblock_lang, /[^\|]+/, "|"),
),

_label_codeblock_lang: _ => token(/[a-zA-Z]+/),
_label_codeblock_body: _ => repeat1(seq(/.+/, /\s*/)),

_label_base: $ => choice(
$._ident_base,
token(prec(PREC.label, /[\\\:\.\-\%\_#&]+/)) // idk how to make it better
Expand All @@ -95,7 +101,7 @@ module.exports = grammar({
seq($._ident_base, rseq(/[\s\-\'_]+/, $._ident_base)), // normal
token("_"), // parent-ref
),
_ident_base: _ => /[\p{L}\d\/]+/,
_ident_base: _ => /[\p{L}\d\/\*]+/,


comment: _ => token(seq('#', /.*/)),
Expand Down
110 changes: 97 additions & 13 deletions src/grammar.json

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

31 changes: 31 additions & 0 deletions src/node-types.json

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

Loading

0 comments on commit f55ef42

Please sign in to comment.