Matteo Scandolo | 46b5610 | 2015-12-16 14:23:08 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Javascript patterns |
| 3 | * |
| 4 | * @author Craig Campbell |
| 5 | * @version 1.0.7 |
| 6 | */ |
| 7 | Rainbow.extend('javascript', [ |
| 8 | |
| 9 | /** |
| 10 | * matches $. or $( |
| 11 | */ |
| 12 | { |
| 13 | 'name': 'selector', |
| 14 | 'pattern': /(\s|^)\$(?=\.|\()/g |
| 15 | }, |
| 16 | { |
| 17 | 'name': 'support', |
| 18 | 'pattern': /\b(window|document)\b/g |
| 19 | }, |
| 20 | { |
| 21 | 'matches': { |
| 22 | 1: 'support.property' |
| 23 | }, |
| 24 | 'pattern': /\.(length|node(Name|Value))\b/g |
| 25 | }, |
| 26 | { |
| 27 | 'matches': { |
| 28 | 1: 'support.function' |
| 29 | }, |
| 30 | 'pattern': /(setTimeout|setInterval)(?=\()/g |
| 31 | |
| 32 | }, |
| 33 | { |
| 34 | 'matches': { |
| 35 | 1: 'support.method' |
| 36 | }, |
| 37 | 'pattern': /\.(getAttribute|push|getElementById|getElementsByClassName|log|setTimeout|setInterval)(?=\()/g |
| 38 | }, |
| 39 | { |
| 40 | 'matches': { |
| 41 | 1: 'support.tag.script', |
| 42 | 2: [ |
| 43 | { |
| 44 | 'name': 'string', |
| 45 | 'pattern': /('|")(.*?)(\1)/g |
| 46 | }, |
| 47 | { |
| 48 | 'name': 'entity.tag.script', |
| 49 | 'pattern': /(\w+)/g |
| 50 | } |
| 51 | ], |
| 52 | 3: 'support.tag.script' |
| 53 | }, |
| 54 | 'pattern': /(<\/?)(script.*?)(>)/g |
| 55 | }, |
| 56 | |
| 57 | /** |
| 58 | * matches any escaped characters inside of a js regex pattern |
| 59 | * |
| 60 | * @see https://github.com/ccampbell/rainbow/issues/22 |
| 61 | * |
| 62 | * this was causing single line comments to fail so it now makes sure |
| 63 | * the opening / is not directly followed by a * |
| 64 | * |
| 65 | * @todo check that there is valid regex in match group 1 |
| 66 | */ |
| 67 | { |
| 68 | 'name': 'string.regexp', |
| 69 | 'matches': { |
| 70 | 1: 'string.regexp.open', |
| 71 | 2: { |
| 72 | 'name': 'constant.regexp.escape', |
| 73 | 'pattern': /\\(.){1}/g |
| 74 | }, |
| 75 | 3: 'string.regexp.cclose', |
| 76 | 4: 'string.regexp.modifier' |
| 77 | }, |
| 78 | 'pattern': /(\/)(?!\*)(.+)(\/)([igm]{0,3})/g |
| 79 | }, |
| 80 | |
| 81 | /** |
| 82 | * matches runtime function declarations |
| 83 | */ |
| 84 | { |
| 85 | 'matches': { |
| 86 | 1: 'storage', |
| 87 | 3: 'entity.function' |
| 88 | }, |
| 89 | 'pattern': /(var)?(\s|^)(.*)(?=\s?=\s?function\()/g |
| 90 | }, |
| 91 | |
| 92 | /** |
| 93 | * matches constructor call |
| 94 | */ |
| 95 | { |
| 96 | 'matches': { |
| 97 | 1: 'keyword', |
| 98 | 2: 'entity.function' |
| 99 | }, |
| 100 | 'pattern': /(new)\s+(.*)(?=\()/g |
| 101 | }, |
| 102 | |
| 103 | /** |
| 104 | * matches any function call in the style functionName: function() |
| 105 | */ |
| 106 | { |
| 107 | 'name': 'entity.function', |
| 108 | 'pattern': /(\w+)(?=:\s{0,}function)/g |
| 109 | } |
| 110 | ]); |