Commit 5b404782 authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

[lib][antlr] Fix typos in Python section of grammar definitions

parent f4d7187d
......@@ -35,198 +35,207 @@ def set_error_reporter(self, err):
def displayRecognitionError(self, tokenNames, re):
hdr = self.getErrorHeader(re)
msg = self.getErrorMessage(re, tokenNames)
self.error_reporter.display(hdr+' '+msg)
self.error_reporter.display(hdr + " " + msg)
def displayExceptionMessage(self, e):
msg = self.getErrorMessage(self, e, tokenNames)
self.error_reporter.display(msg)
def check_ident_dec(self, id, type, line):
"""
@param id : string
"""
line_txt = 'line '+str(line)+':'
line_txt = "line " + str(line) + ":"
if id in self.symb_tab:
self.error_reporter.display(line_txt+" Node double declaration: "+id)
self.error_reporter.display(line_txt + " Node double declaration: " + id)
else:
if type == 'S':
node = self.current_macro.add_simple_node(id, 0,0)
elif type == 'P':
node = self.current_macro.add_perm_node(id, 0,0)
elif type == 'I':
node = self.current_macro.add_input_node(id, 0,0)
else:
self.error_reporter.display(line_txt+ " Unknown type - bug?")
self.symb_tab[id] = node
if type == "S":
node = self.current_macro.add_simple_node(id, 0, 0)
elif type == "P":
node = self.current_macro.add_perm_node(id, 0, 0)
elif type == "I":
node = self.current_macro.add_input_node(id, 0, 0)
else:
self.error_reporter.display(line_txt + " Unknown type - bug?")
self.symb_tab[id] = node
def check_ident_trans(self, id, type, line):
"""
@param id : string
"""
line_txt = 'line '+str(line)+':'
line_txt = "line " + str(line) + ":"
try:
# already used node
node = self.symb_tab[id]
tok = (node.is_input() and type == 'I') or (node.is_perm() and type == 'P') or (type == 'N')
if (not tok) :
self.error_reporter.display(line_txt + " Type error in transition: "+id)
# already used node
node = self.symb_tab[id]
tok = (
(node.is_input() and type == "I")
or (node.is_perm() and type == "P")
or (type == "N")
)
if not tok:
self.error_reporter.display(
line_txt + " Type error in transition: " + id
)
except KeyError:
if type == 'N':
node = self.current_macro.add_simple_node(id, 0,0)
elif type == 'P':
node = self.current_macro.add_perm_node(id, 0,0)
elif type == 'I':
node = self.current_macro.add_input_node(id, 0,0)
else:
self.error_reporter.display(line_txt+ " Unknown type - bug?")
self.symb_tab[id] = node
if type == "N":
node = self.current_macro.add_simple_node(id, 0, 0)
elif type == "P":
node = self.current_macro.add_perm_node(id, 0, 0)
elif type == "I":
node = self.current_macro.add_input_node(id, 0, 0)
else:
self.error_reporter.display(line_txt + " Unknown type - bug?")
self.symb_tab[id] = node
return node
def check_ident_start(self, id, line):
"""
@param id : string
"""
line_txt = 'line '+str(line)+':'
line_txt = "line " + str(line) + ":"
try:
# already used node, must be simple or macro
node = self.symb_tab[id]
tnok = node.is_input() or node.is_perm()
if tnok:
self.error_reporter.display(line_txt+ " Type error in start transition: "+id)
# already used node, must be simple or macro
node = self.symb_tab[id]
tnok = node.is_input() or node.is_perm()
if tnok:
self.error_reporter.display(
line_txt + " Type error in start transition: " + id
)
except KeyError:
node = self.current_macro.add_simple_node(id, 0,0)
self.symb_tab[id] = node
node = self.current_macro.add_simple_node(id, 0, 0)
self.symb_tab[id] = node
return node
def check_ident_deg(self, id, line):
"""
@param id : string
"""
line_txt = 'line '+str(line)+':'
line_txt = "line " + str(line) + ":"
try:
# already used node, must be simple
node = self.symb_tab[id]
if not (node.is_simple() or node.is_macro()):
# degradation allowed from macro nodes - TO MODIFY??
self.error_reporter.display(line_txt+" Type error in degradation transition: "+id)
# already used node, must be simple
node = self.symb_tab[id]
if not (node.is_simple() or node.is_macro()):
# degradation allowed from macro nodes - TO MODIFY??
self.error_reporter.display(
line_txt + " Type error in degradation transition: " + id
)
except KeyError:
node = self.current_macro.add_simple_node(id, 0,0)
self.symb_tab[id] = node
node = self.current_macro.add_simple_node(id, 0, 0)
self.symb_tab[id] = node
return node
def build_transition(self, id1, modif, id2, modif2, gc, note, line):
line_txt = 'line '+str(line)+':'
line_txt = "line " + str(line) + ":"
if modif:
type = self.modif_code(modif)
type = self.modif_code(modif)
else:
type = 'N'
type = "N"
ori = self.check_ident_trans(id1, type, line)
if modif2:
type2 = self.modif_code(modif)
type2 = self.modif_code(modif)
else:
type2 = 'N'
type2 = "N"
target = self.check_ident_trans(id2, type2, line)
# check if origin and target are in the same macro
if not ori.father == target.father:
self.error_reporter.display(line_txt+" Node:"+id1+ " and node:"+id2 + " are not in the same macro")
self.error_reporter.display(line_txt + " Node:" + id1 + " and node:" + id2 + " are not in the same macro")
if gc[0]:
event = gc[0]
event = gc[0]
else:
event = ''
event = ""
if gc[1]:
cond = gc[1]
cond = gc[1]
else:
cond = ''
cond = ""
note_txt = self.clean_note(note)
t = self.current_macro.add_transition(ori, target)
if event:
t.set_event(event)
t.set_event(event)
t.set_condition(cond)
if len(note_txt)>0:
t.note = note_txt
def build_start_transition(self, id, note, line):
ori = self.current_macro.add_start_node(0,0)
if len(note_txt) > 0:
t.note = note_txt
def build_start_transition(self, id, note, line):
ori = self.current_macro.add_start_node(0, 0)
target = self.check_ident_start(id, line)
t = self.current_macro.add_transition(ori, target)
if note:
note_txt = self.clean_note(note)
t.set_note(note_txt)
note_txt = self.clean_note(note)
t.set_note(note_txt)
def build_deg_transition(self, id, gc, note, line):
target = self.current_macro.add_trap_node(0,0)
target = self.current_macro.add_trap_node(0, 0)
ori = self.check_ident_deg(id, line)
event = gc[0]
cond = gc[1]
self.clean_note(note)
t = self.current_macro.add_transition(ori, target)
if event:
t.set_event(event)
t.set_event(event)
t.set_condition(cond)
def enter_macro(self, id, line):
line_txt = 'line '+str(line)+':'
line_txt = "line " + str(line) + ":"
self.macro_pile.append(self.current_macro)
try:
node = self.symb_tab[id]
if not node.is_macro():
self.error_reporter.display(line_txt+ " Not macro node used as macro:"+id)
return
else:
self.error_reporter.display(line_txt+ " Macro double definition:"+id)
node = self.symb_tab[id]
if not node.is_macro():
self.error_reporter.display(
line_txt + " Not macro node used as macro:" + id
)
return
else:
self.error_reporter.display(line_txt + " Macro double definition:" + id)
except KeyError:
node = self.current_macro.add_macro_subnode(id,0,0, 0.25, 0.25)
self.symb_tab[id] = node
node = self.current_macro.add_macro_subnode(id, 0, 0, 0.25, 0.25)
self.symb_tab[id] = node
self.current_macro = node
def leave_macro(self, id=None):
self.current_macro = self.macro_pile.pop()
def clean_note(self, note):
return note[1:-1]
def modif_code(self, modif):
if modif == '/p':
return 'P'
elif modif == '/i':
return 'I'
if modif == "/p":
return "P"
elif modif == "/i":
return "I"
def check_end(self):
if len(self.macro_pile)>0:
self.error_reporter.display("Bad macro imbrication - missing \endmacro?")
if len(self.macro_pile) > 0:
self.error_reporter.display("Bad macro imbrication - missing \endmacro?")
}
// RULES
// boolean expressions in conditions
cad_model[model]
// boolean expressions in conditions
cad_model[model]
@init{
self.model = model
self.macro_pile = []
self.symb_tab = dict()} :
{self.current_macro = self.model.get_root()}
(NAME id_dec=IDENT {self.model.name = $id_dec.text})?
(macro|transition|dec)+
{self.check_end()}
(txt=constraints {self.model.constraints = $txt.text})?
EOF
EOF
;
dec :{type = 'S'}
id_dec=IDENT (m=modifier {type = self.modif_code($m.text)})? SC
{self.check_ident_dec($id_dec.text, type, $id_dec.line)}
;
transition :
id1=IDENT (m=modifier)? TARROW id2=IDENT SC gc=guard (m2=modifier)? ntext=note SC
{self.build_transition($id1.text, $m.text, $id2.text, $m2.text, $gc.guard_component, $ntext.text, $id1.line)}
| id3=IDENT TARROW SC gc1=guard ntext1=note SC // degradation transition
{self.build_deg_transition($id3.text, $gc1.guard_component, $ntext1.text, $id3.line)}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment