xref: /OpenGrok/opengrok-indexer/src/main/jflex/analysis/verilog/VerilogProductions.lexh (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
24IdentifierAnyChar = [A-Za-z_$0-9]
25CompilerDirective = \` [A-Za-z_]+
26EscapedIdentifier = \\[^\s]+
27SimpleIdentifier = [A-Za-z_] {IdentifierAnyChar}*
28SystemTaskFunctionIdentifier = "$" {IdentifierAnyChar}+
29
30Number = {Sign}? ({Integer} | {Real})
31Integer = ({Decimal_integer} | {Hexadecimal} | {Binary} | {Octal})
32Decimal_integer = ({UnsignedNumber} |
33        {NzUnsignedNumber}? {DecimalBase} ({UnsignedNumber} | [XxZz\?]) _*)
34Hexadecimal = {Size}? {HexBase} {HEXDIG} ("_" | {HEXDIG})*
35Binary = {Size}? {BinaryBase} {BINDIG} ("_" | {BINDIG})*
36Octal = {Size}? {OctalBase} {OCTDIG} ("_" | {OCTDIG})*
37Real = ({FixedPointNumber} |
38        {UnsignedNumber} ("." {UnsignedNumber})? [Ee] {Sign}? {UnsignedNumber})
39UnbasedUnsized = \' [01XxZz]
40Time = ({UnsignedNumber} | {FixedPointNumber})
41        ("s" | "fs" | "ms" | "ns" | "ps" | "us")
42UnsignedNumber = {DIGIT} ("_" | {DIGIT})*
43NzUnsignedNumber = [1-9] ("_" | {DIGIT})*
44FixedPointNumber = {UnsignedNumber} "." {UnsignedNumber}
45BasePrefix = \' [Ss]?
46DecimalBase = {BasePrefix} [Dd]
47HexBase =     {BasePrefix} [Hh]
48BinaryBase =  {BasePrefix} [Bb]
49OctalBase =   {BasePrefix} [Oo]
50DIGIT = [0-9]
51HEXDIG = [0-9a-fA-FXxZz\?]
52BINDIG = [01XxZz\?]
53OCTDIG = [0-7XxZz\?]
54Size = {NzUnsignedNumber}
55Sign = [\+\-]
56
57Delay = "#" ({UnsignedNumber} | {Real} | {Time} | "1step")
58
59/*
60 * COMMENT : block comment
61 * SCOMMENT : single-line comment
62 * STRING : string literal
63 */
64%state COMMENT SCOMMENT STRING
65
66%%
67<YYINITIAL> {
68    {SimpleIdentifier} | {SystemTaskFunctionIdentifier} |
69            {CompilerDirective}    {
70        chkLOC();
71        if (offerSymbol(yytext(), 0, false) && returnOnSymbol()) {
72            return yystate();
73        }
74    }
75
76    {EscapedIdentifier}    {
77        chkLOC();
78        String id = yytext().substring(1);
79        offer("\\");
80        if (offerSymbol(id, 1, true) && returnOnSymbol()) {
81            return yystate();
82        }
83    }
84
85    {Number} | {UnbasedUnsized} | {Time} | {Delay}    {
86        chkLOC();
87        onDisjointSpanChanged(HtmlConsts.NUMBER_CLASS, yychar);
88        offer(yytext());
89        onDisjointSpanChanged(null, yychar);
90    }
91
92    "/*"    {
93        yypush(COMMENT);
94        onDisjointSpanChanged(HtmlConsts.COMMENT_CLASS, yychar);
95        offer(yytext());
96    }
97
98    "//"    {
99        yypush(SCOMMENT);
100        onDisjointSpanChanged(HtmlConsts.COMMENT_CLASS, yychar);
101        offer(yytext());
102    }
103
104    \"    {
105        chkLOC();
106        yypush(STRING);
107        onDisjointSpanChanged(HtmlConsts.STRING_CLASS, yychar);
108        offer(yytext());
109    }
110}
111
112<COMMENT> {
113    /*
114     * Nesting of block comments is not recognized by SystemVerilog.
115     */
116
117    "*/"    {
118        offer(yytext());
119        onDisjointSpanChanged(null, yychar);
120        yypop();
121    }
122
123    {WhspChar}*{EOL}    {
124        onDisjointSpanChanged(null, yychar);
125        onEndOfLineMatched(yytext(), yychar);
126        onDisjointSpanChanged(HtmlConsts.COMMENT_CLASS, yychar);
127    }
128}
129
130<SCOMMENT> {
131    {WhspChar}*{EOL}    {
132        onDisjointSpanChanged(null, yychar);
133        yypop();
134        onEndOfLineMatched(yytext(), yychar);
135    }
136}
137
138<STRING> {
139    \"    {
140        chkLOC();
141        offer(yytext());
142        onDisjointSpanChanged(null, yychar);
143        yypop();
144    }
145
146    \\[\"\\]    {
147        chkLOC();
148        offer(yytext());
149    }
150
151    {WhspChar}*{EOL}    {
152        onDisjointSpanChanged(null, yychar);
153        onEndOfLineMatched(yytext(), yychar);
154        onDisjointSpanChanged(HtmlConsts.STRING_CLASS, yychar);
155    }
156}
157
158<YYINITIAL, COMMENT, SCOMMENT, STRING> {
159    {WhspChar}*{EOL}    {
160        onEndOfLineMatched(yytext(), yychar);
161    }
162
163    \s    {
164        offer(yytext());
165    }
166
167    [^]    {
168        chkLOC();
169        offer(yytext());
170    }
171}
172
173<COMMENT, SCOMMENT, STRING> {
174    {BrowseableURI}    {
175        chkLOC();
176        if (takeAllContent()) {
177            onUriMatched(yytext(), yychar);
178        }
179    }
180}
181