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