Package org.stringtemplate.v4

Examples of org.stringtemplate.v4.AutoIndentWriter


    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

    @Override
    public ST genExpr(CodeGenerator generator,
                    STGroup templates,
                    DFA dfa)
    {
      ST result = null;
      for (SemanticContext operand : operands) {
        if (result == null) {
          result = operand.genExpr(generator, templates, dfa);
          continue;
        }

        ST eST;
        if ( templates!=null ) {
          eST = templates.getInstanceOf("andPredicates");
        }
        else {
          eST = new ST("(<left>&&<right>)");
        }
        eST.add("left", result);
        eST.add("right", operand.genExpr(generator,templates,dfa));
        result = eST;
      }

      return result;
    }
View Full Code Here

    @Override
    public ST genExpr(CodeGenerator generator,
                    STGroup templates,
                    DFA dfa)
    {
      ST eST;
      if ( templates!=null ) {
        eST = templates.getInstanceOf("orPredicates");
      }
      else {
        eST = new ST("(<operands; separator=\"||\">)");
      }
      for (SemanticContext semctx : operands) {
        eST.add("operands", semctx.genExpr(generator,templates,dfa));
      }
      return eST;
    }
View Full Code Here

    @Override
    public ST genExpr(CodeGenerator generator,
                    STGroup templates,
                    DFA dfa)
    {
      ST eST;
      if ( templates!=null ) {
        eST = templates.getInstanceOf("notPredicate");
      }
      else {
        eST = new ST("!(<pred>)");
      }
      eST.add("pred", ctx.genExpr(generator,templates,dfa));
      return eST;
    }
View Full Code Here

    this.cycles = cycles;
  }

  @Override
  public String toString() {
    ST st = getMessageTemplate();
    st.add("listOfCycles", cycles);
    return super.toString(st);
  }
View Full Code Here

        // add output vocab file; e.g., T.tokens. This is always generated to
        // the base output directory, which will be just . if there is no -o option
        //
        files.add(new File(tool.getOutputDirectory(), generator.getVocabFileName()));
        // are we generating a .h file?
        ST headerExtST = null;
        ST extST = generator.getTemplates().getInstanceOf("codeFileExtension");
        if (generator.getTemplates().isDefined("headerFile")) {
            headerExtST = generator.getTemplates().getInstanceOf("headerFileExtension");
            String suffix = Grammar.grammarTypeToFileNameSuffix[grammar.type];
            String fileName = grammar.name + suffix + headerExtST.render();
            files.add(new File(outputDir, fileName));
        }
        if (grammar.type == Grammar.COMBINED) {
            // add autogenerated lexer; e.g., TLexer.java TLexer.h TLexer.tokens
            // don't add T__.g (just a temp file)
           
            String suffix = Grammar.grammarTypeToFileNameSuffix[Grammar.LEXER];
            String lexer = grammar.name + suffix + extST.render();
            files.add(new File(outputDir, lexer));

            // TLexer.h
            if (headerExtST != null) {
                String header = grammar.name + suffix + headerExtST.render();
                files.add(new File(outputDir, header));
            }
        // for combined, don't generate TLexer.tokens
        }

        // handle generated files for imported grammars
        List<Grammar> imports =
                grammar.composite.getDelegates(grammar.composite.getRootGrammar());
        for (Grammar g : imports) {
            outputDir = tool.getOutputDirectory(g.getFileName());
            String fname = groomQualifiedFileName(outputDir.toString(), g.getRecognizerName() + extST.render());
            files.add(new File(fname));
        }

        if (files.isEmpty()) {
            return null;
View Full Code Here

TOP

Related Classes of org.stringtemplate.v4.AutoIndentWriter

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.