Skip to content

Commit

Permalink
Groovy REPL: configure parser comment delimiters
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Nov 12, 2021
1 parent b8c26ce commit bd2c218
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,8 @@ private static class ArgsParser {
private boolean quoted;
private boolean doubleQuoted;
private String line;
private String command;
private String variable;
private String command = "";
private String variable = "";
private List<String> args;
private final Parser parser;

Expand Down Expand Up @@ -926,11 +926,15 @@ public void parse(String line) {
this.line = line;
ParsedLine pl = parser.parse(line, 0, ParseContext.SPLIT_LINE);
enclosedArgs(pl.words());
this.command = parser.getCommand(args.get(0));
if (!parser.validCommandName(command)) {
this.command = "";
if (!args.isEmpty()) {
this.command = parser.getCommand(args.get(0));
if (!parser.validCommandName(command)) {
this.command = "";
}
this.variable = parser.getVariable(args.get(0));
} else {
this.line = "";
}
this.variable = parser.getVariable(args.get(0));
}

public String line() {
Expand Down
2 changes: 2 additions & 0 deletions demo/src/main/java/org/jline/demo/Repl.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ public static void main(String[] args) {
parser.setEofOnUnclosedQuote(true);
parser.setEscapeChars(null);
parser.setRegexCommand("[:]{0,1}[a-zA-Z!]{1,}\\S*"); // change default regex to support shell commands
parser.blockCommentDelims(new DefaultParser.BlockCommentDelims("/*", "*/"))
.lineCommentDelims(new String[]{"//", "#"});
Terminal terminal = TerminalBuilder.builder().build();
if (terminal.getWidth() == 0 || terminal.getHeight() == 0) {
terminal.setSize(new Size(120, 40)); // hard coded terminal size when redirecting
Expand Down
1 change: 0 additions & 1 deletion demo/src/main/scripts/init.jline
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ pipe |:: '.collectMany{' '}'
pipe |? '.findAll{' '}'
pipe |?1 '.find{' '}'
pipe |! '.each{' '}'
pipe |# '.take(' ')'
pipe |& '.' ' '
pipe grep '.collect{it.toString()}.findAll{it=~/' '/}'
alias null '|& identity{}'
Expand Down

0 comments on commit bd2c218

Please sign in to comment.