Skip to content

Commit 423d71b

Browse files
committed
Add Swift.lexh, and fix {Number} -- in SwiftSymbolTokenizer too
1 parent 4e06955 commit 423d71b

File tree

4 files changed

+52
-17
lines changed

4 files changed

+52
-17
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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) 2017, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
23+
*/
24+
25+
/*
26+
* TODO add unicode as stated in
27+
* https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/LexicalStructure.html#//apple_ref/swift/grammar/identifier-head
28+
*/
29+
30+
/* TODO: prohibit '$' in identifiers? */
31+
Identifier = [:jletter:] [:jletterdigit:]*
32+
33+
Number = ({binary} | {octal} | {hexadecimal} | \-?({decimal} | {floating}))
34+
binary = 0[bB][01_][01_]*
35+
octal = 0[oO][0-7][0-7_]*
36+
hexadecimal = 0[xX] {hexadecimal0}
37+
hexadecimal0 = [0-9a-fA-F][0-9a-fA-F_]*
38+
decimal = [0-9][0-9_]*
39+
floating = ({decimal} ("." {decimal})? ([eE] [\+\-]? {decimal})? |
40+
{hexadecimal} ("." {hexadecimal0})? ([pP] [\+\-]? {decimal})?)

src/org/opensolaris/opengrok/analysis/swift/SwiftSymbolTokenizer.lex

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@
2323
*/
2424

2525
/*
26-
* Gets Java symbols - ignores comments, strings, keywords
26+
* Gets Swift symbols - ignores comments, strings, keywords
2727
*/
2828

29-
// comments can be nested in kotlin, so below logic doesn't allow that with yybegin we save only one nesting
30-
// same for strings
31-
3229
package org.opensolaris.opengrok.analysis.swift;
3330
import org.opensolaris.opengrok.analysis.JFlexTokenizer;
3431

@@ -45,11 +42,10 @@ super(in);
4542
%include CommonTokenizer.lexh
4643
%char
4744

48-
/* TODO add unicode as stated in https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/LexicalStructure.html#//apple_ref/swift/grammar/identifier-head */
49-
Identifier = [:jletter:] [:jletterdigit:]*
50-
5145
%state STRING COMMENT SCOMMENT QSTRING TSTRING
5246

47+
%include Common.lexh
48+
%include Swift.lexh
5349
%%
5450

5551
/* TODO : support identifiers escaped by ` `*/
@@ -60,6 +56,8 @@ Identifier = [:jletter:] [:jletterdigit:]*
6056
return yystate(); }
6157
}
6258

59+
{Number} {}
60+
6361
\" { yybegin(STRING); }
6462
\' { yybegin(QSTRING); }
6563
\"\"\" { yybegin(TSTRING); }
@@ -87,9 +85,10 @@ Identifier = [:jletter:] [:jletterdigit:]*
8785
}
8886

8987
<SCOMMENT> {
90-
\n { yybegin(YYINITIAL);}
88+
{WhspChar}*{EOL} { yybegin(YYINITIAL);}
9189
}
9290

9391
<YYINITIAL, STRING, COMMENT, SCOMMENT, QSTRING, TSTRING> {
92+
{WhiteSpace} |
9493
[^] {}
9594
}

src/org/opensolaris/opengrok/analysis/swift/SwiftXref.lex

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,8 @@ import org.opensolaris.opengrok.web.Util;
4949
protected void setLineNumber(int x) { yyline = x; }
5050
%}
5151

52-
/* TODO: prohibit '$' in identifiers? */
53-
Identifier = [:jletter:] [:jletterdigit:]*
54-
5552
File = [a-zA-Z]{FNameChar}* "." ("java"|"properties"|"props"|"xml"|"conf"|"txt"|"htm"|"html"|"ini"|"jnlp"|"jad"|"diff"|"patch")
5653

57-
Number = (0[xX][0-9a-fA-F]+|[0-9]+\.[0-9]+|[0-9]+)(([eE][+-]?[0-9]+)?[ufdlUFDL]*)?
58-
5954
/* TODO support markdown in comments
6055
SdocWithClassArg = "@throws" | "@exception"
6156
SdocWithParamNameArg = "@param"
@@ -69,6 +64,7 @@ ParamName = {Identifier} | "<" {Identifier} ">"
6964
%include Common.lexh
7065
%include CommonURI.lexh
7166
%include CommonPath.lexh
67+
%include Swift.lexh
7268
%%
7369
<YYINITIAL>{
7470
\{ { incScope(); writeUnicodeChar(yycharat(0)); }

test/org/opensolaris/opengrok/analysis/swift/sample_xref.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,25 +172,25 @@
172172
<a class="l" name="164" href="#164">164</a><span class='fold-space'>&nbsp;</span>
173173
<a class="l" name="165" href="#165">165</a><span class='fold-space'>&nbsp;</span> @<a href="/source/s?defs=objc" class="intelliWindow-symbol" data-definition-place="undefined-in-file">objc</a> <b>private</b> <b>func</b> <a class="xf" name="changeDate"/><a href="/source/s?refs=changeDate" class="xf intelliWindow-symbol" data-definition-place="def">changeDate</a>(<a href="/source/s?defs=btn" class="intelliWindow-symbol" data-definition-place="undefined-in-file">btn</a>: <a href="/source/s?defs=UIButton" class="intelliWindow-symbol" data-definition-place="undefined-in-file">UIButton</a>) &#123;
174174
<a class="l" name="166" href="#166">166</a><span class='fold-space'>&nbsp;</span>
175-
<a class="l" name="167" href="#167">167</a><span class='fold-space'>&nbsp;</span> <b>if</b> <a href="/source/s?defs=btn" class="intelliWindow-symbol" data-definition-place="undefined-in-file">btn</a>.<a href="/source/s?defs=tag" class="intelliWindow-symbol" data-definition-place="undefined-in-file">tag</a> == <span class="n">0</span> + <span class="n">0</span><a href="/source/s?defs=b10" class="intelliWindow-symbol" data-definition-place="undefined-in-file">b10</a> - <span class="n">0</span><a href="/source/s?defs=b1_0" class="intelliWindow-symbol" data-definition-place="undefined-in-file">b1_0</a> &#123;
175+
<a class="l" name="167" href="#167">167</a><span class='fold-space'>&nbsp;</span> <b>if</b> <a href="/source/s?defs=btn" class="intelliWindow-symbol" data-definition-place="undefined-in-file">btn</a>.<a href="/source/s?defs=tag" class="intelliWindow-symbol" data-definition-place="undefined-in-file">tag</a> == <span class="n">0</span> + <span class="n">0b10</span> - <span class="n">0b1_0</span> &#123;
176176
<a class="l" name="168" href="#168">168</a><span class='fold-space'>&nbsp;</span>
177177
<a class="l" name="169" href="#169">169</a><span class='fold-space'>&nbsp;</span> <a class="d intelliWindow-symbol" href="#selectedDate" data-definition-place="defined-in-file">selectedDate</a> = <b>self</b>.<a href="/source/s?defs=monthView" class="intelliWindow-symbol" data-definition-place="undefined-in-file">monthView</a>.<a href="/source/s?defs=anim" class="intelliWindow-symbol" data-definition-place="undefined-in-file">anim</a>(<a href="/source/s?defs=direction" class="intelliWindow-symbol" data-definition-place="undefined-in-file">direction</a>: .<a href="/source/s?defs=backward" class="intelliWindow-symbol" data-definition-place="undefined-in-file">backward</a>, <a href="/source/s?defs=date" class="intelliWindow-symbol" data-definition-place="undefined-in-file">date</a>: <a class="d intelliWindow-symbol" href="#selectedDate" data-definition-place="defined-in-file">selectedDate</a>)
178178
<a class="hl" name="170" href="#170">170</a><span class='fold-space'>&nbsp;</span> <a href="/source/s?defs=_" class="intelliWindow-symbol" data-definition-place="undefined-in-file">_</a> = <b>self</b>.<a href="/source/s?defs=dayView" class="intelliWindow-symbol" data-definition-place="undefined-in-file">dayView</a>.<a href="/source/s?defs=anim" class="intelliWindow-symbol" data-definition-place="undefined-in-file">anim</a>(<a href="/source/s?defs=direction" class="intelliWindow-symbol" data-definition-place="undefined-in-file">direction</a>: .<a href="/source/s?defs=identity" class="intelliWindow-symbol" data-definition-place="undefined-in-file">identity</a>, <a href="/source/s?defs=date" class="intelliWindow-symbol" data-definition-place="undefined-in-file">date</a>: <a class="d intelliWindow-symbol" href="#selectedDate" data-definition-place="defined-in-file">selectedDate</a>)
179179
<a class="l" name="171" href="#171">171</a><span class='fold-space'>&nbsp;</span> <a href="/source/s?defs=_" class="intelliWindow-symbol" data-definition-place="undefined-in-file">_</a> = <b>self</b>.<a href="/source/s?defs=yearView" class="intelliWindow-symbol" data-definition-place="undefined-in-file">yearView</a>.<a href="/source/s?defs=anim" class="intelliWindow-symbol" data-definition-place="undefined-in-file">anim</a>(<a href="/source/s?defs=direction" class="intelliWindow-symbol" data-definition-place="undefined-in-file">direction</a>: .<a href="/source/s?defs=identity" class="intelliWindow-symbol" data-definition-place="undefined-in-file">identity</a>, <a href="/source/s?defs=date" class="intelliWindow-symbol" data-definition-place="undefined-in-file">date</a>: <a class="d intelliWindow-symbol" href="#selectedDate" data-definition-place="defined-in-file">selectedDate</a>)
180180
<a class="l" name="172" href="#172">172</a><span class='fold-space'>&nbsp;</span>
181-
<a class="l" name="173" href="#173">173</a><span class='fold-space'>&nbsp;</span> &#125; <b>else</b> <b>if</b> <a href="/source/s?defs=btn" class="intelliWindow-symbol" data-definition-place="undefined-in-file">btn</a>.<a href="/source/s?defs=tag" class="intelliWindow-symbol" data-definition-place="undefined-in-file">tag</a> == <span class="n">1</span> + <span class="n">0</span><a href="/source/s?defs=o70" class="intelliWindow-symbol" data-definition-place="undefined-in-file">o70</a> - <span class="n">0</span><a href="/source/s?defs=o7_0" class="intelliWindow-symbol" data-definition-place="undefined-in-file">o7_0</a> &#123;
181+
<a class="l" name="173" href="#173">173</a><span class='fold-space'>&nbsp;</span> &#125; <b>else</b> <b>if</b> <a href="/source/s?defs=btn" class="intelliWindow-symbol" data-definition-place="undefined-in-file">btn</a>.<a href="/source/s?defs=tag" class="intelliWindow-symbol" data-definition-place="undefined-in-file">tag</a> == <span class="n">1</span> + <span class="n">0o70</span> - <span class="n">0o7_0</span> &#123;
182182
<a class="l" name="174" href="#174">174</a><span class='fold-space'>&nbsp;</span>
183183
<a class="l" name="175" href="#175">175</a><span class='fold-space'>&nbsp;</span> <a class="d intelliWindow-symbol" href="#selectedDate" data-definition-place="defined-in-file">selectedDate</a> = <b>self</b>.<a href="/source/s?defs=monthView" class="intelliWindow-symbol" data-definition-place="undefined-in-file">monthView</a>.<a href="/source/s?defs=anim" class="intelliWindow-symbol" data-definition-place="undefined-in-file">anim</a>(<a href="/source/s?defs=direction" class="intelliWindow-symbol" data-definition-place="undefined-in-file">direction</a>: .<a href="/source/s?defs=forward" class="intelliWindow-symbol" data-definition-place="undefined-in-file">forward</a>, <a href="/source/s?defs=date" class="intelliWindow-symbol" data-definition-place="undefined-in-file">date</a>: <a class="d intelliWindow-symbol" href="#selectedDate" data-definition-place="defined-in-file">selectedDate</a>)
184184
<a class="l" name="176" href="#176">176</a><span class='fold-space'>&nbsp;</span> <a href="/source/s?defs=_" class="intelliWindow-symbol" data-definition-place="undefined-in-file">_</a> = <b>self</b>.<a href="/source/s?defs=dayView" class="intelliWindow-symbol" data-definition-place="undefined-in-file">dayView</a>.<a href="/source/s?defs=anim" class="intelliWindow-symbol" data-definition-place="undefined-in-file">anim</a>(<a href="/source/s?defs=direction" class="intelliWindow-symbol" data-definition-place="undefined-in-file">direction</a>: .<a href="/source/s?defs=identity" class="intelliWindow-symbol" data-definition-place="undefined-in-file">identity</a>, <a href="/source/s?defs=date" class="intelliWindow-symbol" data-definition-place="undefined-in-file">date</a>: <a class="d intelliWindow-symbol" href="#selectedDate" data-definition-place="defined-in-file">selectedDate</a>)
185185
<a class="l" name="177" href="#177">177</a><span class='fold-space'>&nbsp;</span> <a href="/source/s?defs=_" class="intelliWindow-symbol" data-definition-place="undefined-in-file">_</a> = <b>self</b>.<a href="/source/s?defs=yearView" class="intelliWindow-symbol" data-definition-place="undefined-in-file">yearView</a>.<a href="/source/s?defs=anim" class="intelliWindow-symbol" data-definition-place="undefined-in-file">anim</a>(<a href="/source/s?defs=direction" class="intelliWindow-symbol" data-definition-place="undefined-in-file">direction</a>: .<a href="/source/s?defs=identity" class="intelliWindow-symbol" data-definition-place="undefined-in-file">identity</a>, <a href="/source/s?defs=date" class="intelliWindow-symbol" data-definition-place="undefined-in-file">date</a>: <a class="d intelliWindow-symbol" href="#selectedDate" data-definition-place="defined-in-file">selectedDate</a>)
186186
<a class="l" name="178" href="#178">178</a><span class='fold-space'>&nbsp;</span>
187-
<a class="l" name="179" href="#179">179</a><span class='fold-space'>&nbsp;</span> &#125; <b>else</b> <b>if</b> <a href="/source/s?defs=btn" class="intelliWindow-symbol" data-definition-place="undefined-in-file">btn</a>.<a href="/source/s?defs=tag" class="intelliWindow-symbol" data-definition-place="undefined-in-file">tag</a> == <span class="n">2</span> + <span class="n">0xFF0</span> - <span class="n">0xFF0</span> + <span class="n">0xF</span><a href="/source/s?defs=p2" class="intelliWindow-symbol" data-definition-place="undefined-in-file">p2</a> - <span class="n">0xF</span><a href="/source/s?defs=P2" class="intelliWindow-symbol" data-definition-place="undefined-in-file">P2</a> + <span class="n">0x0</span><a href="/source/s?defs=p" class="intelliWindow-symbol" data-definition-place="undefined-in-file">p</a>-<span class="n">2</span> - <span class="n">0x0</span><a href="/source/s?defs=p" class="intelliWindow-symbol" data-definition-place="undefined-in-file">p</a>-<span class="n">2</span> &#123;
187+
<a class="l" name="179" href="#179">179</a><span class='fold-space'>&nbsp;</span> &#125; <b>else</b> <b>if</b> <a href="/source/s?defs=btn" class="intelliWindow-symbol" data-definition-place="undefined-in-file">btn</a>.<a href="/source/s?defs=tag" class="intelliWindow-symbol" data-definition-place="undefined-in-file">tag</a> == <span class="n">2</span> + <span class="n">0xFF0</span> - <span class="n">0xFF0</span> + <span class="n">0xFp2</span> - <span class="n">0xFP2</span> + <span class="n">0x0p-2</span> - <span class="n">0x0p-2</span> &#123;
188188
<a class="hl" name="180" href="#180">180</a><span class='fold-space'>&nbsp;</span>
189189
<a class="l" name="181" href="#181">181</a><span class='fold-space'>&nbsp;</span> <a class="d intelliWindow-symbol" href="#selectedDate" data-definition-place="defined-in-file">selectedDate</a> = <b>self</b>.<a href="/source/s?defs=dayView" class="intelliWindow-symbol" data-definition-place="undefined-in-file">dayView</a>.<a href="/source/s?defs=anim" class="intelliWindow-symbol" data-definition-place="undefined-in-file">anim</a>(<a href="/source/s?defs=direction" class="intelliWindow-symbol" data-definition-place="undefined-in-file">direction</a>: .<a href="/source/s?defs=backward" class="intelliWindow-symbol" data-definition-place="undefined-in-file">backward</a>, <a href="/source/s?defs=date" class="intelliWindow-symbol" data-definition-place="undefined-in-file">date</a>: <a class="d intelliWindow-symbol" href="#selectedDate" data-definition-place="defined-in-file">selectedDate</a>)
190190
<a class="l" name="182" href="#182">182</a><span class='fold-space'>&nbsp;</span> <a href="/source/s?defs=_" class="intelliWindow-symbol" data-definition-place="undefined-in-file">_</a> = <b>self</b>.<a href="/source/s?defs=monthView" class="intelliWindow-symbol" data-definition-place="undefined-in-file">monthView</a>.<a href="/source/s?defs=anim" class="intelliWindow-symbol" data-definition-place="undefined-in-file">anim</a>(<a href="/source/s?defs=direction" class="intelliWindow-symbol" data-definition-place="undefined-in-file">direction</a>: .<a href="/source/s?defs=identity" class="intelliWindow-symbol" data-definition-place="undefined-in-file">identity</a>, <a href="/source/s?defs=date" class="intelliWindow-symbol" data-definition-place="undefined-in-file">date</a>: <a class="d intelliWindow-symbol" href="#selectedDate" data-definition-place="defined-in-file">selectedDate</a>)
191191
<a class="l" name="183" href="#183">183</a><span class='fold-space'>&nbsp;</span> <a href="/source/s?defs=_" class="intelliWindow-symbol" data-definition-place="undefined-in-file">_</a> = <b>self</b>.<a href="/source/s?defs=yearView" class="intelliWindow-symbol" data-definition-place="undefined-in-file">yearView</a>.<a href="/source/s?defs=anim" class="intelliWindow-symbol" data-definition-place="undefined-in-file">anim</a>(<a href="/source/s?defs=direction" class="intelliWindow-symbol" data-definition-place="undefined-in-file">direction</a>: .<a href="/source/s?defs=identity" class="intelliWindow-symbol" data-definition-place="undefined-in-file">identity</a>, <a href="/source/s?defs=date" class="intelliWindow-symbol" data-definition-place="undefined-in-file">date</a>: <a class="d intelliWindow-symbol" href="#selectedDate" data-definition-place="defined-in-file">selectedDate</a>)
192192
<a class="l" name="184" href="#184">184</a><span class='fold-space'>&nbsp;</span>
193-
<a class="l" name="185" href="#185">185</a><span class='fold-space'>&nbsp;</span> &#125; <b>else</b> <b>if</b> <a href="/source/s?defs=btn" class="intelliWindow-symbol" data-definition-place="undefined-in-file">btn</a>.<a href="/source/s?defs=tag" class="intelliWindow-symbol" data-definition-place="undefined-in-file">tag</a> == <span class="n">3</span> + <span class="n">4</span><a href="/source/s?defs=_2" class="intelliWindow-symbol" data-definition-place="undefined-in-file">_2</a>.<span class="n">0</span> - <span class="n">4</span><a href="/source/s?defs=_2" class="intelliWindow-symbol" data-definition-place="undefined-in-file">_2</a>.<span class="n">0</span> + -<span class="n">1.0</span><a href="/source/s?defs=_0e2" class="intelliWindow-symbol" data-definition-place="undefined-in-file">_0e2</a> - -<span class="n">1.0e2</span> + <span class="n">2e1</span><a href="/source/s?defs=_0" class="intelliWindow-symbol" data-definition-place="undefined-in-file">_0</a> - <span class="n">2e10</span> &#123;
193+
<a class="l" name="185" href="#185">185</a><span class='fold-space'>&nbsp;</span> &#125; <b>else</b> <b>if</b> <a href="/source/s?defs=btn" class="intelliWindow-symbol" data-definition-place="undefined-in-file">btn</a>.<a href="/source/s?defs=tag" class="intelliWindow-symbol" data-definition-place="undefined-in-file">tag</a> == <span class="n">3</span> + <span class="n">4_2.0</span> - <span class="n">4_2.0</span> + <span class="n">-1.0_0e2</span> - <span class="n">-1.0e2</span> + <span class="n">2e1_0</span> - <span class="n">2e10</span> &#123;
194194
<a class="l" name="186" href="#186">186</a><span class='fold-space'>&nbsp;</span>
195195
<a class="l" name="187" href="#187">187</a><span class='fold-space'>&nbsp;</span> <a class="d intelliWindow-symbol" href="#selectedDate" data-definition-place="defined-in-file">selectedDate</a> = <b>self</b>.<a href="/source/s?defs=dayView" class="intelliWindow-symbol" data-definition-place="undefined-in-file">dayView</a>.<a href="/source/s?defs=anim" class="intelliWindow-symbol" data-definition-place="undefined-in-file">anim</a>(<a href="/source/s?defs=direction" class="intelliWindow-symbol" data-definition-place="undefined-in-file">direction</a>: .<a href="/source/s?defs=forward" class="intelliWindow-symbol" data-definition-place="undefined-in-file">forward</a>, <a href="/source/s?defs=date" class="intelliWindow-symbol" data-definition-place="undefined-in-file">date</a>: <a class="d intelliWindow-symbol" href="#selectedDate" data-definition-place="defined-in-file">selectedDate</a>)
196196
<a class="l" name="188" href="#188">188</a><span class='fold-space'>&nbsp;</span> <a href="/source/s?defs=_" class="intelliWindow-symbol" data-definition-place="undefined-in-file">_</a> = <b>self</b>.<a href="/source/s?defs=monthView" class="intelliWindow-symbol" data-definition-place="undefined-in-file">monthView</a>.<a href="/source/s?defs=anim" class="intelliWindow-symbol" data-definition-place="undefined-in-file">anim</a>(<a href="/source/s?defs=direction" class="intelliWindow-symbol" data-definition-place="undefined-in-file">direction</a>: .<a href="/source/s?defs=identity" class="intelliWindow-symbol" data-definition-place="undefined-in-file">identity</a>, <a href="/source/s?defs=date" class="intelliWindow-symbol" data-definition-place="undefined-in-file">date</a>: <a class="d intelliWindow-symbol" href="#selectedDate" data-definition-place="defined-in-file">selectedDate</a>)

0 commit comments

Comments
 (0)