DefaultParser implements Parser { @Override public String getVariable(final String line) { String out = null; if (regexVariable != null) { Pattern patternCommand = Pattern.compile("^\\s*(" + regexVariable + ")\\s*=[^=~].*"); Matcher matcher = patternCommand.matcher(line); if (matcher.find()) { out = matcher.group(1); } } return out; }  DefaultParser quoteChars(final char[] chars); DefaultParser escapeChars(final char[] chars); DefaultParser eofOnUnclosedQuote(boolean eofOnUnclosedQuote); DefaultParser eofOnUnclosedBracket(Bracket... brackets); DefaultParser eofOnEscapedNewLine(boolean eofOnEscapedNewLine); DefaultParser regexVariable(String regexVariable); DefaultParser regexCommand(String regexCommand); DefaultParser commandGroup(int commandGroup); void setQuoteChars(final char[] chars); char[] getQuoteChars(); void setEscapeChars(final char[] chars); char[] getEscapeChars(); void setEofOnUnclosedQuote(boolean eofOnUnclosedQuote); boolean isEofOnUnclosedQuote(); void setEofOnEscapedNewLine(boolean eofOnEscapedNewLine); boolean isEofOnEscapedNewLine(); void setEofOnUnclosedBracket(Bracket... brackets); void setRegexVariable(String regexVariable); void setRegexCommand(String regexCommand); void setCommandGroup(int commandGroup); @Override boolean validCommandName(String name); @Override boolean validVariableName(String name); @Override String getCommand(final String line); @Override String getVariable(final String line); ParsedLine parse(final String line, final int cursor, ParseContext context); boolean isDelimiter(final CharSequence buffer, final int pos); boolean isQuoted(final CharSequence buffer, final int pos); boolean isQuoteChar(final CharSequence buffer, final int pos); @Override boolean isEscapeChar(char ch); boolean isEscapeChar(final CharSequence buffer, final int pos); boolean isEscaped(final CharSequence buffer, final int pos); boolean isDelimiterChar(CharSequence buffer, int pos);  }
@Test public void testVariable() { DefaultParser parser = new DefaultParser(); assertEquals("variable", parser.getVariable("variable=command")); assertEquals("variable.key", parser.getVariable("variable.key=command")); assertEquals("variable['key']", parser.getVariable("variable['key']=command")); assertEquals("variable['key']", parser.getVariable("variable['key'] = statement")); }