Package org.jnode.shell.syntax

Examples of org.jnode.shell.syntax.MuAlternation


        }
    }

    @Test
    public void testAlternationConstructor() {
        new MuAlternation(new MuSymbol("hi"), new MuSymbol("mom"));
        new MuAlternation(new MuSymbol("hi"), null);
    }
View Full Code Here


        }
    }

    @Test
    public void testResolveBackReferences() {
        MuSyntax syntax = new MuAlternation("root", new MuBackReference("root"), null);
        syntax.resolveBackReferences();
        Assert.assertEquals(((MuAlternation) syntax).getAlternatives()[0], syntax);

        syntax =
                new MuAlternation("root", new MuSequence(new MuBackReference("root"),
                        new MuBackReference("root")), null);
        syntax.resolveBackReferences();
        MuSyntax[] tmp = ((MuAlternation) syntax).getAlternatives();
        Assert.assertEquals(((MuSequence) tmp[0]).getElements()[0], syntax);
        Assert.assertEquals(((MuSequence) tmp[0]).getElements()[1], syntax);

        try {
            syntax = new MuAlternation("root", new MuBackReference("foo"), null);
            syntax.resolveBackReferences();
            Assert.fail("expected SFE");
        } catch (SyntaxFailureException ex) {
            // expected
        }
    }
View Full Code Here

        Assert.assertEquals("<l1> ::= 'hi' 'mum'", new MuSequence("l1", new MuSymbol("hi"),
                new MuSymbol("mum")).format());
        Assert.assertEquals("<l1> ::= <l2> 'mum'\n<l2> ::= 'hi'", new MuSequence("l1",
                new MuSymbol("l2", "hi"), new MuSymbol("mum")).format());

        Assert.assertEquals("<*Start*> ::= ( 'hi' | 'mum' )", new MuAlternation(new MuSymbol("hi"),
                new MuSymbol("mum")).format());
        Assert.assertEquals("<*Start*> ::= ( 'hi' |  )",
                new MuAlternation(new MuSymbol("hi"), null).format());
        Assert.assertEquals("<l1> ::= ( 'hi' | 'mum' )", new MuAlternation("l1",
                new MuSymbol("hi"), new MuSymbol("mum")).format());
        Assert.assertEquals("<l1> ::= ( <l2> | 'mum' )\n<l2> ::= 'hi'", new MuAlternation("l1",
                new MuSymbol("l2", "hi"), new MuSymbol("mum")).format());
    }
View Full Code Here

                new MuSymbol("l2", "hi"), new MuSymbol("mum")).format());
    }

    @Test
    public void testFormat2() {
        MuSyntax syntax = new MuAlternation("root", new MuBackReference("root"), null);
        Assert.assertEquals("<root> ::= ( <[root]> |  )\n<[root]> ::= <root>", syntax.format());
        syntax.resolveBackReferences();
        Assert.assertEquals("<root> ::= ( <root> |  )", syntax.format());
    }
View Full Code Here

    }

    @Test
    public void testStatelessParsing3() throws NoTokensAvailableException, CommandSyntaxException {
        // <start> :: = 'a' | 'b'
        MuSyntax syntax = new MuAlternation(new MuSymbol("a"), new MuSymbol("b"));
        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"a"});
        parser.parse(syntax, null, cl.tokenIterator(), null);
View Full Code Here

    @Test
    public void testStatelessParsing4() throws NoTokensAvailableException, CommandSyntaxException {
        // <root> ::= 'b' | ( 'a' <root> )
        MuSyntax syntax =
                new MuAlternation("root", new MuSymbol("b"), new MuSequence(new MuSymbol("a"),
                        new MuBackReference("root")));
        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"b"});

        parser.parse(syntax, null, cl.tokenIterator(), null);

        try {
            cl = new CommandLine(new String[] {"a", "b"});
            parser.parse(syntax, null, cl.tokenIterator(), null);
            Assert.fail("expected SFE");
        } catch (SyntaxFailureException ex) {
            // expected
        }

        syntax.resolveBackReferences();
        cl = new CommandLine(new String[] {"a", "b"});
        parser.parse(syntax, null, cl.tokenIterator(), null);

        cl = new CommandLine(new String[] {"a", "a", "b"});
        parser.parse(syntax, null, cl.tokenIterator(), null);
View Full Code Here

    @Test
    public void testStatelessParsing5() throws NoTokensAvailableException, CommandSyntaxException {
        // <root> ::= ( 'a' <root> ) | 'b'
        MuSyntax syntax =
                new MuAlternation("root", new MuSequence(new MuSymbol("a"), new MuBackReference(
                        "root")), new MuSymbol("b"));
        MuParser parser = new MuParser();
        CommandLine cl;

        syntax.resolveBackReferences();

        cl = new CommandLine(new String[] {"b"});

        parser.parse(syntax, null, cl.tokenIterator(), null);

        syntax.resolveBackReferences();
        cl = new CommandLine(new String[] {"a", "b"});
        parser.parse(syntax, null, cl.tokenIterator(), null);

        cl = new CommandLine(new String[] {"a", "a", "b"});
        parser.parse(syntax, null, cl.tokenIterator(), null);
View Full Code Here

    @Test
    public void testStatelessParsing6() throws NoTokensAvailableException, CommandSyntaxException {
        // <root> ::= ( ( 'a' <root> ) | ( 'b' 'c' ) ) | ( ( 'a' <root> ) | 'b'
        // ) )
        MuSyntax syntax = new MuAlternation("root", new MuAlternation(new MuSequence(new MuSymbol("a"),
            new MuBackReference("root")), new MuSequence(new MuSymbol("b"), new MuSymbol("c"))),
            new MuAlternation(new MuSequence(new MuSymbol("a"), new MuBackReference("root")), new MuSymbol("b")));
        MuParser parser = new MuParser();
        CommandLine cl;

        syntax.resolveBackReferences();

        cl = new CommandLine(new String[] {"b"});

        parser.parse(syntax, null, cl.tokenIterator(), null);

        syntax.resolveBackReferences();
        cl = new CommandLine(new String[] {"a", "b"});
        parser.parse(syntax, null, cl.tokenIterator(), null);

        cl = new CommandLine(new String[] {"a", "a", "b"});
        parser.parse(syntax, null, cl.tokenIterator(), null);
View Full Code Here

    @Test
    public void testPathological() throws NoTokensAvailableException, CommandSyntaxException {
        // Pathological grammar.
        // <root> ::= 'b' | ( <root> <root> )
        MuSyntax syntax =
                new MuAlternation("root", new MuSymbol("b"), new MuSequence(new MuBackReference(
                        "root"), new MuBackReference("root")));
        MuParser parser = new MuParser();
        CommandLine cl;

        syntax.resolveBackReferences();

        // This doesn't hit the infinite loop ...
        cl = new CommandLine(new String[] {"b"});
        parser.parse(syntax, null, cl.tokenIterator(), null);
View Full Code Here

        IntegerArgument intArg = new IntegerArgument("intArg", Argument.MULTIPLE);
        FileArgument fileArg = new FileArgument("fileArg", Argument.MULTIPLE);
        ArgumentBundle bundle = new ArgumentBundle(intArg, fileArg);

        // <start> :: = <<intArg>> | <<fileArg>>
        MuSyntax syntax = new MuAlternation(new MuArgument("intArg"), new MuArgument("fileArg"));
        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"1"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
View Full Code Here

TOP

Related Classes of org.jnode.shell.syntax.MuAlternation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.