git @ Cat's Eye Technologies Eqthy / 6a20513
Refactor into `objects` module, and small flake8 cleanups. Chris Pressey 2 years ago
5 changed file(s) with 26 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
1111 if line.startswith(" "):
1212 new_lines.append(line[4:])
1313 return "\n".join(new_lines)
14
1415
1516 def main(args):
1617 argparser = ArgumentParser()
0 """Objects in the Eqthy document structure."""
1 from collections import namedtuple
2
3 Document = namedtuple('Document', ['axioms', 'theorems'])
4 Axiom = namedtuple('Axiom', ['name', 'eqn'])
5 Theorem = namedtuple('Theorem', ['name', 'eqn', 'steps'])
6 Step = namedtuple('Step', ['eqn', 'hint'])
7
8 # hints
9
10 Reflexivity = namedtuple('Reflexivity', [])
11 Substitution = namedtuple('Substitution', ['term', 'variable'])
12 Congruence = namedtuple('Congruence', ['variable', 'term'])
13 Reference = namedtuple('Reference', ['name', 'side'])
0 from collections import namedtuple
1
0 from eqthy.objects import (
1 Document, Axiom, Theorem, Step,
2 Reflexivity, Substitution, Congruence, Reference
3 )
24 from eqthy.scanner import Scanner, EqthySyntaxError
35 from eqthy.terms import Term, Variable, Eqn
46
1618 # Term := Var | Ctor ["(" [Term {"," Term} ")"].
1719
1820
19 Document = namedtuple('Document', ['axioms', 'theorems'])
20 Axiom = namedtuple('Axiom', ['name', 'eqn'])
21 Theorem = namedtuple('Theorem', ['name', 'eqn', 'steps'])
22 Step = namedtuple('Step', ['eqn', 'hint'])
23 Reflexivity = namedtuple('Reflexivity', [])
24 Substitution = namedtuple('Substitution', ['term', 'variable'])
25 Congruence = namedtuple('Congruence', ['variable', 'term'])
26 Reference = namedtuple('Reference', ['name', 'side'])
27
28
2921 class Parser(object):
3022 def __init__(self, text, filename):
3123 self.scanner = Scanner(text, filename)
4032 while self.scanner.on('theorem'):
4133 theorems.append(self.theorem())
4234 if not (axioms or theorems):
43 raise EqthySyntaxError(self.scanner.filename, self.scanner.line_number, "Eqthy document is empty")
35 raise EqthySyntaxError(
36 self.scanner.filename,
37 self.scanner.line_number,
38 "Eqthy document is empty"
39 )
4440 return Document(axioms=axioms, theorems=theorems)
4541
4642 def axiom(self):
124124
125125
126126 def all_rewrites(pattern, substitution, term):
127 """Given a term, and a rule (a pattern and a substitution), return
127 """Given a rule (a pattern and a substitution) and a term, return
128128 a list of the terms that would result from rewriting the term
129129 in all the possible ways by the rule."""
130130
0 # TODO: these should probably come from a "eqthy.hints" module
1 from eqthy.parser import Reflexivity, Substitution, Congruence, Reference
0 from eqthy.objects import Reflexivity, Substitution, Congruence, Reference
21 from eqthy.terms import Eqn, all_rewrites, render, RewriteRule, replace
32
43