Пример #1
0
 private void parseIf(IfContext context, IfStatement ifStatement) throws IfStatementError {
   ifStatement.acceptCondition(parseCondition(context));
   if (context.isEOF()) {
     throw new IfStatementError(
         Messages.TclIfProcessor_missingThenBlock, context.start(), context.end());
   }
   if (checkKeyword(context, THEN)) {
     if (context.isEOF()) {
       throw new IfStatementError(
           Messages.TclIfProcessor_missingThenBlock, context.start(), context.end());
     }
   }
   ifStatement.acceptThen(parseBranch(context, true, Messages.TclIfProcessor_incorrectThenBlock));
   if (!context.isEOF()) {
     if (checkKeyword(context, ELSEIF)) {
       final ASTNode elseIfKeyword = context.get(context.index - 1);
       final IfStatement nestedIf = new IfStatement(elseIfKeyword.sourceStart(), context.end());
       parseIf(context, nestedIf);
       ifStatement.acceptElse(nestedIf);
     } else {
       if (checkKeyword(context, ELSE)) {
         if (context.isEOF()) {
           throw new IfStatementError(
               Messages.TclIfProcessor_incorrectElse, context.start(), context.end());
         }
       }
       ifStatement.acceptElse(
           parseBranch(context, false, Messages.TclIfProcessor_incorrectElseBlock));
     }
   }
 }
Пример #2
0
 private ASTNode parseCondition(IfContext context) throws IfStatementError {
   if (context.isEOF()) {
     throw new IfStatementError(
         Messages.TclIfProcessor_missingCondition, context.start(), context.end());
   }
   ASTNode node = context.get();
   if (node instanceof TclBlockExpression) {
     TclBlockExpression bl = (TclBlockExpression) node;
     List parseBlock = bl.parseBlockSimple(false);
     ASTListNode list = new ASTListNode(bl.sourceStart() + 1, bl.sourceEnd() - 1);
     for (int j = 0; j < parseBlock.size(); j++) {
       Object st = parseBlock.get(j);
       if (st instanceof TclStatement) {
         List expressions = ((TclStatement) st).getExpressions();
         for (int k = 0; k < expressions.size(); k++) {
           ASTNode expr = (ASTNode) expressions.get(k);
           list.addNode(expr);
         }
       }
     }
     return list;
   } else if (node instanceof SimpleReference) {
     return node;
   } else if (node instanceof TclAdvancedExecuteExpression) {
     TclAdvancedExecuteExpression ex = (TclAdvancedExecuteExpression) node;
     List childs = ex.getChilds();
     return new ASTListNode(node.sourceStart(), node.sourceEnd(), childs);
   } else if (node instanceof TclExecuteExpression) {
     return node;
   } else if (node instanceof Block) {
     return node;
   }
   throw new IfStatementError(Messages.TclIfProcessor_incorrectCondition, node);
 }
Пример #3
0
 public ASTNode process(TclStatement statement, ITclParser parser, ASTNode parent) {
   final IfContext context = new IfContext(parser, statement);
   IfStatement ifStatement = new IfStatement(context.start(), context.end());
   addToParent(parent, ifStatement);
   try {
     parseIf(context, ifStatement);
     if (!context.isEOF()) {
       final ASTNode extraBegin = context.get(context.index);
       final ASTNode extraEnd = context.get(context.size() - 1);
       report(
           parser,
           Messages.TclIfProcessor_unexpectedStatements,
           extraBegin.sourceStart(),
           extraEnd.sourceEnd(),
           ProblemSeverities.Error);
     }
   } catch (IfStatementError e) {
     // if (DLTKCore.DEBUG) {
     // e.printStackTrace();
     // }
     report(parser, e.getMessage(), e.start, e.end, ProblemSeverities.Error);
   }
   return ifStatement;
 }