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) 2017, 2021, Oracle and/or its affiliates. All rights reserved. 22 * Portions Copyright (c) 2017, Chris Fraire <cfraire@me.com>. 23 */ 24 25 /* 26 * Cross reference a Json file 27 */ 28 29 package org.opengrok.indexer.analysis.json; 30 31 import org.opengrok.indexer.analysis.JFlexSymbolMatcher; 32 import java.io.IOException; 33 import org.opengrok.indexer.web.HtmlConsts; 34 %% 35 %public 36 %class JsonXref 37 %extends JFlexSymbolMatcher 38 %unicode 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 %} 50 51 File = [a-zA-Z]{FNameChar}* "." ([Jj][Ss] | 52 [Pp][Rr][Oo][Pp][Ee][Rr][Tt][Ii][Ee][Ss] | [Pp][Rr][Oo][Pp][Ss] | 53 [Xx][Mm][Ll] | [Cc][Oo][Nn][Ff] | [Tt][Xx][Tt] | [Hh][Tt][Mm] | 54 [Hh][Tt][Mm][Ll]? | [Ii][Nn][Ii] | [Dd][Ii][Ff][Ff] | [Pp][Aa][Tt][Cc][Hh]) 55 56 %state STRING 57 58 %include ../Common.lexh 59 %include ../CommonURI.lexh 60 %include ../CommonPath.lexh 61 %include Json.lexh 62 %% 63 <YYINITIAL>{ 64 65 66 //TODO add support for identifiers on the left side, restruct the way how we see quoted strings, ctags detect them as identifiers, xref should print them that way too 67 //improve per http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf 68 {Identifier} { 69 phLOC(); 70 String id = yytext(); 71 onFilteredSymbolMatched(id, yychar, Consts.kwd); 72 } 73 74 "<" ({File}|{FPath}) ">" { 75 phLOC(); 76 onNonSymbolMatched("<", yychar); 77 String path = yytext(); 78 path = path.substring(1, path.length() - 1); 79 onFilelikeMatched(path, yychar + 1); 80 onNonSymbolMatched(">", yychar + 1 + path.length()); 81 } 82 83 /* 84 { onPathlikeMatched(yytext(), '.', false, yychar); } 85 */ 86 87 {Number} { 88 phLOC(); 89 onDisjointSpanChanged(HtmlConsts.NUMBER_CLASS, yychar); 90 onNonSymbolMatched(yytext(), yychar); 91 onDisjointSpanChanged(null, yychar); 92 } 93 94 \" { 95 phLOC(); 96 yypush(STRING); 97 onDisjointSpanChanged(HtmlConsts.STRING_CLASS, yychar); 98 onNonSymbolMatched(yytext(), yychar); 99 } 100 } 101 102 <STRING> { 103 \\[\"\\] | 104 \" {WhspChar}+ \" { phLOC(); onNonSymbolMatched(yytext(), yychar); } 105 \" { 106 phLOC(); 107 onNonSymbolMatched(yytext(), yychar); 108 yypop(); 109 } 110 } 111 112 <YYINITIAL, STRING> { 113 {WhspChar}*{EOL} { onEndOfLineMatched(yytext(), yychar); } 114 [[\s]--[\n]] { onNonSymbolMatched(yytext(), yychar); } 115 [^\n] { phLOC(); onNonSymbolMatched(yytext(), yychar); } 116 } 117 118 <STRING> { 119 {FPath} { 120 phLOC(); 121 onPathlikeMatched(yytext(), '/', false, yychar); 122 } 123 124 {File} 125 { 126 phLOC(); 127 String path = yytext(); 128 onFilelikeMatched(path, yychar); 129 } 130 131 {BrowseableURI} { 132 phLOC(); 133 onUriMatched(yytext(), yychar); 134 } 135 136 {FNameChar}+ "@" {FNameChar}+ "." {FNameChar}+ 137 { 138 phLOC(); 139 onEmailAddressMatched(yytext(), yychar); 140 } 141 } 142