Skip to content

Commit

Permalink
#150-Correct/Modify Parser Code
Browse files Browse the repository at this point in the history
Added new rules implementation about map contained types declaration in module `fe_parser.py`.
  • Loading branch information
schmouk committed Sep 19, 2019
1 parent 06dfb1c commit 2b6ecc1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/FrontEnd/Errors/fe_syntax_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ class FESyntaxErrors:
LIST_END = 'missing ] at end of list specification, leads to unpaired [',
LIST_EXPR = 'missing or badly formed expression after [ in list specification',

MAP_CONTAINED_TYPE = 'missing or badly formed list of types for map contained types (type of contained values or keys)',
MAP_CONTAINED_TYPE_END = 'missing closing '>' at end of list of types for map contained types',
MAP_CONTAINED_VALUE_TYPE = 'missing or badly formed list of types for map contained types after comma (type of contained values)',
MAP_EXPR = 'missing or badly formed expression after : in map-form clause or map item specification',
MAP_ITEM_SEP = 'missing : after expression in map item specification',
MAP_LIST_COMPR = 'missing "," or missing/badly-formed for-comprehension in map form',
Expand Down
37 changes: 35 additions & 2 deletions src/FrontEnd/Parser/fe_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2507,15 +2507,48 @@ def _map_list_or_comprehension(self) -> bool:
else:
return self._for_comprehension()

#-------------------------------------------------------------------------
def _map_contained_types(self) -> bool:
#=======================================================================
# <map contained types> ::= '<' <TYPE> <map contained types'>
# | EPS
#=======================================================================
if self._current.is_LT():
self._append_syntaxic_node()
self._next_token_node()
if not self._TYPE():
self._append_error( FESyntaxErrors.MAP_CONTAINED_TYPE )
return self._map_contained_types_1()
else:
return False

#-------------------------------------------------------------------------
def _map_contained_types_1(self) -> bool:
#=======================================================================
# <map contained types'> ::= ',' <TYPE> '>'
# | '>'
#=======================================================================
if self._current.is_COMMA():
self._append_syntaxic_node()
self._next_token_node()
if not self._TYPE():
self._append_error( FESyntaxErrors.MAP_CONTAINED_VALUE_TYPE )
if self._current.is_GT():
self._append_syntaxic_node()
self._next_token_node()
else:
self._append_error( FESyntaxErrors.MAP_CONTAINED_TYPE_END )
return True

#-------------------------------------------------------------------------
def _map_type(self) -> bool:
#=======================================================================
# <<map type> ::= "map" <contained type>
# <<map type> ::= "map" <map contained types>
#=======================================================================
if self._current.is_MAP():
self._append_syntaxic_node()
self._next_token_node()
self._contaioned_type() ## (notice: always returns True)
self._map_contained_types() ## (notice: always returns True)
return True
else:
return False
Expand Down

0 comments on commit 2b6ecc1

Please sign in to comment.