Package org.lilystudio.smarty4j

Examples of org.lilystudio.smarty4j.ParseException


      for (int i = 0; i < len; i++) {
        try {
          parameters[i] = definitions[i]
              .getExpression(i < values.size() ? values.get(i) : null);
        } catch (ParseException e) {
          throw new ParseException("第" + i + "个参数" + e.getMessage());
        }
      }

      setParameters(parameters);
    }
View Full Code Here


  @Override
  public void init(Template parent, boolean ransack, List<IExpression> values)
      throws ParseException {
    super.init(parent, ransack, values);
    if ((getParameter(0) == null) || (getParameter(1) == null)) {
      throw new ParseException("replace参数错误");
    }
    rule = Pattern.compile(p.matcher(getParameter(0).toString()).replaceAll(
        "\\\\$1"));
    replacement = Utilities.escapeReg(getParameter(1).toString());
  }
View Full Code Here

          operations[lastOperation] = null;
          isFirst = true;
        } else if (word == C_R_GROUP) {
          while (true) {
            if (lastOperation < 0) {
              throw new ParseException("缺失左括号");
            }
            Operation op = operations[lastOperation];
            lastOperation--;
            if (op != null) {
              expressionSize -= op.process(expressions, expressionSize, mode);
            } else {
              break;
            }
          }
          isFirst = false;
        } else {
          for (Operation op : opers) {
            outer: for (Object[] name : op.names) {
              // 有一些操作符是由一组汉字组成的, 需要比较每一个
              int len = name.length;
              int index = i + len - 1;
              if (index < end) {
                for (; index >= i; index--) {
                  if (!name[index - i].equals(words[index])) {
                    continue outer;
                  }
                }
                // 如果栈内存在优先级较高的符号, 需要将数据弹出栈
                int priority = op.priority;
                for (; lastOperation >= 0; lastOperation--) {
                  Operation tmp = operations[lastOperation];
                  if ((tmp != null) && (priority <= tmp.priority)) {
                    expressionSize -= tmp.process(expressions, expressionSize,
                        mode);
                  } else {
                    break;
                  }
                }
                lastOperation++;
                operations[lastOperation] = op;
                i += len;
                continue main;
              }
            }
            isFirst = true;
          }
          throw new ParseException("不能识别的运算符");
        }
      }
      i++;
    }

    // 处理完表达式后, 将所有的数据弹出栈
    for (; lastOperation >= 0; lastOperation--) {
      expressionSize -= operations[lastOperation].process(expressions,
          expressionSize, mode);
    }

    if (expressionSize == 1) {
      return expressions[0];
    } else {
      throw new ParseException("表达式语法错误");
    }
  }
View Full Code Here

    while (index < wordSize) {
      // 如果输出包含变量调节器, 初始化变量调节器节点
      if (Operation.C_B_OR == words[index]) {
        index++;
        if (index == wordSize) {
          throw new ParseException("变量调节器没有名称");
        } else {
          // 读取变量调节器的名称
          Object o = words[index];
          if (!(o instanceof String)) {
            throw new ParseException("变量调节器名称必须是字符串");
          } else {
            // 变量调节器名必须是字符串
            String name = (String) o;
            index++;
            List<IExpression> values = new ArrayList<IExpression>();
            outer: while ((index < wordSize)
                && Operation.C_COLON == words[index]) {
              index++;
              while (true) {
                if (index >= wordSize) {
                  break outer;
                }
                // 读取变量调节器的参数
                o = words[index];
                index++;
                // 检查参数分隔符的合法性
                if (Operation.C_COLON == o) {
                  values.add(null);
                  continue;
                }
                // 识别参数类型
                if (o instanceof IExpression) {
                  values.add((IExpression) o);
                } else if (o instanceof String) {
                  if ("true".equals(o)) {
                    values.add(new TrueCheck());
                  } else if ("false".equals(o)) {
                    values.add(new FalseCheck());
                  } else {
                    throw new ParseException("不能识别的保留字");
                  }
                } else if (o instanceof Integer) {
                  values.add(new ConstInteger(((Number) o).intValue()));
                } else if (o instanceof Double) {
                  values.add(new ConstDouble(((Number) o).doubleValue()));
                } else {
                  throw new ParseException("不能识别的参数");
                }
                break;
              }
            }
            boolean ransack;
View Full Code Here

   *           参数验证错误时产生异常
   */
  IExpression getExpression(IExpression expression) throws ParseException {
    if (expression == null) {
      if (required) {
        throw new ParseException("必须指定");
      } else {
        return value;
      }
    } else {
      switch (type) {
      case BOOLEAN:
        if (!(expression instanceof TrueCheck || expression instanceof FalseCheck)) {
          throw new ParseException("必须是true或false");
        }
        break;
      case INTEGER:
        if (!(expression instanceof ConstInteger)) {
          throw new ParseException("必须是整数");
        }
        break;
      case DOUBLE:
        if (!(expression instanceof ConstInteger)
            && !(expression instanceof ConstDouble)) {
          throw new ParseException("必须是浮点数");
        }
        break;
      case STRING:
        if (!(expression instanceof StringExpression)) {
          throw new ParseException("必须是字符串");
        }
        break;
      case OBJECT:
        break;
      case BOOLOBJECT:
View Full Code Here

        ParameterCharacter definition = definitions[i];
        String name = (String) definition.getCustom();
        try {
          parameters[i] = definition.getExpression(fields.get(name));
        } catch (ParseException e) {
          throw new ParseException(name + e.getMessage());
        }
      }
      setParameters(parameters);
    }
  }
View Full Code Here

            if (word instanceof Integer) {
              value = new ConstInteger(-((Integer) word));
            } else if (word instanceof Double) {
              value = new ConstDouble(-((Double) word));
            } else {
              throw new ParseException("不能识别的函数参数值");
            }
          } else if (word instanceof Integer) {
            value = new ConstInteger((Integer) word);
          } else if (word instanceof Double) {
            value = new ConstDouble((Double) word);
          } else if ("true".equals(word) || "yes".equals(word)
              || "on".equals(word)) {
            value = new TrueCheck();
          } else if ("false".equals(word) || "no".equals(word)
              || "off".equals(word)) {
            value = new FalseCheck();
          } else if ("null".equals(word)) {
            value = new NullExpression();
          } else if (word instanceof String) {
            value = new StringExpression((String) word);
          } else {
            throw new ParseException("不能识别的函数参数值");
          }

          if (index + 3 < wordSize && words[index + 3] == Operation.C_B_OR) {

          }
          fields.put((String) name, value);
          continue;
        }
        throw new ParseException("函数参数语法错误");
      }
      process(parameters, fields);
    }
  }
View Full Code Here

        ParentType.class);

    if (parentType != null) {
      String name = parentType.name();
      if (!name.equals(parent.getName())) {
        throw new ParseException(getClass().getSimpleName().substring(1)
            + "只能位于" + name + "中");
      }
    }

    this.parent = parent;
View Full Code Here

    } else if (scope.equals("parent")) {
      type = 1;
    } else if (scope.equals("global")) {
      type = 0;
    } else {
      throw new ParseException("scope必须是: global, parent, local");
    }
  }
View Full Code Here

      throws ParseException {
    super.init(parent, ransack, values);
    if (getParameter(2) != null) {
      locale = locales.get(getParameter(2).toString());
      if (locale == null) {
        throw new ParseException("不支持的地区");
      }
    }
    locale = Locale.getDefault();
  }
View Full Code Here

TOP

Related Classes of org.lilystudio.smarty4j.ParseException

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.