Skip to content

Commit e7aa298

Browse files
authored
Merge pull request #1766 from shaehn/powershellAddition
Powershell addition
2 parents 6338d29 + 78bc0f3 commit e7aa298

File tree

15 files changed

+1453
-70
lines changed

15 files changed

+1453
-70
lines changed

build.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
246246
<run-jflex dir="${gen.analysis.dir}/javascript" name="JavaScriptXref"/>
247247
<run-jflex dir="${gen.analysis.dir}/lua" name="LuaSymbolTokenizer"/>
248248
<run-jflex dir="${gen.analysis.dir}/lua" name="LuaXref"/>
249+
<run-jflex dir="${gen.analysis.dir}/powershell" name="PowershellSymbolTokenizer"/>
250+
<run-jflex dir="${gen.analysis.dir}/powershell" name="PowershellXref"/>
249251
<run-jflex dir="${gen.analysis.dir}/python" name="PythonSymbolTokenizer"/>
250252
<run-jflex dir="${gen.analysis.dir}/python" name="PythonXref"/>
251253
<run-jflex dir="${gen.analysis.dir}/rust" name="RustSymbolTokenizer"/>

nbproject/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ javadoc.encoding=${source.encoding}
9494
build.test.classes.dir=${build.dir}/test/classes
9595
jar.index=${jnlp.enabled}
9696
file.reference.jrcs.jar=lib/jrcs.jar
97-
javac.compilerargs=-Xlint\:unchecked
97+
javac.compilerargs=-Xlint:unchecked
9898
source.encoding=UTF-8
9999
jnlp.signing.keystore=
100100
meta.inf.dir=${src.dir}/META-INF

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import org.opensolaris.opengrok.analysis.json.JsonAnalyzerFactory;
8383
import org.opensolaris.opengrok.analysis.kotlin.KotlinAnalyzerFactory;
8484
import org.opensolaris.opengrok.analysis.sh.ShAnalyzerFactory;
85+
import org.opensolaris.opengrok.analysis.powershell.PowershellAnalyzerFactory;
8586
import org.opensolaris.opengrok.analysis.sql.PLSQLAnalyzerFactory;
8687
import org.opensolaris.opengrok.analysis.sql.SQLAnalyzerFactory;
8788
import org.opensolaris.opengrok.analysis.swift.SwiftAnalyzerFactory;
@@ -177,6 +178,7 @@ public class AnalyzerGuru {
177178
new CxxAnalyzerFactory(),
178179
new ErlangAnalyzerFactory(),
179180
new ShAnalyzerFactory(),
181+
new PowershellAnalyzerFactory(),
180182
PlainAnalyzerFactory.DEFAULT_INSTANCE,
181183
new UuencodeAnalyzerFactory(),
182184
new GZIPAnalyzerFactory(),

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

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ private void initialize() throws IOException {
215215

216216
command.add("--langdef=rust");
217217
command.add("--langmap=rust:+.rs");
218-
command.add("--regex-rust=/^[[:space:]]*(#\\[[^\\]]\\][[:space:]]*)*(pub[[:space:]]+)?(extern[[:space:]]+)?(\"[^\"]+\"[[:space:]]+)?(unsafe[[:space:]]+)?fn[[:space:]]+([[:alnum:]_]+)/\\6/h,functions,function definitions/");
218+
//command.add("--regex-rust=/^[[:space:]]*(#\\[[^\\]]\\][[:space:]]*)*(pub[[:space:]]+)?(extern[[:space:]]+)?(\"[^\"]+\"[[:space:]]+)?(unsafe[[:space:]]+)?fn[[:space:]]+([[:alnum:]_]+)/\\6/h,functions,function definitions/");
219+
command.add("--regex-rust=/^[[:space:]]*(#\\[[^]]+\\][[:space:]]*)*(pub[[:space:]]+)?(extern[[:space:]]+)?(\\\"[^\\\"]+\\\"[[:space:]]+)?(unsafe[[:space:]]+)?fn[[:space:]]+([[:alnum:]_]+)/\\6/h,functions,function definitions/");
219220
command.add("--regex-rust=/^[[:space:]]*(pub[[:space:]]+)?type[[:space:]]+([[:alnum:]_]+)/\\2/T,types,type definitions/");
220221
command.add("--regex-rust=/^[[:space:]]*(pub[[:space:]]+)?enum[[:space:]]+([[:alnum:]_]+)/\\2/g,enum,enumeration names/");
221222
command.add("--regex-rust=/^[[:space:]]*(pub[[:space:]]+)?struct[[:space:]]+([[:alnum:]_]+)/\\2/S,structure names/");
@@ -239,6 +240,28 @@ private void initialize() throws IOException {
239240
command.add("--regex-pascal=/^(uses|interface|implementation)$/\\1/s,Section/");
240241
command.add("--regex-pascal=/^unit[[:space:]]+([a-zA-Z0-9_<>, ]+)[;(]/\\1/u,unit/");
241242

243+
// PowerShell
244+
command.add("--langdef=Posh");
245+
command.add("--langmap=Posh:+.ps1,Posh:+.psm1");
246+
command.add("--regex-Posh=/\\$(\\{[^}]+\\})/\\1/v,variable/");
247+
command.add("--regex-Posh=/\\$([[:alnum:]_]+([:.][[:alnum:]_]+)*)/\\1/v,variable/");
248+
command.add("--regex-Posh=/^[[:space:]]*(:[^[:space:]]+)/\\1/l,label/");
249+
250+
if (!env.isUniversalCtags()) {
251+
command.add("--regex-Posh=/^[[:space:]]*([Ff]unction|[Ff]ilter)[[:space:]]+([^({[:space:]]+)[[:space:]]*(\\(([^)]+)\\))?/\\2/f,function,functions/");
252+
} else {
253+
command.add("--_fielddef-Posh=signature,signatures");
254+
command.add("--fields-Posh=+{signature}");
255+
256+
// escaped variable markers
257+
command.add("--regex-Posh=/`\\$([[:alnum:]_]+([:.][[:alnum:]_]+)*)/\\1//{exclusive}");
258+
command.add("--regex-Posh=/`\\$(\\{[^}]+\\})/\\1//{exclusive}");
259+
command.add("--regex-Posh=/#.*\\$([[:alnum:]_]+([:.][[:alnum:]_]+)*)/\\1//{exclusive}");
260+
command.add("--regex-Posh=/#.*\\$(\\{[^}]+\\})/\\1//{exclusive}");
261+
command.add("--regex-Posh=/^[[:space:]]*(function|filter)[[:space:]]+([^({[:space:]]+)[[:space:]]*(\\(([^)]+)\\))?/\\2/f,function,functions/{icase}{exclusive}{_field=signature:(\\4)}");
262+
263+
}
264+
242265
//PLEASE add new languages ONLY with POSIX syntax (see above wiki link)
243266

244267
/* Add extra command line options for ctags. */
@@ -518,19 +541,43 @@ private void readTags(Definitions defs) {
518541
//TODO if some languages use different character for separating arguments, below needs to be adjusted
519542
String[] args = signature.split(",");
520543
for (String arg : args) {
521-
//log.fine("Param = "+ arg);
522-
int space = arg.lastIndexOf(' ');//TODO this is not the best way, but works to find the last string(name) in the argument, hence skipping type
523-
if (space > 0 && space < arg.length()) {
524-
String afters = arg.substring(space + 1);
525-
//FIXME this will not work for typeless languages such as python or assignments inside signature ... but since ctags doesn't provide signatures for python yet and assigning stuff in signature is not the case for c or java, we don't care ...
526-
String[] names = afters.split("[\\W]"); //this should just parse out variables, we assume first non empty text is the argument name
527-
for (String name : names) {
528-
if (name.length() > 0) {
529-
//log.fine("Param Def = "+ string);
530-
addTag(defs, seenSymbols, lnum, name, "argument",
544+
//TODO this algorithm assumes that data types occur to
545+
// the left of the argument name, so it will not
546+
// work for languages like rust, kotlin, etc. which
547+
// place the data type to the right of the argument name.
548+
// Need an attribute from ctags to indicate data type location.
549+
// ----------------------------------------------------------------
550+
// When no assignment of default values,
551+
// expecting: <type> <name>, or <name>
552+
//
553+
// When default value assignment applied to parameter,
554+
// expecting: <type> <name> = <value> or
555+
// <name> = <value>
556+
// (Note whitespace content made irrelevant)
557+
558+
// Need to ditch the default assignment value
559+
// so that the extraction loop below will work.
560+
// This assumes all languages use '=' to assign value.
561+
562+
if (arg.indexOf("=") != -1) {
563+
String[] a = arg.split("=");
564+
arg = a[0]; // throws away assigned value
565+
}
566+
567+
// Strip out all non 'word' class symbols
568+
// which leaves just names intact.
569+
String [] names = arg.trim().split("[\\W]");
570+
String name;
571+
572+
// Walk the array backwards from the end and
573+
// the parameter name should always be the first
574+
// non-empty element encountered.
575+
for (int ii=names.length-1; ii >= 0; ii--) {
576+
name = names[ii];
577+
if (name.length() > 0) {
578+
addTag(defs, seenSymbols, lnum, name, "argument",
531579
def.trim() + signature.trim(), null, signature);
532580
break;
533-
}
534581
}
535582
}
536583
}

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

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,15 @@ protected String getProjectPostfix(boolean encoded) {
238238
protected void startScope() {
239239
if (scopesEnabled && scope == null) {
240240
int line = getLineNumber();
241-
List<Tag> tags = defs.getTags(line);
242-
if (tags != null) {
243-
for (Tag tag : tags) {
244-
if (tag.type.startsWith("function") || tag.type.startsWith("method")) {
245-
scope = new Scope(tag.line, tag.line, tag.symbol, tag.namespace, tag.signature);
246-
scopeLevel = 0;
247-
break;
241+
if (defs != null) {
242+
List<Tag> tags = defs.getTags(line);
243+
if (tags != null) {
244+
for (Tag tag : tags) {
245+
if (tag.type.startsWith("function") || tag.type.startsWith("method")) {
246+
scope = new Scope(tag.line, tag.line, tag.symbol, tag.namespace, tag.signature);
247+
scopeLevel = 0;
248+
break;
249+
}
248250
}
249251
}
250252
}
@@ -518,7 +520,8 @@ protected void startNewLine() throws IOException {
518520

519521
if (foldingEnabled && scopesEnabled) {
520522
if (iconId != null) {
521-
out.write("<a href=\"#\" onclick='fold(this.parentNode.id)' id='");
523+
// Fix for #1764 remove line below and add this -> out.write("<a style='cursor:pointer;' onclick='fold(this.parentNode.id)' id='");
524+
out.write("<a href='#' onclick='fold(this.parentNode.id)' id='");
522525
out.write(iconId);
523526
/* space inside span for IE support */
524527
out.write("'><span class='fold-icon'>&nbsp;</span></a>");
@@ -539,10 +542,10 @@ protected void startNewLine() throws IOException {
539542
*/
540543
protected void writeSymbol(String symbol, Set<String> keywords, int line)
541544
throws IOException {
542-
writeSymbol(symbol, keywords, line, true);
545+
writeSymbol(symbol, keywords, line, true, false);
543546
}
544547

545-
/**
548+
/**
546549
* Write a symbol and generate links as appropriate.
547550
*
548551
* @param symbol the symbol to write
@@ -555,9 +558,27 @@ protected void writeSymbol(String symbol, Set<String> keywords, int line)
555558
protected void writeSymbol(
556559
String symbol, Set<String> keywords, int line, boolean caseSensitive)
557560
throws IOException {
561+
writeSymbol(symbol, keywords, line, caseSensitive, false);
562+
}
563+
564+
/**
565+
* Write a symbol and generate links as appropriate.
566+
*
567+
* @param symbol the symbol to write
568+
* @param keywords a set of keywords recognized by this analyzer (no links
569+
* will be generated if the symbol is a keyword)
570+
* @param line the line number on which the symbol appears
571+
* @param caseSensitive Whether the keyword list is case sensitive
572+
* @param quote Whether the symbol gets quoted in links or not
573+
* @throws IOException if an error occurs while writing to the stream
574+
*/
575+
protected void writeSymbol(
576+
String symbol, Set<String> keywords, int line, boolean caseSensitive, boolean quote)
577+
throws IOException {
558578
String[] strs = new String[1];
559579
strs[0] = "";
560580
String jsEscapedSymbol = symbol.replace("'", "\\'");
581+
String qt = (quote) ? "&quot;" : "";
561582

562583
String check = caseSensitive ? symbol : symbol.toLowerCase();
563584
if (keywords != null && keywords.contains( check )) {
@@ -596,7 +617,7 @@ protected void writeSymbol(
596617
out.append("<a href=\"");
597618
out.append(urlPrefix);
598619
out.append("refs=");
599-
out.append(symbol);
620+
out.append(qt+symbol+qt);
600621
appendProject();
601622
out.append("\" class=\"");
602623
out.append(style_class);
@@ -629,7 +650,7 @@ protected void writeSymbol(
629650
out.append("<a href=\"");
630651
out.append(urlPrefix);
631652
out.append("defs=");
632-
out.append(symbol);
653+
out.append(qt+symbol+qt);
633654
appendProject();
634655
out.append("\"");
635656
out.append(" class=\"intelliWindow-symbol\"");

0 commit comments

Comments
 (0)