1
0
This repository has been archived on 2025-03-06. You can view files and clone it, but cannot push or open issues or pull requests.

52 lines
1.0 KiB
JavaScript

module.exports = grammar({
name: 'minizinc',
extras: $ => [/\s/, $.line_comment, $.block_comment],
rules: {
source_file: $ => seq(sepBy(';', $._items), optional(';')),
_items: $ => choice(
$.assignment_item,
// TODO: Other statements types
),
assignment_item: $ => seq(
field('name', $.identifier),
'=',
field('expr', $._expression)
),
_expression: $ => choice(
$._literal,
// TODO: Other expression types
),
_literal: $ => choice(
// TODO: absent,
$.boolean_literal,
// TODO: float_literal,
// TODO: integer_literal,
// TODO: string_literal,
),
boolean_literal: $ => choice('true', 'false'),
identifier: $ => /[A-Za-z][A-Za-z0-9_]*/,
line_comment: $ => token(seq('%', /.*/)),
block_comment: $ => token(seq('/*', /[^*]*\*+([^/*][^*]*\*+)*/, '/')),
}
});
function sepBy1(sep, rule) {
return seq(rule, repeat(seq(sep, rule)))
}
function sepBy(sep, rule) {
return optional(sepBy1(sep, rule))
}