1 /* 2 * Copyright (c) 2002-2016, the original author or authors. 3 * 4 * This software is distributable under the BSD license. See the terms of the 5 * BSD license in the documentation provided with this software. 6 * 7 * https://opensource.org/licenses/BSD-3-Clause 8 */ 9 package jdk.internal.org.jline.reader; 10 11 public interface Parser { 12 parse(String line, int cursor, ParseContext context)13 ParsedLine parse(String line, int cursor, ParseContext context) throws SyntaxError; 14 parse(String line, int cursor)15 default ParsedLine parse(String line, int cursor) throws SyntaxError { 16 return parse(line, cursor, ParseContext.UNSPECIFIED); 17 } 18 isEscapeChar(char ch)19 default boolean isEscapeChar(char ch) { 20 return ch == '\\'; 21 } 22 23 enum ParseContext { 24 UNSPECIFIED, 25 26 /** Try a real "final" parse. 27 * May throw EOFError in which case we have incomplete input. 28 */ 29 ACCEPT_LINE, 30 31 /** Parse to find completions (typically after a Tab). 32 * We should tolerate and ignore errors. 33 */ 34 COMPLETE, 35 36 /** Called when we need to update the secondary prompts. 37 * Specifically, when we need the 'missing' field from EOFError, 38 * which is used by a "%M" in a prompt pattern. 39 */ 40 SECONDARY_PROMPT 41 } 42 } 43