Skip to content

Commit

Permalink
git pMerge branch 'main' of https://github.com/jsiek/deduce
Browse files Browse the repository at this point in the history
  • Loading branch information
HalflingHelper committed Dec 22, 2024
2 parents 2ee5b8d + 26e8a59 commit 90ba892
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
18 changes: 14 additions & 4 deletions rec_desc_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,14 @@ def parse_term_hi():

elif token.type == 'LPAR':
advance()
while_parsing = 'while parsing parenthesized term\n' \
+ '\tterm ::= "(" term ")"\n'

term = parse_term()
if current_token().type != 'RPAR':
error(meta_from_tokens(current_token(), current_token()),
'expected closing parentheses, not\n\t' \
+ current_token().value)
+ current_token().value + '\n' + while_parsing)
advance()
return term

Expand Down Expand Up @@ -1307,10 +1310,17 @@ def parse_statement():
name = parse_identifier()
return Import(meta_from_tokens(token, previous_token()), name)
elif token.type == 'PRINT':
while_parsing = 'while parsing\n' \
+ '\tstatement ::= "print" term\n'
advance()
subject = parse_term()
meta = meta_from_tokens(token, previous_token())
return Print(meta, subject)
try:
subject = parse_term()
meta = meta_from_tokens(token, previous_token())
return Print(meta, subject)
except Exception as e:
meta = meta_from_tokens(token, previous_token())
raise Exception(str(e) + '\n' + error_header(meta) + while_parsing)

elif token.type == 'THEOREM' or token.type == 'LEMMA':
return parse_theorem()
elif token.type == 'UNION':
Expand Down
9 changes: 9 additions & 0 deletions test/should-error/paren_term.pf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Nat
import List

function sum(List<Nat>) -> Nat {
sum([]) = 0
sum(node(x, xs)) = x + sum(xs)
}

print(sum, [1,2,3])
8 changes: 8 additions & 0 deletions test/should-error/paren_term.pf.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
./test/should-error/paren_term.pf:9.10-9.11: expected closing parentheses, not
,
while parsing parenthesized term
term ::= "(" term ")"

./test/should-error/paren_term.pf:9.1-9.10: while parsing
statement ::= "print" term

0 comments on commit 90ba892

Please sign in to comment.