xref: /OpenGrok/opengrok-indexer/src/main/jflex/analysis/verilog/VerilogSymbolTokenizer.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) 2019, Chris Fraire <cfraire@me.com>.
22  */
23 
24 package org.opengrok.indexer.analysis.verilog;
25 
26 import java.io.IOException;
27 import org.opengrok.indexer.web.HtmlConsts;
28 %%
29 %public
30 %class VerilogSymbolTokenizer
31 %extends VerilogLexer
32 %unicode
33 %int
34 %char
35 %include ../CommonLexer.lexh
36 %{
37     private String lastSymbol;
38 
39     /**
40      * Resets the Verilog tracked state; {@inheritDoc}
41      */
42     @Override
reset()43     public void reset() {
44         super.reset();
45         lastSymbol = null;
46     }
47 
48     @Override
offer(String value)49     public void offer(String value) throws IOException {
50         // noop
51     }
52 
53     @Override
offerSymbol(String value,int captureOffset,boolean ignoreKwd)54     public boolean offerSymbol(String value, int captureOffset,
55             boolean ignoreKwd) throws IOException {
56         if (ignoreKwd || !Consts.kwd.contains(value)) {
57             lastSymbol = value;
58             onSymbolMatched(value, yychar + captureOffset);
59             return true;
60         } else {
61             lastSymbol = null;
62         }
63         return false;
64     }
65 
66     @Override
skipSymbol()67     public void skipSymbol() {
68         lastSymbol = null;
69     }
70 
71     @Override
offerKeyword(String value)72     public void offerKeyword(String value) throws IOException {
73         lastSymbol = null;
74     }
75 
76     @Override
startNewLine()77     public void startNewLine() throws IOException {
78         // noop
79     }
80 
81     @Override
disjointSpan(String className)82     public void disjointSpan(String className) throws IOException {
83         // noop
84     }
85 
86     @Override
phLOC()87     public void phLOC() {
88         // noop
89     }
90 
takeAllContent()91     protected boolean takeAllContent() {
92         return false;
93     }
94 
returnOnSymbol()95     protected boolean returnOnSymbol() {
96         return lastSymbol != null;
97     }
98 
99     /**
100      * Gets the constant value created by JFlex to represent COMMENT.
101      */
102     @Override
COMMENT()103     int COMMENT() { return COMMENT; }
104 
105     /**
106      * Gets the constant value created by JFlex to represent SCOMMENT.
107      */
108     @Override
SCOMMENT()109     int SCOMMENT() { return SCOMMENT; }
110 %}
111 
112 %include ../Common.lexh
113 %include ../CommonURI.lexh
114 %include VerilogProductions.lexh
115