use of org.apache.felix.gogo.runtime.Parser.Statement in project felix by apache.
the class Parser method doParse.
private ParsedLine doParse(CharSequence line, int cursor) throws SyntaxError {
org.apache.felix.gogo.runtime.Parser parser = new org.apache.felix.gogo.runtime.Parser(line);
Program program = parser.program();
List<Statement> statements = parser.statements();
// Find corresponding statement
Statement statement = null;
for (int i = statements.size() - 1; i >= 0; i--) {
Statement s = statements.get(i);
if (s.start() <= cursor) {
boolean isOk = true;
// check if there are only spaces after the previous statement
if (s.start() + s.length() < cursor) {
for (int j = s.start() + s.length(); isOk && j < cursor; j++) {
isOk = Character.isWhitespace(line.charAt(j));
}
}
statement = s;
break;
}
}
if (statement != null) {
return new ParsedLineImpl(program, statement, cursor, statement.tokens());
} else {
// TODO:
return new ParsedLineImpl(program, program, cursor, Collections.<Token>singletonList(program));
}
}
use of org.apache.felix.gogo.runtime.Parser.Statement in project felix by apache.
the class TestParser method testParentheses.
@Test
public void testParentheses() {
Parser parser = new Parser("(a|b)|(d|f)");
Program p = parser.program();
assertEquals("a|b", ((Sequence) ((Statement) ((Pipeline) p.tokens().get(0)).tokens().get(0)).tokens().get(0)).program().toString());
parser = new Parser("grep (d.*)|grep (d|f)");
p = parser.program();
assertEquals("d.*", ((Sequence) ((Statement) ((Pipeline) p.tokens().get(0)).tokens().get(0)).tokens().get(1)).program().toString());
}
use of org.apache.felix.gogo.runtime.Parser.Statement in project felix by apache.
the class TestParser method testSimpleValue.
@Test
public void testSimpleValue() {
Program p = new Parser("abc def.ghi http://www.osgi.org?abc=\\&x=1 [1,2,3] {{{{{{{xyz}}}}}}} (immediate) {'{{{{{'} {\\{} 'abc{}'").program();
List<Token> x = ((Statement) p.tokens().get(0)).tokens();
assertEquals("abc", x.get(0).toString());
assertEquals("def.ghi", x.get(1).toString());
assertEquals("http://www.osgi.org?abc=\\&x=1", x.get(2).toString());
assertEquals("[1,2,3]", x.get(3).toString());
assertEquals("{{{{{{{xyz}}}}}}}", x.get(4).toString());
assertEquals("(immediate)", x.get(5).toString());
assertEquals("{'{{{{{'}", x.get(6).toString());
assertEquals("{\\{}", x.get(7).toString());
assertEquals("'abc{}'", x.get(8).toString());
}
Aggregations