1 | header |
---|
2 | { |
---|
3 | using System.Globalization; |
---|
4 | } |
---|
5 | |
---|
6 | options |
---|
7 | { |
---|
8 | language = "CSharp"; |
---|
9 | } |
---|
10 | |
---|
11 | /* |
---|
12 | [The "BSD licence"] |
---|
13 | Copyright (c) 2002-2005 Kunle Odutola |
---|
14 | All rights reserved. |
---|
15 | |
---|
16 | Redistribution and use in source and binary forms, with or without |
---|
17 | modification, are permitted provided that the following conditions |
---|
18 | are met: |
---|
19 | 1. Redistributions of source code must retain the above copyright |
---|
20 | notice, this list of conditions and the following disclaimer. |
---|
21 | 2. Redistributions in binary form must reproduce the above copyright |
---|
22 | notice, this list of conditions and the following disclaimer in the |
---|
23 | documentation and/or other materials provided with the distribution. |
---|
24 | 3. The name of the author may not be used to endorse or promote products |
---|
25 | derived from this software without specific prior written permission. |
---|
26 | |
---|
27 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
---|
28 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
---|
29 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
---|
30 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
---|
31 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
---|
32 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
---|
33 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
---|
34 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
35 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
---|
36 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
37 | |
---|
38 | |
---|
39 | /// <summary> |
---|
40 | /// The basic building block of C# Preprocessors and Lexers. |
---|
41 | /// </summary> |
---|
42 | /// |
---|
43 | /// <remarks> |
---|
44 | /// <para> |
---|
45 | /// The Lexer defined below is effectively an abstract base class that collects together a |
---|
46 | /// number of rules that are useful to all Preprocessors and Lexers for the C# language. |
---|
47 | /// </para> |
---|
48 | /// |
---|
49 | /// <para> |
---|
50 | /// History |
---|
51 | /// </para> |
---|
52 | /// |
---|
53 | /// <para> |
---|
54 | /// 26-Jan-2003 kunle Derived this Lexer from the original combined grammar <br/> |
---|
55 | /// </para> |
---|
56 | /// |
---|
57 | /// </remarks> |
---|
58 | |
---|
59 | |
---|
60 | */ |
---|
61 | class CSharpLexerBase extends UnicodeLexerBase; |
---|
62 | |
---|
63 | options |
---|
64 | { |
---|
65 | importVocab = UnicodeLexerBase; |
---|
66 | exportVocab = CSharpLexerBase; |
---|
67 | charVocabulary = '\u0000'..'\uFFFE'; // All UNICODE characters except \uFFFF [and \u0000 to \u0002 used by ANTLR] |
---|
68 | k = 2; |
---|
69 | testLiterals = false; // don't automatically test for literals |
---|
70 | defaultErrorHandler = false; |
---|
71 | } |
---|
72 | |
---|
73 | tokens |
---|
74 | { |
---|
75 | TRUE = "true"; |
---|
76 | FALSE = "false"; |
---|
77 | DEFAULT = "default"; |
---|
78 | |
---|
79 | PP_DEFINE; |
---|
80 | PP_UNDEFINE; |
---|
81 | PP_COND_IF; |
---|
82 | PP_COND_ELIF; |
---|
83 | PP_COND_ELSE; |
---|
84 | PP_COND_ENDIF; |
---|
85 | PP_LINE; |
---|
86 | PP_ERROR; |
---|
87 | PP_WARNING; |
---|
88 | PP_REGION; |
---|
89 | PP_ENDREGION; |
---|
90 | |
---|
91 | PP_FILENAME; |
---|
92 | PP_IDENT; |
---|
93 | PP_STRING; |
---|
94 | PP_NUMBER; |
---|
95 | |
---|
96 | WHITESPACE; |
---|
97 | } |
---|
98 | |
---|
99 | //====================================== |
---|
100 | // Start of Lexer Rules |
---|
101 | //====================================== |
---|
102 | |
---|
103 | // The following group of rules are shared by C# Preprocessors and Lexers |
---|
104 | QUOTE : '"' ; |
---|
105 | OPEN_PAREN : '(' ; |
---|
106 | CLOSE_PAREN : ')' ; |
---|
107 | LOG_NOT : '!' ; |
---|
108 | LOG_AND : "&&" ; |
---|
109 | LOG_OR : "||" ; |
---|
110 | EQUAL : "==" ; |
---|
111 | NOT_EQUAL : "!=" ; |
---|
112 | |
---|
113 | |
---|
114 | //====================================== |
---|
115 | // Section A.1.3 Comments |
---|
116 | // |
---|
117 | SL_COMMENT |
---|
118 | : "//" ( NOT_NEWLINE )* (NEWLINE)? |
---|
119 | ; |
---|
120 | |
---|
121 | //====================================== |
---|
122 | // Section A.1.1 Line terminators |
---|
123 | // |
---|
124 | //protected |
---|
125 | NEWLINE |
---|
126 | : ( '\r' // MacOS-style newline |
---|
127 | ( options { generateAmbigWarnings=false; } |
---|
128 | : '\n' // DOS/Windows style newline |
---|
129 | )? |
---|
130 | | '\n' // UNIX-style newline |
---|
131 | | '\u2028' // UNICODE line separator |
---|
132 | | '\u2029' // UNICODE paragraph separator |
---|
133 | ) |
---|
134 | { newline(); } |
---|
135 | ; |
---|
136 | |
---|
137 | protected NOT_NEWLINE |
---|
138 | : ~( '\r' | '\n' | '\u2028' | '\u2029' ) |
---|
139 | ; |
---|
140 | |
---|
141 | |
---|
142 | //====================================== |
---|
143 | // Section A.1.2 White space |
---|
144 | // |
---|
145 | |
---|
146 | protected NON_NEWLINE_WHITESPACE |
---|
147 | : '\t' // horiz_tab |
---|
148 | // | ' ' // space -- commented out because UNICODE_CLASS_Zs contains space too |
---|
149 | | '\f' // form_feed |
---|
150 | | '\u000B' // '\u000B' == '\v' == vert_tab |
---|
151 | | UNICODE_CLASS_Zs |
---|
152 | ; |
---|
153 | |
---|
154 | |
---|
155 | //====================================== |
---|
156 | // Section A.1.5 Unicode character escape sequences |
---|
157 | // |
---|
158 | protected UNICODE_ESCAPE_SEQUENCE |
---|
159 | : '\\' |
---|
160 | ( 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT |
---|
161 | | 'U' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT |
---|
162 | ) |
---|
163 | ; |
---|
164 | |
---|
165 | |
---|
166 | protected DECIMAL_DIGIT |
---|
167 | : ('0'..'9') |
---|
168 | ; |
---|
169 | |
---|
170 | protected HEX_DIGIT |
---|
171 | : ('0'..'9'|'A'..'F'|'a'..'f') |
---|
172 | ; |
---|
173 | |
---|
174 | |
---|
175 | protected LETTER_CHARACTER |
---|
176 | : UNICODE_CLASS_Lu |
---|
177 | | UNICODE_CLASS_Ll |
---|
178 | | UNICODE_CLASS_Lt |
---|
179 | | UNICODE_CLASS_Lm |
---|
180 | | UNICODE_CLASS_Lo |
---|
181 | | UNICODE_CLASS_Nl |
---|
182 | ; |
---|
183 | |
---|
184 | protected DECIMAL_DIGIT_CHARACTER |
---|
185 | : UNICODE_CLASS_Nd |
---|
186 | ; |
---|
187 | |
---|
188 | protected CONNECTING_CHARACTER |
---|
189 | : UNICODE_CLASS_Pc |
---|
190 | ; |
---|
191 | |
---|
192 | protected COMBINING_CHARACTER |
---|
193 | : UNICODE_CLASS_Mn |
---|
194 | | UNICODE_CLASS_Mc |
---|
195 | ; |
---|
196 | |
---|
197 | protected FORMATTING_CHARACTER |
---|
198 | : UNICODE_CLASS_Cf |
---|
199 | ; |
---|
200 | |
---|