xref: /OpenGrok/opengrok-indexer/src/main/jflex/analysis/perl/PerlSymbolTokenizer.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) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
22  * Portions Copyright (c) 2017, 2019, Chris Fraire <cfraire@me.com>.
23  */
24 
25 /*
26  * Gets Perl symbols - ignores comments, strings, keywords
27  */
28 
29 package org.opengrok.indexer.analysis.perl;
30 
31 import java.io.IOException;
32 import java.util.regex.Pattern;
33 import org.opengrok.indexer.util.StringUtils;
34 import org.opengrok.indexer.web.HtmlConsts;
35 %%
36 %public
37 %class PerlSymbolTokenizer
38 %extends PerlLexer
39 %unicode
40 %int
41 %char
42 %include ../CommonLexer.lexh
43 %{
44     private String lastSymbol;
45 
46     /**
47      * Resets the Perl tracked state; {@inheritDoc}
48      */
reset()49     public void reset() {
50         super.reset();
51         lastSymbol = null;
52     }
53 
54     @Override
offer(String value)55     public void offer(String value) throws IOException {
56         // noop
57     }
58 
59     @Override
offerSymbol(String value,int captureOffset,boolean ignoreKwd)60     public boolean offerSymbol(String value, int captureOffset,
61         boolean ignoreKwd)
62             throws IOException {
63         if (ignoreKwd || !Consts.kwd.contains(value)) {
64             lastSymbol = value;
65             onSymbolMatched(value, yychar + captureOffset);
66             return true;
67         } else {
68             lastSymbol = null;
69         }
70         return false;
71     }
72 
73     @Override
skipSymbol()74     public void skipSymbol() {
75         lastSymbol = null;
76     }
77 
78     @Override
offerKeyword(String value)79     public void offerKeyword(String value) throws IOException {
80         lastSymbol = null;
81     }
82 
83     @Override
startNewLine()84     public void startNewLine() throws IOException {
85         // noop
86     }
87 
88     @Override
disjointSpan(String className)89     public void disjointSpan(String className) throws IOException {
90         // noop
91     }
92 
93     @Override
phLOC()94     public void phLOC() {
95         // noop
96     }
97 
98     @Override
abortQuote()99     public void abortQuote() throws IOException {
100         yypop();
101         if (areModifiersOK()) {
102             yypush(QM);
103         }
104         disjointSpan(null);
105     }
106 
107     // If the state is YYINITIAL, then transitions to INTRA; otherwise does
108     // nothing, because other transitions would have saved the state.
maybeIntraState()109     public void maybeIntraState() {
110         if (yystate() == YYINITIAL) {
111             yybegin(INTRA);
112         }
113     }
114 
takeAllContent()115     protected boolean takeAllContent() {
116         return false;
117     }
118 
returnOnSymbol()119     protected boolean returnOnSymbol() {
120         return lastSymbol != null;
121     }
122 
skipLink(String url,Pattern p)123     protected void skipLink(String url, Pattern p) {
124         int n = StringUtils.countPushback(url, p);
125         if (n > 0) {
126             yypushback(n);
127         }
128     }
129 
130     /**
131      * Gets the constant value created by JFlex to represent QUOxLxN.
132      */
133     @Override
QUOxLxN()134     int QUOxLxN() { return QUOxLxN; }
135 
136     /**
137      * Gets the constant value created by JFlex to represent QUOxN.
138      */
139     @Override
QUOxN()140     int QUOxN() { return QUOxN; }
141 
142     /**
143      * Gets the constant value created by JFlex to represent QUOxL.
144      */
145     @Override
QUOxL()146     int QUOxL() { return QUOxL; }
147 
148     /**
149      * Gets the constant value created by JFlex to represent QUO.
150      */
151     @Override
QUO()152     int QUO() { return QUO; }
153 
154     /**
155      * Gets the constant value created by JFlex to represent HEREinxN.
156      */
157     @Override
HEREinxN()158     int HEREinxN() { return HEREinxN; }
159 
160     /**
161      * Gets the constant value created by JFlex to represent HERExN.
162      */
163     @Override
HERExN()164     int HERExN() { return HERExN; }
165 
166     /**
167      * Gets the constant value created by JFlex to represent HEREin.
168      */
169     @Override
HEREin()170     int HEREin() { return HEREin; }
171 
172     /**
173      * Gets the constant value created by JFlex to represent HERE.
174      */
175     @Override
HERE()176     int HERE() { return HERE; }
177 
178     /**
179      * Gets the constant value created by JFlex to represent SCOMMENT.
180      */
181     @Override
SCOMMENT()182     int SCOMMENT() { return SCOMMENT; }
183 
184     /**
185      * Gets the constant value created by JFlex to represent POD.
186      */
187     @Override
POD()188     int POD() { return POD; }
189 %}
190 
191 %include ../Common.lexh
192 %include ../CommonURI.lexh
193 %include ../CommonPath.lexh
194 %include PerlProductions.lexh
195