69 lines
1.9 KiB
JavaScript
69 lines
1.9 KiB
JavaScript
module.exports = grammar({
|
|
name: 'Groovy',
|
|
conflicts: $ => [
|
|
[$.qualified_name]
|
|
],
|
|
rules: {
|
|
// TODO: add the actual grammar rules
|
|
source_file: $ => seq(
|
|
optional($._shebang_comment),
|
|
optional(seq($.package_declaration, repeat($._sep))),
|
|
optional($._script_statements)
|
|
),
|
|
static_modifier: $ => 'static',
|
|
_shebang_comment: $ => token.immediate(/#!.*\n/),
|
|
_script_statements: $ => seq(
|
|
$._script_statement,
|
|
repeat(
|
|
seq(
|
|
$._sep,
|
|
$._script_statement
|
|
)
|
|
),
|
|
repeat($._sep)
|
|
),
|
|
import_declaration: $ => seq(
|
|
'import',
|
|
optional($.static_modifier),
|
|
field('name',
|
|
seq($.qualified_name,
|
|
optional($.wildcard_import)
|
|
)
|
|
)
|
|
),
|
|
wildcard_import: $ => seq('.','*'),
|
|
package_declaration: $ => seq(
|
|
optional($._annotations),
|
|
'package',
|
|
field('name', $.qualified_name)
|
|
),
|
|
_annotations: $ => seq(
|
|
$.annotation,
|
|
repeat($.annotation)
|
|
),
|
|
annotation: $ => seq(
|
|
'@',
|
|
$.qualified_name
|
|
),
|
|
_script_statement: $ => choice(
|
|
$.import_declaration,
|
|
$.statement,
|
|
$.method_declaration
|
|
),
|
|
expression: $ => choice(
|
|
$.qualified_name
|
|
),
|
|
qualified_name: $ => seq(
|
|
$.identifier,
|
|
repeat(seq('.', $.identifier))
|
|
),
|
|
identifier: $ => /[A-Za-z_][A-Za-z_0-9]*/,
|
|
statement: $ => choice(
|
|
$.expression
|
|
),
|
|
method_declaration: $ => seq('def', field('name', $.identifier)),
|
|
_sep: $ => choice('\n', ';'),
|
|
word: $ => $.identifier
|
|
}
|
|
});
|