Skip to content

Commit 1b7ac6c

Browse files
Copilothzhangxyz
andcommitted
Fix BNF README to match actual parse/unparse behavior from tests
Co-authored-by: hzhangxyz <[email protected]>
1 parent 89c162f commit 1b7ac6c

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

bnf/README.md

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,22 @@ premise1, premise2 -> conclusion
108108
For structured terms:
109109
- Functions: `f(a, b)`
110110
- Subscripts: `a[i, j]`
111-
- Binary operators: `a + b`
112-
- Unary operators: `~ a`
111+
- Binary operators: `(a + b)` (parenthesized)
112+
- Unary operators: `(~ a)` (parenthesized)
113113

114114
### Syntax Comparison Table
115115

116-
| Description | Dsp Format (Input) | Ds Format (Output) |
116+
| Description | Dsp Format (parse input / unparse output) | Ds Format |
117117
|-------------|-------------------|-------------------|
118118
| Simple rule | `a, b -> c` | `a\nb\n----\nc` |
119-
| Axiom (no premises) | `a` | `----\na` |
119+
| Axiom (parse input) | `a` | `----\na` |
120+
| Axiom (unparse output) | ` -> a` | `----\na` |
120121
| Function call | `f(a, b) -> c` | `(function f a b)\n----------------\nc` |
121122
| Subscript | `a[i, j] -> b` | `(subscript a i j)\n-----------------\nb` |
122123
| Binary operator | `(a + b) -> c` | `(binary + a b)\n--------------\nc` |
123-
| Unary operator | `~ a -> b` | `(unary ~ a)\n-----------\nb` |
124-
| Complex expression | `(a + b) * c, d[i] -> f(g, h)` | `(binary * (binary + a b) c)\n(subscript d i)\n---------------------------\n(function f g h)` |
124+
| Unary operator (parse input) | `~ a -> b` | `(unary ~ a)\n-----------\nb` |
125+
| Unary operator (unparse output) | `(~ a) -> b` | `(unary ~ a)\n-----------\nb` |
126+
| Complex expression | `((a + b) * c), d[i] -> f(g, h)` | `(binary * (binary + a b) c)\n(subscript d i)\n---------------------------\n(function f g h)` |
125127

126128
## API Reference
127129

@@ -225,18 +227,11 @@ print(ds)
225227
from apyds_bnf import unparse
226228

227229
# Unparse multiple rules
228-
ds = """a
229-
----
230-
b
231-
232-
c
233-
----
234-
d"""
230+
ds = "a\n----\nb\n\nc\n----\nd"
235231
dsp = unparse(ds)
236232
print(dsp)
237-
# Output:
238-
# a -> b
239-
# c -> d
233+
# Output: a -> b
234+
# c -> d
240235
```
241236

242237
### Round-trip Conversion

0 commit comments

Comments
 (0)