Package org.stringtemplate.v4

Examples of org.stringtemplate.v4.STGroupString


        }

        markedStates.add(s); // mark this node as completed.

        // first add this node
        ST stateST;
        if ( s.isAcceptState() ) {
            stateST = stlib.getInstanceOf("stopstate");
        }
        else {
            stateST = stlib.getInstanceOf("state");
        }
        stateST.add("name", getStateLabel(s));
        dot.add("states", stateST);

        if ( s.isAcceptState() )  {
            return; // don't go past end of rule node to the follow states
        }

        // special case: if decision point, then line up the alt start states
        // unless it's an end of block
    if ( ((NFAState)s).isDecisionState() ) {
      GrammarAST n = ((NFAState)s).associatedASTNode;
      if ( n!=null && n.getType()!=ANTLRParser.EOB ) {
        ST rankST = stlib.getInstanceOf("decision-rank");
        NFAState alt = (NFAState)s;
        while ( alt!=null ) {
          rankST.add("states", getStateLabel(alt));
          if ( alt.transition[1] !=null ) {
            alt = (NFAState)alt.transition[1].target;
          }
          else {
            alt=null;
          }
        }
        dot.add("decisionRanks", rankST);
      }
    }

        // make a DOT edge for each transition
    ST edgeST;
    for (int i = 0; i < s.getNumberOfTransitions(); i++) {
            Transition edge = s.transition(i);
            if ( edge instanceof RuleClosureTransition ) {
                RuleClosureTransition rr = ((RuleClosureTransition)edge);
                // don't jump to other rules, but display edge to follow node
                edgeST = stlib.getInstanceOf("edge");
        if ( rr.rule.grammar != grammar ) {
          edgeST.add("label", "<" + rr.rule.grammar.name + "." + rr.rule.name + ">");
        }
        else {
          edgeST.add("label", "<" + rr.rule.name + ">");
        }
        edgeST.add("src", getStateLabel(s));
        edgeST.add("target", getStateLabel(rr.followState));
        edgeST.add("arrowhead", arrowhead);
                dot.add("edges", edgeST);
        walkRuleNFACreatingDOT(dot, rr.followState);
                continue;
            }
      if ( edge.isAction() ) {
        edgeST = stlib.getInstanceOf("action-edge");
      }
      else if ( edge.isEpsilon() ) {
        edgeST = stlib.getInstanceOf("epsilon-edge");
      }
      else {
        edgeST = stlib.getInstanceOf("edge");
      }
      edgeST.add("label", getEdgeLabel(edge));
            edgeST.add("src", getStateLabel(s));
      edgeST.add("target", getStateLabel(edge.target));
      edgeST.add("arrowhead", arrowhead);
            dot.add("edges", edgeST);
            walkRuleNFACreatingDOT(dot, edge.target); // keep walkin'
        }
    }
View Full Code Here


  }

  /** Return a new template instance every time someone tries to print
   *  a Message.
   */
  public ST getMessageTemplate() { return new ST(msgST); }
View Full Code Here

  public ST getMessageTemplate() { return new ST(msgST); }

  /** Return a new template instance for the location part of a Message.
   *  TODO: Is this really necessary? -Kay
   */
  public ST getLocationTemplate() { return new ST(locationST); }
View Full Code Here

    super(msgID,arg,null);
    this.e = e;
  }
  @Override
  public String toString() {
    ST st = getMessageTemplate();
    if ( arg!=null ) {
      st.add("arg", arg);
    }
    if ( arg2!=null ) {
      st.add("arg2", arg2);
    }
    if ( e!=null ) {
      st.add("exception", e);
      st.add("stackTrace", e.getStackTrace());
    }
    return super.toString(st);
  }
View Full Code Here

    column = decisionASTNode.getCharPositionInLine();
    String fileName = probe.dfa.nfa.grammar.getFileName();
    if ( fileName!=null ) {
      file = fileName;
    }
    ST st = getMessageTemplate();
    st.add("enclosingRule",
            probe.dfa.getNFADecisionStartState().enclosingRule.name);

    return super.toString(st);
  }
View Full Code Here

    String fileName = probe.dfa.nfa.grammar.getFileName();
    if ( fileName!=null ) {
      file = fileName;
    }

    ST st = getMessageTemplate();
    st.add("targetRules", targetRules);
    st.add("alt", alt);
    st.add("callSiteStates", callSiteStates);

    List<Label> labels =
      probe.getSampleNonDeterministicInputSequence(sampleBadState);
    String input = probe.getInputSequenceDisplay(labels);
    st.add("input", input);

    return super.toString(st);
  }
View Full Code Here

    String fileName = probe.dfa.nfa.grammar.getFileName();
    if ( fileName!=null ) {
      file = fileName;
    }

    ST st = getMessageTemplate();
    // Now fill template with information about problemState
    List<Label> labels = probe.getSampleNonDeterministicInputSequence(problemState);
    String input = probe.getInputSequenceDisplay(labels);
    st.add("input", input);

    if ( probe.dfa.isTokensRuleDecision() ) {
      Set<Integer> disabledAlts = probe.getDisabledAlternatives(problemState);
      for (Integer altI : disabledAlts) {
        String tokenName =
          probe.getTokenNameForTokensRuleAlt(altI);
        // reset the line/col to the token definition (pick last one)
        NFAState ruleStart =
          probe.dfa.nfa.grammar.getRuleStartState(tokenName);
        line = ruleStart.associatedASTNode.getLine();
        column = ruleStart.associatedASTNode.getCharPositionInLine();
        st.add("disabled", tokenName);
      }
    }
    else {
      st.add("disabled", probe.getDisabledAlternatives(problemState));
    }

    List<Integer> nondetAlts = probe.getNonDeterministicAltsForState(problemState);
    NFAState nfaStart = probe.dfa.getNFADecisionStartState();
    // all state paths have to begin with same NFA state
    int firstAlt = 0;
    if ( nondetAlts!=null ) {
      for (Integer displayAltI : nondetAlts) {
        if ( DecisionProbe.verbose ) {
          int tracePathAlt =
            nfaStart.translateDisplayAltToWalkAlt(displayAltI);
          if ( firstAlt == 0 ) {
            firstAlt = tracePathAlt;
          }
          List<? extends NFAState> path =
            probe.getNFAPathStatesForAlt(firstAlt,
                           tracePathAlt,
                           labels);
          st.addAggr("paths.{alt, states}", displayAltI, path);
        }
        else {
          if ( probe.dfa.isTokensRuleDecision() ) {
            // alts are token rules, convert to the names instead of numbers
            String tokenName =
              probe.getTokenNameForTokensRuleAlt(displayAltI);
            st.add("conflictingTokens", tokenName);
          }
          else {
            st.add("conflictingAlts", displayAltI);
          }
        }
      }
    }
    st.add("hasPredicateBlockedByAction", problemState.dfa.hasPredicateBlockedByAction);
    return super.toString(st);
  }
View Full Code Here

   */
  public GrammarAST addArtificialMatchTokensRule(GrammarAST grammarAST,
                           List<String> ruleNames,
                           List<String> delegateNames,
                           boolean filterMode) {
    ST matchTokenRuleST;
    if ( filterMode ) {
      matchTokenRuleST = new ST(
          ARTIFICIAL_TOKENS_RULENAME+
          " options {k=1; backtrack=true;} : <rules; separator=\"|\">;");
    }
    else {
      matchTokenRuleST = new ST(
          ARTIFICIAL_TOKENS_RULENAME+" : <rules; separator=\"|\">;");
    }

    // Now add token rule references
    for (int i = 0; i < ruleNames.size(); i++) {
      String rname = ruleNames.get(i);
      matchTokenRuleST.add("rules", rname);
    }
    for (int i = 0; i < delegateNames.size(); i++) {
      String dname = delegateNames.get(i);
      matchTokenRuleST.add("rules", dname+".Tokens");
    }
    //System.out.println("tokens rule: "+matchTokenRuleST.toString());
    GrammarAST r = parseArtificialRule(matchTokenRuleST.render());
    addRule(grammarAST, r);
    //addRule((GrammarAST)parser.getAST());
    //return (GrammarAST)parser.getAST();
    return r;
  }
View Full Code Here

                    DFA dfa)
    {
      if ( templates!=null ) {
        return templates.getInstanceOf("true_value");
      }
      return new ST("true");
    }
View Full Code Here

                    DFA dfa)
    {
      if ( templates!=null ) {
        return templates.getInstanceOf("false");
      }
      return new ST("false");
    }
View Full Code Here

TOP

Related Classes of org.stringtemplate.v4.STGroupString

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.