xref: /OpenGrok/opengrok-indexer/src/main/jflex/analysis/r/RProductions.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) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
22 * Portions Copyright (c) 2017, 2019-2020, Chris Fraire <cfraire@me.com>.
23 */
24
25<YYINITIAL> {
26    ^ "#line" / {WhspChar}    {
27        chkLOC();
28        offerKeyword(yytext());
29    }
30
31    // Special infix operators with only letters
32    "%in%" | "%o%" | "%x%" | "%" \p{L}+ "%"    {
33        offer("%");
34        offerKeyword(yytext().substring(1, yylength() - 1));
35        offer("%");
36    }
37
38    // Special infix operators otherwise
39    "%%" | "%*%" | "%/%" | "%" [\p{L}\p{M}\p{N}\p{P}\p{S}--[\%]]+ "%"    {
40        offer(yytext());
41    }
42
43    // Special identifiers starting with a dot
44    "..." | ".." [1-9] {decimal}*    {
45        offer(yytext());
46    }
47
48    {Identifier}    {
49        chkLOC();
50        if (offerSymbol(yytext(), 0, false) && returnOnSymbol()) {
51            return yystate();
52        }
53    }
54
55    {Number}    {
56        chkLOC();
57        onDisjointSpanChanged(HtmlConsts.NUMBER_CLASS, yychar);
58        offer(yytext());
59        onDisjointSpanChanged(null, yychar + yylength());
60    }
61
62    \'    {
63        chkLOC();
64        yypush(QSTRING);
65        onDisjointSpanChanged(HtmlConsts.STRING_CLASS, yychar);
66        offer(yytext());
67    }
68
69    \"    {
70        chkLOC();
71        yypush(STRING);
72        onDisjointSpanChanged(HtmlConsts.STRING_CLASS, yychar);
73        offer(yytext());
74    }
75
76    "#"    {
77        yypush(SCOMMENT);
78        onDisjointSpanChanged(HtmlConsts.COMMENT_CLASS, yychar);
79        offer(yytext());
80    }
81}
82
83<QSTRING> {
84    \'    {
85        chkLOC();
86        offer(yytext());
87        yypop();
88        onDisjointSpanChanged(null, yychar + yylength());
89    }
90}
91
92<STRING> {
93    \"    {
94        chkLOC();
95        offer(yytext());
96        yypop();
97        onDisjointSpanChanged(null, yychar + yylength());
98    }
99}
100
101<QSTRING, STRING> {
102    \\[\'\"\\]    {
103        chkLOC();
104        offer(yytext());
105    }
106
107    {MaybeWhsp}{EOL}    {
108        onDisjointSpanChanged(null, yychar);
109        onEndOfLineMatched(yytext(), yychar);
110        onDisjointSpanChanged(HtmlConsts.STRING_CLASS, yychar);
111    }
112}
113
114<SCOMMENT> {
115    {MaybeWhsp}{EOL}    {
116        yypushback(yylength());
117        yypop();
118        onDisjointSpanChanged(null, yychar);
119    }
120}
121
122<YYINITIAL> {
123    {MaybeWhsp}{EOL}    {
124        onEndOfLineMatched(yytext(), yychar);
125    }
126}
127
128<YYINITIAL, SCOMMENT, QSTRING, STRING> {
129    // Only one whitespace char at a time.
130    {WhspChar} | [[\s]--[\n\r]]    {
131        offer(yytext());
132    }
133
134    // Only one char at a time.
135    [^\n\r]    {
136        chkLOC();
137        offer(yytext());
138    }
139}
140
141// "string links" and "comment links"
142<SCOMMENT, QSTRING, STRING> {
143    {FPath}    {
144        chkLOC();
145        if (takeAllContent()) {
146            onPathlikeMatched(yytext(), '/', false, yychar);
147        }
148    }
149
150    {File}    {
151        chkLOC();
152        if (takeAllContent()) {
153            String path = yytext();
154            onFilelikeMatched(path, yychar);
155        }
156    }
157
158    {FNameChar}+ "@" {FNameChar}+ "." {FNameChar}+    {
159        chkLOC();
160        if (takeAllContent()) {
161            onEmailAddressMatched(yytext(), yychar);
162        }
163    }
164
165    {BrowseableURI}    {
166        chkLOC();
167        if (takeAllContent()) {
168            onUriMatched(yytext(), yychar, null);
169        }
170    }
171}
172