Package org.jnode.shell.syntax

Examples of org.jnode.shell.syntax.CommandSyntaxException


    private NumberRange parseRange(String text) throws CommandSyntaxException {
        int delimPos = text.indexOf(rangeDelim);
        int start;
        int end;
        if (text.equals(rangeDelim)) {
            throw new CommandSyntaxException("Invalid number range");
        }
        if (delimPos == -1) {
            // this is ok, as we allow a single integer to represent the range n-n
            start = end = parseInt(text);
        } else if (delimPos == 0) {
            start = min;
            end = parseInt(text.substring(rangeDelim.length(), text.length()));
        } else if (delimPos == (text.length() - rangeDelim.length())) {
            start = parseInt(text.substring(0, delimPos));
            end = max;
        } else {
            start = parseInt(text.substring(0, delimPos));
            end   = parseInt(text.substring(delimPos + rangeDelim.length(), text.length()));
        }
        try {
            return new NumberRange(start, end, min - 1, max + 1);
        } catch (IllegalArgumentException ex) {
            throw new CommandSyntaxException("Invalid number range");
        }
    }
View Full Code Here


    private int parseInt(String text) throws CommandSyntaxException {
        int n;
        try {
            n = Integer.parseInt(text);
        } catch (NumberFormatException ex) {
            throw new CommandSyntaxException("Invalid number range");
        }
        if (n < min || n > max) {
            throw new CommandSyntaxException("Number out of range");
        }
        return n;
    }
View Full Code Here

            DeviceUtils.getDevicesByAPI(KeyboardAPI.class);

        if (argAdd.isSet()) {
            String layoutID = getLayoutID(mgr);
            if (!argClass.isSet()) {
                throw new CommandSyntaxException(ex_syntax_class);
            }
            String className = argClass.getValue();
            mgr.add(layoutID, className);
            out.format(fmt_add, layoutID);
        } else if (argRemove.isSet()) {
View Full Code Here

    private String getLayoutID(KeyboardLayoutManager mgr) throws CommandSyntaxException {
        if (!argTriple.isSet()) {
            if (argLayout.isSet()) {
                return argLayout.getValue();
            } else {
                throw new CommandSyntaxException(ex_syntax_layout);
            }
        } else {
            if (!argCountry.isSet()) {
                throw new CommandSyntaxException(ex_syntax_country);
            }
            String country = argCountry.getValue();
            String language = argLanguage.isSet() ? argLanguage.getValue() : "";
            String variant = argVariant.isSet() ? argVariant.getValue() : "";
            if (language.trim().length() == 0) {
View Full Code Here

        String commandName = commandLine.getCommandName();
        bracketted = (commandName != null && commandName.equals("["));
        args = commandLine.getArguments();
        try {
            if (bracketted && args.length == 0) {
                throw new CommandSyntaxException("missing ']'");
            } else if (bracketted && !args[args.length - 1].equals("]")) {
                processAsOptions(args);
                res = true;
            } else {
                lastArg = bracketted ? args.length - 2 : args.length - 1;
                if (lastArg == -1) {
                    res = false;
                } else {
                    Object obj = evaluate();
                    if (pos <= lastArg) {
                        if (args[pos].equals(")")) {
                            throw new CommandSyntaxException("unmatched ')'");
                        } else {
                            throw new AssertionError("I'm confused!  pos = " + pos +
                                    ", lastArg = " + lastArg + ", next arg is " + args[pos]);
                        }
                    }
View Full Code Here

        evaluatePrimary(nested);
        while (pos <= lastArg) {
            String tok = next();
            Operator op = OPERATOR_MAP.get(tok);
            if (op == null) {
                throw new CommandSyntaxException("expected an operator");
            }
            switch(op.kind) {
                case OP_UNARY:
                    throw new CommandSyntaxException("misplaced unary operator");
                case OP_BINARY:
                    evaluatePrimary(nested);
                    reduceAndPush(op, popOperand());
                    break;
                case OP_SPECIAL:
                    if (op.opNo == OP_LPAREN) {
                        throw new CommandSyntaxException("misplaced '('");
                    } else if (op.opNo == OP_RPAREN) {
                        if (!nested) {
                            throw new CommandSyntaxException("misplaced ')'");
                        }
                        back();
                        return;
                    }
            }
View Full Code Here

                case OP_UNARY:
                    operatorStack.push(op);
                    operandStack.push(next());
                    break;
                case OP_BINARY:
                    throw new CommandSyntaxException("misplaced binary operator");
                case OP_SPECIAL:
                    if (op.opNo == OP_LPAREN) {
                        operatorStack.push(op); // ... as a marker.
                        evaluateExpression(true);
                        if (!next().equals(")")) {
                            throw new CommandSyntaxException("missing ')'");
                        }
                        while (operatorStack.peek() != op) {
                            reduce();
                        }
                        if (operatorStack.pop() != op) {
                            throw new AssertionError("cannot find my marker!");
                        }
                    } else {
                        throw new CommandSyntaxException("unmatched ')'");
                    }
            }
        }
    }
View Full Code Here

            if (option.equals("--help")) {
                err.println("Don't panic!");
            } else if (option.equals("--version")) {
                err.println("JNode test 0.0");
            } else {
                throw new CommandSyntaxException("unknown option '" + option + '\'');
            }
        }
    }
View Full Code Here

        operandStack.push(value);
    }

    private Object popOperand() throws CommandSyntaxException {
        if (operandStack.isEmpty()) {
            throw new CommandSyntaxException("missing LHS for operator");
        }
        return operandStack.pop();
    }
View Full Code Here

            return (Long) obj;
        } else if (obj instanceof String) {
            try {
                return Long.parseLong((String) obj);
            } catch (NumberFormatException ex) {
                throw new CommandSyntaxException(
                        "operand is not a number: '" + obj.toString() + '\'');
            }
        } else {
            throw new CommandSyntaxException("subexpression is not an INTEGER");
        }
    }
View Full Code Here

TOP

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

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.