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) 2016, 2021, Oracle and/or its affiliates. All rights reserved. 22 * Portions Copyright (c) 2017-2018, Chris Fraire <cfraire@me.com>. 23 */ 24 25 /* 26 * Cross reference a Pascal file 27 */ 28 29 package org.opengrok.indexer.analysis.pascal; 30 31 import org.opengrok.indexer.analysis.JFlexSymbolMatcher; 32 import org.opengrok.indexer.analysis.ScopeAction; 33 import org.opengrok.indexer.web.HtmlConsts; 34 %% 35 %public 36 %class PascalXref 37 %extends JFlexSymbolMatcher 38 %unicode 39 %ignorecase 40 %int 41 %char 42 %include ../CommonLexer.lexh 43 %include ../CommonXref.lexh 44 %{ chkLOC()45 protected void chkLOC() { 46 switch (yystate()) { 47 case COMMENT: 48 case PCOMMENT: 49 case SCOMMENT: 50 break; 51 default: 52 phLOC(); 53 break; 54 } 55 } 56 %} 57 58 File = [a-zA-Z]{FNameChar}* "." ("pas"|"properties"|"props"|"xml"|"conf"|"txt"|"htm"|"html"|"ini"|"diff"|"patch") 59 60 %state COMMENT PCOMMENT SCOMMENT QSTRING 61 62 %include ../Common.lexh 63 %include ../CommonURI.lexh 64 %include ../CommonPath.lexh 65 %include Pascal.lexh 66 %% 67 <YYINITIAL>{ 68 "begin" { chkLOC(); onScopeChanged(ScopeAction.INC, yytext(), yychar); } 69 "end" { chkLOC(); onScopeChanged(ScopeAction.DEC, yytext(), yychar); } 70 \; { chkLOC(); onScopeChanged(ScopeAction.END, yytext(), yychar); } 71 72 \&{Identifier} { 73 chkLOC(); 74 String id = yytext(); 75 onNonSymbolMatched("&", yychar); 76 onSymbolMatched(id.substring(1), yychar + 1); 77 } 78 {Identifier} { 79 chkLOC(); 80 String id = yytext(); 81 onFilteredSymbolMatched(id, yychar, Consts.kwd); 82 } 83 84 "<" ({File}|{FPath}) ">" { 85 chkLOC(); 86 onNonSymbolMatched("<", yychar); 87 String path = yytext(); 88 path = path.substring(1, path.length() - 1); 89 onFilelikeMatched(path, yychar + 1); 90 onNonSymbolMatched(">", yychar + 1 + path.length()); 91 } 92 93 {Number} { 94 chkLOC(); 95 onDisjointSpanChanged(HtmlConsts.NUMBER_CLASS, yychar); 96 onNonSymbolMatched(yytext(), yychar); 97 onDisjointSpanChanged(null, yychar); 98 } 99 100 {ControlString} { 101 chkLOC(); 102 onDisjointSpanChanged(HtmlConsts.STRING_CLASS, yychar); 103 onNonSymbolMatched(yytext(), yychar); 104 onDisjointSpanChanged(null, yychar); 105 } 106 107 \' { 108 yybegin(QSTRING); 109 onDisjointSpanChanged(HtmlConsts.STRING_CLASS, yychar); 110 onNonSymbolMatched(yytext(), yychar); 111 } 112 \{ { 113 yypush(COMMENT); 114 onDisjointSpanChanged(HtmlConsts.COMMENT_CLASS, yychar); 115 onNonSymbolMatched(yytext(), yychar); 116 } 117 "(*" { 118 yypush(PCOMMENT); 119 onDisjointSpanChanged(HtmlConsts.COMMENT_CLASS, yychar); 120 onNonSymbolMatched(yytext(), yychar); 121 } 122 "//" { 123 yybegin(SCOMMENT); 124 onDisjointSpanChanged(HtmlConsts.COMMENT_CLASS, yychar); 125 onNonSymbolMatched(yytext(), yychar); 126 } 127 } 128 129 <QSTRING> { 130 \'\' { chkLOC(); onNonSymbolMatched(yytext(), yychar); } 131 \' { 132 chkLOC(); 133 yybegin(YYINITIAL); 134 onNonSymbolMatched(yytext(), yychar); 135 onDisjointSpanChanged(null, yychar); 136 } 137 } 138 139 <COMMENT> { 140 \} { 141 yypop(); 142 onNonSymbolMatched(yytext(), yychar); 143 if (yystate() == YYINITIAL) onDisjointSpanChanged(null, yychar); 144 } 145 "(*" { 146 yypush(PCOMMENT); 147 onNonSymbolMatched(yytext(), yychar); 148 } 149 } 150 151 <PCOMMENT> { 152 "*)" { 153 yypop(); 154 onNonSymbolMatched(yytext(), yychar); 155 if (yystate() == YYINITIAL) onDisjointSpanChanged(null, yychar); 156 } 157 \{ { 158 yypush(COMMENT); 159 onNonSymbolMatched(yytext(), yychar); 160 } 161 } 162 163 <SCOMMENT> { 164 {WhspChar}*{EOL} { 165 yybegin(YYINITIAL); 166 onDisjointSpanChanged(null, yychar); 167 onEndOfLineMatched(yytext(), yychar); 168 } 169 } 170 171 172 <YYINITIAL, COMMENT, PCOMMENT, SCOMMENT, QSTRING> { 173 {WhspChar}*{EOL} { onEndOfLineMatched(yytext(), yychar); } 174 [[\s]--[\n]] { onNonSymbolMatched(yytext(), yychar); } 175 [^\n] { chkLOC(); onNonSymbolMatched(yytext(), yychar); } 176 } 177 178 <COMMENT, PCOMMENT, SCOMMENT, QSTRING> { 179 {FPath} 180 { chkLOC(); onPathlikeMatched(yytext(), '/', false, yychar); } 181 182 {File} 183 { 184 chkLOC(); 185 String path = yytext(); 186 onFilelikeMatched(path, yychar); 187 } 188 189 {FNameChar}+ "@" {FNameChar}+ "." {FNameChar}+ 190 { 191 chkLOC(); 192 onEmailAddressMatched(yytext(), yychar); 193 } 194 } 195 196 <COMMENT, SCOMMENT> { 197 {BrowseableURI} { 198 chkLOC(); 199 onUriMatched(yytext(), yychar); 200 } 201 } 202 203 <PCOMMENT> { 204 {BrowseableURI} { 205 chkLOC(); 206 onUriMatched(yytext(), yychar, PascalUtils.END_OLD_PASCAL_COMMENT); 207 } 208 } 209 210 <QSTRING> { 211 {BrowseableURI} { 212 chkLOC(); 213 onUriMatched(yytext(), yychar, PascalUtils.CHARLITERAL_APOS_DELIMITER); 214 } 215 } 216