more
[cdsspec-compiler.git] / src / edu / uci / eecs / specCompiler / specExtraction / ParserUtils.java
index 61d0da7..201bb8c 100644 (file)
@@ -1,10 +1,14 @@
 package edu.uci.eecs.specCompiler.specExtraction;
 
 package edu.uci.eecs.specCompiler.specExtraction;
 
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
 import java.util.ArrayList;
 
 import java.util.ArrayList;
 
-import edu.uci.eecs.specCompiler.codeGenerator.SemanticsChecker;
-import edu.uci.eecs.specCompiler.grammerParser.ParseException;
-import edu.uci.eecs.specCompiler.grammerParser.SpecParser;
+import edu.uci.eecs.specCompiler.codeGenerator.Environment;
+import edu.uci.eecs.specCompiler.grammerParser.utilParser.ParseException;
+import edu.uci.eecs.specCompiler.grammerParser.utilParser.UtilParser;
 
 public class ParserUtils {
        public static String trimSpace(String line) {
 
 public class ParserUtils {
        public static String trimSpace(String line) {
@@ -42,16 +46,42 @@ public class ParserUtils {
 
        public static String getTemplateStr(String templateLine) {
                String templateStr = null;
 
        public static String getTemplateStr(String templateLine) {
                String templateStr = null;
+               ArrayList<VariableDeclaration> templateArgs;
                try {
                try {
-                       ArrayList<String> args = SpecParser.getTemplateArg(templateLine);
-                       templateStr = "<" + args.get(1);
-                       for (int i = 1; i < args.size() / 2; i++) {
-                               templateStr = templateStr + ", " + args.get(i * 2 + 1);
+                       templateArgs = UtilParser.getTemplateArg(templateLine);
+                       templateStr = "<" + templateArgs.get(0).name;
+                       for (int i = 1; i < templateArgs.size(); i++) {
+                               templateStr = templateStr + ", " + templateArgs.get(i).name;
                        }
                        templateStr = templateStr + ">";
                } catch (ParseException e) {
                        e.printStackTrace();
                }
                        }
                        templateStr = templateStr + ">";
                } catch (ParseException e) {
                        e.printStackTrace();
                }
+
                return templateStr;
        }
                return templateStr;
        }
+
+       public static void write2File(File file, ArrayList<String> content) {
+               String newFileName = Environment.GENERATED_FILE_DIR + "/"
+                               + file.getParentFile().getName() + "/" + file.getName();
+
+               File newFile = new File(newFileName);
+               newFile.getParentFile().mkdirs();
+               if (!newFile.exists()) {
+                       try {
+                               newFile.createNewFile();
+                       } catch (IOException e) {
+                               e.printStackTrace();
+                       }
+               }
+               try {
+                       BufferedWriter bw = new BufferedWriter(new FileWriter(newFile));
+                       for (int i = 0; i < content.size(); i++) {
+                               bw.write(content.get(i) + "\n");
+                       }
+                       bw.flush();
+               } catch (IOException e) {
+                       e.printStackTrace();
+               }
+       }
 }
 }