Package org.jnode.shell

Examples of org.jnode.shell.ShellSyntaxException


                    sb.append((char) ch);
                    break;
            }
            ch = ci.nextCh();
        }
        throw new ShellSyntaxException("Unmatched \"'\" (double quote)");
    }
View Full Code Here


                    sb.append((char) ch);
                    break;
            }
            ch = ci.nextCh();
        }
        throw new ShellSyntaxException("Unmatched '\"' (single quote)");
    }
View Full Code Here

                    sb.append((char) ch);
                    break;
            }
            ch = ci.nextCh();
        }
        throw new ShellSyntaxException("Unmatched \"`\" (back quote)");
    }
View Full Code Here

        int ch = ci.peekCh();
        if (ch == '#') {
            ci.nextCh();
            String parameter = parseParameter(ci);
            if (ci.nextCh() != '}') {
                throw new ShellSyntaxException("Unmatched \"{\"");
            }
            String value = variable(parameter);
            return (value != null) ? Integer.toString(value.length()) : "0";
        }
        String parameter = parseParameter(ci);
        ch = ci.nextCh();
        int operator = NONE;
        switch (ch) {
            case -1:
                throw new ShellSyntaxException("Unmatched \"{\"");
            case '}':
                break;
            case '#':
                if (ci.peekCh() == '#') {
                    ci.nextCh();
                    operator = DHASH;
                } else {
                    operator = HASH;
                }
                break;
            case '%':
                if (ci.peekCh() == '%') {
                    ci.nextCh();
                    operator = DPERCENT;
                } else {
                    operator = PERCENT;
                }
                break;
            case ':':
                switch (ci.peekCh()) {
                    case '=':
                        operator = COLONEQUALS;
                        break;
                    case '+':
                        operator = COLONPLUS;
                        break;
                    case '?':
                        operator = COLONQUERY;
                        break;
                    case '-':
                        operator = COLONMINUS;
                        break;
                    default:
                        throw new ShellSyntaxException("bad substitution operator");
                }
                ci.nextCh();
                break;
            case '=':
                operator = EQUALS;
                break;
            case '?':
                operator = QUERY;
                break;
            case '+':
                operator = PLUS;
                break;
            case '-':
                operator = MINUS;
                break;
            default:
                throw new ShellSyntaxException("unrecognized substitution operator (\"" + (char) ch + "\")");
        }
        String value = variable(parameter);
        if (operator == NONE) {
            return (value != null) ? value : "";
        }
        String word = dollarBacktickExpand(ci, '}').toString();
        if (ci.nextCh() != '}') {
            throw new ShellSyntaxException("Unmatched \"{\"");
        }
        switch (operator) {
            case MINUS:
                return (value == null) ? word : value;
            case COLONMINUS:
View Full Code Here

        } else {
            try {
                int argNo = Integer.parseInt(parameter);
                return argVariable(argNo);
            } catch (NumberFormatException ex) {
                throw new ShellSyntaxException("bad substitution");
            }
        }
    }
View Full Code Here

            ci.nextCh();
            return dollarParenParenExpand(ci);
        } else {
            String commandLine = dollarBacktickExpand(ci, ')').toString();
            if (ci.nextCh() != ')') {
                throw new ShellSyntaxException("Unmatched \"(\" (left parenthesis)");
            }
            return runBacktickCommand(commandLine);
        }
    }
View Full Code Here

                    } else {
                        sb.append(')');
                    }
                    break;
                case -1:
                    throw new ShellSyntaxException("Unmatched \"((\" (double left parenthesis)");
                default:
                    sb.append((char) ch);
            }
            ci.nextCh();
        } while (!done);
View Full Code Here

            switch (ex.getControl()) {
                case BjorneInterpreter.BRANCH_EXIT:
                    // The script will exit immediately
                    return ex.getCount();
                case BjorneInterpreter.BRANCH_BREAK:
                    throw new ShellSyntaxException(
                            "'break' has been executed in an inappropriate context");
                case BjorneInterpreter.BRANCH_CONTINUE:
                    throw new ShellSyntaxException(
                            "'continue' has been executed in an inappropriate context");
                case BjorneInterpreter.BRANCH_RETURN:
                    throw new ShellSyntaxException(
                            "'return' has been executed in an inappropriate context");
                default:
                    throw new ShellFailureException(
                            "unknown 'control' in BjorneControlException");
            }
View Full Code Here

                case PLUSPLUS:
                case MINUSMINUS:
                    prefixOp += PREFIX;
                    break;
                default:
                    throw new ShellSyntaxException("Unexpected infix operator");
            }
            skipWhiteSpace(ci);
            pushOperand(evalPrimary(ci));
            if (prefixOp != NONE) {
                pushOperator(prefixOp, mark);
            }
            skipWhiteSpace(ci);
            int op = parseExpressionOperator(ci);
            if (op == PLUSPLUS || op == MINUSMINUS) {
                pushOperator(op, mark);
                skipWhiteSpace(ci);
                op = parseExpressionOperator(ci);
            }
           
            ch = skipWhiteSpace(ci);
            if (op == NONE) {
                if (ch != -1 && ch != ')') {
                    throw new ShellSyntaxException("Expected an infix operator in expression");
                }
                break;
            } else if (op == PLUSPLUS || op == MINUSMINUS) {
                throw new ShellSyntaxException("Expected an infix operator in expression");
            } else if (ch == ')') {
                throw new ShellSyntaxException("Expected a number or variable name in expression");
            }
            pushOperator(op, mark);
        }
        if (valStack.size() == 0) {
            throw new ShellSyntaxException("No expression within \"$((...))\"");
        }
        while (opStack.size() > mark) {
            evalOperation();
        }
        return valStack.removeFirst();
View Full Code Here

                res = new Primary(null, -operand1.getValue());
                break;
            case PLUSPLUS + PREFIX:
            case MINUSMINUS + PREFIX:
                if (operand1.name == null) {
                    throw new ShellSyntaxException("Cannot apply ++ or -- to a number or a subexpression");
                }
                value = evalName(operand1.name) + (op == PLUSPLUS + PREFIX ? 1 : -1);
                context.setVariable(operand1.name, Long.toString(value));
                res = new Primary(null, value);
                break;
            case PLUSPLUS:
            case MINUSMINUS:
                if (operand1.name == null) {
                    throw new ShellSyntaxException("Cannot apply ++ or -- to a number or a subexpression");
                }
                value = evalName(operand1.name);
                context.setVariable(operand1.name, Long.toString(value + (op == PLUSPLUS ? 1 : -1)));
                res = new Primary(null, value);
                break;
View Full Code Here

TOP

Related Classes of org.jnode.shell.ShellSyntaxException

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.