-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.js
43 lines (28 loc) · 1005 Bytes
/
grammar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/// <reference types="tree-sitter-cli/dsl" />
// @ts-check
module.exports = grammar({
name: 'nuf',
word: $ => $.identifier,
rules: {
source_file: $ => repeat($._statement),
_statement: $ => seq($._expression, $.delimiter),
_expression: $ => choice(
$.custom_name,
$.identifier,
$.function_call,
$.string,
$.binary_expression,
),
binary_expression: $ => choice(
prec.left(1, seq($._expression, 'inside', $._expression))
),
delimiter: _ => choice(';', ',', ':'),
bracket: _ => choice('(', ')', '{', '}'),
string: _ => seq('"', /[a-zA-Z0-9_ ]*/, '"'),
hash_block: $ => seq($.bracket, $.string, $.delimiter, $.string, $.delimiter, $.bracket),
function_call: $ => seq($.identifier, $.bracket, repeat($._function_call_argument), $.bracket),
_function_call_argument: $ => choice($.string, $.hash_block, $.delimiter),
custom_name: _ => seq('--', /[a-zA-Z0-9_]+/),
identifier: _ => /[a-z_]+/,
}
});