Search in sources :

Example 11 with Program

use of org.apache.felix.gogo.runtime.Parser.Program 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());
}
Also used : Program(org.apache.felix.gogo.runtime.Parser.Program) Statement(org.apache.felix.gogo.runtime.Parser.Statement) Sequence(org.apache.felix.gogo.runtime.Parser.Sequence) Pipeline(org.apache.felix.gogo.runtime.Parser.Pipeline) Test(org.junit.Test)

Example 12 with Program

use of org.apache.felix.gogo.runtime.Parser.Program 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());
}
Also used : Program(org.apache.felix.gogo.runtime.Parser.Program) Statement(org.apache.felix.gogo.runtime.Parser.Statement) Test(org.junit.Test)

Aggregations

Program (org.apache.felix.gogo.runtime.Parser.Program)12 Statement (org.apache.felix.gogo.runtime.Parser.Statement)12 Test (org.junit.Test)8 Pipeline (org.apache.felix.gogo.runtime.Parser.Pipeline)5 ParsedLineImpl (org.apache.felix.gogo.jline.ParsedLineImpl)2 EOFError (org.apache.felix.gogo.runtime.EOFError)2 Token (org.apache.felix.gogo.runtime.Token)2 Command (org.apache.karaf.shell.api.console.Command)2 CommandLine (org.apache.karaf.shell.api.console.CommandLine)2 Parser (org.apache.karaf.shell.api.console.Parser)2 ParsedLine (org.jline.reader.ParsedLine)2 ArrayList (java.util.ArrayList)1 Sequence (org.apache.felix.gogo.runtime.Parser.Sequence)1 SyntaxError (org.apache.felix.gogo.runtime.SyntaxError)1 Function (org.apache.felix.service.command.Function)1 RegionType (org.jline.reader.LineReader.RegionType)1 AttributedString (org.jline.utils.AttributedString)1 AttributedStringBuilder (org.jline.utils.AttributedStringBuilder)1