Skip to content

Commit c527202

Browse files
authored
Merge pull request #1833 from idodeclare/feature/perl_symbols
Feature/perl symbols
2 parents ab72ced + c48e2ca commit c527202

File tree

13 files changed

+2056
-650
lines changed

13 files changed

+2056
-650
lines changed

src/org/opensolaris/opengrok/analysis/JFlexTokenizer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opensolaris.opengrok.analysis;
2425

@@ -113,4 +114,13 @@ public void yypush(int newState) {
113114
public void yypop() {
114115
this.yybegin(this.stack.pop());
115116
}
117+
118+
/**
119+
* reset current yy state, and clear stack
120+
* @param newState state id
121+
*/
122+
public void yyjump(int newState) {
123+
yybegin(newState);
124+
this.stack.clear();
125+
}
116126
}

src/org/opensolaris/opengrok/analysis/JFlexXref.java

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
/*
2121
* Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright 2011 Jens Elkner.
23+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
2324
*/
2425
package org.opensolaris.opengrok.analysis;
2526

@@ -537,27 +538,31 @@ protected void startNewLine() throws IOException {
537538
* @param keywords a set of keywords recognized by this analyzer (no links
538539
* will be generated if the symbol is a keyword)
539540
* @param line the line number on which the symbol appears
541+
* @return true if the {@code symbol} was not in {@code keywords} or if
542+
* {@code keywords} was null
540543
* @throws IOException if an error occurs while writing to the stream
541544
*/
542-
protected void writeSymbol(String symbol, Set<String> keywords, int line)
545+
protected boolean writeSymbol(String symbol, Set<String> keywords, int line)
543546
throws IOException {
544-
writeSymbol(symbol, keywords, line, true, false);
547+
return writeSymbol(symbol, keywords, line, true, false);
545548
}
546549

547-
/**
550+
/**
548551
* Write a symbol and generate links as appropriate.
549552
*
550553
* @param symbol the symbol to write
551554
* @param keywords a set of keywords recognized by this analyzer (no links
552555
* will be generated if the symbol is a keyword)
553556
* @param line the line number on which the symbol appears
554557
* @param caseSensitive Whether the keyword list is case sensitive
558+
* @return true if the {@code symbol} was not in {@code keywords} or if
559+
* {@code keywords} was null
555560
* @throws IOException if an error occurs while writing to the stream
556561
*/
557-
protected void writeSymbol(
562+
protected boolean writeSymbol(
558563
String symbol, Set<String> keywords, int line, boolean caseSensitive)
559564
throws IOException {
560-
writeSymbol(symbol, keywords, line, caseSensitive, false);
565+
return writeSymbol(symbol, keywords, line, caseSensitive, false);
561566
}
562567

563568
/**
@@ -569,21 +574,45 @@ protected void writeSymbol(
569574
* @param line the line number on which the symbol appears
570575
* @param caseSensitive Whether the keyword list is case sensitive
571576
* @param quote Whether the symbol gets quoted in links or not
577+
* @return true if the {@code symbol} was not in {@code keywords} or if
578+
* {@code keywords} was null
579+
* @throws IOException if an error occurs while writing to the stream
580+
*/
581+
protected boolean writeSymbol(String symbol, Set<String> keywords,
582+
int line, boolean caseSensitive, boolean quote)
583+
throws IOException {
584+
return writeSymbol(symbol, keywords, line, caseSensitive, quote, false);
585+
}
586+
587+
/**
588+
* Write a symbol and generate links as appropriate.
589+
*
590+
* @param symbol the symbol to write
591+
* @param keywords a set of keywords recognized by this analyzer (no links
592+
* will be generated if the symbol is a keyword)
593+
* @param line the line number on which the symbol appears
594+
* @param caseSensitive Whether the keyword list is case sensitive
595+
* @param quote Whether the symbol gets quoted in links or not
596+
* @param isKeyword Whether the symbol is certainly a keyword without
597+
* bothering to look up in a defined {@code keywords}
598+
* @return true if the {@code symbol} was not in {@code keywords} or if
599+
* {@code keywords} was null and if-and-only-if {@code isKeyword} is false
572600
* @throws IOException if an error occurs while writing to the stream
573601
*/
574-
protected void writeSymbol(
575-
String symbol, Set<String> keywords, int line, boolean caseSensitive, boolean quote)
602+
protected boolean writeSymbol(
603+
String symbol, Set<String> keywords, int line, boolean caseSensitive,
604+
boolean quote, boolean isKeyword)
576605
throws IOException {
577606
String[] strs = new String[1];
578607
strs[0] = "";
579608
String jsEscapedSymbol = symbol.replace("'", "\\'");
580609
String qt = (quote) ? "&quot;" : "";
581610

582611
String check = caseSensitive ? symbol : symbol.toLowerCase();
583-
if (keywords != null && keywords.contains( check )) {
612+
if (isKeyword || (keywords != null && keywords.contains( check ))) {
584613
// This is a keyword, so we don't create a link.
585614
out.append("<b>").append(symbol).append("</b>");
586-
615+
return false;
587616
} else if (defs != null && defs.hasDefinitionAt(symbol, line, strs)) {
588617
// This is the definition of the symbol.
589618
String type = strs[0];
@@ -658,6 +687,18 @@ protected void writeSymbol(
658687
out.append(symbol);
659688
out.append("</a>");
660689
}
690+
return true;
691+
}
692+
693+
/**
694+
* Write an {@code htmlize()}d keyword symbol
695+
*
696+
* @param symbol the symbol to write
697+
* @param line the line number on which the symbol appears
698+
* @throws IOException if an error occurs while writing to the stream
699+
*/
700+
protected void writeKeyword(String symbol, int line) throws IOException {
701+
writeSymbol(htmlize(symbol), null, line, false, false, true);
661702
}
662703

663704
/**
@@ -711,4 +752,14 @@ public void yypop() throws IOException {
711752
out.write(popString);
712753
}
713754
}
755+
756+
/**
757+
* reset current yy state, and clear stack
758+
* @param newState state id
759+
*/
760+
public void yyjump(int newState) {
761+
yybegin(newState);
762+
this.stack.clear();
763+
this.stackPopString.clear();
764+
}
714765
}

src/org/opensolaris/opengrok/analysis/perl/Consts.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
* Holds static hash set containing the Perl keywords
3131
*/
3232
public class Consts{
33+
public static final String SC = "<span class=\"c\">";
34+
public static final String SN = "<span class=\"n\">";
35+
public static final String SS = "<span class=\"s\">";
36+
public static final String ZS = "</span>";
37+
3338
public static final Set<String> kwd = new HashSet<String>() ;
3439
static {
3540
// Note that keywords with 1 letter will be ignored for {Identifier}
@@ -46,16 +51,25 @@ public class Consts{
4651
kwd.add("alarm");
4752
kwd.add("and");
4853
kwd.add("atan2");
54+
kwd.add("attributes");
55+
kwd.add("autodie");
4956
kwd.add("AUTOLOAD");
57+
kwd.add("autouse");
5058
kwd.add("base");
5159
kwd.add("BEGIN");
60+
kwd.add("bigint");
61+
kwd.add("bignum");
62+
kwd.add("bigrat");
5263
kwd.add("bind");
5364
kwd.add("binmode");
5465
kwd.add("bless");
66+
kwd.add("blib");
5567
kwd.add("break");
5668
kwd.add("byte");
69+
kwd.add("bytes");
5770
kwd.add("caller");
5871
kwd.add("carp");
72+
kwd.add("charnames");
5973
kwd.add("chdir");
6074
kwd.add("CHECK");
6175
kwd.add("chmod");
@@ -69,6 +83,7 @@ public class Consts{
6983
kwd.add("cmp");
7084
kwd.add("confess");
7185
kwd.add("connect");
86+
kwd.add("constant");
7287
kwd.add("continue");
7388
kwd.add("CORE");
7489
kwd.add("cos");
@@ -80,13 +95,15 @@ public class Consts{
8095
kwd.add("defined");
8196
kwd.add("delete");
8297
kwd.add("DESTROY");
98+
kwd.add("diagnostics");
8399
kwd.add("die");
84100
kwd.add("do");
85101
kwd.add("dump");
86102
kwd.add("each");
87103
kwd.add("else");
88104
kwd.add("elseif"); /* parsed "but only to warn you ..." */
89105
kwd.add("elsif");
106+
kwd.add("encoding");
90107
kwd.add("END");
91108
kwd.add("endgrent");
92109
kwd.add("endhostent");
@@ -105,8 +122,10 @@ public class Consts{
105122
kwd.add("exp");
106123
kwd.add("fc");
107124
kwd.add("fcntl");
125+
kwd.add("feature");
108126
kwd.add("fields");
109127
kwd.add("fileno");
128+
kwd.add("filetest");
110129
kwd.add("flock");
111130
kwd.add("for");
112131
kwd.add("foreach");
@@ -162,10 +181,12 @@ public class Consts{
162181
kwd.add("lcfirst");
163182
kwd.add("le");
164183
kwd.add("length");
184+
kwd.add("less");
165185
kwd.add("lib");
166186
kwd.add("link");
167187
kwd.add("listen");
168188
kwd.add("local");
189+
kwd.add("locale");
169190
kwd.add("localtime");
170191
kwd.add("lock");
171192
kwd.add("log");
@@ -174,6 +195,7 @@ public class Consts{
174195
kwd.add("m");
175196
kwd.add("map");
176197
kwd.add("mkdir");
198+
kwd.add("mro");
177199
kwd.add("msgctl");
178200
kwd.add("msgget");
179201
kwd.add("msgrcv");
@@ -187,11 +209,15 @@ public class Consts{
187209
kwd.add("oct");
188210
kwd.add("open");
189211
kwd.add("opendir");
212+
kwd.add("ops");
190213
kwd.add("or");
191214
kwd.add("ord");
192215
kwd.add("our");
216+
kwd.add("overload");
217+
kwd.add("overloading");
193218
kwd.add("pack");
194219
kwd.add("package");
220+
kwd.add("parent");
195221
kwd.add("pipe");
196222
kwd.add("pop");
197223
kwd.add("pos");
@@ -206,6 +232,7 @@ public class Consts{
206232
kwd.add("qw");
207233
kwd.add("qx");
208234
kwd.add("rand");
235+
kwd.add("re");
209236
kwd.add("read");
210237
kwd.add("readdir");
211238
kwd.add("readline");
@@ -275,6 +302,8 @@ public class Consts{
275302
kwd.add("syswrite");
276303
kwd.add("tell");
277304
kwd.add("telldir");
305+
kwd.add("threads::shared");
306+
kwd.add("threads");
278307
kwd.add("tie");
279308
kwd.add("tied");
280309
kwd.add("time");
@@ -298,10 +327,12 @@ public class Consts{
298327
kwd.add("values");
299328
kwd.add("vars");
300329
kwd.add("vec");
330+
kwd.add("vmsish");
301331
kwd.add("wait");
302332
kwd.add("waitpid");
303333
kwd.add("wantarray");
304334
kwd.add("warn");
335+
kwd.add("warnings::register");
305336
kwd.add("warnings");
306337
kwd.add("when");
307338
kwd.add("while");

src/org/opensolaris/opengrok/analysis/perl/PerlAnalyzerFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2010, 2015 Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
2223
*/
2324

2425
package org.opensolaris.opengrok.analysis.perl;
@@ -44,6 +45,7 @@ public class PerlAnalyzerFactory extends FileAnalyzerFactory {
4445

4546
private static final String[] SUFFIXES = {
4647
"PL",
48+
"PLX",
4749
"PERL",
4850
"PM",
4951
"PH"

0 commit comments

Comments
 (0)