1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.github.maven_nar.cpptasks.borland;
21
22 import java.io.IOException;
23 import java.io.Reader;
24 import java.util.Vector;
25
26 import com.github.maven_nar.cpptasks.parser.AbstractParser;
27 import com.github.maven_nar.cpptasks.parser.AbstractParserState;
28 import com.github.maven_nar.cpptasks.parser.LetterState;
29 import com.github.maven_nar.cpptasks.parser.WhitespaceOrLetterState;
30
31
32
33
34
35
36 public final class BorlandCfgParser extends AbstractParser {
37 private final AbstractParserState newLineState;
38 private final Vector<String> path = new Vector<>();
39
40
41
42
43
44 public BorlandCfgParser(final char switchChar) {
45
46
47
48
49
50 final AbstractParserState quote = new CfgFilenameState(this, new char[] {
51 '"'
52 });
53
54
55
56 final AbstractParserState unquote = new CfgFilenameState(this, new char[] {
57 ' ', '\n', '\r'
58 });
59 final AbstractParserState quoteBranch = new QuoteBranchState(this, quote, unquote);
60 final AbstractParserState toNextSwitch = new ConsumeToSpaceOrNewLine(this);
61 final AbstractParserState switchState = new LetterState(this, switchChar, quoteBranch, toNextSwitch);
62 this.newLineState = new WhitespaceOrLetterState(this, '-', switchState);
63 }
64
65 @Override
66 public void addFilename(final String include) {
67 this.path.addElement(include);
68 }
69
70 @Override
71 public AbstractParserState getNewLineState() {
72 return this.newLineState;
73 }
74
75 public String[] parsePath(final Reader reader) throws IOException {
76 this.path.setSize(0);
77 super.parse(reader);
78 final String[] retval = new String[this.path.size()];
79 this.path.copyInto(retval);
80 return retval;
81 }
82 }