xref: /OpenGrok/opengrok-indexer/src/main/jflex/analysis/clojure/ClojureXref.lex (revision d219b4cea555a12b602d2d5518daa22134ad4879)
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) 2015, 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 Clojure file
27  */
28 
29 package org.opengrok.indexer.analysis.clojure;
30 
31 import java.io.IOException;
32 import org.opengrok.indexer.analysis.JFlexSymbolMatcher;
33 import org.opengrok.indexer.web.HtmlConsts;
34 %%
35 %public
36 %class ClojureXref
37 %extends JFlexSymbolMatcher
38 %unicode
39 %int
40 %char
41 %include ../CommonLexer.lexh
42 %include ../CommonXref.lexh
43 %{
44   private int nestedComment;
45 
46   /**
47    * Resets the Clojure tracked state; {@inheritDoc}
48    */
49   @Override
reset()50   public void reset() {
51       super.reset();
52       nestedComment = 0;
53   }
54 
55   @Override
yypop()56   public void yypop() throws IOException {
57       onDisjointSpanChanged(null, yychar);
58       super.yypop();
59   }
60 
chkLOC()61   protected void chkLOC() {
62       switch (yystate()) {
63           case COMMENT:
64           case SCOMMENT:
65               break;
66           default:
67               phLOC();
68               break;
69       }
70   }
71 %}
72 
73 File = [a-zA-Z] {FNameChar}+ "." ([a-zA-Z]+)
74 
75 %state  STRING COMMENT SCOMMENT
76 
77 %include ../Common.lexh
78 %include ../CommonURI.lexh
79 %include ../CommonPath.lexh
80 %include Clojure.lexh
81 %%
82 <YYINITIAL>{
83 
84 {Identifier} {
85     chkLOC();
86     String id = yytext();
87     onFilteredSymbolMatched(id, yychar, Consts.kwd);
88 }
89 
90  {Number}    {
91     chkLOC();
92     onDisjointSpanChanged(HtmlConsts.NUMBER_CLASS, yychar);
93     onNonSymbolMatched(yytext(), yychar);
94     onDisjointSpanChanged(null, yychar);
95  }
96 
97  \"     {
98     chkLOC();
99     yypush(STRING);
100     onDisjointSpanChanged(HtmlConsts.STRING_CLASS, yychar);
101     onNonSymbolMatched(yytext(), yychar);
102  }
103  ";"    {
104     yypush(SCOMMENT);
105     onDisjointSpanChanged(HtmlConsts.COMMENT_CLASS, yychar);
106     onNonSymbolMatched(yytext(), yychar);
107  }
108 }
109 
110 <STRING> {
111  \" {WhspChar}+ \" |
112  \\[\"\\]    { chkLOC(); onNonSymbolMatched(yytext(), yychar); }
113  \"     {
114     chkLOC();
115     onNonSymbolMatched(yytext(), yychar);
116     yypop();
117  }
118 }
119 
120 <YYINITIAL, COMMENT> {
121  "#|"   {
122     if (nestedComment++ == 0) {
123         yypush(COMMENT);
124         onDisjointSpanChanged(HtmlConsts.COMMENT_CLASS, yychar);
125     }
126     onNonSymbolMatched(yytext(), yychar);
127  }
128 }
129 
130 <COMMENT> {
131  "|#"   {
132     onNonSymbolMatched(yytext(), yychar);
133     if (--nestedComment == 0) {
134         yypop();
135     }
136  }
137 }
138 
139 <SCOMMENT> {
140   {WhspChar}*{EOL} {
141     yypop();
142     onEndOfLineMatched(yytext(), yychar);
143   }
144 }
145 
146 <YYINITIAL, STRING, COMMENT, SCOMMENT> {
147 {WhspChar}*{EOL}    { onEndOfLineMatched(yytext(), yychar); }
148  [[\s]--[\n]]    { onNonSymbolMatched(yytext(), yychar); }
149  [^\n]    { chkLOC(); onNonSymbolMatched(yytext(), yychar); }
150 }
151 
152 <STRING, COMMENT, SCOMMENT> {
153  {FPath}    {
154     chkLOC();
155     onPathlikeMatched(yytext(), '/', false, yychar);
156  }
157 
158 {File}
159         {
160         chkLOC();
161         String path = yytext();
162         onFilelikeMatched(path, yychar);
163  }
164 
165 {BrowseableURI}    {
166           chkLOC();
167           onUriMatched(yytext(), yychar);
168         }
169 
170 {FNameChar}+ "@" {FNameChar}+ "." {FNameChar}+
171         {
172           chkLOC();
173           onEmailAddressMatched(yytext(), yychar);
174         }
175 }
176