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) 2010, 2016, Oracle and/or its affiliates. All rights reserved. 22 * Portions Copyright (c) 2017, 2019-2020, Chris Fraire <cfraire@me.com>. 23 */ 24 25<HERE> { 26 ^ {Identifier} / {MaybeWhsp}{EOL} { 27 chkLOC(); 28 maybeHereEnd(yytext()); 29 } 30} 31 32<HEREin> { 33 ^ {MaybeWhsp} {Identifier} / {MaybeWhsp}{EOL} { 34 chkLOC(); 35 maybeHereEnd(yytext()); 36 } 37} 38 39<YYINITIAL> { 40 "<<" "-"? {MaybeWhsp} {Identifier} { 41 chkLOC(); 42 hereOp(yytext()); 43 } 44 45 {Identifier} { 46 chkLOC(); 47 if (offerSymbol(yytext(), 0, false)) { 48 yypush(POST_IDENTIFIER); 49 if (returnOnSymbol()) { 50 return yystate(); 51 } 52 } 53 } 54 55 {Numeric_literal} { 56 chkLOC(); 57 onDisjointSpanChanged(HtmlConsts.NUMBER_CLASS, yychar); 58 offer(yytext()); 59 onDisjointSpanChanged(null, yychar + yylength()); 60 } 61 62 \" { 63 chkLOC(); 64 yypush(QUOTED); 65 onDisjointSpanChanged(HtmlConsts.STRING_CLASS, yychar); 66 offer(yytext()); 67 } 68 69 "#" | "//" { 70 yypush(SCOMMENT); 71 onDisjointSpanChanged(HtmlConsts.COMMENT_CLASS, yychar); 72 offer(yytext()); 73 } 74 75 "/*" { 76 yypush(COMMENT); 77 onDisjointSpanChanged(HtmlConsts.COMMENT_CLASS, yychar); 78 offer(yytext()); 79 } 80 81 [\{\}] { 82 chkLOC(); 83 String capture = yytext(); 84 if (!maybeInterpolationEnd(capture)) { 85 offer(capture); 86 } 87 } 88} 89 90<QUOTED, STRING, HERE, HEREin> { 91 \\\\ { 92 chkLOC(); 93 offer(yytext()); 94 } 95} 96 97<QUOTED, STRING> { 98 \\\" { 99 chkLOC(); 100 offer(yytext()); 101 } 102 103 \" { 104 chkLOC(); 105 offer(yytext()); 106 yypop(); 107 onDisjointSpanChanged(null, yychar + yylength()); 108 } 109} 110 111<QUOTED, HERE, HEREin> { 112 /* 113 * Handle the escaping of interpolation and directive introductions as just 114 * regular quoted expression. 115 */ 116 ("$$" | "%%") "{" { 117 chkLOC(); 118 offer(yytext()); 119 } 120 121 // Interpolation or directive introduction 122 [$%] "{" { 123 chkLOC(); 124 offer(yytext()); 125 onDisjointSpanChanged(null, yychar); 126 yypush(YYINITIAL); 127 pushData(); 128 interpOp(); 129 } 130} 131 132<QUOTED, STRING, HERE, HEREin> { 133 /* 134 * For HCL quoted template expressions or string literals, "literal newline 135 * sequences are not permitted," but we'll handle anyway to avoid a possible 136 * JFlex "Error: could not match input" if a user accidentally violated 137 * HCL syntax. 138 */ 139 140 {MaybeWhsp}{EOL} { 141 onDisjointSpanChanged(null, yychar); 142 onEndOfLineMatched(yytext(), yychar); 143 onDisjointSpanChanged(HtmlConsts.STRING_CLASS, yychar); 144 } 145} 146 147<COMMENT> { 148 {MaybeWhsp}{EOL} { 149 onDisjointSpanChanged(null, yychar); 150 onEndOfLineMatched(yytext(), yychar); 151 onDisjointSpanChanged(HtmlConsts.COMMENT_CLASS, yychar); 152 } 153 154 "*/" { 155 offer(yytext()); 156 onDisjointSpanChanged(null, yychar); 157 yypop(); 158 } 159} 160 161<SCOMMENT> { 162 {MaybeWhsp}{EOL} { 163 yypushback(yylength()); 164 yypop(); 165 onDisjointSpanChanged(null, yychar); 166 } 167} 168 169<YYINITIAL, POST_IDENTIFIER> { 170 {MaybeWhsp}{EOL} { 171 if (maybeHereStart()) { 172 yypushback(yylength()); 173 } else { 174 onEndOfLineMatched(yytext(), yychar); 175 } 176 } 177} 178 179<POST_IDENTIFIER> { 180 \" { 181 chkLOC(); 182 yypop(); // Pop out of POST_IDENTIFIER first. 183 yypush(STRING); 184 onDisjointSpanChanged(HtmlConsts.STRING_CLASS, yychar); 185 offer(yytext()); 186 } 187} 188 189<YYINITIAL, POST_IDENTIFIER, COMMENT, SCOMMENT, QUOTED, STRING, HERE, HEREin> { 190 // Only one whitespace char at a time. 191 {WhspChar} | [[\s]--[\n\r]] { 192 offer(yytext()); 193 } 194} 195 196<POST_IDENTIFIER> { 197 // Any other character after handling above causes POST_IDENTIFIER to end. 198 [^] { 199 yypushback(yylength()); 200 yypop(); 201 } 202} 203 204<YYINITIAL, COMMENT, SCOMMENT, QUOTED, STRING, HERE, HEREin> { 205 // Only one char at a time. 206 [^\n\r] { 207 chkLOC(); 208 offer(yytext()); 209 } 210} 211 212// "string links" and "comment links" 213<COMMENT, SCOMMENT, QUOTED, STRING, HERE, HEREin> { 214 {FPath} { 215 chkLOC(); 216 if (takeAllContent()) { 217 onPathlikeMatched(yytext(), '/', false, yychar); 218 } 219 } 220 221 {File} { 222 chkLOC(); 223 if (takeAllContent()) { 224 String path = yytext(); 225 onFilelikeMatched(path, yychar); 226 } 227 } 228 229 {FNameChar}+ "@" {FNameChar}+ "." {FNameChar}+ { 230 chkLOC(); 231 if (takeAllContent()) { 232 onEmailAddressMatched(yytext(), yychar); 233 } 234 } 235} 236 237<COMMENT, SCOMMENT, QUOTED, STRING, HERE, HEREin> { 238 {BrowseableURI} { 239 chkLOC(); 240 if (takeAllContent()) { 241 onUriMatched(yytext(), yychar, null); 242 } 243 } 244} 245