Package org.jnode.shell.syntax

Examples of org.jnode.shell.syntax.MuParser$ChoicePoint


    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);

        try {
            cl = new CommandLine(new String[] {"a", "a", "c"});
            parser.parse(syntax, null, cl.tokenIterator(), null);
            Assert.fail("expected SEE");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here


        // <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);

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

        try {
            cl = new CommandLine(new String[] {"a", "a", "c"});
            parser.parse(syntax, null, cl.tokenIterator(), null);
            Assert.fail("expected SEE");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here

        // 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);

        // But this does ...
        cl = new CommandLine(new String[] {"a"});
        try {
            parser.parse(syntax, null, cl.tokenIterator(), null);
            Assert.fail("expected SFE");
        } catch (SyntaxFailureException ex) {
            Assert.assertEquals(
                    "Parse exceeded the step limit (" + MuParser.DEFAULT_STEP_LIMIT + "). " +
                            "Either the command line is too large, or the syntax is too complex (or pathological)",
View Full Code Here

@SuppressWarnings("deprecation")
public class MuParserTest {

    @Test
    public void testInstantiation() {
        new MuParser();
    }
View Full Code Here

    @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"});

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

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

        try {
            cl = new CommandLine(new String[] {"a", "a"});
            parser.parse(syntax, null, cl.tokenIterator(), null);
            Assert.fail("parse didn't fail");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
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);
        try {
            cl = new CommandLine(new String[] {"a"});
            parser.parse(syntax, null, cl.tokenIterator(), null);
            Assert.fail("parse didn't fail");
        } catch (CommandSyntaxException ex) {
            // expected
        }
        try {
            cl = new CommandLine(new String[] {"a"});
            parser.parse(syntax, null, cl.tokenIterator(), null);
            Assert.fail("parse didn't fail");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
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);

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

        try {
            cl = new CommandLine(new String[] {"c"});
            parser.parse(syntax, null, cl.tokenIterator(), null);
            Assert.fail("parse didn't fail");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here

    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);

        try {
            cl = new CommandLine(new String[] {"a", "a", "c"});
            parser.parse(syntax, null, cl.tokenIterator(), null);
            Assert.fail("expected SEE");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here

        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"});

        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(new Integer(1), intArg.getValue());

        try {
            cl = new CommandLine(new String[] {"X"});
            parser.parse(syntax, null, cl.tokenIterator(), bundle);
            Assert.fail("parse didn't fail");
        } catch (CommandSyntaxException ex) {
            // expected
        }

        try {
            cl = new CommandLine(new String[] {"1", "1"});
            parser.parse(syntax, null, cl.tokenIterator(), bundle);
            Assert.fail("parse didn't fail");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here

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

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

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

        Assert.assertEquals(new Integer(1), intArg.getValue());
        Assert.assertEquals(new File("x"), fileArg.getValue());

        try {
            cl = new CommandLine(new String[] {"1"});
            parser.parse(syntax, null, cl.tokenIterator(), bundle);
            Assert.fail("parse didn't fail");
        } catch (CommandSyntaxException ex) {
            // expected
        }
        try {
            cl = new CommandLine(new String[] {"1", ""});
            parser.parse(syntax, null, cl.tokenIterator(), bundle);
            Assert.fail("parse didn't fail");
        } catch (CommandSyntaxException ex) {
            // expected
        }
View Full Code Here

TOP

Related Classes of org.jnode.shell.syntax.MuParser$ChoicePoint

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.