Commit 03248704 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Support "nextstate via entrypoint" followed by inputs

parent facba563
...@@ -180,10 +180,11 @@ def _state(ast, scene, states, terminators, parent=None): ...@@ -180,10 +180,11 @@ def _state(ast, scene, states, terminators, parent=None):
# state in that case: it will be rendered together with all its (possible) # state in that case: it will be rendered together with all its (possible)
# INPUT children in the render_terminator function. # INPUT children in the render_terminator function.
for term in terminators: for term in terminators:
state_label = ast.via or ast.inputString
if(term.kind == 'next_state' and if(term.kind == 'next_state' and
term.pos_x == ast.pos_x and term.pos_x == ast.pos_x and
term.pos_y == ast.pos_y and term.pos_y == ast.pos_y and
term.inputString == ast.inputString): term.inputString == state_label):
raise TypeError('This state is a terminator') raise TypeError('This state is a terminator')
new_state = sdlSymbols.State(parent=None, ast=ast) new_state = sdlSymbols.State(parent=None, ast=ast)
if new_state not in scene.items(): if new_state not in scene.items():
...@@ -345,7 +346,8 @@ def _terminator(ast, scene, parent, states): ...@@ -345,7 +346,8 @@ def _terminator(ast, scene, parent, states):
symbol = sdlSymbols.State(parent=parent, ast=ast) symbol = sdlSymbols.State(parent=parent, ast=ast)
# If the terminator is also a new state, render the inputs below # If the terminator is also a new state, render the inputs below
for state_ast in states: for state_ast in states:
if (state_ast.inputString == ast.inputString and state_label = state_ast.via or state_ast.inputString
if (state_label == ast.inputString and
state_ast.pos_x == ast.pos_x and state_ast.pos_x == ast.pos_x and
state_ast.pos_y == ast.pos_y): state_ast.pos_y == ast.pos_y):
symbol.nested_scene = state_ast.composite or \ symbol.nested_scene = state_ast.composite or \
......
...@@ -3733,6 +3733,7 @@ def state(root, parent, context): ...@@ -3733,6 +3733,7 @@ def state(root, parent, context):
asterisk_state = False asterisk_state = False
asterisk_input = None asterisk_input = None
st_x, st_y = 0, 0 st_x, st_y = 0, 0
via_stop = None
for child in root.getChildren(): for child in root.getChildren():
if isinstance(child, antlr3.tree.CommonErrorNode): if isinstance(child, antlr3.tree.CommonErrorNode):
# There was a parsing error # There was a parsing error
...@@ -3749,6 +3750,7 @@ def state(root, parent, context): ...@@ -3749,6 +3750,7 @@ def state(root, parent, context):
state_def.charPositionInLine = child.getCharPositionInLine() state_def.charPositionInLine = child.getCharPositionInLine()
for statename in child.getChildren(): for statename in child.getChildren():
state_def.statelist.append(statename.toString()) state_def.statelist.append(statename.toString())
via_stop = child.getTokenStopIndex()
elif child.type == lexer.ASTERISK: elif child.type == lexer.ASTERISK:
asterisk_state = True asterisk_state = True
state_def.inputString = get_input_string(child) state_def.inputString = get_input_string(child)
...@@ -3845,10 +3847,10 @@ def state(root, parent, context): ...@@ -3845,10 +3847,10 @@ def state(root, parent, context):
errors.extend(err) errors.extend(err)
elif child.type == lexer.VIA: elif child.type == lexer.VIA:
# case of a state to be merged with a NEXTSTATE having a via clause # case of a state to be merged with a NEXTSTATE having a via clause
# stopped HERE: have to extract the string "statename via blah" # in the via field we keep "state via entrypoint"
# to make sure it matches the NEXTSTATE start = via_stop
print ("state via:", get_input_string(root)) stop = child.getTokenStopIndex()
state_def.via = child.getChild(0).text state_def.via = token_stream(root).toString(start, stop)
elif child.type == 0: elif child.type == 0:
# Parser error, already caught # Parser error, already caught
pass pass
...@@ -5320,7 +5322,7 @@ def parseSingleElement(elem='', string='', context=None): ...@@ -5320,7 +5322,7 @@ def parseSingleElement(elem='', string='', context=None):
# syntax_errors.append(w.strip()) # syntax_errors.append(w.strip())
# Get the root of the Antlr-AST to build our own AST entry # Get the root of the Antlr-AST to build our own AST entry
root = r.tree root = r.tree
print (isinstance(tree, antlr3.tree.CommonErrorNode)) #print (isinstance(tree, antlr3.tree.CommonErrorNode))
root.token_stream = parser.getTokenStream() root.token_stream = parser.getTokenStream()
backend_ptr = eval(elem) backend_ptr = eval(elem)
try: try:
......
# $ANTLR 3.5.2 sdl92.g 2020-01-16 12:43:34 # $ANTLR 3.5.2 sdl92.g 2020-01-17 13:43:15
import sys import sys
from antlr3 import * from antlr3 import *
......
# $ANTLR 3.5.2 sdl92.g 2020-01-16 12:43:34 # $ANTLR 3.5.2 sdl92.g 2020-01-17 13:43:14
   
import sys import sys
from antlr3 import * from antlr3 import *
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