From 224349ac9c80ce2c9ce0521f27e1d9ef5228e8ad Mon Sep 17 00:00:00 2001 From: John Maschmeyer Date: Tue, 16 Oct 2012 18:54:11 -0500 Subject: [PATCH 1/5] If no file is specified for --dotComplete or --parenComplete, read from stdin instead --- main.d | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/main.d b/main.d index 65ad307..5ea47fc 100644 --- a/main.d +++ b/main.d @@ -172,7 +172,27 @@ void main(string[] args) importDirs ~= dirName(args[1]); else importDirs ~= getcwd(); - auto tokens = args[1].readText().tokenize(); + bool useStdin = false; + try + { + to!size_t(args[1]); + useStdin = true; + } + catch(ConvException e) {} + Token[] tokens; + if (useStdin) + { + string f; + char[] buf; + while (stdin.readln(buf)) + f ~= buf; + tokens = f.tokenize(); + } + else + { + tokens = args[1].readText().tokenize(); + args.popFront(); + } auto mod = parseModule(tokens); CompletionContext context = new CompletionContext(mod); context.importDirectories = importDirs; @@ -185,9 +205,9 @@ void main(string[] args) } auto complete = AutoComplete(tokens, context); if (parenComplete) - writeln(complete.parenComplete(to!size_t(args[2]))); + writeln(complete.parenComplete(to!size_t(args[1]))); else if (dotComplete) - writeln(complete.dotComplete(to!size_t(args[2]))); + writeln(complete.dotComplete(to!size_t(args[1]))); return; } From 258e10aef6872f2ca3d723d72dbf1fb179036307 Mon Sep 17 00:00:00 2001 From: John Maschmeyer Date: Tue, 16 Oct 2012 19:35:40 -0500 Subject: [PATCH 2/5] Cleaned up a few things --- main.d | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/main.d b/main.d index 5ea47fc..d1d3502 100644 --- a/main.d +++ b/main.d @@ -172,23 +172,17 @@ void main(string[] args) importDirs ~= dirName(args[1]); else importDirs ~= getcwd(); - bool useStdin = false; + Token[] tokens; try { - to!size_t(args[1]); - useStdin = true; - } - catch(ConvException e) {} - Token[] tokens; - if (useStdin) - { + to!size_t(args[1]); string f; char[] buf; while (stdin.readln(buf)) - f ~= buf; + f ~= buf; tokens = f.tokenize(); } - else + catch(ConvException e) { tokens = args[1].readText().tokenize(); args.popFront(); From 12e242ca0feb4d1a14e5330258cfbc4fcf348aa7 Mon Sep 17 00:00:00 2001 From: John Maschmeyer Date: Wed, 17 Oct 2012 18:04:48 -0500 Subject: [PATCH 3/5] Added stdin as an alternative to a filename for all other modes except for ctags. Ctags requires the filename, so it still requires a filename. --- README.md | 20 ++++++++++---------- main.d | 43 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d199d7e..82921b6 100644 --- a/README.md +++ b/README.md @@ -2,23 +2,23 @@ Dscanner is a tool used to analyze D source code. ### Options -* **--dotComplete** _sourceFile_ _cursorPosition_ - Provide autocompletion for the +* **--dotComplete** [_sourceFile_] _cursorPosition_ - Provide autocompletion for the insertion of the dot operator. The cursor position is the character position in -the **file**, not the position in the line. -* **--sloc** _sourceFiles_ - count the number of logical lines of code in the given -source files. -* **--json** _sourceFile_ - Generate a JSON summary of the given source file -* **--parenComplete** _sourceFile_ _cursorPosition_ - Provides a listing of function +the **file**, not the position in the line. If no file is specified the file is read from stdin. +* **--sloc** [_sourceFiles_] - count the number of logical lines of code in the given +source files. If no files are specified, a file is read from stdin. +* **--json** [_sourceFile_] - Generate a JSON summary of the given source file. If no file is specifed, the file is read from stdin. +* **--parenComplete** [_sourceFile_] _cursorPosition_ - Provides a listing of function parameters or pre-defined version identifiers at the cursor position. The cursor -position is the character position in the **file**, not the line. -* **--highlight** _sourceFile_ - Syntax-highlight the given source file. The +position is the character position in the **file**, not the line. If no file is specified, the contents are read from stdin. +* **--highlight** [_sourceFile_] - Syntax-highlight the given source file. The resulting HTML will be written to standard output. * **-I** _includePath_ - Include _includePath_ in the list of paths used to search for imports. By default dscanner will search in the current working directory as well as any paths specified in /etc/dmd.conf. This is only used for the ---parenComplete and --dotComplete options +--parenComplete and --dotComplete options. If no file is specified, the file is read from stdin. * **--ctags** _sourceFile_ - Generates ctags information from the given source -code file. +code file. Note that ctags information requires a filename, so stdin cannot be used in place of a filename. * **--recursive** **-R** **-r** _directory_ - When used with --ctags, dscanner will produce ctags output for all .d and .di files contained within _directory_ and its sub-directories. diff --git a/main.d b/main.d index d1d3502..6622845 100644 --- a/main.d +++ b/main.d @@ -155,14 +155,37 @@ void main(string[] args) if (sloc) { - writeln(args[1..$].map!(a => a.readText().tokenize())().joiner() - .count!(a => isLineOfCode(a.type))()); + if (args.length == 1) + { + string f; + char[] buf; + while (stdin.readln(buf)) + f ~= buf; + f.tokenize().count!(a => isLineOfCode(a.type))(); + } + else + { + writeln(args[1..$].map!(a => a.readText().tokenize())().joiner() + .count!(a => isLineOfCode(a.type))()); + } + return; } if (highlight) { - highlighter.highlight(args[1].readText().tokenize(IterationStyle.EVERYTHING)); + if (args.length == 1) + { + string f; + char[] buf; + while (stdin.readln(buf)) + f ~= buf; + highlighter.highlight(f.tokenize(IterationStyle.EVERYTHING)); + } + else + { + highlighter.highlight(args[1].readText().tokenize(IterationStyle.EVERYTHING)); + } return; } @@ -207,7 +230,19 @@ void main(string[] args) if (json) { - auto tokens = tokenize(readText(args[1])); + Token[] tokens; + if (args.length == 1) + { + string f; + char[] buf; + while (stdin.readln(buf)) + f ~= buf; + tokens = tokenize(f); + } + else + { + tokens = tokenize(readText(args[1])); + } auto mod = parseModule(tokens); mod.writeJSONTo(stdout); return; From ae49c5449cb8e21635b28d522fff4821301b19e6 Mon Sep 17 00:00:00 2001 From: John Maschmeyer Date: Wed, 17 Oct 2012 18:13:14 -0500 Subject: [PATCH 4/5] Made sloc print when using stdin instead of a file. --- main.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.d b/main.d index 6622845..d8bb134 100644 --- a/main.d +++ b/main.d @@ -161,7 +161,7 @@ void main(string[] args) char[] buf; while (stdin.readln(buf)) f ~= buf; - f.tokenize().count!(a => isLineOfCode(a.type))(); + writeln(f.tokenize().count!(a => isLineOfCode(a.type))()); } else { From dd62f275c776221f7467724d1d8809c0e91b64d6 Mon Sep 17 00:00:00 2001 From: John Maschmeyer Date: Mon, 22 Oct 2012 18:46:50 -0500 Subject: [PATCH 5/5] Switched string appends to use appender --- main.d | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/main.d b/main.d index d8bb134..d773905 100644 --- a/main.d +++ b/main.d @@ -157,11 +157,11 @@ void main(string[] args) { if (args.length == 1) { - string f; + auto f = appender!string(); char[] buf; while (stdin.readln(buf)) - f ~= buf; - writeln(f.tokenize().count!(a => isLineOfCode(a.type))()); + f.put(buf); + writeln(f.data.tokenize().count!(a => isLineOfCode(a.type))()); } else { @@ -176,11 +176,11 @@ void main(string[] args) { if (args.length == 1) { - string f; + auto f = appender!string(); char[] buf; while (stdin.readln(buf)) - f ~= buf; - highlighter.highlight(f.tokenize(IterationStyle.EVERYTHING)); + f.put(buf); + highlighter.highlight(f.data.tokenize(IterationStyle.EVERYTHING)); } else { @@ -199,11 +199,11 @@ void main(string[] args) try { to!size_t(args[1]); - string f; + auto f = appender!string(); char[] buf; while (stdin.readln(buf)) - f ~= buf; - tokens = f.tokenize(); + f.put(buf); + tokens = f.data.tokenize(); } catch(ConvException e) { @@ -233,11 +233,11 @@ void main(string[] args) Token[] tokens; if (args.length == 1) { - string f; + auto f = appender!string(); char[] buf; while (stdin.readln(buf)) - f ~= buf; - tokens = tokenize(f); + f.put(buf); + tokens = tokenize(f.data); } else {