feat(lang): complete extends to modifies keyword migration

This commit completes the migration started in the previous commit,
updating all remaining files:

- Lexer: Changed token from Extends to Modifies
- Parser: Updated lalrpop grammar rules and AST field names
- AST: Renamed Schedule.extends field to modifies
- Grammar: Updated tree-sitter grammar.js
- Tree-sitter: Regenerated parser.c and node-types.json
- Examples: Updated baker-family work schedules
- Tests: Updated schedule composition tests and corpus
- Docs: Updated all reference documentation and tutorials
- Validation: Updated error messages and validation logic
- Package: Bumped version to 0.3.1 in all package manifests

All 554 tests pass.
This commit is contained in:
2026-02-16 22:55:04 +00:00
parent 2c898347ee
commit 47fafdc2bf
109 changed files with 5045 additions and 41939 deletions

View File

@@ -1,6 +1,8 @@
[workspace]
[package]
name = "tree-sitter-storybook"
version = "0.2.0"
version = "0.3.1"
description = "Tree-sitter grammar for Storybook narrative DSL"
authors = ["Storybook Contributors"]
license = "MIT"

View File

@@ -259,7 +259,7 @@ module.exports = grammar({
schedule_declaration: $ => seq(
'schedule',
field('name', $.identifier),
optional(seq('extends', field('extends', $.identifier))),
optional(seq('modifies', field('modifies', $.identifier))),
field('body', $.schedule_body)
),

View File

@@ -1,6 +1,6 @@
{
"name": "tree-sitter-storybook",
"version": "0.1.0",
"version": "0.3.1",
"description": "Tree-sitter grammar for Storybook narrative DSL",
"main": "bindings/node",
"types": "bindings/node",

View File

@@ -1,4 +1,5 @@
{
"$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json",
"name": "storybook",
"word": "identifier",
"rules": {
@@ -1294,11 +1295,11 @@
"members": [
{
"type": "STRING",
"value": "extends"
"value": "modifies"
},
{
"type": "FIELD",
"name": "extends",
"name": "modifies",
"content": {
"type": "SYMBOL",
"name": "identifier"
@@ -3086,6 +3087,6 @@
"precedences": [],
"externals": [],
"inline": [],
"supertypes": []
}
"supertypes": [],
"reserved": {}
}

View File

@@ -1367,7 +1367,7 @@
}
]
},
"extends": {
"modifies": {
"multiple": false,
"required": false,
"types": [
@@ -1444,6 +1444,7 @@
{
"type": "source_file",
"named": true,
"root": true,
"fields": {},
"children": {
"multiple": true,
@@ -2087,7 +2088,8 @@
},
{
"type": "block_comment",
"named": true
"named": true,
"extra": true
},
{
"type": "character",
@@ -2121,10 +2123,6 @@
"type": "enum",
"named": false
},
{
"type": "extends",
"named": false
},
{
"type": "fail_always",
"named": false
@@ -2175,12 +2173,17 @@
},
{
"type": "line_comment",
"named": true
"named": true,
"extra": true
},
{
"type": "location",
"named": false
},
{
"type": "modifies",
"named": false
},
{
"type": "not",
"named": false

File diff suppressed because it is too large Load Diff

View File

@@ -13,12 +13,16 @@ extern "C" {
#define ts_builtin_sym_end 0
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
typedef uint16_t TSStateId;
#ifndef TREE_SITTER_API_H_
typedef uint16_t TSStateId;
typedef uint16_t TSSymbol;
typedef uint16_t TSFieldId;
typedef struct TSLanguage TSLanguage;
typedef struct TSLanguageMetadata {
uint8_t major_version;
uint8_t minor_version;
uint8_t patch_version;
} TSLanguageMetadata;
#endif
typedef struct {
@@ -27,10 +31,11 @@ typedef struct {
bool inherited;
} TSFieldMapEntry;
// Used to index the field and supertype maps.
typedef struct {
uint16_t index;
uint16_t length;
} TSFieldMapSlice;
} TSMapSlice;
typedef struct {
bool visible;
@@ -48,6 +53,7 @@ struct TSLexer {
uint32_t (*get_column)(TSLexer *);
bool (*is_at_included_range_start)(const TSLexer *);
bool (*eof)(const TSLexer *);
void (*log)(const TSLexer *, const char *, ...);
};
typedef enum {
@@ -79,6 +85,12 @@ typedef struct {
uint16_t external_lex_state;
} TSLexMode;
typedef struct {
uint16_t lex_state;
uint16_t external_lex_state;
uint16_t reserved_word_set_id;
} TSLexerMode;
typedef union {
TSParseAction action;
struct {
@@ -87,8 +99,13 @@ typedef union {
} entry;
} TSParseActionEntry;
typedef struct {
int32_t start;
int32_t end;
} TSCharacterRange;
struct TSLanguage {
uint32_t version;
uint32_t abi_version;
uint32_t symbol_count;
uint32_t alias_count;
uint32_t token_count;
@@ -104,13 +121,13 @@ struct TSLanguage {
const TSParseActionEntry *parse_actions;
const char * const *symbol_names;
const char * const *field_names;
const TSFieldMapSlice *field_map_slices;
const TSMapSlice *field_map_slices;
const TSFieldMapEntry *field_map_entries;
const TSSymbolMetadata *symbol_metadata;
const TSSymbol *public_symbol_map;
const uint16_t *alias_map;
const TSSymbol *alias_sequences;
const TSLexMode *lex_modes;
const TSLexerMode *lex_modes;
bool (*lex_fn)(TSLexer *, TSStateId);
bool (*keyword_lex_fn)(TSLexer *, TSStateId);
TSSymbol keyword_capture_token;
@@ -124,15 +141,48 @@ struct TSLanguage {
void (*deserialize)(void *, const char *, unsigned);
} external_scanner;
const TSStateId *primary_state_ids;
const char *name;
const TSSymbol *reserved_words;
uint16_t max_reserved_word_set_size;
uint32_t supertype_count;
const TSSymbol *supertype_symbols;
const TSMapSlice *supertype_map_slices;
const TSSymbol *supertype_map_entries;
TSLanguageMetadata metadata;
};
static inline bool set_contains(const TSCharacterRange *ranges, uint32_t len, int32_t lookahead) {
uint32_t index = 0;
uint32_t size = len - index;
while (size > 1) {
uint32_t half_size = size / 2;
uint32_t mid_index = index + half_size;
const TSCharacterRange *range = &ranges[mid_index];
if (lookahead >= range->start && lookahead <= range->end) {
return true;
} else if (lookahead > range->end) {
index = mid_index;
}
size -= half_size;
}
const TSCharacterRange *range = &ranges[index];
return (lookahead >= range->start && lookahead <= range->end);
}
/*
* Lexer Macros
*/
#ifdef _MSC_VER
#define UNUSED __pragma(warning(suppress : 4101))
#else
#define UNUSED __attribute__((unused))
#endif
#define START_LEXER() \
bool result = false; \
bool skip = false; \
UNUSED \
bool eof = false; \
int32_t lookahead; \
goto start; \
@@ -148,6 +198,17 @@ struct TSLanguage {
goto next_state; \
}
#define ADVANCE_MAP(...) \
{ \
static const uint16_t map[] = { __VA_ARGS__ }; \
for (uint32_t i = 0; i < sizeof(map) / sizeof(map[0]); i += 2) { \
if (map[i] == lookahead) { \
state = map[i + 1]; \
goto next_state; \
} \
} \
}
#define SKIP(state_value) \
{ \
skip = true; \
@@ -166,7 +227,7 @@ struct TSLanguage {
* Parse Table Macros
*/
#define SMALL_STATE(id) id - LARGE_STATE_COUNT
#define SMALL_STATE(id) ((id) - LARGE_STATE_COUNT)
#define STATE(id) id
@@ -176,7 +237,7 @@ struct TSLanguage {
{{ \
.shift = { \
.type = TSParseActionTypeShift, \
.state = state_value \
.state = (state_value) \
} \
}}
@@ -184,7 +245,7 @@ struct TSLanguage {
{{ \
.shift = { \
.type = TSParseActionTypeShift, \
.state = state_value, \
.state = (state_value), \
.repetition = true \
} \
}}
@@ -197,14 +258,15 @@ struct TSLanguage {
} \
}}
#define REDUCE(symbol_val, child_count_val, ...) \
{{ \
.reduce = { \
.type = TSParseActionTypeReduce, \
.symbol = symbol_val, \
.child_count = child_count_val, \
__VA_ARGS__ \
}, \
#define REDUCE(symbol_name, children, precedence, prod_id) \
{{ \
.reduce = { \
.type = TSParseActionTypeReduce, \
.symbol = symbol_name, \
.child_count = children, \
.dynamic_precedence = precedence, \
.production_id = prod_id \
}, \
}}
#define RECOVER() \

View File

@@ -26,10 +26,10 @@ schedule WorkDay {
value: (identifier)))))))
==================
Schedule with extends
Schedule with modifies
==================
schedule BakerDay extends WorkDay {
schedule BakerDay modifies WorkDay {
block early_prep {
05:00 -> 08:00
}
@@ -41,7 +41,7 @@ schedule BakerDay extends WorkDay {
(declaration
(schedule_declaration
name: (identifier)
extends: (identifier)
modifies: (identifier)
body: (schedule_body
(schedule_block
name: (identifier)
@@ -53,7 +53,7 @@ schedule BakerDay extends WorkDay {
Schedule with override
==================
schedule CustomDay extends BaseDay {
schedule CustomDay modifies BaseDay {
override work {
06:00 -> 14:00
intensity: "high"
@@ -66,7 +66,7 @@ schedule CustomDay extends BaseDay {
(declaration
(schedule_declaration
name: (identifier)
extends: (identifier)
modifies: (identifier)
body: (schedule_body
(override_block
name: (identifier)