remove obsolete ref modifier and callback keyword
[vala-lang.git] / vala / scanner.l
blobbff13c341329f353794f68e6df78614e2522b0f2
1 /* scanner.l
2  *
3  * Copyright (C) 2006-2007  Jürg Billeter, Raffaele Sandrini
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
18  *
19  * Author:
20  *      Jürg Billeter <j@bitron.ch>
21  *      Raffaele Sandrini <rasa@gmx.ch>
22  */
25 #include "vala.h"
26 #include "parser.h"
28 #define YY_DECL int yylex (YYSTYPE *yylval_param, YYLTYPE *yylloc_param, ValaParser *parser)
30 #define uploc   { yylloc->first_column = yylloc->last_column + 1; yylloc->last_column += yyleng; }
32 static gboolean file_comment = FALSE;
35 %option yylineno
36 %option bison-bridge
37 %option bison-locations
38 %option noyywrap
39 %option nounput
41 %x IN_COMMENT
43 space                           [ \t\n]*
44 ident                           [[:alnum:]_]+
45 decimal_integer_literal         (0|[1-9][[:digit:]]*)
46 real_literal                    [[:digit:]]+"."[[:digit:]]*{real_suffix}?
47 hex_digit                       [[:digit:]A-fa-f]
48 octal_digit                     [0-7]
49 octal_integer_literal           0{octal_digit}+
50 hexadecimal_integer_literal     0x{hex_digit}+
51 integer_suffix                  L|LL|U|UL|ULL
52 real_suffix                     F
53 single_character                [^\'\\]
54 single_string_literal_character [^\"\\]
55 simple_escape_sequence          \\[\'\"\?\\abfnrtv]
56 hexadecimal_escape_sequence     \\x{hex_digit}{hex_digit}?{hex_digit}?{hex_digit}?
57 character                       ({single_character}|{simple_escape_sequence})
58 string_literal_character        ({single_string_literal_character}|{simple_escape_sequence})
59 character_literal               \'{character}+\'
60 string_literal                  \"{string_literal_character}*\"
61 integer_literal                 ({decimal_integer_literal}|{hexadecimal_integer_literal}|{octal_integer_literal}){integer_suffix}?
62 literal                         ({integer_literal}|{real_literal}|{character_literal}|{string_literal})
66 "/*"                            { uploc; file_comment = (yylineno == 1); BEGIN (IN_COMMENT); }
67 <IN_COMMENT>"*/"                { uploc; BEGIN (INITIAL); yytext[yyleng - 2] = '\0'; vala_parser_push_comment (parser, yytext, file_comment); }
68 <IN_COMMENT>[^*\n]+             { uploc; yymore (); }
69 <IN_COMMENT>"*"                 { uploc; yymore (); }
70 <IN_COMMENT>\n                  { yylloc->first_line = yylloc->last_line = yylineno; yylloc->first_column = 1; yylloc->last_column = 0; yymore (); }
72 "//".*                          { uploc; vala_parser_push_comment (parser, g_strdup (yytext + 2), FALSE); }
74 "{"             { uploc; return OPEN_BRACE; }
75 "}"             { uploc; return CLOSE_BRACE; }
76 "("({space}"weak")?{space}{ident}("."{ident})?("<"({ident}".")?{ident}(","({ident}".")?{ident})*">")?("["{space}"]")*{space}")"{space}("("|{ident}|{literal})   { yyless (1); uploc; return OPEN_CAST_PARENS; }
77 "("             { uploc; return OPEN_PARENS; }
78 ")"             { uploc; return CLOSE_PARENS; }
79 "[]"            { uploc; return BRACKET_PAIR; }
80 "["             { uploc; return OPEN_BRACKET; }
81 "]"             { uploc; return CLOSE_BRACKET; }
82 "..."           { uploc; return ELLIPSIS; }
83 "."             { uploc; return DOT; }
84 ":"             { uploc; return COLON; }
85 ","             { uploc; return COMMA; }
86 ";"             { uploc; return SEMICOLON; }
87 "#"             { uploc; return HASH; }
88 "?"             { uploc; return INTERR; }
90 "|="            { uploc; return ASSIGN_BITWISE_OR; }
91 "&="            { uploc; return ASSIGN_BITWISE_AND; }
92 "^="            { uploc; return ASSIGN_BITWISE_XOR; }
93 "+="            { uploc; return ASSIGN_ADD; }
94 "-="            { uploc; return ASSIGN_SUB; }
95 "*="            { uploc; return ASSIGN_MUL; }
96 "/="            { uploc; return ASSIGN_DIV; }
97 "%="            { uploc; return ASSIGN_PERCENT; }
98 "<<="           { uploc; return ASSIGN_SHIFT_LEFT; }
99 ">>="           { uploc; return ASSIGN_SHIFT_RIGHT; }
101 "++"            { uploc; return OP_INC; }
102 "--"            { uploc; return OP_DEC; }
103 "=="            { uploc; return OP_EQ; }
104 "!="            { uploc; return OP_NE; }
105 "<<"            { uploc; return OP_SHIFT_LEFT; }
106 ">>"            { uploc; return OP_SHIFT_RIGHT; }
107 "<="            { uploc; return OP_LE; }
108 ">="            { uploc; return OP_GE; }
109 "=>"            { uploc; return LAMBDA; }
110 "<"(("ref"|"weak")" "+)?({ident}".")?{ident}"#"?("[]""#"?)?(","" "*({ident}".")?{ident}"#"?("[]""#"?)?)*">"     { yyless (1); uploc; return GENERIC_LT; }
111 "<"             { uploc; return OP_LT; }
112 ">"             { uploc; return OP_GT; }
113 "!"             { uploc; return OP_NEG; }
114 "||"            { uploc; return OP_OR; }
115 "|"             { uploc; return BITWISE_OR; }
116 "&&"            { uploc; return OP_AND; }
117 "&"             { uploc; return BITWISE_AND; }
118 "^"             { uploc; return CARRET; }
119 "~"             { uploc; return TILDE; }
121 "="             { uploc; return ASSIGN; }
122 "+"             { uploc; return PLUS; }
123 "-"             { uploc; return MINUS; }
124 "*"             { uploc; return STAR; }
125 "/"             { uploc; return DIV; }
126 "%"             { uploc; return PERCENT; }
128 "@"[[:alnum:]_]+        { uploc; yylval->str = g_strdup (yytext + 1); return IDENTIFIER; }
130 "abstract"      { uploc; return ABSTRACT; }
131 "base"          { uploc; return BASE; }
132 "break"         { uploc; return BREAK; }
133 "case"          { uploc; return CASE; }
134 "catch"         { uploc; return CATCH; }
135 "class"         { uploc; return CLASS; }
136 "const"         { uploc; return CONST; }
137 "construct"     { uploc; return CONSTRUCT; }
138 "continue"      { uploc; return CONTINUE; }
139 "default"       { uploc; return DEFAULT; }
140 "delegate"      { uploc; return DELEGATE; }
141 "do"            { uploc; return DO; }
142 "else"          { uploc; return ELSE; }
143 "enum"          { uploc; return ENUM; }
144 "false"         { uploc; return VALA_FALSE; }
145 "finally"       { uploc; return FINALLY; }
146 "flags"         { uploc; return FLAGS; }
147 "for"           { uploc; return FOR; }
148 "foreach"       { uploc; return FOREACH; }
149 "get"           { uploc; return GET; }
150 "if"            { uploc; return IF; }
151 "in"            { uploc; return IN; }
152 "interface"     { uploc; return INTERFACE; }
153 "is"            { uploc; return IS; }
154 "lock"          { uploc; return LOCK; }
155 "namespace"     { uploc; return NAMESPACE; }
156 "new"           { uploc; return NEW; }
157 "null"          { uploc; return VALA_NULL; }
158 "out"           { uploc; return OUT; }
159 "override"      { uploc; return OVERRIDE; }
160 "private"       { uploc; return PRIVATE; }
161 "protected"     { uploc; return PROTECTED; }
162 "public"        { uploc; return PUBLIC; }
163 "ref"           { uploc; return REF; }
164 "set"           { uploc; return SET; }
165 "signal"        { uploc; return SIGNAL; }
166 "sizeof"        { uploc; return SIZEOF; }
167 "static"        { uploc; return STATIC; }
168 "struct"        { uploc; return STRUCT; }
169 "switch"        { uploc; return SWITCH; }
170 "return"        { uploc; return RETURN; }
171 "this"          { uploc; return THIS; }
172 "throw"         { uploc; return THROW; }
173 "throws"        { uploc; return THROWS; }
174 "true"          { uploc; return VALA_TRUE; }
175 "try"           { uploc; return TRY; }
176 "typeof"        { uploc; return TYPEOF; }
177 "using"         { uploc; return USING; }
178 "var"           { uploc; return VAR; }
179 "virtual"       { uploc; return VIRTUAL; }
180 "weak"          { uploc; return WEAK; }
181 "while"         { uploc; return WHILE; }
183 {real_literal}          { uploc; yylval->str = g_strdup (yytext); return REAL_LITERAL; }
184 {integer_literal}       { uploc; yylval->str = g_strdup (yytext); return INTEGER_LITERAL; }
186 {character_literal}     { uploc; yylval->str = g_strdup (yytext); return CHARACTER_LITERAL; }
187 {string_literal}        { uploc; yylval->str = g_strdup (yytext); return STRING_LITERAL; }
189 {ident}                 { uploc; yylval->str = g_strdup (yytext); return IDENTIFIER; }
191 [ \t]+          { uploc; /* eat up whitespace */ }
192 [\n]+           { yylloc->first_line = yylloc->last_line = yylineno; yylloc->first_column = 1; yylloc->last_column = 0; }
194 .       { uploc; fprintf (stderr, "%d: syntax error: unexpected character ´%s´\n", yylloc->first_line, yytext); }