microsoft/TypeAgent
Publicmirrored from https://github.com/microsoft/TypeAgentAvailable
Commit
Add export keyword support for .agr grammar rules (#2027)
## Summary
Add `export` keyword syntax for rule definitions in `.agr` grammar
files. Only rules explicitly marked with `export` are importable by
other files.
### Syntax
```
export <Greeting> = hello -> "hello";
<Internal> = internal helper -> "internal"; // not importable
```
### Changes
- **Parser**: Recognize `export <RuleName> = ...` syntax, set `exported`
flag on `RuleDefinition`, preserve comments between the export keyword
and rule name
- **Compiler**: Build `exportedNames` set from exported definitions,
block imports of non-exported rules (named imports produce errors,
wildcard imports silently skip), suppress "defined but never used"
warning for exported rules
- **Writer**: Emit `export ` prefix and `afterExportComments` in
round-trip output
- **Tests**: Parser (8 tests), writer (6 tests), compiler warning (1
test), and import integration tests (7 tests) — all existing import
tests updated to use `export` keyword on importable rules
### Semantics
- Only rules with the `export` keyword can be imported by other `.agr`
files
- Named imports of non-exported rules produce a compile error: `Rule
'<X>' is not exported from 'file.agr'`
- Wildcard imports (`import * from ...`) silently skip non-exported
rules
- Exported rules that aren't used internally don't trigger the "defined
but never used" warningChanged files
7 files listed