28 lines
875 B
JavaScript
28 lines
875 B
JavaScript
/**
|
|
* @file Morphismbase grammar for tree-sitter
|
|
* @author Michael Sippel <senvas@exobiont.de>
|
|
* @license GPLv3
|
|
*/
|
|
|
|
/// <reference types="tree-sitter-cli/dsl" />
|
|
// @ts-check
|
|
|
|
module.exports = grammar({
|
|
name: "morphismbase",
|
|
|
|
rules: {
|
|
source_file: ($) => $.morphbase,
|
|
|
|
morphbase: ($) => seq($.include, repeat($.stmnt)),
|
|
include: ($) => seq("```", /([^\`]*)/, "```"),
|
|
stmnt: ($) => choice($.comment, $.def),
|
|
comment: ($) => prec.right(seq("/*", /([^\*]*)/, "*/")),
|
|
def: ($) => choice($.typedef, $.morphdef),
|
|
typedef: ($) => prec.right(seq("type", $.ident, "=", $.type, ";")),
|
|
morphdef: ($) => prec.right(seq("morph", $.ident, ":", $.type, "=", $.impl, ";")),
|
|
ident: ($) => /([a-zA-Z$][0-9a-zA-Z_\-]*)/,
|
|
type: ($) => /([^\`\=\;]*)/,
|
|
impl: ($) => seq("```", $.impl_c_code, "```"),
|
|
impl_c_code: (_) => /([^\`]*)/,
|
|
},
|
|
});
|