Package fbench.translate

Examples of fbench.translate.ParseResult


          stString = stString.substring(1, stString.length() - 1);
        }*/
       
        stString = FBench.removeHTML(stString);
       
      ParseResult result = null;
        Translator translator = TranslatorSource.getInstance().getTranslator("ST", targetLanguage);
      if(translator != null){
        ParseContext context = new ParseContext(new StringReader(stString), ParseTarget.guardCondition, document);
        result = translator.parse(context);
      }
      else{
        return;
      }
     
      if(result != null && !result.hasErrors()){
        String newCondition = guard + "&(" + result.getSource() + ")";
        elem.setAttribute("Condition", newCondition);
      }
      else{
        String newCondition = guard + "&(" + stString + ")";
        System.err.println(result.getErrors().get(0) + " in " + elem.getNodeName() + ": " + newCondition);
      }
      }
  }
View Full Code Here


   
    private void translateAlgorithms(Element elem){
      if(elem.getNodeName().toLowerCase().equals("algorithm")){
        Element codeNode = (Element)elem.getChildNodes().item(0);
        if(codeNode.getAttribute("Text").length() > 0){
          ParseResult result = null;
         
          String sourceLanguage;
          String nodeName = codeNode.getNodeName();
          if(nodeName.equalsIgnoreCase("Other")){
            sourceLanguage = codeNode.getAttribute("Language");
          }
          else{
            sourceLanguage = nodeName;
          }
         
          String code = codeNode.getAttribute("Text");
          code = FBench.removeHTML(code);
         
          Translator translator = TranslatorSource.getInstance().getTranslator(sourceLanguage, targetLanguage);
          if(translator != null){
            ParseContext context = new ParseContext(new StringReader(code), ParseTarget.algorithm, document);
            result = translator.parse(context);
          }
          else{
            System.out.println("No translator: " +
                sourceLanguage + " to " + targetLanguage + " (" + elem.getAttribute("Name") + ")");
            return;
          }
                   
          if(result != null && !result.hasErrors()){
            elem.removeChild(codeNode);
           
            if(targetLanguage.equalsIgnoreCase("ST")){
              codeNode = document.createElement("ST");
            }
            else if(targetLanguage.equalsIgnoreCase("LD")){
              codeNode = document.createElement("LD");
            }
            else if(targetLanguage.equalsIgnoreCase("FBD")){
              codeNode = document.createElement("FBD");
            }
            else{
              codeNode = document.createElement("Other");
              codeNode.setAttribute("Language", targetLanguage);
            }
           
            String source = result.getSource();
            source = XmlWriter.replaceChars(source);
            codeNode.setAttribute("Text", source);
            elem.appendChild(codeNode);
          }
          else if(result != null){
            System.out.println("\nAlgorithm: " + elem.getAttribute("Name") +
                " (" + codeNode.getNodeName() + ") parse failure.");
            ArrayList<ParseError> errors = result.getErrors();
            for(int i = 0; i < errors.size(); i++){
              System.err.println(errors.get(i).toString());
            }
          }
          else{
View Full Code Here

TOP

Related Classes of fbench.translate.ParseResult

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.