grammar.js를 parser 기준 규칙으로 정합화

This commit is contained in:
2026-08-17 04:05:15 +09:00
parent 88b0c83538
commit fe5f853feb
+11 -2
View File
@@ -1,5 +1,5 @@
// Minimal Tree-sitter grammar for Ferro syntax highlighting in Zed. // Minimal Tree-sitter grammar for Ferro syntax highlighting in Zed.
// This intentionally models lexical structure rather than full Ferro semantics. // `parser.c` is normative; this file is the editor-copy.
module.exports = grammar({ module.exports = grammar({
name: "ferro", name: "ferro",
@@ -10,6 +10,8 @@ module.exports = grammar({
rules: { rules: {
source_file: $ => repeat(choice( source_file: $ => repeat(choice(
$.unit_decl,
$.import_decl,
$.line_comment, $.line_comment,
$.block_comment, $.block_comment,
$.string_literal, $.string_literal,
@@ -25,6 +27,11 @@ module.exports = grammar({
line_comment: _ => token(seq("//", /[^\n]*/)), line_comment: _ => token(seq("//", /[^\n]*/)),
unit_decl: $ => seq("unit", $.dotted_identifier, ";"),
import_decl: $ => seq("import", $.dotted_identifier,
optional(seq("as", $.identifier)), ";"),
// Ferro block comments may nest. Keeping this rule recursive makes syntax // Ferro block comments may nest. Keeping this rule recursive makes syntax
// highlighting follow the compiler lexer instead of flattening nested /* */. // highlighting follow the compiler lexer instead of flattening nested /* */.
block_comment: $ => seq( block_comment: $ => seq(
@@ -92,9 +99,11 @@ module.exports = grammar({
"+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=",
"==", "!=", "<=", ">=", "<<", ">>", "->", "=>", "..", "==", "!=", "<=", ">=", "<<", ">>", "->", "=>", "..",
"+%", "-%", "*%", "+%", "-%", "*%",
"+", "-", "*", "/", "%", "=", "<", ">", "&", "|", "^", "~", "!", "?", "+", "-", "*", "/", "%", "=", "<", ">", "&", "|", "^", "!", "?",
)), )),
dotted_identifier: _ => /[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*/,
punctuation: _ => token(choice( punctuation: _ => token(choice(
"(", ")", "{", "}", "[", "]", ",", ";", ":", ".", "(", ")", "{", "}", "[", "]", ",", ";", ":", ".",
)), )),