Exemplo n.º 1
0
  public Pack fromDefault(Pack pack) {
    Rule rule = pack.getRule();
    Target target = rule.getTarget();
    TuplePrototype targetPrototype = target.getPrototype();

    Function call = pack.getPriorCall();
    if (call == null) {
      throw new DefaultPackExpansionException("Cannot use implicit pack in a call-free chain.");
    }
    TuplePrototype callPrototype = target.getPrototype();

    if (callPrototype.size() != targetPrototype.size()) {
      throw new DefaultPackExpansionException(
          "Default pack cannot be created because tuple prototypes are of different lengths.");
    }

    Pack newPack = (Pack) adaptor.dupNode(pack);

    for (int i = 0; i < targetPrototype.size(); i++) {
      TupleRef ref = (TupleRef) adaptor.create(TUPLE_REF, "");
      adaptor.addChild(ref, adaptor.create(NUMBER, Integer.toString(i)));
      adaptor.addChild(newPack, ref);
    }

    return newPack;
  }
Exemplo n.º 2
0
  // $ANTLR start "topdown"
  // /Volumes/scratch/jcottam/workspace/Stencil/Stencil/Core/stencil/parser/DefaultPack.g:92:1:
  // topdown : ^(r= PACK DEFAULT ) ->;
  public final DefaultPack.topdown_return topdown() throws RecognitionException {
    DefaultPack.topdown_return retval = new DefaultPack.topdown_return();
    retval.start = input.LT(1);

    StencilTree root_0 = null;

    StencilTree _first_0 = null;
    StencilTree _last = null;

    StencilTree r = null;
    StencilTree DEFAULT1 = null;

    StencilTree r_tree = null;
    StencilTree DEFAULT1_tree = null;
    RewriteRuleNodeStream stream_DEFAULT = new RewriteRuleNodeStream(adaptor, "token DEFAULT");
    RewriteRuleNodeStream stream_PACK = new RewriteRuleNodeStream(adaptor, "token PACK");

    try {
      // /Volumes/scratch/jcottam/workspace/Stencil/Stencil/Core/stencil/parser/DefaultPack.g:92:8:
      // ( ^(r= PACK DEFAULT ) ->)
      // /Volumes/scratch/jcottam/workspace/Stencil/Stencil/Core/stencil/parser/DefaultPack.g:92:10:
      // ^(r= PACK DEFAULT )
      {
        _last = (StencilTree) input.LT(1);
        {
          StencilTree _save_last_1 = _last;
          StencilTree _first_1 = null;
          _last = (StencilTree) input.LT(1);
          r = (StencilTree) match(input, PACK, FOLLOW_PACK_in_topdown68);
          if (state.failed) return retval;
          if (state.backtracking == 1) stream_PACK.add(r);

          if (state.backtracking == 1) if (_first_0 == null) _first_0 = r;
          match(input, Token.DOWN, null);
          if (state.failed) return retval;
          _last = (StencilTree) input.LT(1);
          DEFAULT1 = (StencilTree) match(input, DEFAULT, FOLLOW_DEFAULT_in_topdown70);
          if (state.failed) return retval;
          if (state.backtracking == 1) stream_DEFAULT.add(DEFAULT1);

          match(input, Token.UP, null);
          if (state.failed) return retval;
          _last = _save_last_1;
        }

        // AST REWRITE
        // elements:
        // token labels:
        // rule labels: retval
        // token list labels:
        // rule list labels:
        // wildcard labels:
        if (state.backtracking == 1) {
          retval.tree = root_0;
          RewriteRuleSubtreeStream stream_retval =
              new RewriteRuleSubtreeStream(
                  adaptor, "rule retval", retval != null ? retval.tree : null);

          root_0 = (StencilTree) adaptor.nil();
          // 92:28: ->
          {
            adaptor.addChild(root_0, fromDefault((Pack) r));
          }

          retval.tree = (StencilTree) adaptor.rulePostProcessing(root_0);
          input.replaceChildren(
              adaptor.getParent(retval.start),
              adaptor.getChildIndex(retval.start),
              adaptor.getChildIndex(_last),
              retval.tree);
        }
      }

    } catch (RecognitionException re) {
      reportError(re);
      recover(input, re);
    } finally {
    }
    return retval;
  }