64 lines
1.8 KiB
JavaScript
64 lines
1.8 KiB
JavaScript
module.exports = grammar({
|
|
name: 'Groovy',
|
|
|
|
rules: {
|
|
// TODO: add the actual grammar rules
|
|
source_file: $ => seq(
|
|
optional($._shebang_comment),
|
|
optional(seq($.package_definition, repeat($._nl_semicolon))),
|
|
repeat(
|
|
choice(
|
|
seq(
|
|
$.import_statement,
|
|
repeat1($._nl_semicolon)
|
|
),
|
|
seq(
|
|
$.script_part,
|
|
repeat1($._nl_semicolon)
|
|
)
|
|
)
|
|
),
|
|
optional($.script_part)
|
|
),
|
|
import_statement: $ => seq(
|
|
'import',
|
|
optional('static'),
|
|
field('name',
|
|
seq(
|
|
$.identifier,
|
|
repeat(seq('.', $.identifier)),
|
|
optional(seq('.', '*')
|
|
)
|
|
)
|
|
)
|
|
),
|
|
_shebang_comment: $ => token.immediate(/#!.*\n/),
|
|
package_definition: $ => seq(
|
|
'package',
|
|
field('name', seq(
|
|
$.identifier,
|
|
repeat(seq('.', $.identifier))))
|
|
),
|
|
script_part: $ => choice(
|
|
$.statement,
|
|
$.method_declaration
|
|
),
|
|
expression: $ => choice(
|
|
$.path_expression
|
|
),
|
|
path_expression: $ => seq(
|
|
repeat(
|
|
seq($.identifier, '.')
|
|
),
|
|
$.identifier
|
|
),
|
|
identifier: $ => /[A-Za-z_][A-Za-z_0-9]*/,
|
|
statement: $ => choice(
|
|
$.expression
|
|
),
|
|
method_declaration: $ => seq('def', field('name', $.identifier)),
|
|
_nl_semicolon: $ => choice('\n', ';'),
|
|
word: $ => $.identifier
|
|
}
|
|
});
|