[jsinterp] Handling comments
This commit is contained in:
parent
d328b8c6c2
commit
2c85715b93
@ -74,7 +74,7 @@ class TestJSInterpreter(unittest.TestCase):
|
|||||||
|
|
||||||
def test_comments(self):
|
def test_comments(self):
|
||||||
'Skipping: Not yet fully implemented'
|
'Skipping: Not yet fully implemented'
|
||||||
return
|
# return
|
||||||
jsi = JSInterpreter('''
|
jsi = JSInterpreter('''
|
||||||
function x() {
|
function x() {
|
||||||
var x = /* 1 + */ 2;
|
var x = /* 1 + */ 2;
|
||||||
|
@ -64,14 +64,19 @@ _EXP_RE = r'''(?P<id>%(name)s)|(?P<val>%(val)s)|(?P<op>%(op)s)|%(par)s''' % {
|
|||||||
} # TODO validate expression (it's probably recursive!)
|
} # TODO validate expression (it's probably recursive!)
|
||||||
_ARRAY_ELEMENT_RE = r'%(name)s\s*\[\s*(%(index)s)\s*\]' % {'name': _NAME_RE, 'index': _EXP_RE}
|
_ARRAY_ELEMENT_RE = r'%(name)s\s*\[\s*(%(index)s)\s*\]' % {'name': _NAME_RE, 'index': _EXP_RE}
|
||||||
|
|
||||||
token = re.compile(r'''(?x)\s*
|
_COMMENT_RE = r'/\*(?:(?!\*/)(?:\n|.))*\*/'
|
||||||
((?P<rsv>%(rsv)s)|(?P<call>%(call)s)|(?P<field>\.%(name)s)|
|
|
||||||
|
token = re.compile(r'''(?x)\s*(
|
||||||
|
(?P<comment>%(comment)s)|
|
||||||
|
(?P<rsv>%(rsv)s)|(?P<call>%(call)s)|(?P<field>\.%(name)s)|
|
||||||
(?P<assign>%(aop)s)|(%(exp)s)|
|
(?P<assign>%(aop)s)|(%(exp)s)|
|
||||||
(?P<end>;))\s*''' % {
|
(?P<end>;)
|
||||||
|
)\s*''' % {
|
||||||
'rsv': _RESERVED_RE,
|
'rsv': _RESERVED_RE,
|
||||||
'call': _CALL_RE,
|
'call': _CALL_RE,
|
||||||
'name': _NAME_RE,
|
'name': _NAME_RE,
|
||||||
'aop': _ASSIGN_OPERATORS_RE,
|
'aop': _ASSIGN_OPERATORS_RE,
|
||||||
|
'comment': _COMMENT_RE,
|
||||||
'exp': _EXP_RE
|
'exp': _EXP_RE
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -96,6 +101,8 @@ class JSInterpreter(object):
|
|||||||
if token_id == 'end':
|
if token_id == 'end':
|
||||||
yield stmt
|
yield stmt
|
||||||
stmt = ''
|
stmt = ''
|
||||||
|
elif token_id == 'comment':
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
if token_id == 'rsv':
|
if token_id == 'rsv':
|
||||||
pass
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user