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.parser;
21
22 import java.io.IOException;
23 import java.io.Reader;
24 import java.util.Vector;
25
26
27
28
29
30
31
32 public final class CParser extends AbstractParser implements Parser {
33 private final Vector<String> includes = new Vector<>();
34 private final AbstractParserState newLineState;
35
36
37
38
39
40 public CParser() {
41 final AbstractParserState quote = new FilenameState(this, new char[] {
42 '"'
43 });
44 final AbstractParserState bracket = new FilenameState(this, new char[] {
45 '>'
46 });
47 final AbstractParserState postE = new PostE(this, bracket, quote);
48
49
50
51 final AbstractParserState e = new LetterState(this, 'e', postE, null);
52 final AbstractParserState d = new LetterState(this, 'd', e, null);
53 final AbstractParserState u = new LetterState(this, 'u', d, null);
54 final AbstractParserState l = new LetterState(this, 'l', u, null);
55 final AbstractParserState c = new LetterState(this, 'c', l, null);
56 final AbstractParserState n = new LetterState(this, 'n', c, null);
57
58
59
60 final AbstractParserState t = new LetterState(this, 't', postE, null);
61 final AbstractParserState r = new LetterState(this, 'r', t, null);
62 final AbstractParserState o = new LetterState(this, 'o', r, null);
63 final AbstractParserState p = new LetterState(this, 'p', o, null);
64 final AbstractParserState m = new LetterState(this, 'm', p, null);
65
66
67
68 final AbstractParserState n_m = new BranchState(this, new char[] {
69 'n', 'm'
70 }, new AbstractParserState[] {
71 n, m
72 }, null);
73 final AbstractParserState i = new WhitespaceOrLetterState(this, 'i', n_m);
74 this.newLineState = new WhitespaceOrLetterState(this, '#', i);
75 }
76
77 @Override
78 public void addFilename(final String include) {
79 this.includes.addElement(include);
80 }
81
82 @Override
83 public String[] getIncludes() {
84 final String[] retval = new String[this.includes.size()];
85 this.includes.copyInto(retval);
86 return retval;
87 }
88
89 @Override
90 public AbstractParserState getNewLineState() {
91 return this.newLineState;
92 }
93
94 @Override
95 public void parse(final Reader reader) throws IOException {
96 this.includes.setSize(0);
97 super.parse(reader);
98 }
99 }