mirror of
https://github.com/elladunbar/tree-sitter-zanscript.git
synced 2025-11-05 15:19:55 -06:00
216 lines
3.2 KiB
JavaScript
216 lines
3.2 KiB
JavaScript
/// <reference types="tree-sitter-cli/dsl" />
|
|
// @ts-check
|
|
|
|
module.exports = grammar({
|
|
name: 'zanscript',
|
|
|
|
extras: $ => [
|
|
/\s/
|
|
],
|
|
|
|
word: $ => $.identifier,
|
|
|
|
rules: {
|
|
translation_unit: $ => repeat($._top_level_item),
|
|
|
|
_top_level_item: $ => choice(
|
|
$._directive,
|
|
$._command,
|
|
$._statement,
|
|
),
|
|
|
|
_directive: $ => choice(
|
|
$.define,
|
|
$.include,
|
|
),
|
|
|
|
define: $ => seq(
|
|
choice(
|
|
'DEFINE',
|
|
'define',
|
|
'Define',
|
|
),
|
|
$.match,
|
|
$.match,
|
|
),
|
|
|
|
include: $ => seq(
|
|
choice(
|
|
'INCLUDE',
|
|
'include',
|
|
'Include',
|
|
),
|
|
$.identifier,
|
|
),
|
|
|
|
_command: $ => choice(
|
|
$.action,
|
|
$._control,
|
|
),
|
|
|
|
action: $ => seq(
|
|
choice(
|
|
'ACTION',
|
|
'action',
|
|
'Action',
|
|
),
|
|
$.identifier,
|
|
$.block,
|
|
choice(
|
|
'COMPLETE',
|
|
'complete',
|
|
'Complete',
|
|
),
|
|
),
|
|
|
|
_control: $ => choice(
|
|
$.branch,
|
|
$.loop,
|
|
),
|
|
|
|
branch: $ => seq(
|
|
choice(
|
|
'IF',
|
|
'if',
|
|
'If',
|
|
),
|
|
$.comparison,
|
|
$.block,
|
|
optional(
|
|
seq(
|
|
choice(
|
|
'ELSE',
|
|
'else',
|
|
'Else',
|
|
),
|
|
$.block,
|
|
),
|
|
),
|
|
choice(
|
|
'ENDIF',
|
|
'endif',
|
|
'Endif',
|
|
'EndIf',
|
|
),
|
|
),
|
|
|
|
loop: $ => seq(
|
|
choice(
|
|
'WHILE',
|
|
'while',
|
|
'While',
|
|
),
|
|
$.comparison,
|
|
$.block,
|
|
choice(
|
|
'ENDWHILE',
|
|
'endwhile',
|
|
'Endwhile',
|
|
),
|
|
),
|
|
|
|
comparison: $ => seq(
|
|
$._argument,
|
|
choice(
|
|
'<',
|
|
'>',
|
|
'=',
|
|
),
|
|
$._argument,
|
|
),
|
|
|
|
block: $ => repeat1(
|
|
choice(
|
|
$._statement,
|
|
$._command,
|
|
),
|
|
),
|
|
|
|
_statement: $ => choice(
|
|
$.function,
|
|
$.assignment,
|
|
$.comment,
|
|
),
|
|
|
|
function: $ => seq(
|
|
field("name", $.identifier),
|
|
'(',
|
|
optional(
|
|
repeat(
|
|
seq(
|
|
$._argument,
|
|
',',
|
|
),
|
|
),
|
|
),
|
|
optional(
|
|
$._argument,
|
|
),
|
|
')',
|
|
),
|
|
|
|
_argument: $ => choice(
|
|
$.identifier,
|
|
$.number,
|
|
$.string,
|
|
$.variable,
|
|
),
|
|
|
|
assignment: $ => seq(
|
|
$.variable,
|
|
'=',
|
|
$._expression,
|
|
),
|
|
|
|
_expression: $ => seq(
|
|
$._argument,
|
|
optional(
|
|
repeat(
|
|
seq(
|
|
choice(
|
|
'+',
|
|
'-',
|
|
'*',
|
|
'/',
|
|
),
|
|
$._argument,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
|
|
comment: $ => seq(
|
|
'#',
|
|
/.*/,
|
|
),
|
|
|
|
variable: $ => /@[a-zA-Z0-9_]+/,
|
|
|
|
match: $ => /[a-zA-Z0-9_.]+/,
|
|
|
|
identifier: $ => /[a-zA-Z_][a-zA-Z0-9_]*/,
|
|
|
|
number: $ => /\d+(\.\d+)?/,
|
|
|
|
string: $ => /['"].*['"]/,
|
|
|
|
//builtin: $ => choice(
|
|
// "AUTOREFERENCE",
|
|
// "FEEDER",
|
|
// "LIGHTS",
|
|
// "LOAD",
|
|
// "LOG",
|
|
// "LOGAPPEND",
|
|
// "LOGCREATE",
|
|
// "LOGDATA",
|
|
// "LOGFIELD",
|
|
// "LOGRUN",
|
|
// "PANLIGHT",
|
|
// "PICTURE",
|
|
// "SET",
|
|
// "SETCOLOUR",
|
|
// "SETLIGHT",
|
|
//
|
|
//)
|
|
}
|
|
});
|