diff options
author | yavanosta <yavanosta@yandex-team.ru> | 2015-04-20 01:43:06 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-20 08:43:15 +0000 |
commit | 33a7c5f7419d8be6388ccf71f85e47072c7baa7c (patch) | |
tree | b2abae9dddbf61a9182ca56648e8b1ee7af9f8e6 /tools/json_comment_eater | |
parent | 130a0b7f79b39e30a74d7eed511b44961029db5d (diff) | |
download | chromium_src-33a7c5f7419d8be6388ccf71f85e47072c7baa7c.zip chromium_src-33a7c5f7419d8be6388ccf71f85e47072c7baa7c.tar.gz chromium_src-33a7c5f7419d8be6388ccf71f85e47072c7baa7c.tar.bz2 |
Provide ability to use multiline comments in json files
There is two reasons to add it:
1. Browser parse files like _api_features.json in runtime with c++
parser which removes multiline comment normaly, but
json_comment_eater while processing files for docs site not.
It would be better if parsers did it equally.
2. It's convenient thing to use during development, when you need to
disable some code block.
R=kalman@chromium.org
BUG=473575
TEST=Script can be tested with json_comment_eater_test.py
Review URL: https://codereview.chromium.org/1079923004
Cr-Commit-Position: refs/heads/master@{#325804}
Diffstat (limited to 'tools/json_comment_eater')
-rw-r--r-- | tools/json_comment_eater/everything.json | 9 | ||||
-rw-r--r-- | tools/json_comment_eater/everything_expected.json | 7 | ||||
-rwxr-xr-x | tools/json_comment_eater/json_comment_eater.py | 7 |
3 files changed, 21 insertions, 2 deletions
diff --git a/tools/json_comment_eater/everything.json b/tools/json_comment_eater/everything.json index 31db503..4dc8e45 100644 --- a/tools/json_comment_eater/everything.json +++ b/tools/json_comment_eater/everything.json @@ -9,5 +9,12 @@ "escaped\"": "string\"isescaped", "more//": "\"more", "so\\many": "\\\\escapes\\\\\"whoa", - "comment//inmiddle": "of string" + "comment//inmiddle": "of string", + "comments": "yo", /* Comments all have a /* in them. */ + "strings": "yes", /* Comment with "strings" and " character */ + "more/*": "\"more", + /* SOMECOMMENT + "with": "anything\"" //inside + */ + "and": /*can be anywhere */ "in string" } diff --git a/tools/json_comment_eater/everything_expected.json b/tools/json_comment_eater/everything_expected.json index 3fa02c1..5c6442c 100644 --- a/tools/json_comment_eater/everything_expected.json +++ b/tools/json_comment_eater/everything_expected.json @@ -9,5 +9,10 @@ "escaped\"": "string\"isescaped", "more//": "\"more", "so\\many": "\\\\escapes\\\\\"whoa", - "comment//inmiddle": "of string" + "comment//inmiddle": "of string", + "comments": "yo", + "strings": "yes", + "more/*": "\"more", + + "and": "in string" } diff --git a/tools/json_comment_eater/json_comment_eater.py b/tools/json_comment_eater/json_comment_eater.py index 93261bf..d61ece2 100755 --- a/tools/json_comment_eater/json_comment_eater.py +++ b/tools/json_comment_eater/json_comment_eater.py @@ -50,11 +50,18 @@ def _ReadComment(input, start, output): output.append(eol_token) return eol_token_index + len(eol_token) +def _ReadMultilineComment(input, start, output): + end_tokens = ('*/',) + end_token_index, end_token = _FindNextToken(input, end_tokens, start) + if end_token is None: + raise Exception("Multiline comment end token (*/) not found") + return end_token_index + len(end_token) def Nom(input): token_actions = { '"': _ReadString, '//': _ReadComment, + '/*': _ReadMultilineComment, } output = [] pos = 0 |