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