Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: lib/snippets.js

Issue 29761597: Issue 6538, 6781 - Implement script parsing for snippets (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Move singleCharacterEscapes to outer scope Created July 11, 2018, 6:56 p.m.
Right Patch Set: Revert Patch Set 8 Created July 12, 2018, 10:56 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | test/snippets.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 /** 83 /**
84 * Parses a script and returns a list of all its commands and their arguments 84 * Parses a script and returns a list of all its commands and their arguments
85 * @param {string} script 85 * @param {string} script
86 * @return {Array.<string[]>} 86 * @return {Array.<string[]>}
87 */ 87 */
88 function parseScript(script) 88 function parseScript(script)
89 { 89 {
90 let tree = []; 90 let tree = [];
91 91
92 let escape = false; 92 let escape = false;
93 let literal = false; 93 let withinQuotes = false;
94 94
95 let unicodeEscape = null; 95 let unicodeEscape = null;
96 96
97 let call = []; 97 let call = [];
98 let argument = ""; 98 let argument = "";
99 99
100 for (let character of script.trim() + ";") 100 for (let character of script.trim() + ";")
101 { 101 {
102 if (unicodeEscape != null) 102 if (unicodeEscape != null)
103 { 103 {
(...skipping 16 matching lines...) Expand all
120 unicodeEscape = ""; 120 unicodeEscape = "";
121 else 121 else
122 argument += singleCharacterEscapes.get(character) || character; 122 argument += singleCharacterEscapes.get(character) || character;
123 } 123 }
124 else if (character == "\\") 124 else if (character == "\\")
125 { 125 {
126 escape = true; 126 escape = true;
127 } 127 }
128 else if (character == "'") 128 else if (character == "'")
129 { 129 {
130 literal = !literal; 130 withinQuotes = !withinQuotes;
131 } 131 }
132 else if (literal || character != ";" && !/\s/u.test(character)) 132 else if (withinQuotes || character != ";" && !/\s/u.test(character))
133 { 133 {
134 argument += character; 134 argument += character;
135 } 135 }
136 else 136 else
137 { 137 {
138 if (argument) 138 if (argument)
139 { 139 {
140 call.push(argument); 140 call.push(argument);
141 argument = ""; 141 argument = "";
142 } 142 }
143 143
144 if (character == ";" && call.length > 0) 144 if (character == ";" && call.length > 0)
145 { 145 {
146 tree.push(call); 146 tree.push(call);
147 call = []; 147 call = [];
148 } 148 }
149 } 149 }
150 } 150 }
151 151
152 return tree; 152 return tree;
153 } 153 }
154 154
155 exports.parseScript = parseScript; 155 exports.parseScript = parseScript;
LEFTRIGHT
« no previous file | test/snippets.js » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld