Grammar and editor tasks
Use this guide when changing FCSTM syntax, highlighting, or editor support. For exact file maps and command lists, see Grammar and editor tooling reference. For design rationale, see Grammar tooling explanation.
Decide what kind of change this is
Change |
Must update |
Usually also update |
|---|---|---|
New parseable syntax |
ANTLR grammar, generated parser outputs, listener/AST/model import, tests, DSL docs. |
Pygments, TextMate, VSCode diagnostics/completion/hover. |
New keyword or operator spelling |
Lexer grammar, parser grammar when used in rules, highlighters, editor validation. |
DSL reference examples and LLM grammar guide. |
New semantic interpretation of existing syntax |
Model import/validation, simulator or renderer behavior, tests, semantic docs. |
Editor diagnostics if authoring feedback changes. |
Highlighting-only correction |
Pygments or TextMate assets, editor validation. |
Documentation examples when they taught the wrong form. |
VSCode authoring feature change |
VSCode TypeScript providers and focused verification suite. |
TextMate grammar if the feature depends on token classification. |
Change parser grammar
Edit
pyfcstm/dsl/grammar/GrammarParser.g4and/orpyfcstm/dsl/grammar/GrammarLexer.g4.Regenerate ANTLR outputs:
make antlr_buildUpdate
pyfcstm/dsl/listener.pyandpyfcstm/dsl/node.pywhen parse tree shape or AST node shape changes.Update model import and validation if the construct has semantic meaning.
Add tests that prove both accepted and rejected forms.
Update user-facing DSL docs and the packaged LLM grammar guide when prompt or user syntax changes.
Operator and keyword ordering
When adding operators, keep longer tokens before shorter prefixes in lexer and highlighting rules. Examples:
**before*;<<before<;<=and>=before<and>;==and!=before=and!;&&and||before single-character forms.
When adding keywords, update the grammar and all syntax display layers in the same change. A keyword that parses but does not highlight creates documentation and editor drift.
Synchronize highlighting
After grammar or keyword changes, update both highlighter families:
pyfcstm/highlight/pygments_lexer.pyfor Sphinx and Python-side highlighting.editors/fcstm.tmLanguage.jsonfor TextMate-compatible editors.Run the editor/highlight validation command:
python editors/validate.py
If a docs-only PR does not run the editor command, say that explicitly in the PR comment. Grammar or editor behavior changes should not skip it silently.
Update VSCode support
Inspect editors/vscode/ when authoring behavior changes. Typical places are:
src/diagnostics.tsfor syntax diagnostics and Problems-panel feedback;src/symbols.tsfor Outline and breadcrumbs;src/completion.tsfor keyword and symbol completion;src/hover.tsfor hover explanations;snippets/fcstm.code-snippetsfor user snippets.
Build the extension package when packaging behavior matters:
make vscode
Use make vscode_clean only when cleaning local extension build outputs.
Verify Python and Sphinx highlighting
For Python tools, confirm the Pygments alias is visible:
python -c "from pygments.lexers import get_lexer_by_name; print(get_lexer_by_name('fcstm'))"
For Sphinx pages, use .. code-block:: fcstm examples and build the docs in
both languages when visible documentation changes:
NO_CONTENTS_BUILD=1 READTHEDOCS_LANGUAGE=en sphinx-build -b html docs/source /tmp/pyfcstm-docs-en
NO_CONTENTS_BUILD=1 READTHEDOCS_LANGUAGE=zh sphinx-build -b html docs/source /tmp/pyfcstm-docs-zh
If highlighting fails in Sphinx, check setup.py and docs/source/conf.py
before changing examples.
Install and verify the VSCode extension
For local development, build and install the package produced by the Makefile:
make vscode
code --install-extension editors/vscode/build/fcstm-language-support-0.1.0.vsix
After installation, open a .fcstm file and verify:
The bottom-right language mode is
FCSTM.Keywords, operators, comments, and literals are highlighted.
Outline shows variables, states, and events.
Typing
stateoffers completions.Hovering over keywords such as
pseudooreffectshows help text.A deliberately invalid file reports syntax diagnostics in Problems.
Run VSCode verification suites
When extension behavior changes, run focused suites before the aggregate check:
cd editors/vscode
make verify-p0.2 # parser integration
make verify-p0.3 # syntax diagnostics
make verify-p0.4 # document symbols
make verify-p0.5 # completion support
make verify-p0.6 # hover documentation
make verify
Syntax-only documentation updates may record that Node.js-backed checks were not run, but parser/editor changes should include the relevant suites.
Update prompt-facing grammar guide
When syntax or parse rules change, update the packaged LLM grammar guide:
make sha256
SKIP_SLOW_TESTS=1 make unittest RANGE_DIR=./llm
Commit the Markdown guide and checksum together. If the grammar guide did not change, record why it was outside the change scope.
Worked grammar-change playbooks
Use these playbooks to decide how much of the toolchain must move with a syntax change.
Change type |
Minimum files to inspect |
Required checks |
Common failure if skipped |
|---|---|---|---|
Add a parser keyword or operator. |
|
|
Parser accepts text that highlighters or LLM guidance still teach incorrectly. |
Change parse-tree shape. |
Grammar files, generated parser output, |
Parser tests plus model import/export tests. |
Syntax parses but AST/model conversion loses data. |
Add editor authoring support. |
TextMate grammar, |
|
VSCode suggests syntax that Python model import rejects. |
Update only examples or docs wording. |
Human docs, prompt-facing grammar guide when syntax advice changes. |
Sphinx build, example parse commands, |
Human docs and LLM prompts drift apart. |
Concrete review checklist
Before requesting review, attach this evidence to the PR body or comment:
exact grammar files changed, or an explicit statement that grammar files are untouched;
whether generated parser files were regenerated;
whether listener/model/import/export code changed;
highlighter/editor assets checked or intentionally out of scope;
LLM grammar guide and checksum decision;
Python and JavaScript/editor test boundary decision.
Document and review the change
Before review, include:
the syntax forms added, changed, or deliberately rejected;
parser/model tests or docs-only validation rationale;
highlighter and editor validation commands;
generated parser or documentation outputs that were regenerated;
any old examples that were removed or redirected.
A grammar change is ready only when parser behavior, model semantics, highlighting, editor feedback, user docs, and tests all tell the same story.