# Fin "AST"
-class SyntaxError(Exception):
+class ParserError(Exception):
pass
def skip(str, to_skip, current=None, val=''):
return (None, str)
(tok, val, str) = skip(str, SP, tok, val)
if tok != ID and tok != ARR:
- raise SyntaxError('ID or ARR expected, got %s' % tokstr[tok])
+ raise ParserError('ID or ARR expected, got %s' % tokstr[tok])
# tipo
is_array = False
if tok == ARR:
# sp
(tok, val, str) = tokenize(str)
if tok != SP:
- raise SyntaxError('SP expected, got %s' % tokstr[tok])
+ raise ParserError('SP expected, got %s' % tokstr[tok])
(tok, val, str) = skip(str, SP, tok, val)
# nombre
if tok != ID:
- raise SyntaxError('ID expected, got %s' % tokstr[tok])
+ raise ParserError('ID expected, got %s' % tokstr[tok])
attr = Attr(type_name, is_array, val)
(tok, val, str) = skip(str, SP)
if tok != EOL:
- raise SyntaxError('EOL expected, got %s' % tokstr[tok])
+ raise ParserError('EOL expected, got %s' % tokstr[tok])
return (attr, str)
def parse_message(str):
if tok == EOF:
return (None, str)
elif tok != ID:
- raise SyntaxError('ID expected, got %s' % tokstr[tok])
+ raise ParserError('ID expected, got %s' % tokstr[tok])
msg = Message(val)
dprint('parse_message(): msg = %s', msg)
(tok, val, str) = skip(str, SP)
if tok != EOL:
- raise SyntaxError('EOL expected, got %s' % tokstr[tok])
+ raise ParserError('EOL expected, got %s' % tokstr[tok])
# ya tengo EOL, vienen atributos (o fin de mensaje)
(attr, str) = parse_attr(str)
while attr: