1
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
# Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
# The contents of this file are subject to the terms of either the GNU
6
# General Public License Version 2 only ("GPL") or the Common
7
# Development and Distribution License("CDDL") (collectively, the
8
# "License"). You may not use this file except in compliance with the
9
# License. You can obtain a copy of the License at
10
# http://www.netbeans.org/cddl-gplv2.html
11
# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
12
# specific language governing permissions and limitations under the
13
# License. When distributing the software, include this License Header
14
# Notice in each file and include the License file at
15
# nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
16
# particular file as subject to the "Classpath" exception as provided
17
# by Sun in the GPL Version 2 section of the License file that
18
# accompanied this code. If applicable, add the following below the
19
# License Header, with the fields enclosed by brackets [] replaced by
20
# your own identifying information:
21
# "Portions Copyrighted [year] [name of copyright owner]"
25
# The Original Software is NetBeans. The Initial Developer of the Original
26
# Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
27
# Microsystems, Inc. All Rights Reserved.
29
# If you wish your version of this file to be governed by only the CDDL
30
# or only the GPL Version 2, indicate your decision by adding
31
# "[Contributor] elects to include this software in this distribution
32
# under the [CDDL or GPL Version 2] license." If you do not indicate a
33
# single choice of license, a recipient has the option to distribute
34
# your version of this file under either the CDDL, the GPL Version 2 or
35
# to extend the choice of license to its licensees as provided above.
36
# However, if you add GPL Version 2 code and therefore, elected the GPL
37
# Version 2 license, then the option applies only if the new code is
38
# made subject to such option by the copyright holder.
42
########### tokens #############################################################
45
process:org.netbeans.modules.languages.html.HTML.process;
49
TOKEN:php_comment:( "/*" - "*/" )
50
TOKEN:php_line_comment:( ("#"|"//") [^ "\n" "\r"]* )
110
TOKEN:php_builtin_function: (
121
TOKEN:php_include_keyword: (
128
TOKEN:php_type_cast: (
129
( "(" [" " "\t"]* "array" [" " "\t"]* ")" ) |
130
( "(" [" " "\t"]* "bool" [" " "\t"]* ")" ) |
131
( "(" [" " "\t"]* "boolean" [" " "\t"]* ")" ) |
132
( "(" [" " "\t"]* "float" [" " "\t"]* ")" ) |
133
( "(" [" " "\t"]* "int" [" " "\t"]* ")" ) |
134
( "(" [" " "\t"]* "integer" [" " "\t"]* ")" ) |
135
( "(" [" " "\t"]* "real" [" " "\t"]* ")" ) |
136
( "(" [" " "\t"]* "object" [" " "\t"]* ")" ) |
137
( "(" [" " "\t"]* "string" [" " "\t"]* ")" )
140
TOKEN:php_operator: (
141
"=" | "+=" | "-=" | "*=" | "/=" | ".=" | "%=" | "&=" | "|=" | "^=" | "~=" | "<<=" | ">>=" |
142
"==" | "!=" | "===" | "!==" | "<>" | ">" | "<" | ">=" | "<=" |
143
"<<" | ">>" | "++" | "--" |
144
"&&" | "||" | "->" | "=>" | "::" |
145
"?" | ":" | "*" | "/" | "-" | "+" | "." | "," |
146
"(" | ")" | "[" | "]" | "!" | "@" | "%" | "^" | "&" |
150
TOKEN:php_separator: ( [";" "{" "}"] )
152
TOKEN:php_string:( "\"" [^ "\"" "\n" "\r"]* "\"" )
153
TOKEN:php_string: ( "\'" [^ "\'" "\n" "\r"]* "\'" )
154
TOKEN:php_string: ("`" [^ "`" "\n" "\r"]* "`" )
155
TOKEN:php_number:( ["0" - "9"] ["0" - "9" "."]* )
156
TOKEN:php_integer:( ["0" - "9"] ["0" - "9"]* )
157
TOKEN:php_whitespace:( [" " "\t" "\n" "\r"]+ )
159
"$" ["a"-"z" "A"-"Z" "_"]
160
["a"-"z" "A"-"Z" "0"-"9" "_"]*
162
TOKEN:php_identifier:(
163
["a"-"z" "A"-"Z" "_"]
164
["a"-"z" "A"-"Z" "0"-"9" "_"]*
167
TOKEN:php_delimiter: ( "?>" | "%>" ):<DEFAULT>
169
########### grammar ############################################################
173
SKIP:php_line_comment
175
S = ( SourceElement ) +;
177
SourceElement = Statement;
179
Statement = Block | BreakStatement | ClassDefinition | ContinueStatement | DoStatement |
180
EchoStatement | EmptyStatement | ExpressionStatement | ForEachStatement | ForStatement |
181
FunctionDefinition | GlobalStatement | IfStatement | InterfaceDefinition |
182
ReturnStatement | SwitchStatement | StaticStatement | WhileStatement;
184
Block = "{" StatementList "}";
185
StatementList = ( Statement )*;
187
BreakStatement = "break" [ <php_integer> ] ";";
189
ContinueStatement = "continue" [ <php_integer> ] ";";
191
DoStatement = "do" Statement WhileCommon ";";
193
EchoStatement = ("echo" | "print") EchoArguments ";";
194
EchoArguments = ( "(" [ Expression ] ")" ) | [ Expression ( "," Expression )* ];
196
EmptyStatement = ";";
198
ExpressionStatement = Expression ";";
200
ForEachStatement = ForeachCommon ( ForeachStatementCurly | ForeachStatementColon );
201
ForeachStatementCurly = Statement;
202
ForeachStatementColon = ":" StatementList "endforeach" ";";
203
ForeachCommon = "foreach" "(" Expression "as" <php_variable> [ "=>" <php_variable> ] ")";
205
ForStatement = ForCommon ( ForStatementCurly | ForStatementColon );
206
ForCommon = "for" "(" Expression ";" Expression ";" Expression ")";
207
ForStatementCurly = Statement;
208
ForStatementColon = ":" StatementList "endfor" ";";
210
GlobalStatement = "global" <php_variable> ( "," <php_variable> )* ";";
212
IfStatement = IfCommon ( IfStatementCurly | IfStatementColon );
213
IfCommon = "if" "(" Expression ")";
214
IfStatementCurly = Statement ( "elsif" "(" Expression ")" Statement )* [ "else" Statement ];
215
IfStatementColon = ":" StatementList
216
( "elsif" "(" Expression ")" ":" StatementList )* [ "else" ":" StatementList ] "endif" ";";
218
ReturnStatement = "return" [ Expression ] ";";
220
SwitchStatement = SwitchCommon ( SwitchStatementCurly | SwitchStatementColon );
221
SwitchCommon = "switch" "(" Expression ")";
222
SwitchStatementCurly = "{" ( CaseClause )* [ DefaultClause ] ( CaseClause )* "}";
223
CaseClause = "case" Expression ":" StatementList;
224
DefaultClause = "default" ":" StatementList;
225
SwitchStatementColon = ":" ( CaseClause )* [ DefaultClause ] ( CaseClause )* "endswitch" ";";
227
StaticStatement = "static" StaticVariable "=" Expression ";";
228
StaticVariable = <php_variable>;
230
WhileStatement = WhileCommon ( WhileStatementCurly | WhileStatementColon );
231
WhileCommon = "while" "(" Expression ")";
232
WhileStatementCurly = Statement;
233
WhileStatementColon = ":" StatementList "endwhile" ";";
235
Expression = LogicalORExpression | DefineExpression;
236
LogicalORExpression = LogicalXORExpression ( "or" LogicalXORExpression )*;
237
LogicalXORExpression = LogicalANDExpression ( "xor" LogicalANDExpression )*;
238
LogicalANDExpression = AssignmentExpression ( "and" AssignmentExpression )*;
239
AssignmentExpression = ConditionalExpression ( AssignmentOperator ConditionalExpression )*;
240
AssignmentOperator = "=" | "+=" | "-=" | "*=" | "/=" | ".=" | "%=" | "&=" | "|=" | "^=" | "~=" | "<<=" | ">>=";
241
ConditionalExpression = LogicalORORExpression [ "?" LogicalORORExpression ":" LogicalORORExpression ];
242
LogicalORORExpression = LogicalANDANDExpression ( "||" LogicalANDANDExpression )*;
243
LogicalANDANDExpression = BitwiseORExpression ( "&&" BitwiseORExpression )*;
244
BitwiseORExpression = BitwiseXORExpression ( "|" BitwiseXORExpression )*;
245
BitwiseXORExpression = BitwiseANDExpression ( "^" BitwiseANDExpression )*;
246
BitwiseANDExpression = EqualityExpression ( "&" EqualityExpression )*;
247
EqualityExpression = RelationalExpression [ EqualityOperator RelationalExpression ];
248
EqualityOperator = "==" | "!=" | "<>" | "===" | "!==";
249
RelationalExpression = BitShiftExpression [ RelationalOperator BitShiftExpression ];
250
RelationalOperator = "<" | "<=" | ">" | ">=";
251
BitShiftExpression = AdditiveExpression ( BitShiftOperator AdditiveExpression )*;
252
BitShiftOperator = "<<" | ">>";
253
AdditiveExpression = MultiplicativeExpression ( AdditiveOperator MultiplicativeExpression )*;
254
AdditiveOperator = "+" | "-" | ".";
255
MultiplicativeExpression = PostfixExpression ( MultiplicativeOperator PostfixExpression )*;
256
MultiplicativeOperator = "*" | "/" | "%";
257
PostfixExpression = UnaryExpression [ "++" | "--" ];
258
UnaryExpression = LeftHandSideExpression | ( UnaryOperator UnaryExpression );
259
UnaryOperator = "!" | "~" | "-" | "++" | "--" | "@" | <php_type_cast>;
260
LeftHandSideExpression = CallExpression | NewExpression | BuiltInCallExpression |
261
IncludeExpression | ArrayExpression;
262
CallExpression = PrimaryExpression ( MemberOperator | Arguments )*;
263
DefineExpression = "define" "(" ConstantName "," Expression [ "," Expression ] ")";
264
ConstantName = <php_string>;
266
ArrayExpression = "array" "(" [ ArrayElement ( "," ArrayElement )* ] ")";
267
ArrayElement = AssociativeArrayElement | Expression;
268
AssociativeArrayElement = ArrayId "=>" Expression;
269
ArrayId = <php_integer> | <php_string>;
271
BuiltInCallExpression = <php_builtin_function> Arguments;
273
IncludeExpression = <php_include_keyword> IncludeArgument;
274
IncludeArgument = Expression;
276
NewExpression = [ "&" ] "new" <php_identifier> Arguments;
277
MemberOperator = "[" [ Expression ] "]" | ClassMemberOperator;
278
ClassMemberOperator = "->" <php_identifier>;
279
Arguments = "(" [ Expression ( "," Expression )* ] ")";
280
PrimaryExpression = ConstantExpression | ClassStaticPrimaryExpression | <php_variable> |
282
ConstantExpression = <php_number> | <php_string> | "null" | "true" | "false";
283
ClassStaticPrimaryExpression = <php_identifier> [ "::" ( <php_identifier> | <php_variable> )];
285
FunctionDefinition = FunctionDeclarartion FunctionBody;
286
FunctionDeclarartion = "function" [ "&" ] FunctionName "(" FormalParameterList ")";
287
FunctionName = <php_identifier>;
288
FormalParameterList = [ FormalParameter ( "," FormalParameter )*];
289
FormalParameter = [ "&" ] <php_variable> [ "=" ConstantExpression ];
290
FunctionBody = Block;
292
InterfaceDefinition = "interface" ClassName [ "extends" <php_identifier> ( "," <php_identifier> )* ] InterfaceBody;
293
InterfaceBody = "{" [ InterfaceStatementList ] "}";
294
InterfaceStatementList = InterfaceStatement ";" (InterfaceStatement ";")*;
295
InterfaceStatement = FunctionDeclarartion | ClassConstDeclaration;
296
ClassConstDeclaration = "const" <php_identifier> "=" ConstantExpression;
298
ClassDefinition = [ "abstract" ] "class" ClassName [ "extends" <php_identifier> ]
299
[ "implements" <php_identifier> ( "," <php_identifier> )* ] ClassBody;
300
ClassName = <php_identifier>;
301
ClassBody = "{" ( ClassStatement )* "}";
302
ClassStatement = (( ClassVarDeclaration | ClassConstDeclaration | AbstractFunctionDeclarartion) ";" ) |
303
ClassDefinition | FunctionDefinition | InterfaceDefinition;
304
ClassVarDeclaration = ( "var" | "public" | "protected" | "private" ) <php_variable> [ "=" ConstantExpression];
305
AbstractFunctionDeclarartion = "abstract" FunctionDeclarartion;
307
########## Errors ##############################################################
311
message:"LBL_SYNTAX_ERROR";
316
message:"LBL_UNEXPECTED_CHARACTER";
319
BUNDLE "org.netbeans.modules.languages.php.resources.Bundle"
321
########### code folding #######################################################
324
expand_type_action_name:"Expand Classes";
325
collapse_type_action_name:"Collapse Classes";
328
expand_type_action_name:"Expand Methods";
329
collapse_type_action_name:"Collapse Methods";
331
FOLD:InterfaceBody: {
332
expand_type_action_name:"Expand Classes";
333
collapse_type_action_name:"Collapse Classes";
336
expand_type_action_name:"Expand Comments";
337
collapse_type_action_name:"Collapse Comments";
339
FOLD:php_line_comment: {
340
expand_type_action_name:"Expand Comments";
341
collapse_type_action_name:"Collapse Comments";
344
########### navigator ##########################################################
346
NAVIGATOR:FunctionDeclarartion: {
347
display_name: org.netbeans.modules.languages.php.Php.functionName;
348
icon: "org/netbeans/modules/languages/resources/method.gif";
352
# NAVIGATOR:VariableDeclaration: {
353
# display_name: "$php_identifier$";
354
# tooltip: "$js_identifier$ $Initializer$";
355
# icon: "/org/netbeans/modules/languages/resources/variable.gif";
358
NAVIGATOR:ClassDefinition: {
359
display_name: org.netbeans.modules.languages.php.Php.className;
360
icon: "org/netbeans/modules/languages/resources/class.gif";
364
NAVIGATOR:DefineExpression: {
365
display_name: org.netbeans.modules.languages.php.Php.constantName;
366
icon: "org/netbeans/modules/languages/php/resources/constant.gif";
371
NAVIGATOR:InterfaceDefinition: {
372
display_name: org.netbeans.modules.languages.php.PhpView.className;
373
icon: "org/netbeans/modules/languages/resources/class.gif";
376
########### colors #############################################################
379
color_name: "element";
380
default_coloring: "keyword";
383
color_name: "element";
384
default_coloring: "keyword";
387
COLOR:attribute_value: {
388
default_coloring: "string";
390
COLOR:line_comment: {
391
default_coloring: "comment";
393
COLOR:php_variable: {
394
foreground_color: "0x098618";
396
COLOR:ClassMemberOperator: {
397
color_name: "php_variable";
398
foreground_color: "0x0dc223";
401
COLOR:php_separator: {
402
color_name: "php_operator";
405
COLOR:php_builtin_function: {
406
default_coloring: "keyword";
409
COLOR:php_include_keyword: {
410
default_coloring: "keyword";
413
COLOR:php_type_cast: {
414
default_coloring: "keyword";
426
INDENT "\\s*(((if|while)\\s*\\(|else\\s*|else\\s+if\\s*\\(|for\\s*\\(.*\\))[^{;]*)"
428
#STORE:php_identifier: {
430
# name:"$PropertyName$";