grammar.js
· 812 B · JavaScript
Raw
Playground
/**
* @file Nova grammar
* @author nouveau
*/
module.exports = grammar({
name: "nova",
rules: {
program: $ => repeat($.rule),
rule: $ => seq(
'|',
repeat($.rule_lhs),
'|',
optional('\n'),
repeat($.rule_rhs)
),
rule_lhs: $ => seq(
$.stack,
optional($.anticonsumption_suffix),
optional('\n')
),
rule_rhs: $ => seq(
$.stack,
optional('\n')
),
stack: $ => seq(
$.stack_label,
repeat(choice($.variable, $.term)),
),
stack_label: $ => seq(
':',
choice($.port, repeat($.label)),
':'
),
variable: $ => seq('$', $.term),
port: $ => seq('@', $.label),
label: $ => /[^\n\r\t |:?@]+/,
term: $ => /[^\n\r\t |:]+/,
anticonsumption_suffix: $ => '?',
}
});
| 1 | /** |
| 2 | * @file Nova grammar |
| 3 | * @author nouveau |
| 4 | */ |
| 5 | |
| 6 | module.exports = grammar({ |
| 7 | name: "nova", |
| 8 | |
| 9 | rules: { |
| 10 | program: $ => repeat($.rule), |
| 11 | |
| 12 | rule: $ => seq( |
| 13 | '|', |
| 14 | repeat($.rule_lhs), |
| 15 | '|', |
| 16 | optional('\n'), |
| 17 | repeat($.rule_rhs) |
| 18 | ), |
| 19 | |
| 20 | rule_lhs: $ => seq( |
| 21 | $.stack, |
| 22 | optional($.anticonsumption_suffix), |
| 23 | optional('\n') |
| 24 | ), |
| 25 | |
| 26 | rule_rhs: $ => seq( |
| 27 | $.stack, |
| 28 | optional('\n') |
| 29 | ), |
| 30 | |
| 31 | stack: $ => seq( |
| 32 | $.stack_label, |
| 33 | repeat(choice($.variable, $.term)), |
| 34 | ), |
| 35 | |
| 36 | stack_label: $ => seq( |
| 37 | ':', |
| 38 | choice($.port, repeat($.label)), |
| 39 | ':' |
| 40 | ), |
| 41 | |
| 42 | variable: $ => seq('$', $.term), |
| 43 | port: $ => seq('@', $.label), |
| 44 | label: $ => /[^\n\r\t |:?@]+/, |
| 45 | term: $ => /[^\n\r\t |:]+/, |
| 46 | anticonsumption_suffix: $ => '?', |
| 47 | } |
| 48 | }); |
| 49 |