import java.io.LineNumberReader;
import java.util.ArrayList;
+import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils.Text;
+
/**
* <p>
* This class represents the specification extractor of the specification. The
*/
public class SpecExtractor {
private ArrayList<SpecConstruct> _constructs;
- private StringBuilder _extractedSpecText;
-
- private enum State {
- Neutral, HeadParsed, BeginParsed, EndParsed
- }
-
- private State _curState;
-
private StringBuilder _potentialConstruct;
- private int _startLine, _endLine;
+ private int _beginLine, _endLine;
SpecExtractor() {
_constructs = new ArrayList<SpecConstruct>();
- _extractedSpecText = new StringBuilder();
- _curState = State.Neutral;
_potentialConstruct = new StringBuilder();
}
* </p>
* @param files
*/
- private void extract(File[] files) {
+ public void extract(File[] files) {
for (int i = 0; i < files.length; i++)
extract(files[i]);
}
- private void extract(File file) {
+ public void extract(File file) {
try {
LineNumberReader reader = new LineNumberReader(new FileReader(file));
- String prevLine = "", curLine;
- ArrayList<String> text;
+ String prevLine = "", curLine, trimedLine;
+ StringBuilder specText = new StringBuilder();
+ boolean _foundHead = false;
+ int specIndex = 0;
while ((curLine = reader.readLine()) != null) {
-
+ if (prevLine.endsWith("\\"))
+ continue;
+ trimedLine = trimSpace(curLine);
+ if (!_foundHead) {
+ if (trimedLine.startsWith("/**")) {
+ _beginLine = reader.getLineNumber();
+ _foundHead = true;
+ if (trimedLine.endsWith("*/")) {
+ _endLine = reader.getLineNumber();
+ _foundHead = false;
+
+ System.out.println("Spec<" + specIndex + "> Begin: "
+ + _beginLine + " End: " + _endLine);
+ System.out.println(curLine);
+ }
+ }
+ } else {
+ if (trimedLine.endsWith("*/")) {
+ _endLine = reader.getLineNumber();
+ _foundHead = false;
+ specText.append("\n");
+ specText.append(curLine);
+
+ System.out.println("Spec<" + specIndex + "> Begin: "
+ + _beginLine + " End: " + _endLine);
+ System.out.println(curLine);
+
+ specText = new StringBuilder();
+ } else {
+
+ }
+ }
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
- private void parseHead(String prevLine, String line) {
- assert (_curState == State.Neutral);
-
- // "\" is the C/C++ line break. If the previous line ends with "\",
- // it may be part of a string literal.
- if (prevLine.endsWith("\\"))
- return;
- String newLine = trimBeginningSpace(line);
-// if (newLine.startsWith("/**") &&
-// (newLine.length() == 3 ||
- }
-
- private void parseBegin(String line) {
-
- }
-
- private void parseEnd(String line) {
-
- }
-
- private void parseTail(String line) {
-
- }
-
- private String trimBeginningSpace(String line) {
- int i;
+ private String trimSpace(String line) {
+ int i, j;
+ char ch;
for (i = 0; i < line.length(); i++) {
- char ch = line.charAt(i);
+ ch = line.charAt(i);
if (ch == ' ' || ch == '\t')
i++;
else
break;
}
- return line.substring(i);
+ for (j = line.length() - 1; j >= 0; j--) {
+ ch = line.charAt(j);
+ if (ch == ' ' || ch == '\t')
+ j--;
+ else
+ break;
+ }
+ if (i > j)
+ return "";
+ else
+ return line.substring(i, j + 1);
+ }
+
+ public static void main(String[] argvs) {
+ SpecExtractor extractor = new SpecExtractor();
+ File file = new File("./grammer/spec1.txt");
+ extractor.extract(file);
}
}