Package org.jnode.shell.syntax

Examples of org.jnode.shell.syntax.MuSyntax$FormatState


    }

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

        cl = new CommandLine(new String[] {"a"});
View Full Code Here


    }

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

        cl = new CommandLine(new String[] {"a", "b"});
        parser.parse(syntax, null, cl.tokenIterator(), null);
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

        }
    }

    @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

                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

    public void testStatefullParsing1() throws NoTokensAvailableException, CommandSyntaxException {
        IntegerArgument intArg = new IntegerArgument("intArg", Argument.MULTIPLE);
        ArgumentBundle bundle = new ArgumentBundle(intArg);

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

        cl = new CommandLine(new String[] {"1"});
View Full Code Here

TOP

Related Classes of org.jnode.shell.syntax.MuSyntax$FormatState

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.