Created
August 8, 2023 23:18
-
-
Save itod/1c58d1ec9088e94d10094e4c6331c537 to your computer and use it in GitHub Desktop.
PHP Syntax Highlighting Grammar for @VintageText
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
file | |
: thing+ | |
; | |
@entryPoint | |
thing | |
: semi | |
| pi_beg | |
| pi_end | |
| func_decl | |
| class_decl | |
| interface_decl | |
| repeat_stmt | |
| include_stmt | |
| keyword | |
| assign_stmt | |
| expr | |
| Any | |
; | |
# EXPRESSION | |
expr | |
: bin_expr (tri_question expr tri_colon expr)? | |
; | |
tri_question ('keyword.control.conditional.php') | |
: Symbol['?'] | |
; | |
tri_colon ('keyword.control.conditional.php') | |
: Symbol[':'] | |
; | |
bin_expr | |
: atom_chain (bin_op atom_chain)* | |
; | |
bin_op ('keyword.operator.php') | |
: Symbol[/\.|&&|=&|\|\||<>|<=|>=|===?|<|>|!==?|\+=|-=|\*=|\/=|\/\/=|%=|&=|\|=|\^=|>>=|<<=|\*=|\+|-|\*\*|\*|\/|\/\/|%|<<|>>|&|\||\^|~/] | |
; | |
neg_atom | |
: unary_op? atom | |
; | |
unary_op | |
: unary_not | |
| unary_plus_plus | |
| unary_minus_minus | |
| unary_minus | |
; | |
unary_not ('keyword.operator.php') | |
: Symbol['!'] | |
; | |
unary_minus ('constant.numeric.php') | |
: Symbol['-'] | |
; | |
unary_plus_plus ('keyword.operator.php') | |
: Symbol['++'] | |
; | |
unary_minus_minus ('keyword.operator.php') | |
: Symbol['--'] | |
; | |
atom | |
: literal | |
| variable | |
| allocation | |
| subExpr | |
| func_call | |
| identifier | |
; | |
subExpr | |
: open_paren expr close_paren | |
; | |
open_paren ('punctuation.definition.expression.begin.php') | |
: Symbol['('] | |
; | |
close_paren ('punctuation.definition.expression.end.php') | |
: Symbol[')'] | |
; | |
literal | |
: string | |
| number | |
| constant | |
| array | |
; | |
allocation | |
: new func_call | |
; | |
new ('keyword.other.new') | |
: Lower['new'] | |
; | |
atom_chain | |
: chain_head (prop_arrow chain_tail)* | |
; | |
chain_head | |
: neg_atom item_access? | |
; | |
chain_tail | |
: (method_call | all_caps | property) item_access? | |
; | |
prop_arrow ('keyword.operator.class') | |
: Symbol['->'] | |
; | |
property ('variable.other.object.property.php') | |
: Word | |
; | |
# ITEM ACCESS | |
item_access | |
: access_beg slice access_end | |
; | |
access_beg ('punctuation.definition.item-access.begin.php') | |
: Symbol['['] | |
; | |
access_end ('punctuation.definition.item-access.end.php') | |
: Symbol[']'] | |
; | |
slice | |
: expr (colon expr?)* | |
; | |
colon ('punctuation.separator.php') | |
: Symbol[':'] | |
; | |
# ASSIGN STMT | |
assign_stmt | |
: {atom_chain assign_op}? atom_chain assign_op expr | |
; | |
assign_op | |
: assign_eq | |
| assign_augmented | |
; | |
assign_eq ('keyword.operator.assignment.php') | |
: Symbol['='] | |
; | |
assign_augmented ('keyword.operator.assignment.augmented.python') | |
: Symbol[/\+=|-=|\*=|\/=|\/\/=|%=|&=|=&|\|=|\^=|>>=|<<=|/] | |
; | |
# REPEAT STMT | |
repeat_stmt | |
: foreach open_paren variable as variable close_paren | |
; | |
foreach ('keyword.control.php') | |
: Lower['foreach'] | |
; | |
as ('keyword.operator.logical.php') | |
: Lower['as'] | |
; | |
# INCLUDE_STMT | |
include_stmt ('meta.include.php') | |
: keyword_include expr | |
; | |
keyword_include ('keyword.control.import.include.php') | |
: Lower['require_once'] | |
| Lower['include_once'] | |
; | |
# FUNC DECL | |
func_decl | |
: func_keyword amp? func_name params func_return? | |
| {func_modifier_list func_keyword? amp? func_name param_open_paren}? func_modifier_list func_keyword? amp? func_name params func_return? | |
; | |
func_modifier_list | |
: func_modifier+ | |
; | |
func_modifier ('storage.modifier.php') | |
: Lower[/public|protected|private|static|final|abstract/] | |
; | |
func_keyword ('storage.type.function.php') | |
: Lower['function'] | |
; | |
amp ('storage.modifier.reference') | |
: Symbol['&'] | |
; | |
func_name ('entity.name.function.php') | |
: Word | |
; | |
params | |
: param_open_paren param_list? param_close_paren | |
; | |
param_open_paren ('punctuation.definition.parameters.begin.php') | |
: Symbol['('] | |
; | |
param_close_paren ('punctuation.definition.parameters.end.php') | |
: Symbol[')'] | |
; | |
param_list ('meta.function.parameters.php') | |
: param (param_comma param)* | |
; | |
param | |
# Type &$foo = bar | |
: {param_type_list? param_name param_eq}? param_type_list? param_name param_eq param_val | |
# Type &$foo || &$foo | |
| param_type_list? param_val | |
; | |
param_type_list | |
: param_type (type_bar param_type)* | |
; | |
param_type ('support.class.php') | |
: question? Word | |
; | |
type_bar ('punctuation.separator.types.php') | |
: Symbol['|'] | |
; | |
param_name ('variable.parameter.function.php') | |
: variable | |
; | |
param_eq ('keyword.operator.assignment.php') | |
: Symbol['='] | |
; | |
param_val | |
: pack_dots? amp? expr | |
; | |
pack_dots ('keyword.operator.pack.php') | |
: Symbol['...'] | |
; | |
param_comma ('punctuation.separator.parameters.php') | |
: Symbol[','] | |
; | |
func_return | |
: return_colon return_type_list | |
; | |
return_type_list | |
: return_type (type_bar return_type)* | |
; | |
return_type ('support.class.php') | |
: question? Word | |
; | |
return_colon ('punctuation.separator.return-type.php') | |
: Symbol[':'] | |
; | |
# CLASS DECL | |
class_decl | |
: class_keyword class_name (extends_keyword inherited_class)? | |
; | |
class_keyword ('storage.type.class.php') | |
: Lower['class'] | |
; | |
class_name ('entity.name.type.class.php') | |
: Word | |
; | |
extends_keyword ('storage.modifier.extends.php') | |
: Lower['extends'] | |
; | |
inherited_class ('entity.other.inherited-class.php') | |
: Word | |
; | |
# INTERFACE DECL | |
interface_decl | |
: interface_keyword interface_name (extends_keyword inherited_class)? | |
; | |
interface_keyword ('storage.type.interface.php') | |
: Lower['interface'] | |
; | |
interface_name ('entity.name.type.interface.php') | |
: Word | |
; | |
# KEYWORD | |
keyword ('keyword.php') | |
: Lower[/as|do|fn|if|or|and|die|for|new|try|use|var|xor|case|each|echo|else|eval|exit|from|goto|list|array|break|catch|class|clone|const|empty|endif|final|isset|match|print|throw|trait|unset|while|yield|yield|elseif|endfor|global|public|return|static|switch|declare|default|extends|finally|foreach|include|private|require|abstract|callable|continue|endwhile|function|readonly|endswitch|insteadof|interface|namespace|protected|enddeclare|endforeach|implements|instanceof|include_once|require_once/] | |
; | |
# FUNCTION CALL | |
func_call | |
: {called_func arg_open_paren}? called_func args | |
; | |
called_func | |
: called_func_lower | called_func_upper | |
; | |
called_func_lower ('meta.function-call.php') | |
: Lower | |
; | |
called_func_upper ('meta.constructor-call.php') | |
: Upper | |
; | |
# METHOD CALL | |
method_call | |
: {called_method arg_open_paren}? called_method args | |
; | |
called_method ('meta.method-call.php') | |
: identifier | |
; | |
# ARGUMENTS | |
arg_open_paren ('punctuation.definition.arguments.begin.php') | |
: Symbol['('] | |
; | |
arg_close_paren ('punctuation.definition.arguments.end.php') | |
: Symbol[')'] | |
; | |
args | |
: arg_open_paren arg_list? arg_close_paren | |
; | |
arg_list ('meta.function-call.arguments.php') | |
: arg (arg_comma arg)* | |
; | |
arg | |
: ({arg_name arg_colon}? arg_name arg_colon)? arg_val | |
; | |
arg_name ('variable.argument.function.php') | |
: Word | |
; | |
arg_colon ('keyword.operator.assignment.php') | |
: Symbol[':'] | |
; | |
arg_val | |
: expr | |
; | |
arg_comma ('punctuation.separator.arguments.php') | |
: Symbol[','] | |
; | |
# LITERALS | |
string ('punctuation.definition.string.begin.php', 'string.quoted.php', 'punctuation.definition.string.end.php') | |
: QuotedString | |
; | |
number ('constant.numeric.php') | |
: Number | |
; | |
constant ('constant.language.php') | |
: Word[/null|true|false/] | |
; | |
@entryPoint | |
array ('meta.structure.array.php') | |
: old_array | |
| new_array | |
; | |
old_array | |
: array_keyword open_paren array_list? close_paren | |
; | |
new_array | |
: array_beg array_list? array_end | |
; | |
array_keyword ('support.function.construct.php') | |
: Lower['array'] | |
; | |
array_list | |
: array_item (array_sep array_item)* | |
; | |
array_item | |
: ({literal rocket}? literal rocket)? expr | |
; | |
rocket ('keyword.operator.key.php') | |
: Symbol['=>'] | |
; | |
array_beg ('punctuation.definition.array.begin.php') | |
: Symbol['['] | |
; | |
array_sep ('punctuation.separator.array.php') | |
: Symbol[','] | |
; | |
array_end ('punctuation.definition.array.end.php') | |
: Symbol[']'] | |
; | |
# VARIABLES | |
variable ('variable.other.php') | |
: dollar identifier | |
; | |
identifier | |
: all_caps | |
| lower_id | |
| upper_id | |
; | |
all_caps ('constant.other.allcaps.php') | |
: Upper[/[_A-Z0-9]+/] | |
; | |
lower_id ('meta.identifier.lower.php') | |
: Lower | |
; | |
upper_id ('meta.identifier.lower.php') | |
: Upper | |
; | |
dollar ('punctuation.definition.variable.php') | |
: Symbol['$'] | |
; | |
# SYMBOLS | |
pi_beg ('punctuation.section.imbedded.begin') | |
: Symbol['<?'] Lower['php'] | |
; | |
pi_end ('punctuation.section.imbedded.end') | |
: Symbol['?>'] | |
; | |
semi ('punctuation.terminator.expression.php') | |
: Symbol[';'] | |
; | |
question ('storage.modifier.nullable') | |
: Symbol['?'] | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment