Secondary Prompt Support

21 views
Skip to first unread message

Hamza Eraoui

unread,
Dec 2, 2024, 5:57:32 PM12/2/24
to jline-users
Hi all,
I'm new to JLine, and I'm trying to read multiple lines from the reader when the user presses Shift+Enter. I read in a previous conversation that this feature is built-in to JLine 3. And that I just need to override the parse method after implementing a custom parser, which is what I did. However, I still haven't achieved the desired result.
This is my parse method:

@Override
public ParsedLine parse(String line, int cursor, ParseContext context) throws SyntaxError {

ParsedLine parsedLine = this.defaultParser.parse(line, cursor, context);

if (context == ParseContext.SECONDARY_PROMPT) {
throw new EOFError(-1, -1, "continutation required", line);
}

return parsedLine;
}

What did I do wrong?

This is the whole class:

public class OPMParser implements Parser {

private DefaultParser defaultParser;

public OPMParser() {

this.defaultParser = new DefaultParser();
}

@Override
public ParsedLine parse(String line, int cursor, ParseContext context) throws SyntaxError {

ParsedLine parsedLine = this.defaultParser.parse(line, cursor, context);

if (context == ParseContext.SECONDARY_PROMPT) {
throw new EOFError(-1, -1, "continutation required", line);
}

return parsedLine;
}

@Override
public ParsedLine parse(String line, int cursor) throws SyntaxError {
return Parser.super.parse(line, cursor);
}

@Override
public boolean isEscapeChar(char ch) {
return Parser.super.isEscapeChar(ch);
}

@Override
public boolean validCommandName(String name) {
return Parser.super.validCommandName(name);
}

@Override
public boolean validVariableName(String name) {
return Parser.super.validVariableName(name);
}

@Override
public String getCommand(String line) {
return Parser.super.getCommand(line);
}

@Override
public String getVariable(String line) {
return Parser.super.getVariable(line);
}

}

Thanks in advance for your help.
Hamza,

Guillaume Nodet

unread,
Dec 2, 2024, 6:42:16 PM12/2/24
to jline...@googlegroups.com
Try with 


if (context == ParseContext.ACCEPT_LINE || context == ParseContext.SECONDARY_PROMPT) {
    throw new EOFError(-1, -1, "continuation required", line);
}


Guillaume 


--
You received this message because you are subscribed to the Google Groups "jline-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jline-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jline-users/8c732ea5-3508-4091-bb34-1f1fa8ed1a60n%40googlegroups.com.

Hamza Eraoui

unread,
Dec 2, 2024, 6:48:21 PM12/2/24
to jline-users
It works, but the problem is that it gets stuck on the new line even when I press Enter. 
The passed context is always ACCEPT_LINE, but I need to pass SECONDARY_PROMPT instead. I'm not sure how to do that.

Hamza,

Reply all
Reply to author
Forward
0 new messages