OLD | NEW |
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 !ElemHide.getException(filter, domain)) | 72 !ElemHide.getException(filter, domain)) |
73 { | 73 { |
74 result.push(filter); | 74 result.push(filter); |
75 } | 75 } |
76 } | 76 } |
77 return result; | 77 return result; |
78 } | 78 } |
79 }; | 79 }; |
80 | 80 |
81 exports.Snippets = Snippets; | 81 exports.Snippets = Snippets; |
| 82 |
| 83 /** |
| 84 * Parses a script and returns a list of all its commands and their arguments |
| 85 * @param {string} script |
| 86 * @return {Array.<string[]>} |
| 87 */ |
| 88 function parseScript(script) |
| 89 { |
| 90 let tree = []; |
| 91 |
| 92 let escape = false; |
| 93 let literal = false; |
| 94 |
| 95 let call = []; |
| 96 let argument = ""; |
| 97 |
| 98 for (let character of [...script.trim(), ";"]) |
| 99 { |
| 100 if (escape) |
| 101 { |
| 102 escape = false; |
| 103 |
| 104 argument += character; |
| 105 } |
| 106 else if (character == "\\") |
| 107 { |
| 108 escape = true; |
| 109 } |
| 110 else if (character == "'") |
| 111 { |
| 112 literal = !literal; |
| 113 } |
| 114 else if (literal || character != ";" && !/\s/u.test(character)) |
| 115 { |
| 116 argument += character; |
| 117 } |
| 118 else |
| 119 { |
| 120 if (argument) |
| 121 { |
| 122 call.push(argument); |
| 123 argument = ""; |
| 124 } |
| 125 |
| 126 if (character == ";" && call.length > 0) |
| 127 { |
| 128 tree.push(call); |
| 129 call = []; |
| 130 } |
| 131 } |
| 132 } |
| 133 |
| 134 return tree; |
| 135 } |
| 136 |
| 137 exports.parseScript = parseScript; |
OLD | NEW |