Skip to content

Commit bd2c218

Browse files
committedNov 12, 2021
Groovy REPL: configure parser comment delimiters
1 parent b8c26ce commit bd2c218

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed
 

‎console/src/main/java/org/jline/console/impl/SystemRegistryImpl.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,8 @@ private static class ArgsParser {
837837
private boolean quoted;
838838
private boolean doubleQuoted;
839839
private String line;
840-
private String command;
841-
private String variable;
840+
private String command = "";
841+
private String variable = "";
842842
private List<String> args;
843843
private final Parser parser;
844844

@@ -926,11 +926,15 @@ public void parse(String line) {
926926
this.line = line;
927927
ParsedLine pl = parser.parse(line, 0, ParseContext.SPLIT_LINE);
928928
enclosedArgs(pl.words());
929-
this.command = parser.getCommand(args.get(0));
930-
if (!parser.validCommandName(command)) {
931-
this.command = "";
929+
if (!args.isEmpty()) {
930+
this.command = parser.getCommand(args.get(0));
931+
if (!parser.validCommandName(command)) {
932+
this.command = "";
933+
}
934+
this.variable = parser.getVariable(args.get(0));
935+
} else {
936+
this.line = "";
932937
}
933-
this.variable = parser.getVariable(args.get(0));
934938
}
935939

936940
public String line() {

‎demo/src/main/java/org/jline/demo/Repl.java

+2
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ public static void main(String[] args) {
247247
parser.setEofOnUnclosedQuote(true);
248248
parser.setEscapeChars(null);
249249
parser.setRegexCommand("[:]{0,1}[a-zA-Z!]{1,}\\S*"); // change default regex to support shell commands
250+
parser.blockCommentDelims(new DefaultParser.BlockCommentDelims("/*", "*/"))
251+
.lineCommentDelims(new String[]{"//", "#"});
250252
Terminal terminal = TerminalBuilder.builder().build();
251253
if (terminal.getWidth() == 0 || terminal.getHeight() == 0) {
252254
terminal.setSize(new Size(120, 40)); // hard coded terminal size when redirecting

‎demo/src/main/scripts/init.jline

-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ pipe |:: '.collectMany{' '}'
9696
pipe |? '.findAll{' '}'
9797
pipe |?1 '.find{' '}'
9898
pipe |! '.each{' '}'
99-
pipe |# '.take(' ')'
10099
pipe |& '.' ' '
101100
pipe grep '.collect{it.toString()}.findAll{it=~/' '/}'
102101
alias null '|& identity{}'

0 commit comments

Comments
 (0)
Please sign in to comment.