feat(tree-sitter): add Tree-sitter grammar for Storybook DSL

This commit is contained in:
2026-02-09 22:06:25 +00:00
parent 734eb93f12
commit b100ded3d3
27 changed files with 13383 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
; Bracket matching for Storybook DSL
; Curly braces
("{" @open "}" @close) @bracket
; Parentheses
("(" @open ")" @close) @bracket
; Square brackets
("[" @open "]" @close) @bracket
; Prose blocks (special bracket matching for --- markers)
; Note: Both markers are the same node type
(prose_block
(prose_marker) @open
(prose_marker) @close) @bracket

View File

@@ -0,0 +1,153 @@
; Highlights query for Storybook DSL
; Maps grammar nodes to standard highlight groups
; Comments
(line_comment) @comment.line
(block_comment) @comment.block
; Keywords - Declaration keywords
[
"character"
"template"
"life_arc"
"schedule"
"behavior"
"institution"
"relationship"
"location"
"species"
"enum"
"state"
] @keyword.declaration
; Keywords - Control flow and modifiers
[
"and"
"or"
"not"
"on"
"enter"
"strict"
] @keyword.control
; Keywords - Import/module
[
"use"
"include"
"from"
] @keyword.import
; Keywords - Special
[
"as"
"self"
"other"
"remove"
"append"
"is"
] @keyword.special
; Boolean literals
[
"true"
"false"
] @constant.builtin.boolean
; Numbers
(integer) @constant.numeric.integer
(float) @constant.numeric.float
(time) @constant.numeric.time
(duration) @constant.numeric.duration
; Strings
(string) @string
; Identifiers in different contexts
(character name: (identifier) @type.character)
(template name: (identifier) @type.template)
(life_arc name: (identifier) @type.life_arc)
(schedule name: (identifier) @type.schedule)
(behavior name: (identifier) @type.behavior)
(institution name: (identifier) @type.institution)
(relationship name: (identifier) @type.relationship)
(location name: (identifier) @type.location)
(species name: (identifier) @type.species)
(enum_declaration name: (identifier) @type.enum)
(arc_state name: (identifier) @type.state)
; Field names
(field name: (dotted_path) @property)
; Species reference
(character species: (identifier) @type.builtin)
; Paths and identifiers
(path) @namespace
(identifier) @variable
; Prose blocks - tag and content
(prose_block tag: (identifier) @tag)
(prose_block marker: (prose_marker) @punctuation.delimiter)
(prose_content) @markup.raw
; Operators
[
">"
">="
"<"
"<="
"->"
"is"
] @operator
; Punctuation
[
"{"
"}"
] @punctuation.bracket
[
"("
")"
] @punctuation.bracket
[
"["
"]"
] @punctuation.bracket
[
":"
"::"
";"
","
"."
".."
"*"
"?"
"@"
] @punctuation.delimiter
; Behavior tree nodes
(selector_node "?" @keyword.behavior.selector)
(sequence_node ">" @keyword.behavior.sequence)
(repeat_node "*" @keyword.behavior.repeat)
(action_node (identifier) @function.action)
; Transitions
(transition "->" @operator.transition)
(transition target: (identifier) @type.state)
; Schedule blocks
(schedule_block activity: (identifier) @function.activity)
; Override operations
(override "@" @keyword.override)
(override_op "remove" @keyword.override)
(override_op "append" @keyword.override)
; Template clause
(template_clause "from" @keyword.import)
; Error handling
(ERROR) @error

View File

@@ -0,0 +1,45 @@
; Indentation query for Storybook DSL
; Increase indent after opening braces
[
"{"
"("
"["
] @indent.begin
; Decrease indent before closing braces
[
"}"
")"
"]"
] @indent.end
; Special handling for prose blocks
(prose_block
marker: (prose_marker) @indent.begin
content: (_)
end: (_) @indent.end
)
; Block structures that should indent their contents
[
(block)
(character)
(template)
(life_arc)
(arc_state)
(schedule)
(schedule_block)
(behavior)
(institution)
(relationship)
(location)
(species)
(enum_declaration)
(selector_node)
(sequence_node)
(repeat_node)
] @indent.begin
; Dedent after semicolon at top level
(use_declaration ";" @indent.end)

View File

@@ -0,0 +1,12 @@
; Injections for embedded languages in Storybook
; Treat prose block content as Markdown
((prose_content) @injection.content
(#set! injection.language "markdown"))
; Alternative: If you want to be more specific and only inject for certain tags:
; ((prose_block
; tag: (identifier) @tag
; content: (_) @injection.content)
; (#match? @tag "^(description|backstory|narrative|details|notes)$")
; (#set! injection.language "markdown"))

View File

@@ -0,0 +1,57 @@
; Outline/symbols query for Storybook DSL
; Defines what symbols appear in the document outline
; Characters
(character
name: (identifier) @name
) @symbol.character
; Templates
(template
name: (identifier) @name
) @symbol.template
; Life arcs
(life_arc
name: (identifier) @name
) @symbol.life_arc
; Life arc states
(arc_state
name: (identifier) @name
) @symbol.state
; Schedules
(schedule
name: (identifier) @name
) @symbol.schedule
; Behaviors
(behavior
name: (identifier) @name
) @symbol.behavior
; Institutions
(institution
name: (identifier) @name
) @symbol.institution
; Relationships
(relationship
name: (identifier) @name
) @symbol.relationship
; Locations
(location
name: (identifier) @name
) @symbol.location
; Species
(species
name: (identifier) @name
) @symbol.species
; Enums
(enum_declaration
name: (identifier) @name
) @symbol.enum