Package org.zkoss.zuss.metainfo

Examples of org.zkoss.zuss.metainfo.Expression


    }
  }

  private void parseKeyword(Context ctx, Keyword kw) throws IOException {
    final IfDefinition idef;
    final Expression expr;
    switch (kw.getValue()) {
    case INCLUDE:
      parseInclude(ctx, kw);
      return;
    case CHARSET:
    case IMPORT:
      new RawValue(ctx.block.owner, "@import "+_in.getUntil(";")+'\n', kw.getLine());
      return;
    case MEDIA:
      String scope = _in.getUntil("{");
      if (!scope.endsWith("{"))
        throw error("'{' expected", kw);
      scope = scope.substring(0, scope.length() - 1);
      newBlock(ctx,
        new MediaDefinition(ctx.block.owner, scope, kw.getLine()));
      return;
    case FONTFACE:
        new RawValue(ctx.block.owner, "@font-face "+_in.getUntil("}")+'\n', kw.getLine());
                    return;
    case IF:
      nextAndCheck(ctx, '(', false);
      expr = new Expression(_in.getLine());
      parseExpression(ctx, expr, '{');
      newBlock(ctx,
        new BlockDefinition(
          new IfDefinition(ctx.block.owner, kw.getLine()), expr, expr.getLine()));
      return;
    case ELSE:
      idef = getLastIf(ctx, kw);
      nextAndCheck(ctx, '{', false);
      newBlock(ctx, new BlockDefinition(idef, null, kw.getLine()));
      return;
    case ELIF:
      idef = getLastIf(ctx, kw);
      expr = new Expression(_in.getLine());
      parseExpression(ctx, expr, '{');
      newBlock(ctx, new BlockDefinition(idef, expr, kw.getLine()));
      return;
    }
    throw error(kw+" not supported yet", kw);
View Full Code Here


    final int lineno = id.getLine();
    Token t0 =  next(ctx);
    if (t0 instanceof Symbol) {
      final char symbol = ((Symbol)t0).getValue();
      if (symbol == ':') { //variable definition
        final Expression expr = new Expression(t0.getLine());
          //note: expr is NOT a child of any node but part of VariableDefinition below
        parseExpression(ctx, expr, ';');
        new VariableDefinition(
          ctx.block.owner, name, expr, lineno);
        return;
      } else if (symbol == '{') { //mixin definition
        newBlock(ctx, new MixinDefinition(
          ctx.block.owner, name,
          new ArgumentDefinition[0], lineno));
        return;
      } else if (symbol == ';') { //use of function/mixin
        Expression expr = new Expression(ctx.block.owner, lineno);
        new FunctionValue(expr, name, lineno); //no parenthesis
        return;
      }
    } else if (t0 instanceof Op && ((Op)t0).getValue() == LPAREN) {
      //1) definition of function or mixin
      //2) use of function or mixin
      char cc = _in.peekAfterRPAREN();
      if (cc == ';' || cc == '}' || cc == EOF) { //use of function/mixin
        putback(t0);
        putback(id);
        parseExpression(ctx, new Expression(ctx.block.owner, lineno), EOPAREN);

        t0 = next(ctx);
        if (t0 instanceof Symbol) {
          switch (((Symbol)t0).getValue()) {
          case '}':
            putback(t0);
            //fall thru
          case ';':
            return; //done
          }
        }
        throw error("';' expected; not "+t0, t0);
      }

      //definition of function/mixin
      final ArgumentDefinition[] adefs = parseArguments(ctx);
      t0 = next(ctx);
      if (t0 instanceof Symbol) {
        final char symbol = ((Symbol)t0).getValue();
        if (symbol == ':') { //function definition
          Token t1 = next(ctx);
          if (t1 instanceof Keyword && ((Keyword)t1).getValue() == IMPORT) {
            t0 = next(ctx);
            if (!(t0 instanceof Other))
              throw error("a class name expected, not "+t0, t0);
            nextAndCheck(ctx, ';', true);

            final Method mtd = Classes.getMethod(
              ((Other)t0).getValue(), name, adefs.length,
              getFilename(), t0.getLine());
            new FunctionDefinition(
              ctx.block.owner, name, adefs, mtd, lineno);
            return;
          } else {
            putback(t1);
            final Expression expr = new Expression(t0.getLine());
              //note: expr is NOT a child of any node but part of VariableDefinition below
            parseExpression(ctx, expr, ';');
            new FunctionDefinition(
              ctx.block.owner, name, adefs, expr, lineno);
            return;
View Full Code Here

        new ConstantValue(sdef, "" + symbol, token.getLine());
      } else if (token instanceof Id) {
        //handle @xx or @xxx()
        if (_in.peek() == '(') { //a function invocation
          putback(token);
          parseExpression(ctx, new Expression(sdef, token.getLine()), EOPAREN);
            //note: the expression is a child of sdef
        } else {
          new FunctionValue(sdef, ((Id)token).getValue(), token.getLine()); //no parenthesis
        }
      }
View Full Code Here

        empty = false;
        write(head);
      }
      outStyle(scope, (StyleDefinition)node);
    } else if (node instanceof Expression) { //could be mixin or value expression
      final Expression expr = (Expression)node;
      final MixinInfo mixin = getMixinInfo(scope, expr);
      if (mixin != null) { //yes, a minin
        if (empty) {
          empty = false;
          write(head);
        }

        final Scope subsc = new LocalScope(scope, mixin.argmap, mixin.argmap.values());
        for (NodeInfo subnd: mixin.mixin.getChildren()) {
          empty = outRuleInner(subsc, thisSels, subnd, head, end, empty);
        }
      } else {
      //handle normal expression
        final Object o = evalExpression(scope, expr);
        if (o != null) {
          if (empty) {
            empty = false;
            write(head);
          }
          write(Classes.toString(o));
        }
      }
    } else if (node instanceof IfDefinition) { //in a rule
      for (NodeInfo child: node.getChildren()) {
        final BlockDefinition block = (BlockDefinition)child;
        final Expression expr = block.getCondition();
        if (expr == null || isTrue(scope, expr)) {
          for (NodeInfo subnd: block.getChildren()) {
            empty = outRuleInner(scope, thisSels, subnd, head, end, empty);
          }
          break; //done
View Full Code Here

      final MixinDefinition fd = (MixinDefinition)node;
      scope.setVariable(fd.getName(), fd);
    } else if (node instanceof IfDefinition) { //assume not in a rule (outerSel shall be null)
      for (NodeInfo child: node.getChildren()) {
        final BlockDefinition block = (BlockDefinition)child;
        final Expression expr = block.getCondition();
        if (expr == null || isTrue(scope, expr)) {
          outChildren(scope, outerSels, block);
          break; //done
        }
      }
View Full Code Here

  }
  private Object evalDefinition(Scope scope, FunctionDefinition fdef, Object[] args,
  int lineno) {
    final ArgumentDefinition[] adefs = fdef.getArgumentDefinitions();
    final Object value;
    final Expression expr = fdef.getExpression();
    if (expr != null) {
      final Map<String, Object> argmap = getArgumentMap(adefs, args);
      value = evalExpression(new LocalScope(scope, argmap, argmap.values()), expr);
        //a local scope for function invocation
    } else {
View Full Code Here

TOP

Related Classes of org.zkoss.zuss.metainfo.Expression

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.