Skip to content

Commit

Permalink
Shorten the felis.parser example in README
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeeeT committed Dec 1, 2024
1 parent 4404c0b commit 894299b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ print(pythags)
Parsing (and evaluating) an arithmetic expression with `felis.parser`:

```python
from felis.option import Some
from felis import option
from felis.parser import *

literal = map(int)(map("".join)(some(digit)))

multiplication = take_after(character("*"))(identity(lambda multiplicand: lambda multiplier: multiplicand * multiplier))
division = take_after(character("/"))(identity(lambda dividend: lambda divisor: dividend / divisor))
multiplication = take_after(character("*"))(identity(lambda a: lambda b: a * b))
division = take_after(character("/"))(identity(lambda a: lambda b: a / b))
term_priority_1 = chain_left_1(add(division)(multiplication))(literal)

addition = take_after(character("+"))(identity(lambda augend: lambda addend: augend + addend))
subtraction = take_after(character("-"))(identity(lambda minuend: lambda subtrahend: minuend - subtrahend))
addition = take_after(character("+"))(identity(lambda a: lambda b: a + b))
subtraction = take_after(character("-"))(identity(lambda a: lambda b: a - b))
term_priority_2 = chain_left_1(add(subtraction)(addition))(term_priority_1)

expression = term_priority_2
Expand All @@ -114,7 +114,7 @@ while string := input("> "):
match run(expression)(string):
case None:
print("Syntax error")
case Some(result):
case option.Some(result):
print("Result:", result)
```

Expand Down

0 comments on commit 894299b

Please sign in to comment.