Add simple atoms

This commit is contained in:
Bruno BELANYI 2022-06-01 19:33:42 +02:00
parent 30b2e50367
commit e7ba93870e
5 changed files with 530 additions and 37 deletions

View file

@ -2,8 +2,39 @@ module.exports = grammar({
name: "tiger",
rules: {
// TODO: add the actual grammar rules
source_file: $ => 'hello'
source_file: ($) => choice(
$._expr,
),
_expr: ($) => choice(
"nil",
$.integer_literal,
$.string_literal,
),
integer_literal: (_) => /[0-9]+/,
string_literal: ($) => seq(
'"',
repeat(choice($.escape_sequence, /[^"\\]+/)),
'"',
),
escape_sequence: (_) => token.immediate(
seq(
"\\",
choice(
// Special escapes
choice("a", "b", "f", "n", "r", "t", "v"),
// Octal
/[0-3][0-7]{2}/,
// Hexadecimal
seq("x", /[0-9a-fA-F]{2}/),
// Escaped characters
choice("\\", '"'),
)
)
),
}
});