about summary refs log tree commit diff stats
path: root/tree-sitter/dsk/test-build/grammar.js
blob: 697a76db6a6bc64421c69beaa9d3ce4ef554c60d (plain) (blame)
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
43
44
45
46
47
48
/**
 * Simple test grammar for build system verification
 */

module.exports = grammar({
  name: 'test_lang',

  word: $ => $.identifier,

  rules: {
    // Root rule
    source_file: $ => repeat(choice($.statement, $.expression)),

    // Basic tokens
    identifier: $ => /[a-zA-Z_][a-zA-Z0-9_]*/,
    number: $ => /\d+/,
    string: $ => /"[^"]*"/,

    // Expressions
    expression: $ => choice(
      $.identifier,
      $.number,
      $.string
    ),

    // Statements
    statement: $ => choice(
      $.variable_declaration
    ),

    // Variable declaration
    variable_declaration: $ => seq(
      'let',
      $.identifier,
      '=',
      $.expression,
      ';'
    ),

    // Comments
    line_comment: $ => seq('//', /[^\n]*/)
  },

  extras: $ => [
    /\s/,
    $.line_comment
  ]
});