chacana.grammar¶
PEG grammar definition and input preprocessing.
chacana.grammar
¶
Arpeggio PEG grammar for Chacana tensor expressions.
normalize_input(expr: str) -> str
¶
Apply Unicode NFC normalization and reject out-of-scope characters.
This function MUST be called before parsing to prevent visual spoofing and ensure canonical representation of characters.
Raises:
| Type | Description |
|---|---|
ChacanaParseError
|
if the expression contains characters from disallowed Unicode blocks (e.g., Cyrillic, Arabic, CJK). |
Source code in src/chacana/grammar.py
parse_and_validate(expr: str) -> Any
¶
Parse an expression string and apply post-parse validations.
This function uses a cached parser, parses the (already normalized) input, and runs post-parse checks such as nested symmetrization rejection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr
|
str
|
The expression string (should already be NFC-normalized). |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The Arpeggio parse tree. |
Raises:
| Type | Description |
|---|---|
ChacanaParseError
|
on parse failure or validation failure. |
NoMatch
|
on grammar mismatch (re-raised as-is for callers that catch it directly). |