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