1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * See LICENSE.txt included in this distribution for the specific 9 * language governing permissions and limitations under the License. 10 * 11 * When distributing Covered Code, include this CDDL HEADER in each 12 * file and include the License file at LICENSE.txt. 13 * If applicable, add the following below this CDDL HEADER, with the 14 * fields enclosed by brackets "[]" replaced with your own identifying 15 * information: Portions Copyright [yyyy] [name of copyright owner] 16 * 17 * CDDL HEADER END 18 */ 19 20/* 21 * Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved. 22 * Portions Copyright (c) 2017, 2019, Chris Fraire <cfraire@me.com>. 23 */ 24 25<YYINITIAL> { 26 27 {Identifier} { 28 chkLOC(); 29 if (offerSymbol(yytext(), 0, false) && returnOnSymbol()) { 30 return yystate(); 31 } 32 } 33 34 {NumericLiteral} { 35 chkLOC(); 36 onDisjointSpanChanged(HtmlConsts.NUMBER_CLASS, yychar); 37 offer(yytext()); 38 onDisjointSpanChanged(null, yychar); 39 } 40 41 \" { 42 chkLOC(); 43 yypush(STRING); 44 onDisjointSpanChanged(HtmlConsts.STRING_CLASS, yychar); 45 offer(yytext()); 46 } 47 48 \' { 49 chkLOC(); 50 yypush(QSTRING); 51 onDisjointSpanChanged(HtmlConsts.STRING_CLASS, yychar); 52 offer(yytext()); 53 } 54 55 \` { 56 chkLOC(); 57 yypush(TEMPLATE); 58 onDisjointSpanChanged(HtmlConsts.STRING_CLASS, yychar); 59 offer(yytext()); 60 } 61 62 "/*" { 63 yypush(COMMENT); 64 onDisjointSpanChanged(HtmlConsts.COMMENT_CLASS, yychar); 65 offer(yytext()); 66 } 67 68 "//" { 69 yypush(SCOMMENT); 70 onDisjointSpanChanged(HtmlConsts.COMMENT_CLASS, yychar); 71 offer(yytext()); 72 } 73 74 /* 75 * Literal regexps are in conflict with division "/" and are detected 76 * in javascript based on context and when ambiguous, the division has 77 * a higher precedence. We do a best-effort context matching for 78 * preceding "=" (variable), "(" (function call) or ":" (object). 79 */ 80 [:=(] {WhspChar}* "/" { 81 String capture = yytext(); 82 yypush(REGEXP); 83 offer(capture.substring(0, capture.length() - 1)); 84 onDisjointSpanChanged(HtmlConsts.STRING_CLASS, yychar + yylength() - 1); 85 offer("/"); 86 } 87 88 [\{\}] { 89 chkLOC(); 90 String capture = yytext(); 91 if (notInTemplateOrSubstitutionDoesNotEnd(capture)) { 92 offer(capture); 93 } 94 } 95} 96 97<STRING> { 98 \\[\"\\] { 99 chkLOC(); 100 offer(yytext()); 101 } 102 103 \" { 104 chkLOC(); 105 offer(yytext()); 106 onDisjointSpanChanged(null, yychar); 107 yypop(); 108 } 109} 110 111<REGEXP> { 112 \\[/] { 113 chkLOC(); 114 offer(yytext()); 115 } 116 \/[gimsuy]* { 117 chkLOC(); 118 offer("/"); 119 onDisjointSpanChanged(null, yychar); 120 offer(yytext().substring(1)); 121 yypop(); 122 } 123} 124 125<QSTRING> { 126 \\[\'\\] { 127 chkLOC(); 128 offer(yytext()); 129 } 130 131 \' { 132 chkLOC(); 133 offer(yytext()); 134 onDisjointSpanChanged(null, yychar); 135 yypop(); 136 } 137} 138 139<TEMPLATE> { 140 \\[\`\$\\] { 141 chkLOC(); 142 offer(yytext()); 143 } 144 145 \` { 146 chkLOC(); 147 offer(yytext()); 148 onDisjointSpanChanged(null, yychar); 149 yypop(); 150 } 151 152 "${" { 153 chkLOC(); 154 offer(yytext()); 155 onDisjointSpanChanged(null, yychar); 156 pushData(); 157 substitutionOp(); 158 yypush(YYINITIAL); 159 } 160} 161 162<COMMENT> { 163 "*/" { 164 offer(yytext()); 165 onDisjointSpanChanged(null, yychar); 166 yypop(); 167 } 168} 169 170<SCOMMENT> { 171 {WhspChar}*{EOL} { 172 onDisjointSpanChanged(null, yychar); 173 yypop(); 174 onEndOfLineMatched(yytext(), yychar); 175 } 176} 177 178<YYINITIAL, STRING, REGEXP, COMMENT, SCOMMENT, QSTRING, TEMPLATE> { 179 {WhspChar}*{EOL} { 180 onEndOfLineMatched(yytext(), yychar); 181 } 182 [[\s]--[\n]] { 183 offer(yytext()); 184 } 185 [^\n] { 186 chkLOC(); 187 offer(yytext()); 188 } 189} 190 191<STRING, COMMENT, SCOMMENT, QSTRING, TEMPLATE> { 192 {FPath} { 193 chkLOC(); 194 onPathlikeMatched(yytext(), '/', false, yychar); 195 } 196 197 {File} { 198 chkLOC(); 199 onFilelikeMatched(yytext(), yychar); 200 } 201 202 {FNameChar}+ "@" {FNameChar}+ "." {FNameChar}+ { 203 chkLOC(); 204 onEmailAddressMatched(yytext(), yychar); 205 } 206} 207 208<STRING, SCOMMENT, TEMPLATE> { 209 {BrowseableURI} { 210 chkLOC(); 211 onUriMatched(yytext(), yychar); 212 } 213} 214 215<COMMENT> { 216 {BrowseableURI} { 217 onUriMatched(yytext(), yychar, StringUtils.END_C_COMMENT); 218 } 219} 220 221<QSTRING> { 222 {BrowseableURI} { 223 chkLOC(); 224 onUriMatched(yytext(), yychar, StringUtils.APOS_NO_BSESC); 225 } 226} 227