[jsinterp] Handling comments - my first try
This commit is contained in:
parent
cc17865bc4
commit
1736a72438
@ -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;
|
||||||
|
@ -241,7 +241,23 @@ class JSInterpreter(object):
|
|||||||
raise ExtractorError('Could not find JS function %r' % funcname)
|
raise ExtractorError('Could not find JS function %r' % funcname)
|
||||||
argnames = func_m.group('args').split(',')
|
argnames = func_m.group('args').split(',')
|
||||||
|
|
||||||
return self.build_function(argnames, func_m.group('code'))
|
def validate_token(m):
|
||||||
|
if m.group(0).startswith('/*') and m.group(0).endswith('*/'):
|
||||||
|
return ''
|
||||||
|
elif (m.group(0).startswith('"') and m.group(0).endswith('"') or
|
||||||
|
m.group(0).startswith('\'') and m.group(0).endswith('\'')):
|
||||||
|
return m.group(0)
|
||||||
|
else:
|
||||||
|
# This shouldn't happen
|
||||||
|
return m.group(0)
|
||||||
|
|
||||||
|
# no comment
|
||||||
|
code = re.sub(r'''(?sx)
|
||||||
|
"(?:[^"\\]*(?:\\\\|\\['"nurtbfx/\n]))*[^"\\]*"|
|
||||||
|
'(?:[^'\\]*(?:\\\\|\\['"nurtbfx/\n]))*[^'\\]*'|
|
||||||
|
/\*(?:(?!\*/)(?:\n|.))*\*/''', validate_token, func_m.group('code'))
|
||||||
|
|
||||||
|
return self.build_function(argnames, code)
|
||||||
|
|
||||||
def extract_arguments(self, call):
|
def extract_arguments(self, call):
|
||||||
pattern = re.escape(call) if call.endswith(')') else r'%s\s*\(' % re.escape(call)
|
pattern = re.escape(call) if call.endswith(')') else r'%s\s*\(' % re.escape(call)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user