Add simple atoms
This commit is contained in:
parent
30b2e50367
commit
e7ba93870e
5 changed files with 530 additions and 37 deletions
35
grammar.js
35
grammar.js
|
|
@ -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("\\", '"'),
|
||||
)
|
||||
)
|
||||
),
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue