git @ Cat's Eye Technologies Eqthy / 6e4c4c1
Raise a syntax error if axioms (or anything else) follow a theorem. Chris Pressey 1 year, 1 month ago
3 changed file(s) with 28 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
118118
119119 // This is a comment.
120120 axiom inv(A) = A // This is also a comment.
121 ===> ok
121
122 ===> ok
123
124 A comment may not be the very last thing in the document though.
125 They do need to end with a newline character.
126
127 // This is a comment.
128 axiom inv(A) = A // This is also a comment.
129 ???>
130
131 A theorem may be followed only by another theorem or the end of the
132 document. A theorem may not be followed by, e.g., an axiom.
133
134 axiom inv(A) = A.
135 theorem inv(A) = A proof A = A inv(A) = A qed.
136 axiom dec(A) = A.
137 ???>
122138
123139 ### Check Eqthy Document
124140
3737 axioms.append(self.axiom())
3838 while self.scanner.on('theorem'):
3939 theorems.append(self.theorem())
40 if not (axioms or theorems):
40 if (not axioms) and (not theorems):
4141 raise EqthySyntaxError(
4242 self.scanner.filename,
4343 self.scanner.line_number,
4444 "Eqthy document is empty"
4545 )
46 self.scanner.check_eof()
4647 return Document(axioms=axioms, theorems=theorems)
4748
4849 def axiom(self) -> Axiom:
3838 self.line_number += self.token.count('\n')
3939 return True
4040
41 def scan(self) -> None:
41 def consume_whitespace(self) -> None:
4242 self.scan_pattern(r'[ \t\n\r]*', 'whitespace')
4343 while self.scan_pattern(r'\/\/.*?[\n\r]', 'comment'):
4444 self.scan_pattern(r'[ \t\n\r]*', 'whitespace')
4545 if self.pos >= len(self.text):
4646 self.token = None
4747 self.type = 'EOF'
48
49 def scan(self) -> None:
50 self.consume_whitespace()
51 if self.type == 'EOF':
4852 return
4953 if self.scan_pattern(r'\,|\@|\+|\:|\<|\>|\{|\}|\[|\]|\^', 'operator'):
5054 return
7377 def on_type(self, type: str) -> bool:
7478 return self.type == type
7579
76 def check_type(self, type: str) -> None:
77 if not self.type == type:
78 self.syntax_error("Expected {}, but found '{}'".format(self.type, self.token))
80 def check_eof(self) -> None:
81 self.consume_whitespace()
82 if self.type != 'EOF':
83 self.syntax_error("Expected end of document, but found '{}' ({})".format(self.token, self.type))
7984
8085 def consume(self, token: str) -> bool:
8186 if self.token == token: