|
1 | | -# Keyword Registry Sync Workflow |
| 1 | +# Keyword Registry Sync Workflow |
2 | 2 |
|
3 | 3 | ## Overview |
4 | 4 |
|
5 | | -This GitHub workflow automatically validates that the keyword registry in ree-sitter-multilingual is kept in sync with the reference implementation in multilingual. |
6 | | - |
7 | | -The workflow: |
8 | | -1. Clones both repositories |
9 | | -2. Compares the keyword definitions |
10 | | -3. Reports any mismatches, missing constructs, or language gaps |
11 | | -4. Posts detailed feedback on pull requests |
12 | | -5. Generates a JSON report artifact |
13 | | - |
14 | | -## How It Works |
15 | | - |
16 | | -### Trigger Events |
17 | | - |
18 | | -The workflow runs automatically on: |
19 | | -- **Push** to main/dev branches when data/keywords.yaml changes |
20 | | -- **Pull request** to main when data/keywords.yaml changes |
21 | | -- Manual trigger via GitHub Actions interface |
22 | | - |
23 | | -### Validation Checks |
24 | | - |
25 | | -The workflow performs these checks: |
26 | | - |
27 | | -1. **Missing Constructs** — Constructs defined in the reference but not in tree-sitter-multilingual |
28 | | -2. **Extra Constructs** — Constructs in tree-sitter-multilingual not in the reference |
29 | | -3. **Keyword Mismatches** — Values that differ between reference and target |
30 | | -4. **Language Gaps** — Languages supported by reference but not in tree-sitter-multilingual |
31 | | -5. **Coverage Calculation** — Overall percentage of keywords properly synced |
32 | | - |
33 | | -## Reference Implementation Mapping |
34 | | - |
35 | | -The workflow maps semantic IDs from the reference keywords.json to construct names: |
36 | | - |
37 | | -| Semantic ID | Construct Name | |
38 | | -|---|---| |
39 | | -| COND_IF | if | |
40 | | -| COND_ELSE | else | |
41 | | -| COND_ELIF | elif | |
42 | | -| LOOP_FOR | for | |
43 | | -| LOOP_WHILE | while | |
44 | | -| LOOP_BREAK | break | |
45 | | -| LOOP_CONTINUE | continue | |
46 | | -| FUNC_DEF | def | |
47 | | -| CLASS_DEF | class | |
48 | | -| RETURN | return | |
49 | | -| LET_VAR | let | |
50 | | -| IMPORT | import | |
51 | | -| FROM | from | |
52 | | -| AS | as | |
53 | | -| PASS | pass | |
54 | | -| TRUE | true | |
55 | | -| FALSE | false | |
56 | | -| NONE | none | |
57 | | -| AND | and | |
58 | | -| OR | or | |
59 | | -| NOT | not | |
60 | | -| IN | in | |
61 | | -| IS | is | |
62 | | -| PRINT | print | |
63 | | -| RANGE | range | |
64 | | -| LEN | len | |
65 | | -| TYPE | type | |
66 | | - |
67 | | -## PR Feedback |
68 | | - |
69 | | -When you open a pull request with keyword changes, the workflow posts a comment like: |
70 | | - |
71 | | -\\\ |
| 5 | +This workflow validates that `data/keywords.yaml` stays in sync with the reference implementation in `multilingualprogramming/multilingual`. |
| 6 | + |
| 7 | +It checks: |
| 8 | + |
| 9 | +1. Missing constructs |
| 10 | +2. Extra constructs |
| 11 | +3. Keyword mismatches |
| 12 | +4. Missing language coverage |
| 13 | +5. Overall sync coverage |
| 14 | + |
| 15 | +## Trigger Events |
| 16 | + |
| 17 | +The workflow runs on: |
| 18 | + |
| 19 | +- Pushes to `main` or `dev` when `data/keywords.yaml` changes |
| 20 | +- Pull requests to `main` when `data/keywords.yaml` changes |
| 21 | +- Manual execution from GitHub Actions |
| 22 | + |
| 23 | +## What It Compares |
| 24 | + |
| 25 | +The workflow compares this repository's `data/keywords.yaml` against the reference file: |
| 26 | + |
| 27 | +- `multilingual/multilingualprogramming/resources/usm/keywords.json` |
| 28 | + |
| 29 | +It maps semantic IDs from the reference implementation to construct names used in this grammar. |
| 30 | + |
| 31 | +## Example PR Feedback |
| 32 | + |
| 33 | +Success: |
| 34 | + |
| 35 | +```text |
72 | 36 | ## Keyword Registry Sync Report |
73 | 37 |
|
74 | | -✅ All keywords are in sync with the reference implementation. |
| 38 | +All keywords are in sync with the reference implementation. |
75 | 39 |
|
76 | | -**Coverage**: 100% |
77 | | -\\\ |
| 40 | +Coverage: 100% |
| 41 | +``` |
78 | 42 |
|
79 | | -If there are issues: |
| 43 | +Failure: |
80 | 44 |
|
81 | | -\\\ |
| 45 | +```text |
82 | 46 | ## Keyword Registry Sync Report |
83 | 47 |
|
84 | | -⚠️ Keyword registry sync issues detected. |
| 48 | +Keyword registry sync issues detected. |
85 | 49 |
|
86 | 50 | ### Missing Constructs |
87 | 51 | - break |
88 | 52 | - continue |
89 | 53 |
|
90 | 54 | ### Language Mismatches |
91 | | -Found 3 mismatches: |
92 | | -- if (ja): Expected 'もし', got '如果' |
93 | | -- class (fr): Expected 'classe', got 'class' |
94 | | -- ... and 1 more |
| 55 | +- if (ja): expected 'もし', got '如果' |
| 56 | +- class (fr): expected 'classe', got 'class' |
95 | 57 |
|
96 | | -**Coverage**: 95% |
97 | | -\\\ |
| 58 | +Coverage: 95% |
| 59 | +``` |
98 | 60 |
|
99 | 61 | ## Running Locally |
100 | 62 |
|
101 | | -To validate keywords locally before pushing: |
102 | | - |
103 | | -\\\ash |
104 | | -# Install dependencies |
| 63 | +```bash |
105 | 64 | pip install pyyaml |
106 | 65 |
|
107 | | -# Clone reference implementation |
108 | 66 | git clone https://github.com/multilingualprogramming/multilingual ../multilingual |
109 | 67 |
|
110 | | -# Run sync validation |
111 | 68 | python .github/scripts/sync-keywords.py \ |
112 | 69 | --reference ../multilingual/multilingualprogramming/resources/usm/keywords.json \ |
113 | 70 | --target data/keywords.yaml \ |
114 | 71 | --report sync-report.json |
115 | 72 |
|
116 | | -# Check results |
117 | 73 | python .github/scripts/check-sync-results.py sync-report.json |
118 | 74 |
|
119 | | -# View detailed report |
120 | 75 | cat sync-report.json | jq . |
121 | | -\\\ |
122 | | - |
123 | | -## Updating Keywords |
124 | | - |
125 | | -When updating data/keywords.yaml: |
126 | | - |
127 | | -1. **Check the reference** — Look at the reference implementation in multilingual/multilingualprogramming/resources/usm/keywords.json for the canonical keywords |
128 | | -2. **Sync across languages** — Ensure all 17 supported languages have values |
129 | | -3. **Use correct case** — Match the capitalization from the reference (e.g., True not rue) |
130 | | -4. **Support variants** — The reference may list multiple accepted forms; consider supporting these |
131 | | -5. **Test locally** — Run the sync script before pushing |
| 76 | +``` |
132 | 77 |
|
133 | | -Example: |
| 78 | +## Updating Keywords Safely |
134 | 79 |
|
135 | | -\\\yaml |
136 | | -# Reference has: |
137 | | -# "COND_IF": {"en": "if", "fr": "si", "de": "wenn", ...} |
| 80 | +When editing `data/keywords.yaml`: |
138 | 81 |
|
139 | | -# So in keywords.yaml: |
140 | | -if: |
141 | | - en: if |
142 | | - fr: si |
143 | | - de: wenn |
144 | | - # ... all 17 languages |
145 | | -\\\ |
| 82 | +1. Check the canonical values in the reference implementation. |
| 83 | +2. Keep language coverage aligned across supported constructs. |
| 84 | +3. Match capitalization exactly. |
| 85 | +4. Preserve UTF-8 encoding. |
| 86 | +5. Run the local sync tools before pushing. |
146 | 87 |
|
147 | 88 | ## Troubleshooting |
148 | 89 |
|
149 | | -### Coverage below 95% |
150 | | -Some constructs may be missing or incomplete. Check the workflow artifacts for details. |
| 90 | +### Coverage below threshold |
151 | 91 |
|
152 | | -**Fix:** Add missing languages or constructs to data/keywords.yaml based on the reference. |
| 92 | +Add missing constructs or missing language values to `data/keywords.yaml`. |
153 | 93 |
|
154 | 94 | ### Language mismatches |
155 | | -Keywords don't match the reference implementation. |
156 | 95 |
|
157 | | -**Fix:** Update the values in data/keywords.yaml to match the reference. Run the local sync script to verify. |
| 96 | +Update the values in `data/keywords.yaml` to match the reference implementation. |
158 | 97 |
|
159 | 98 | ### Extra constructs |
160 | | -You have constructs in tree-sitter-multilingual that aren't in the reference. |
161 | | - |
162 | | -**Note:** This is typically OK — you may support additional constructs beyond the reference. Use --strict mode in CI if you want to prevent this. |
163 | | - |
164 | | -## CI Configuration |
165 | | - |
166 | | -### Minimum Coverage Threshold |
167 | | -Set minimum coverage in the workflow (currently 95%): |
168 | | - |
169 | | -\\\yaml |
170 | | -check-sync-results.py sync-report.json --min-coverage 95 |
171 | | -\\\ |
172 | | - |
173 | | -### Strict Mode |
174 | | -Enable strict mode to fail on any warnings: |
175 | 99 |
|
176 | | -\\\yaml |
177 | | -check-sync-results.py sync-report.json --strict |
178 | | -\\\ |
| 100 | +Extra constructs may be acceptable if this grammar intentionally supports more than the reference implementation. |
179 | 101 |
|
180 | 102 | ## File Locations |
181 | 103 |
|
182 | | -- **Workflow definition:** .github/workflows/sync-keywords.yml |
183 | | -- **Sync script:** .github/scripts/sync-keywords.py |
184 | | -- **Check script:** .github/scripts/check-sync-results.py |
185 | | -- **Keyword registry:** data/keywords.yaml |
186 | | -- **Reference implementation:** https://github.com/multilingualprogramming/multilingual |
| 104 | +- Workflow definition: `.github/workflows/sync-keywords.yml` |
| 105 | +- Sync script: `.github/scripts/sync-keywords.py` |
| 106 | +- Check script: `.github/scripts/check-sync-results.py` |
| 107 | +- Update script: `.github/scripts/update-keywords-from-reference.py` |
| 108 | +- Keyword registry: `data/keywords.yaml` |
| 109 | +- Reference implementation: `https://github.com/multilingualprogramming/multilingual` |
187 | 110 |
|
188 | 111 | ## Related |
189 | 112 |
|
190 | 113 | - [Multilingual Repository](https://github.com/multilingualprogramming/multilingual) |
191 | | -- [Universal Semantic Model (USM) Documentation](https://multilingual.readthedocs.io/) |
0 commit comments