Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/jsiek/deduce
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiek committed Dec 16, 2024
2 parents 18d24dd + 3f219d3 commit ac3ca2f
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 16 deletions.
12 changes: 8 additions & 4 deletions Deduce.lark
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ ident: IDENT -> ident
| "fun" var_list "{" term "}" -> lambda
| "generic" ident_list "{" term "}" -> generic
| "switch" term "{" switch_list "}" -> switch
| "all" var_list "." term -> all_formula
| "<" ident_list ">" term -> alltype_formula
| "some" var_list "." term -> some_formula
| "all" type_annot_list "." term -> all_formula
| "<" ident_list ">" term -> alltype_formula
| "some" type_annot_list "." term -> some_formula
| "define" IDENT "=" term ";" term -> define_term
| "?" -> hole_term
| "" -> omitted_term
Expand All @@ -107,6 +107,10 @@ ident: IDENT -> ident
| ident -> single
| ident "," ident_list -> push

?type_annot_list: -> empty_binding
| ident ":" type -> single_binding
| ident ":" type "," type_annot_list -> push_binding

?var_list: -> empty_binding
| ident ":" type -> single_binding
| ident ":" type "," var_list -> push_binding
Expand Down Expand Up @@ -184,7 +188,7 @@ ident: IDENT -> ident
| "sorry" -> sorry_proof
| "{" proof "}"

?proof_stmt: "arbitrary" var_list -> all_intro
?proof_stmt: "arbitrary" type_annot_list -> all_intro
| "assume" IDENT -> imp_intro
| "assume" IDENT ":" term -> imp_intro_explicit
| "assume" ":" term -> imp_intro_anon
Expand Down
35 changes: 31 additions & 4 deletions rec_desc_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def parse_term_hi():

if token.type == 'ALL':
advance()
vars = parse_var_list()
vars = parse_type_annot_list()
if current_token().type != 'DOT':
error(meta_from_tokens(current_token(), current_token()),
'expected "." after parameters of "all", not\n\t' \
Expand Down Expand Up @@ -288,7 +288,7 @@ def parse_term_hi():

elif token.type == 'SOME':
advance()
vars = parse_var_list()
vars = parse_type_annot_list()
if current_token().type != 'DOT':
error(meta_from_tokens(token, current_token()),
'expected "." after parameters of "some", not\n\t' \
Expand Down Expand Up @@ -903,7 +903,7 @@ def parse_proof_statement():

elif token.type == 'ARBITRARY':
advance()
vars = parse_var_list()
vars = parse_type_annot_list()
meta = meta_from_tokens(token, previous_token())
result = None
for j, var in enumerate(reversed(vars)):
Expand Down Expand Up @@ -1154,7 +1154,7 @@ def parse_equation_list():

def parse_theorem():
while_parsing = 'while parsing\n' \
+ '\tproof_stmt ::= "theorem" identfier ":" formula "proof" proof "end"'
+ '\tproof_stmt ::= "theorem" identifier ":" formula "proof" proof "end"'
try:
start_token = current_token()
advance()
Expand Down Expand Up @@ -1510,6 +1510,33 @@ def parse_ident_list():
ident_list.append(ident)
return ident_list

def parse_type_annot_list():
start_tok = current_token()
ident = parse_identifier()
if current_token().type == 'COLON':
advance()
ty = parse_type()
else:
error(meta_from_tokens(current_token(), current_token()), "Missing type annotation. Expected ':' followed by a type.\n" \
+ error_header(meta_from_tokens(start_tok, current_token())) \
+ 'while parsing\n\ttype_annot_list ::= identifier ":" type' \
+ '\n\ttype_annot_list ::= identifier ":" type "," type_annot_list')
type_annot_list = [(ident,ty)]

while current_token().type == 'COMMA':
advance()
ident = parse_identifier()
if current_token().type == 'COLON':
advance()
ty = parse_type()
else:
error(meta_from_tokens(current_token(), current_token()), "Missing type annotation. Expected ':' followed by a type.\n" \
+ error_header(meta_from_tokens(start_tok, current_token())) \
+ 'while parsing\n\ttype_annot_list ::= identifier ":" type' \
+ '\n\ttype_annot_list ::= identifier ":" type "," type_annot_list')
type_annot_list.append((ident, ty))
return type_annot_list

def parse_var_list():
ident = parse_identifier()
if current_token().type == 'COLON':
Expand Down
2 changes: 1 addition & 1 deletion test/should-error/all5.pf.err
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
while parsing
term ::= "all" var_list "." term
./test/should-error/all5.pf:1.1-1.24: while parsing
proof_stmt ::= "theorem" identfier ":" formula "proof" proof "end"
proof_stmt ::= "theorem" identifier ":" formula "proof" proof "end"
2 changes: 1 addition & 1 deletion test/should-error/define_proof_missing_term.pf.err
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
proof_stmt ::= "define" identifier "=" term

./test/should-error/define_proof_missing_term.pf:1.1-3.13: while parsing
proof_stmt ::= "theorem" identfier ":" formula "proof" proof "end"
proof_stmt ::= "theorem" identifier ":" formula "proof" proof "end"
2 changes: 1 addition & 1 deletion test/should-error/induction_case.pf.err
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
conclusion ::= "induction" type ind_case*

./test/should-error/induction_case.pf:16.1-20.14: while parsing
proof_stmt ::= "theorem" identfier ":" formula "proof" proof "end"
proof_stmt ::= "theorem" identifier ":" formula "proof" proof "end"
2 changes: 1 addition & 1 deletion test/should-error/inst-term-angle-bracket.pf.err
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
while trying to parse type arguments for instantiation of an "all" formula:
proof ::= proof "<" type_list ">"
./test/should-error/inst-term-angle-bracket.pf:4.1-8.17: while parsing
proof_stmt ::= "theorem" identfier ":" formula "proof" proof "end"
proof_stmt ::= "theorem" identifier ":" formula "proof" proof "end"
2 changes: 1 addition & 1 deletion test/should-error/missing-colon-in-have.pf.err
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
proof_stmt ::= "have" ":" formula "by" proof

./test/should-error/missing-colon-in-have.pf:1.1-3.7: while parsing
proof_stmt ::= "theorem" identfier ":" formula "proof" proof "end"
proof_stmt ::= "theorem" identifier ":" formula "proof" proof "end"
2 changes: 1 addition & 1 deletion test/should-error/missing-conclusion.pf.err
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
./test/should-error/missing-conclusion.pf:5.1-5.4: missing conclusion after
have Y: true by .
./test/should-error/missing-conclusion.pf:1.1-4.20: while parsing
proof_stmt ::= "theorem" identfier ":" formula "proof" proof "end"
proof_stmt ::= "theorem" identifier ":" formula "proof" proof "end"
2 changes: 1 addition & 1 deletion test/should-error/suffices_misspell.pf.err
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
./test/should-error/suffices_misspell.pf:5.3-5.10: did you mean "suffices" instead of "sufices"?
./test/should-error/suffices_misspell.pf:1.1-4.15: while parsing
proof_stmt ::= "theorem" identfier ":" formula "proof" proof "end"
proof_stmt ::= "theorem" identifier ":" formula "proof" proof "end"
2 changes: 1 addition & 1 deletion test/should-error/theorem_implies8.pf.err
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
while parsing
formula ::= "if" formula "then" formula
./test/should-error/theorem_implies8.pf:1.1-1.20: while parsing
proof_stmt ::= "theorem" identfier ":" formula "proof" proof "end"
proof_stmt ::= "theorem" identifier ":" formula "proof" proof "end"

0 comments on commit ac3ca2f

Please sign in to comment.