Skip to content
Snippets Groups Projects
Commit 3a614c7a authored by Chris's avatar Chris
Browse files

Update python template for records and spacing

parent a3ccf6e3
Branches
No related tags found
No related merge requests found
...@@ -33,19 +33,18 @@ struct(name, declarations, parameters, initializations, functions, equalPredicat ...@@ -33,19 +33,18 @@ struct(name, declarations, parameters, initializations, functions, equalPredicat
class <name>(BStruct): class <name>(BStruct):
def __init__(self<parameters : {par |, <par>}>): def __init__(self<parameters : {par |, <par>}>):
<declarations; separator="\n">
<initializations; separator="\n"> <initializations; separator="\n">
<functions; separator="\n\n"> <functions; separator="\n\n">
def equal(self, <name> o): def equal(self, o: '<name>'):
return BBoolean(<equalPredicates; separator=" and ">) return BBoolean(<equalPredicates; separator=" and ">)
def unequal(self, <name> o): def unequal(self, o: '<name>'):
return BBoolean(<unequalPredicates; separator=" or ">) return BBoolean(<unequalPredicates; separator=" or ">)
__str__(self): def __str__(self):
return "(" + <values; separator=" + \",\" + "> + ")" return "(" + <values; separator=" + \",\" + "> + ")"
def __eq__(self, other): def __eq__(self, other):
...@@ -53,7 +52,7 @@ class <name>(BStruct): ...@@ -53,7 +52,7 @@ class <name>(BStruct):
return False return False
o = other o = other
return <equalPredicates; separator= " && "> return <equalPredicates; separator= " and ">
def __hash__(self): def __hash__(self):
return hash(<fields; separator=", ">) return hash(<fields; separator=", ">)
...@@ -65,7 +64,7 @@ def _get_<variable>(self): ...@@ -65,7 +64,7 @@ def _get_<variable>(self):
>> >>
record_field_get(type, field) ::= << record_field_get(type, field) ::= <<
def get_<field>(): def get_<field>(self):
return self.<field> return self.<field>
>> >>
...@@ -82,12 +81,16 @@ record_access_element(expr, arg, val) ::= << ...@@ -82,12 +81,16 @@ record_access_element(expr, arg, val) ::= <<
>> >>
record_field_override(name, field, type, val, parameters) ::= << record_field_override(name, field, type, val, parameters) ::= <<
def override_<field>(<field>): def override_<field>(self, <field>):
return <name>(<parameters; separator=", ">) save = self.<field>
self.<field> = <field>
object = <name>(self.<parameters; separator=", self.">)
self.<field> = save
return object
>> >>
record_field_initialization(identifier) ::= << record_field_initialization(identifier) ::= <<
self.<identifier> = self.<identifier> self.<identifier> = <identifier>
>> >>
record_assignment(identifier) ::= << record_assignment(identifier) ::= <<
...@@ -253,10 +256,7 @@ if(<predicate>).booleanValue(): ...@@ -253,10 +256,7 @@ if(<predicate>).booleanValue():
>> >>
if_expression_predicate(predicate, ifThen, ifElse) ::= << if_expression_predicate(predicate, ifThen, ifElse) ::= <<
if <predicate>.booleanValue(): <ifThen> if <predicate>.booleanValue() else <ifElse>
<ifThen>
else:
<ifElse>
>> >>
enum_call(machine, class, identifier, isCurrentMachine) ::= << enum_call(machine, class, identifier, isCurrentMachine) ::= <<
...@@ -407,19 +407,19 @@ binary(arg1,operator,arg2) ::= << ...@@ -407,19 +407,19 @@ binary(arg1,operator,arg2) ::= <<
>> >>
or(arg1, arg2) ::= << or(arg1, arg2) ::= <<
BBoolean(<arg1>.booleanValue() or <arg2>.booleanValue()) <arg1> or <arg2>
>> >>
and(arg1, arg2) ::= << and(arg1, arg2) ::= <<
BBoolean(<arg1>.booleanValue() and <arg2>.booleanValue()) <arg1> and <arg2>
>> >>
implies(arg1, arg2) ::= << implies(arg1, arg2) ::= <<
BBoolean(not <arg1>.booleanValue() or <arg2>.booleanValue()) <arg1>.implies(<arg2>)
>> >>
equivalent(arg1, arg2) ::= << equivalent(arg1, arg2) ::= <<
BBoolean((not <arg1>.booleanValue() or <arg2>.booleanValue()) and (not <arg2>.booleanValue() or <arg1>.booleanValue())) <arg1>.equivalent(<arg2>)
>> >>
unary(operator, obj, args) ::= << unary(operator, obj, args) ::= <<
...@@ -428,19 +428,19 @@ unary(operator, obj, args) ::= << ...@@ -428,19 +428,19 @@ unary(operator, obj, args) ::= <<
select(iterationConstruct, predicate, then) ::= << select(iterationConstruct, predicate, then) ::= <<
<iterationConstruct; separator="\n"> <iterationConstruct; separator="\n">
if((<predicate>).booleanValue()): if (<predicate>).booleanValue():
<then> <then>
>> >>
if(iterationConstruct, predicate, then, else1) ::= << if(iterationConstruct, predicate, then, else1) ::= <<
<iterationConstruct; separator="\n"> <iterationConstruct; separator="\n">
if((<predicate>).booleanValue()): if (<predicate>).booleanValue():
<then> <then>
<else1; separator=" "> <else1; separator="\n">
>> >>
elseif(predicate, then) ::= << elseif(predicate, then) ::= <<
else if((<predicate>).booleanValue()): elif (<predicate>).booleanValue():
<then> <then>
>> >>
...@@ -450,15 +450,16 @@ else: ...@@ -450,15 +450,16 @@ else:
>> >>
choice(len, then, choice1) ::= << choice(len, then, choice1) ::= <<
int index = (int) Math.floor(Math.random() * <len>) import random
if(index == 0): index = random.randint(0, <len>-1)
if index == 0:
<then> <then>
<choice1; separator=" "> <choice1; separator="\n">
>> >>
choice1(counter, then) ::= << choice1(counter, then) ::= <<
else if(index == <counter>): elif index == <counter>:
<then> <then>
>> >>
...@@ -477,7 +478,7 @@ any_body(otherIterationConstructs, emptyPredicate, predicate, body) ::= << ...@@ -477,7 +478,7 @@ any_body(otherIterationConstructs, emptyPredicate, predicate, body) ::= <<
<body> <body>
break break
<else> <else>
if((<predicate>).booleanValue()): if (<predicate>).booleanValue():
<body> <body>
break break
<endif> <endif>
...@@ -494,7 +495,7 @@ becomes_such_that_body(otherIterationConstructs, emptyPredicate, predicate, stor ...@@ -494,7 +495,7 @@ becomes_such_that_body(otherIterationConstructs, emptyPredicate, predicate, stor
<stores> <stores>
break break
<else> <else>
if((<predicate>).booleanValue()): if (<predicate>).booleanValue():
<stores> <stores>
break break
<endif> <endif>
...@@ -510,7 +511,7 @@ becomes_such_that_store(lhs, rhs) ::= << ...@@ -510,7 +511,7 @@ becomes_such_that_store(lhs, rhs) ::= <<
while(iterationConstruct1, iterationConstruct2, predicate, then) ::= << while(iterationConstruct1, iterationConstruct2, predicate, then) ::= <<
<iterationConstruct1; separator="\n"> <iterationConstruct1; separator="\n">
while((<predicate>).booleanValue()): while (<predicate>).booleanValue():
<then> <then>
<iterationConstruct2; separator="\n"> <iterationConstruct2; separator="\n">
>> >>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment