From 2c85715b937b42989fb7f62bbba4afdbd62e1aab Mon Sep 17 00:00:00 2001 From: sulyi Date: Wed, 23 Nov 2016 06:19:57 +0100 Subject: [PATCH] [jsinterp] Handling comments --- test/test_jsinterp.py | 2 +- youtube_dl/jsinterp.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/test/test_jsinterp.py b/test/test_jsinterp.py index c24b8ca74..310902e12 100644 --- a/test/test_jsinterp.py +++ b/test/test_jsinterp.py @@ -74,7 +74,7 @@ class TestJSInterpreter(unittest.TestCase): def test_comments(self): 'Skipping: Not yet fully implemented' - return + # return jsi = JSInterpreter(''' function x() { var x = /* 1 + */ 2; diff --git a/youtube_dl/jsinterp.py b/youtube_dl/jsinterp.py index 35d2c0096..fe7ac4dab 100644 --- a/youtube_dl/jsinterp.py +++ b/youtube_dl/jsinterp.py @@ -64,14 +64,19 @@ _EXP_RE = r'''(?P%(name)s)|(?P%(val)s)|(?P%(op)s)|%(par)s''' % { } # TODO validate expression (it's probably recursive!) _ARRAY_ELEMENT_RE = r'%(name)s\s*\[\s*(%(index)s)\s*\]' % {'name': _NAME_RE, 'index': _EXP_RE} -token = re.compile(r'''(?x)\s* - ((?P%(rsv)s)|(?P%(call)s)|(?P\.%(name)s)| +_COMMENT_RE = r'/\*(?:(?!\*/)(?:\n|.))*\*/' + +token = re.compile(r'''(?x)\s*( + (?P%(comment)s)| + (?P%(rsv)s)|(?P%(call)s)|(?P\.%(name)s)| (?P%(aop)s)|(%(exp)s)| - (?P;))\s*''' % { + (?P;) + )\s*''' % { 'rsv': _RESERVED_RE, 'call': _CALL_RE, 'name': _NAME_RE, 'aop': _ASSIGN_OPERATORS_RE, + 'comment': _COMMENT_RE, 'exp': _EXP_RE }) @@ -96,6 +101,8 @@ class JSInterpreter(object): if token_id == 'end': yield stmt stmt = '' + elif token_id == 'comment': + pass else: if token_id == 'rsv': pass