changes
[cdsspec-compiler.git] / src / edu / uci / eecs / specCompiler / specExtraction / SpecInfoScanner.java
1 package edu.uci.eecs.specCompiler.specExtraction;
2
3 import java.util.HashMap;
4 import java.io.File;
5 import java.io.FileNotFoundException;
6 import java.io.FileReader;
7 import java.io.IOException;
8 import java.io.LineNumberReader;
9
10 import java.util.regex.Pattern;
11 import java.util.regex.Matcher;
12
13 /**
14  * <p>
15  * This class will scan all the input files, extract all the "special comments"
16  * (specifications). It should include information: 1. Beginning and end line of
17  * the specs; 2. The next two lines of code if it is interface constrcut.
18  * </p>
19  * 
20  * @author peizhaoo
21  * 
22  */
23 public class SpecInfoScanner {
24         public final HashMap<File, Construct> constructs;
25
26         public SpecInfoScanner() {
27                 constructs = new HashMap<File, Construct>();
28         }
29
30         /**
31          * <p>
32          * Scan
33          * </p>
34          * 
35          * @param file
36          */
37         private void scanFile(File file) {
38                 try {
39                         FileReader fr = new FileReader(file);
40                         LineNumberReader lnr = new LineNumberReader(fr);
41                         String line = null;
42                         // Info to keep when parsing the Spec
43                         // 0 for default, 1 for potential sepc, 2 for in spec
44                         int state = 0;
45                         Pattern pBegin = Pattern.compile("^[\\s|\\t]*/**"), pEnd = Pattern
46                                         .compile("*/$");
47                         while ((line = lnr.readLine()) != null) {
48                                 Matcher m1 = pBegin.matcher(line);
49                                 if (m1.matches())
50                                         state = 1; // Go to 'potential spec' state
51                                 if (state == 1) {
52                                         
53                                 }
54                         }
55                 } catch (FileNotFoundException e) {
56                         e.printStackTrace();
57                 } catch (IOException e) {
58                         e.printStackTrace();
59                 }
60         }
61
62         public void scanFiles(File[] files) {
63                 for (int i = 0; i < files.length; i++) {
64                         scanFile(files[i]);
65                 }
66         }
67 }