Package httl.ast

Examples of httl.ast.SetDirective


        var = v;
      } else {
        type = v.substring(0, i).trim();
        var = v.substring(i + 1).trim();
      }
      directives.add(new SetDirective(parseGenericType(type, o), var, null, false, false, offset));
      o += v.length() + 1;
    }
  }
View Full Code Here


              String type = null;
              if (j > 0) {
                type = var.substring(0, j).trim();
                var = var.substring(j + 1).trim();
              }
              directives.add(new SetDirective(parseGenericType(type, exprOffset), var, expression, export, hide, offset));
              o += v.length() + 1;
            }
          } else {
            defineVariableTypes(value, offset, directives);
          }
        } else if (StringUtils.inArray(name, forDirective)) {
          if (StringUtils.isNumber(value.trim())) {
            value = "__for" + seq.incrementAndGet() + " : 1 .. " + value.trim();
          }
          int i = value.indexOf(" in ");
          int n = 4;
          if (i < 0) {
            i = value.indexOf(':');
            n = 1;
          }
          if (i < 0) {
            throw new ParseException("Miss colon \":\" in invalid directive #for(" + value + ")", offset);
          }
          String var = value.substring(0, i).trim();
          String expr = value.substring(i + n);
          int blank = 0;
          while (blank < expr.length()) {
            if (! Character.isWhitespace(expr.charAt(blank))) {
              break;
            }
            blank ++;
          }
          if (blank > 0) {
            expr = expr.substring(blank);
          }
          Expression expression = (Expression) expressionParser.parse(expr, exprOffset + i + n + blank);
          int j = var.lastIndexOf(' ');
          String type = null;
          if (j > 0) {
            type = var.substring(0, j).trim();
            var = var.substring(j + 1).trim();
          }
          directives.add(new ForDirective(parseGenericType(type, exprOffset), var, expression, offset));
        } else if (StringUtils.inArray(name, ifDirective)) {
          directives.add(new IfDirective((Expression) expressionParser.parse(value, exprOffset), offset));
        } else if (StringUtils.inArray(name, elseDirective)) {
          directives.add(new ElseDirective(StringUtils.isEmpty(value)
              ? null : (Expression) expressionParser.parse(value, exprOffset), offset));
        } else if (StringUtils.inArray(name, breakDirective)) {
          directives.add(new BreakDirective(StringUtils.isBlank(value) ? null : (Expression) expressionParser.parse(value, exprOffset), offset));
        } else if (StringUtils.inArray(name, macroDirective)) {
          String macroName = value;
          String macroParams = null;
          String filter = null;
          int idx = macroName.indexOf("=>");
          if (idx > 0) {
            filter = macroName.substring(idx + 2).trim();
            macroName = macroName.substring(0, idx);
          }
          int i = value.indexOf('(');
          if (i > 0) {
            if (! message.endsWith(")")) {
              throw new ParseException("The #" + name + " directive mismatch right parentheses.", exprOffset);
            }
            macroName = value.substring(0, i);
            macroParams = value.substring(i + 1, value.length() - 1);
          }
          String set = null;
          boolean parent = false;
          boolean hide = false;
          i = macroName.indexOf('=');
          if (i > 0) {
            set = macroName.substring(0, i);
            if (set.endsWith(":")) {
              parent = true;
              set = set.substring(0, set.length() - 1);
            } else if (set.endsWith(".")) {
              hide = true;
              set = set.substring(0, set.length() - 1);
            }
            set = set.trim();
            macroName = macroName.substring(i + 1);
          }
          boolean out = false;
          if (macroName.startsWith("$")) {
            out = true;
            macroName = macroName.substring(macroName.startsWith("$!") ? 2 : 1);
          }
          String expr;
          if (StringUtils.isNotEmpty(filter)) {
            if (filter.contains("(")) {
              expr = filter;
            } else {
              expr = filter + "(" + macroName + ")";
            }
          } else {
            expr = macroName;
          }
          if (StringUtils.isNotEmpty(set)) {
            directives.add(new SetDirective(Template.class, set, (Expression) expressionParser.parse(expr, exprOffset), parent, hide, offset));
          }
          if (out) {
            directives.add(new ValueDirective((Expression) expressionParser.parse(expr, exprOffset), true, offset));
          }
          macroName = macroName.trim();
View Full Code Here

TOP

Related Classes of httl.ast.SetDirective

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.