source: trunk/yao/share/antlr-2.7.7/examples/csharp/csharp_v1/CSharpLexerBase.g @ 1

Last change on this file since 1 was 1, checked in by lnalod, 15 years ago

Initial import of YAO sources

File size: 4.6 KB
Line 
1header
2{
3        using System.Globalization;
4}
5
6options
7{
8        language        = "CSharp";     
9}
10
11/*
12[The "BSD licence"]
13Copyright (c) 2002-2005 Kunle Odutola
14All rights reserved.
15
16Redistribution and use in source and binary forms, with or without
17modification, are permitted provided that the following conditions
18are met:
191. Redistributions of source code must retain the above copyright
20notice, this list of conditions and the following disclaimer.
212. Redistributions in binary form must reproduce the above copyright
22notice, this list of conditions and the following disclaimer in the
23documentation and/or other materials provided with the distribution.
243. The name of the author may not be used to endorse or promote products
25derived from this software without specific prior written permission.
26
27THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
28IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
31INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
36THIS 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*/
61class CSharpLexerBase extends UnicodeLexerBase;
62
63options
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
73tokens
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
104QUOTE                   :       '"'             ;
105OPEN_PAREN              :       '('             ;
106CLOSE_PAREN             :       ')'             ;
107LOG_NOT                 :       '!'             ;
108LOG_AND                 :       "&&"    ;
109LOG_OR                  :       "||"    ;
110EQUAL                   :       "=="    ;
111NOT_EQUAL               :       "!="    ;
112
113
114//======================================
115// Section A.1.3 Comments
116//
117SL_COMMENT
118        :       "//" ( NOT_NEWLINE )* (NEWLINE)?
119        ;
120
121//======================================
122// Section A.1.1 Line terminators
123//
124//protected
125NEWLINE
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
137protected NOT_NEWLINE
138        : ~( '\r' | '\n' | '\u2028' | '\u2029'  )
139        ;
140
141
142//======================================
143// Section A.1.2 White space
144//
145
146protected 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//
158protected 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
166protected DECIMAL_DIGIT
167        :       ('0'..'9')
168        ;
169               
170protected HEX_DIGIT
171        :       ('0'..'9'|'A'..'F'|'a'..'f')
172        ;
173
174
175protected 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
184protected DECIMAL_DIGIT_CHARACTER
185        :       UNICODE_CLASS_Nd
186        ;
187       
188protected CONNECTING_CHARACTER
189        :       UNICODE_CLASS_Pc
190        ;
191       
192protected COMBINING_CHARACTER
193        :       UNICODE_CLASS_Mn
194        |       UNICODE_CLASS_Mc
195        ;
196       
197protected FORMATTING_CHARACTER
198        :       UNICODE_CLASS_Cf
199        ;
200       
Note: See TracBrowser for help on using the repository browser.