Commit 8f399145 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Improve error reporting and better test

parent e0897e45
......@@ -2,7 +2,7 @@
 
# Resource object code
#
# Created: Wed May 18 14:18:26 2016
# Created: Thu May 19 15:06:06 2016
# by: The Resource Compiler for PySide (Qt v4.8.6)
#
# WARNING! All changes made in this file will be lost!
# $ANTLR 3.1.3 Mar 17, 2009 19:23:44 sdl92.g 2016-05-18 14:18:28
# $ANTLR 3.1.3 Mar 17, 2009 19:23:44 sdl92.g 2016-05-19 15:06:08
import sys
from antlr3 import *
......@@ -93,7 +93,7 @@ NOT=171
SPECIFIC=184
STIMULUS=96
THIS=160
ENDPROCEDURE=132
ENDPROCEDURE=133
END=187
AGGREGATION=140
FI=36
......@@ -125,7 +125,7 @@ ACTION=4
T__229=229
STOPIF=98
T__228=228
START=135
START=136
FALSE=173
T__225=225
T__224=224
......@@ -133,7 +133,7 @@ T__227=227
DEFAULT=143
T__226=226
IMPLIES=162
ENDCONNECTION=136
ENDCONNECTION=137
ENDDECISION=151
EXPORT=33
JOIN=55
......@@ -153,10 +153,10 @@ IN=49
FIELD=37
DOT=215
SYNONYM=101
OUT=133
OUT=134
ENDBLOCK=127
STATELIST=95
SEMI=137
SEMI=132
CONNECT=20
ASN1=9
ASSIGN=10
......@@ -216,7 +216,7 @@ ACTIVE=180
Exponent=218
L_PAREN=146
ANY=152
INT=134
INT=135
CHOICE=14
EXTERNAL=35
FIELD_NAME=38
......
This diff is collapsed.
......@@ -281,11 +281,10 @@ parameters_of_sort
;
// procedure: missing the RETURNS statement
// (TODO - but check new SDL2000 syntax that has no RETURNS token)
// procedure
procedure
: cif?
PROCEDURE procedure_id e1=end
PROCEDURE procedure_id (e1=end | SEMI)
fpar?
res=procedure_result?
(text_area | procedure)*
......@@ -307,7 +306,7 @@ procedure_result
fpar
: FPAR formal_variable_param
(',' formal_variable_param)*
end?
end
-> ^(FPAR formal_variable_param+)
;
......@@ -481,7 +480,7 @@ floating_label
state
: cif?
hyperlink?
STATE statelist e=end
STATE statelist (e=end | SEMI)
(state_part)*
ENDSTATE statename? f=end
-> ^(STATE cif? hyperlink? $e? statelist state_part*)
......@@ -601,6 +600,7 @@ composite_state_body
| procedure
| (composite_state_preamble) =>composite_state)*
start* (state | floating_label)*
EOF?
;
......
#!/usr/bin/env python
from opengeode.ogParser import parser_init
from opengeode.ogParser import parser_init, antlr3, sdl92Parser
# detect syntax errors (missing semi after "entry")
# return a string corresponding to a token number:
token = lambda num: sdl92Parser.tokenNames[num]
def test_composite_state_body_1():
''' Detect the syntax error (missing SEMI after "procedure entry") '''
test = parser_init(string=
'''state ENTRYA;
substructure
procedure entry EXTERNAL;
endsubstructure ENTRYA;
''')
test.composite_state_body()
substructure
procedure entry external;
endsubstructure ENTRYA;''')
# Parse and then check that the reported error is the expected one
res = test.composite_state_body()
assert(not isinstance(res.tree, antlr3.tree.CommonErrorNode))
composite = res.tree.children[0]
compo_type = sdl92Parser.tokenNames[composite.type]
assert(compo_type == 'COMPOSITE_STATE')
for each in composite.children:
if isinstance(each, antlr3.tree.CommonErrorNode):
exception = each.trappedException
assert(isinstance(exception,antlr3.NoViableAltException))
assert(token(exception.unexpectedType) == 'EXTERNAL')
def test_composite_state_1():
''' Detect the syntax error (missing SEMI after "procedure entry") '''
test = parser_init(string=
'''state CHECKING;
substructure
......@@ -43,7 +55,7 @@ def test_composite_state_2():
test.composite_state()
def test_composite_state_body_1():
def test_composite_state_body_2():
print('composite_state_body 2:')
test=parser_init(string=
......
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