Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grammar railroad diagram #9051

Open
mingodad opened this issue Apr 4, 2022 · 0 comments
Open

Grammar railroad diagram #9051

mingodad opened this issue Apr 4, 2022 · 0 comments

Comments

@mingodad
Copy link

mingodad commented Apr 4, 2022

It's sad that there is no parser grammar anymore but using the once existing https://github.com/facebook/hhvm/blob/16370ab43249b70c31126d18a700c51b49e7a38f/hphp/hack/doc/pharser/phparser.mly and with a custom parser to extract an EBNF grammar accepted by https://www.bottlecaps.de/rr/ui we can have a nice railroad diagram (https://en.wikipedia.org/wiki/Syntax_diagram) see bellow.

Copy and paste the EBNF shown bellow at https://www.bottlecaps.de/rr/ui on the tab "Edit Grammar" then click on the tab "View Diagram".

start ::=  top_statement* EOF

top_statement ::=  statement
	| declaration
	| HALT_COMPILER LPAREN RPAREN SEMICOLON
	| NAMESPACE namespace_name SEMICOLON
	| NAMESPACE namespace_name LBRACE top_statement* RBRACE
	| NAMESPACE LBRACE top_statement* RBRACE
	| USE NAMESPACE? mixed_group_use_declaration SEMICOLON
	| USE NAMESPACE? use_modifier group_use_declaration SEMICOLON
	| USE NAMESPACE? comma_list SEMICOLON
	| USE NAMESPACE? use_modifier comma_list SEMICOLON
	| CONST comma_list SEMICOLON

identifier ::=  IDENT
	| XHP_COLONID_DEF
	| semi_reserved

name ::=  namespace_name
	| NAMESPACE ANTISLASH namespace_name
	| ANTISLASH namespace_name
	| xhp_reserved

namespace_name ::=  IDENT
	| XHP_COLONID_DEF
	| namespace_name ANTISLASH IDENT

class_special_name ::=  STATIC
	| SELF
	| PARENT
	| SHAPE
	| ARRAY

unparametrized_class_name ::=  STATIC
	| SELF
	| PARENT
	| name

class_name ::=  unparametrized_class_name
	| unparametrized_class_name type_arguments

type_name ::=  CALLABLE
	| SELF
	| PARENT
	| ARRAY
	| name

attribute ::=  ANTISLASH attribute
	| IDENT
	| IDENT COLON attribute
	| IDENT LPAREN comma_list_trailing RPAREN

attributes ::=  SHL nonempty_comma_list_trailing SHR_PREFIX RANGLE

declaration ::=  attributes
	| declare_function
	| declare_class
	| declare_trait
	| declare_interface
	| declare_enum
	| declare_type

declare_function ::=  ASYNC declare_function
	| COROUTINE declare_function
	| FUNCTION AND? identifier ( at_doc_comment )?  type_parameters? LPAREN comma_list_trailing RPAREN return_type? ( at_fn_flags )?  where_constraints? LBRACE statement_inner* RBRACE ( at_fn_flags )?

where_constraints ::=  WHERE comma_list_trailing

where_constraint ::=  type_expr EQUAL type_expr
	| type_expr AS type_expr
	| type_expr SUPER type_expr

declare_class ::=  class_modifier* CLASS identifier type_parameters? ( EXTENDS class_name )? ( IMPLEMENTS comma_list )? ( at_doc_comment )?  LBRACE statement_class* RBRACE

class_modifier ::=  ABSTRACT
	| FINAL

declare_trait ::=  TRAIT identifier type_parameters? ( IMPLEMENTS comma_list )? ( at_doc_comment )?  LBRACE statement_class* RBRACE

declare_interface ::=  INTERFACE identifier type_parameters? ( EXTENDS comma_list )? ( at_doc_comment )?  LBRACE statement_class* RBRACE

declare_enum ::=  ENUM IDENT COLON type_expr ( AS type_expr )? LBRACE lseparated_list_trailing RBRACE

enum_member ::=  identifier EQUAL expr

declare_type ::=  TYPE identifier type_parameters? ( AS type_expr )? EQUAL type_expr SEMICOLON
	| NEWTYPE identifier type_parameters? ( AS type_expr )? EQUAL type_expr SEMICOLON

statement ::=  LBRACE statement_inner* RBRACE
	| statement_if
	| WHILE LPAREN expr RPAREN statement
	| DO statement WHILE LPAREN expr RPAREN SEMICOLON
	| FOR LPAREN comma_list SEMICOLON comma_list SEMICOLON comma_list RPAREN statement
	| SWITCH LPAREN expr RPAREN switch_body
	| BREAK expr? SEMICOLON
	| CONTINUE expr? SEMICOLON
	| RETURN attributes? expr? SEMICOLON
	| GLOBAL comma_list SEMICOLON
	| STATIC comma_list SEMICOLON
	| ECHO comma_list SEMICOLON
	| INLINE_HTML
	| expr SEMICOLON
	| UNSET LPAREN nonempty_comma_list_trailing RPAREN SEMICOLON
	| FOREACH LPAREN expr AWAIT? FOREACH_AS foreach_variable RPAREN statement
	| FOREACH LPAREN expr AWAIT? FOREACH_AS foreach_variable DOUBLE_ARROW foreach_variable RPAREN statement
	| DECLARE LPAREN comma_list RPAREN statement
	| SEMICOLON
	| TRY LBRACE statement_inner* RBRACE try_catch* try_finally?
	| THROW expr SEMICOLON
	| GOTO IDENT SEMICOLON
	| IDENT COLON
	| AWAIT? USING LPAREN expr_pair_list RPAREN SEMICOLON
	| AWAIT? USING LPAREN expr_pair_list RPAREN LBRACE statement_inner* RBRACE
	| AWAIT? USING expr_without_parenthesis SEMICOLON
	| CONCURRENT LBRACE statement_inner* RBRACE

statement_inner ::=  statement
	| declare_function
	| declare_class
	| declare_trait
	| declare_interface
	| HALT_COMPILER LPAREN RPAREN SEMICOLON

initializable_variable ::=  VARIABLE ( EQUAL expr )? ( at_doc_comment )?

try_catch ::=  CATCH LPAREN (OR name)* VARIABLE RPAREN LBRACE statement_inner* RBRACE

try_finally ::=  FINALLY LBRACE statement_inner* RBRACE

foreach_variable ::=  expr
	| AND expr_assignable
	| LIST LPAREN expr_pair_list RPAREN

switch_body ::=  LBRACE SEMICOLON? switch_case* RBRACE

switch_case ::=  CASE expr switch_case_separator statement_inner*
	| DEFAULT switch_case_separator statement_inner*

switch_case_separator ::=  COLON
	| SEMICOLON

statement_if ::=  if_without_else
	| if_without_else ELSE statement

if_without_else ::=  IF LPAREN expr RPAREN statement
	| if_without_else ELSEIF LPAREN expr RPAREN statement

parameter ::=  attributes? parameter_visibility INOUT? type_expr? AND? parameter_core

parameter_visibility ::=  /* empty */
	| PUBLIC
	| PRIVATE
	| PROTECTED

parameter_core ::=  VARIABLE ( EQUAL expr )?
	| ELLIPSIS VARIABLE
	| ELLIPSIS

statement_class ::=  USE comma_list SEMICOLON
	| USE comma_list LBRACE trait_adaptation* RBRACE
	| class_variable_modifiers type_expr? comma_list SEMICOLON
	| class_member_modifier* CONST comma_list SEMICOLON
	| class_member_modifier* COROUTINE? FUNCTION AND? identifier ( at_doc_comment )?  type_parameters? LPAREN comma_list_trailing RPAREN return_type? where_constraints? ( at_fn_flags )?  class_method_body ( at_fn_flags )?
	| REQUIRE EXTENDS class_name SEMICOLON
	| REQUIRE IMPLEMENTS class_name SEMICOLON
	| class_member_modifier* CONST TYPE name ( AS type_expr )? ( EQUAL type_expr )? SEMICOLON
	| XHP_ATTRIBUTE comma_list_trailing SEMICOLON
	| XHP_CHILDREN xhp_children_decl SEMICOLON
	| XHP_CATEGORY comma_list_trailing SEMICOLON

class_method_body ::=  SEMICOLON
	| LBRACE statement_inner* RBRACE

class_variable_modifiers ::=  class_member_modifier+
	| VAR

class_member_modifier ::=  PUBLIC
	| PROTECTED
	| PRIVATE
	| STATIC
	| ABSTRACT
	| FINAL
	| ASYNC
	| attributes

trait_adaptation ::=  trait_precedence SEMICOLON
	| trait_method_reference AS trait_alias SEMICOLON

trait_precedence ::=  name COLONCOLON identifier INSTEADOF comma_list

trait_alias ::=  IDENT
	| reserved_non_modifiers
	| class_member_modifier identifier?

trait_method_reference ::=  identifier
	| name COLONCOLON identifier

constant_declaration ::=  type_expr identifier ( EQUAL expr )? ( at_doc_comment )?
	| identifier ( EQUAL expr )? ( at_doc_comment )?

use_modifier ::=  FUNCTION
	| CONST
	| TYPE

group_use_declaration ::=  namespace_name ANTISLASH LBRACE nonempty_comma_list_trailing RBRACE
	| ANTISLASH namespace_name ANTISLASH LBRACE nonempty_comma_list_trailing RBRACE

mixed_group_use_declaration ::=  namespace_name ANTISLASH LBRACE nonempty_comma_list_trailing RBRACE
	| ANTISLASH namespace_name ANTISLASH LBRACE nonempty_comma_list_trailing RBRACE

inline_use_declaration ::=  unprefixed_use_declaration
	| use_modifier unprefixed_use_declaration

unprefixed_use_declaration ::=  namespace_name
	| namespace_name AS IDENT

use_declaration ::=  ANTISLASH? unprefixed_use_declaration

type_expr ::=  QUESTION type_expr
	| AT type_expr
	| simple_type_expr

simple_type_expr ::=  type_name
	| simple_type_expr type_arguments
	| simple_type_expr COLONCOLON type_name
	| SHAPE LPAREN comma_list_trailing RPAREN
	| LPAREN nonempty_comma_list_trailing RPAREN
	| LPAREN COROUTINE? FUNCTION LPAREN comma_list_trailing RPAREN return_type RPAREN
	| INT_CAST
	| DOUBLE_CAST
	| STRING_CAST
	| OBJECT_CAST
	| BOOL_CAST
	| ARRAY_CAST

rangle ::=  RANGLE
	| SHR_PREFIX

type_arguments ::=  FORK_LANGLE comma_list_trailing rangle

type_parameters ::=  FORK_LANGLE comma_list_trailing rangle

type_variance ::=  /* empty */
	| PLUS
	| MINUS

type_parameter ::=  type_variance type_name type_constraint

type_constraint ::=  /* empty */
	| type_constraint AS type_expr
	| type_constraint SUPER type_expr

type_expr_parameter ::=  type_expr
	| INOUT type_expr
	| ELLIPSIS
	| type_expr ELLIPSIS

return_type ::=  COLON type_expr

expr ::=  open_expr
	| LPAREN expr RPAREN
	| LPAREN attributes expr RPAREN

expr_without_parenthesis ::=  open_expr

open_expr ::=  LNUMBER
	| DNUMBER
	| LINE
	| FILE
	| DIR
	| TRAIT_C
	| METHOD_C
	| FUNC_C
	| NAMESPACE_C
	| CLASS_C
	| BANG expr
	| AWAIT expr
	| TILDE expr
	| CLONE expr
	| AT expr
	| PRINT expr
	| EXIT
	| SUSPEND expr
	| INCLUDE expr
	| INCLUDE_ONCE expr
	| REQUIRE expr
	| REQUIRE_ONCE expr
	| EMPTY LPAREN expr RPAREN
	| EVAL LPAREN expr RPAREN
	| ISSET LPAREN nonempty_comma_list_trailing RPAREN
	| name type_arguments?
	| left COLONCOLON property_name type_arguments?
	| class_special_name COLONCOLON property_name type_arguments?
	| left arrow property_name type_arguments?
	| expr_assignable
	| DOUBLEQUOTE encaps* DOUBLEQUOTE
	| START_HEREDOC encaps* END_HEREDOC
	| PLUS expr
	| MINUS expr
	| left expr_argument_list
	| left BOOLEAN_AND expr
	| left IS_IDENTICAL expr
	| left IS_NOT_IDENTICAL expr
	| left SPACESHIP expr
	| left EQUAL attributes? expr
	| left EQUAL AND expr
	| left IS_EQUAL expr
	| left IS_NOT_EQUAL expr
	| left LANGLE expr
	| left RANGLE expr
	| left IS_SMALLER_OR_EQUAL expr
	| left IS_GREATER_OR_EQUAL expr
	| NEW expr_class_reference
	| structured_literal
	| INT_CAST expr
	| DOUBLE_CAST expr
	| STRING_CAST expr
	| ARRAY_CAST expr
	| OBJECT_CAST expr
	| BOOL_CAST expr
	| UNSET_CAST expr
	| left BOOLEAN_OR expr
	| left LOGICAL_OR expr
	| left LOGICAL_AND expr
	| left LOGICAL_XOR expr
	| left OR expr
	| left AND expr
	| left XOR expr
	| left CONCAT expr
	| left PLUS expr
	| left MINUS expr
	| left MUL expr
	| left POW expr
	| left DIV expr
	| left MOD expr
	| left SHL expr
	| left PIPE_ANGLE expr
	| VARIABLE LONG_DOUBLE_ARROW lambda_body
	| FORK LPAREN comma_list_trailing RPAREN return_type? LONG_DOUBLE_ARROW lambda_body
	| ASYNC LPAREN comma_list_trailing RPAREN return_type? LONG_DOUBLE_ARROW lambda_body
	| ASYNC VARIABLE LONG_DOUBLE_ARROW lambda_body
	| ASYNC LBRACE statement_inner* RBRACE
	| COROUTINE LPAREN comma_list_trailing RPAREN return_type? LONG_DOUBLE_ARROW lambda_body
	| COROUTINE VARIABLE LONG_DOUBLE_ARROW lambda_body
	| COROUTINE LBRACE statement_inner* RBRACE
	| left LBRACKET expr_pair_list RBRACKET
	| left INC
	| INC expr
	| left DEC
	| DEC expr
	| left PLUS_EQUAL expr
	| left MINUS_EQUAL expr
	| left MUL_EQUAL expr
	| left POW_EQUAL expr
	| left DIV_EQUAL expr
	| left CONCAT_EQUAL expr
	| left MOD_EQUAL expr
	| left AND_EQUAL expr
	| left OR_EQUAL expr
	| left XOR_EQUAL expr
	| left SHL_EQUAL expr
	| left SHR_EQUAL expr
	| left QUESTION_QUESTION_EQUAL expr
	| left SHR_PREFIX RANGLE expr
	| left IS type_expr
	| left AS type_expr
	| left INSTANCEOF expr_class_reference
	| left QUESTION AS type_expr
	| left QUESTION COLON expr
	| left QUESTION expr COLON expr
	| left QUESTION_QUESTION expr
	| LIST LPAREN expr_pair_list RPAREN EQUAL expr
	| xhp_html
	| function_expr
	| YIELD
	| YIELD expr
	| YIELD expr DOUBLE_ARROW expr
	| YIELD BREAK

function_expr ::=  STATIC function_expr
	| ASYNC function_expr
	| COROUTINE function_expr
	| FUNCTION AND? ( at_doc_comment )?  LPAREN comma_list_trailing RPAREN return_type? lexical_vars? ( at_fn_flags )?  LBRACE statement_inner* RBRACE ( at_fn_flags )?

lexical_vars ::=  USE LPAREN comma_list_trailing RPAREN

lambda_body ::=  expr
	| LBRACE statement_inner* RBRACE

expr_argument_list ::=  LPAREN comma_list_trailing RPAREN
	| LBRACE expr_pair_list RBRACE

expr_argument ::=  expr
	| AND expr
	| INOUT expr
	| ELLIPSIS expr
	| attributes expr_argument

expr_pair_list ::=  nonempty_comma_list

expr_array_pair ::=  expr DOUBLE_ARROW expr
	| expr
	| expr DOUBLE_ARROW AND expr_assignable
	| AND expr_assignable
	| expr DOUBLE_ARROW LIST LPAREN expr_pair_list RPAREN
	| LIST LPAREN expr_pair_list RPAREN
	| ELLIPSIS expr

property_name ::=  identifier
	| LBRACE expr RBRACE
	| expr_variable

expr_class_reference ::=  class_name
	| expr_variable
	| LPAREN expr RPAREN

structured_literal ::=  ARRAY type_arguments? LPAREN expr_pair_list RPAREN
	| SHAPE type_arguments? LPAREN expr_pair_list RPAREN
	| LBRACKET expr_pair_list RBRACKET
	| ARRAY type_arguments? LBRACKET expr_pair_list RBRACKET
	| CONSTANT_ENCAPSED_STRING

expr_assignable ::=  expr_variable

expr_variable ::=  VARIABLE
	| DOLLAR LBRACE expr RBRACE
	| DOLLAR expr_variable
	| DOLLARDOLLAR

encaps ::=  ENCAPSED_AND_WHITESPACE
	| encaps_var

encaps_var ::=  VARIABLE
	| VARIABLE LBRACKET encaps_var_offset RBRACKET
	| VARIABLE arrow IDENT
	| DOLLAR_OPEN_CURLY_BRACES expr RBRACE
	| DOLLAR_OPEN_CURLY_BRACES VARNAME RBRACE
	| DOLLAR_OPEN_CURLY_BRACES VARNAME LBRACKET expr RBRACKET RBRACE
	| CURLY_OPEN expr RBRACE

encaps_var_offset ::=  IDENT
	| NUM_STRING
	| MINUS NUM_STRING
	| VARIABLE

xhp_html ::=  XHP_OPEN_TAG xhp_attribute* XHP_GT xhp_child* XHP_CLOSE_TAG
	| XHP_OPEN_TAG xhp_attribute* XHP_SLASH_GT

xhp_child ::=  XHP_TEXT
	| xhp_html
	| LBRACE expr RBRACE

xhp_attribute ::=  XHP_ATTR EQUAL xhp_attribute_value
	| LBRACE ELLIPSIS? expr RBRACE

xhp_attribute_value ::=  DOUBLEQUOTE encaps* DOUBLEQUOTE
	| LBRACE expr RBRACE
	| XHP_ATTR

xhp_attribute_decl ::=  XHP_COLONID_DEF
	| xhp_attribute_decl_type xhp_attr_name ( EQUAL expr )? XHP_REQUIRED?

xhp_attribute_decl_type ::=  ENUM LBRACE comma_list_trailing RBRACE
	| VAR
	| type_expr

xhp_attr_name ::=  identifier
	| xhp_attr_name MINUS identifier
	| xhp_attr_name COLON identifier

xhp_children_decl ::=  XHP_ANY
	| EMPTY
	| xhp_children_paren_expr

xhp_children_paren_expr ::=  LPAREN xhp_children_decl_exprs RPAREN
	| LPAREN xhp_children_decl_exprs RPAREN MUL
	| LPAREN xhp_children_decl_exprs RPAREN QUESTION
	| LPAREN xhp_children_decl_exprs RPAREN PLUS

xhp_children_decl_expr ::=  xhp_children_paren_expr
	| xhp_children_decl_tag
	| xhp_children_decl_tag MUL
	| xhp_children_decl_tag QUESTION
	| xhp_children_decl_tag PLUS

xhp_children_decl_exprs ::=  xhp_children_decl_expr
	| xhp_children_decl_exprs COMMA xhp_children_decl_expr
	| xhp_children_decl_exprs OR xhp_children_decl_expr

xhp_children_decl_tag ::=  XHP_ANY
	| XHP_PCDATA
	| XHP_COLONID_DEF
	| XHP_PERCENTID_DEF
	| IDENT

shape_field ::=  QUESTION? expr DOUBLE_ARROW type_expr
	| ELLIPSIS

arrow ::=  ARROW
	| QUESTION_ARROW

xhp_reserved ::=  XHP_ATTRIBUTE
	| XHP_CATEGORY
	| XHP_CHILDREN
	| XHP_ANY
	| XHP_PCDATA

reserved_non_modifiers ::=  xhp_reserved
	| INCLUDE
	| INCLUDE_ONCE
	| EVAL
	| REQUIRE
	| REQUIRE_ONCE
	| LOGICAL_OR
	| LOGICAL_XOR
	| LOGICAL_AND
	| INSTANCEOF
	| INOUT
	| IS
	| NEW
	| CLONE
	| EXIT
	| IF
	| ELSEIF
	| ELSE
	| ENDIF
	| ECHO
	| DO
	| WHILE
	| FOR
	| FOREACH
	| DECLARE
	| AS
	| TRY
	| CATCH
	| FINALLY
	| THROW
	| USE
	| INSTEADOF
	| GLOBAL
	| VAR
	| UNSET
	| ISSET
	| EMPTY
	| CONTINUE
	| GOTO
	| FUNCTION
	| CONST
	| RETURN
	| PRINT
	| YIELD
	| LIST
	| SWITCH
	| CASE
	| DEFAULT
	| BREAK
	| ARRAY
	| CALLABLE
	| EXTENDS
	| IMPLEMENTS
	| NAMESPACE
	| TRAIT
	| INTERFACE
	| CLASS
	| TYPE
	| ENUM
	| LINE
	| FILE
	| DIR
	| CLASS_C
	| TRAIT_C
	| METHOD_C
	| FUNC_C
	| NAMESPACE_C
	| PARENT
	| SELF
	| WHERE
	| SHAPE
	| USING
	| COROUTINE
	| SUSPEND
	| NEWTYPE

semi_reserved ::=  reserved_non_modifiers
	| STATIC
	| ABSTRACT
	| FINAL
	| PRIVATE
	| PROTECTED
	| PUBLIC
	| ASYNC
	| SUPER

dummy ::=  COMMENT DOC_COMMENT NEWLINE SPACES UNKNOWN OPEN_TAG OPEN_TAG_WITH_ECHO CLOSE_TAG CLOSE_TAG_OF_ECHO
	| AND_EQUAL BACKQUOTE BANG BOOLEAN_AND BOOLEAN_OR COALESCE CONCAT CONCAT_EQUAL CURLY_OPEN DEC DIV DIV_EQUAL DNUMBER DOLLAR_OPEN_CURLY_BRACES DOUBLEQUOTE ENCAPSED_AND_WHITESPACE END_HEREDOC FORK INC IS_EQUAL IS_GREATER_OR_EQUAL IS_IDENTICAL IS_NOT_EQUAL IS_SMALLER_OR_EQUAL LANGLE LONG_DOUBLE_ARROW MINUS_EQUAL MOD MOD_EQUAL MUL MUL_EQUAL NUM_STRING OR_EQUAL PIPE_ANGLE PLUS_EQUAL POW POW_EQUAL QUESTION_QUESTION QUESTION_QUESTION_EQUAL SHL_EQUAL SHR_EQUAL SPACESHIP START_HEREDOC TILDE UNSET_CAST VARNAME XHP_ATTR XHP_CLOSE_TAG XHP_GT XHP_OPEN_TAG XHP_PCDATA XHP_PERCENTID_DEF XHP_REQUIRED XHP_SLASH_GT XHP_TEXT XOR XOR_EQUAL YIELD_FROM

lnonempty_list ::=  X llist_aux

llist ::=  llist_aux

llist_aux ::=  /* empty */
	| llist_aux X

lseparated_list ::=  /* empty */
	| lseparated_nonempty_list

lseparated_list_trailing ::=  /* empty */
	| lseparated_nonempty_list sep?

lseparated_nonempty_list ::=  lseparated_nonempty_list_aux

lseparated_nonempty_list_aux ::=  X
	| lseparated_nonempty_list_aux sep X

comma_list ::=  lseparated_list

comma_list_trailing ::=  lseparated_list_trailing

nonempty_comma_list ::=  lseparated_nonempty_list

nonempty_comma_list_trailing ::=  lseparated_nonempty_list COMMA?


//Tokens
//; \("[^"]+"\)\s*, (Lang_[^,]+, \([^)]+\).+
//| \(\S+\)\s+{ \(\S+\) }

WHILE ::= "while"
DO ::= "do"
FOR ::= "for"
FOREACH ::= "foreach"

SELF ::= "self"
PARENT ::= "parent"
IF ::= "if"
ELSE ::= "else"
ELSEIF ::= "elseif"
BREAK ::= "break"
CONTINUE ::= "continue"
SWITCH ::= "switch"
CASE ::= "case"
DEFAULT ::= "default"
RETURN ::= "return"
TRY ::= "try"
CATCH ::= "catch"
FINALLY ::= "finally"
THROW ::= "throw"
EXIT ::= "exit"
EXIT ::= "die"
ARRAY ::= "array"
ARRAY ::= "darray"
ARRAY ::= "varray"
ARRAY ::= "vec"
ARRAY ::= "dict"
ARRAY ::= "keyset"
LIST ::= "list"

/* used for traits too */
AS ::= "as"
INCLUDE ::= "include"
INCLUDE_ONCE ::= "include_once"
REQUIRE ::= "require"
REQUIRE_ONCE ::= "require_once"
CLASS ::= "class"
INTERFACE ::= "interface"
EXTENDS ::= "extends"
IMPLEMENTS ::= "implements"
NEW ::= "new"
CLONE ::= "clone"
INSTANCEOF ::= "instanceof"

/* php 5.4 traits ('use' and 'as' are used for traits and other things) */
TRAIT ::= "trait"
INSTEADOF ::= "insteadof"

/* php 5.3 namespace */
NAMESPACE ::= "namespace"

/* used for traits and namespace */
USE ::= "use"
ABSTRACT ::= "abstract"
FINAL ::= "final"
PUBLIC ::= "public"
PROTECTED ::= "protected"
PRIVATE ::= "private"
ECHO ::= "echo"
PRINT ::= "print"
EVAL ::= "eval"
GLOBAL ::= "global"
FUNCTION ::= "function"
EMPTY ::= "empty"
CONST ::= "const"
VAR ::= "var"
DECLARE ::= "declare"
STATIC ::= "static"
UNSET ::= "unset"
ISSET ::= "isset"
LINE ::= "__line__"
FILE ::= "__file__"
DIR ::= "__dir__"
FUNC_C ::= "__function__"
METHOD_C ::= "__method__"
CLASS_C ::= "__class__"
TRAIT_C ::= " __trait__"
NAMESPACE_C ::= "__namespace__"
/* ENDIF ::= "endif"
ENDSWITCH ::= "endswitch"
ENDDECLARE ::= "enddeclare"

/* old: ; "__halt_compiler", HALT_COMPILER; */
ASYNC ::= "async"
SUPER ::= "super"
COROUTINE ::= "coroutine"
SUSPEND ::= "suspend"

/* php-facebook-ext: */
YIELD ::= "yield"
AWAIT ::= "await"
USING ::= "using"
CONCURRENT ::= "concurrent"

/* php-facebook-ext: */
TYPE ::= "type"
NEWTYPE ::= "newtype"
SHAPE ::= "shape"
IS ::= "is"
INOUT ::= "inout"
WHERE ::= "where"

/* xhp: having those XHP keywords handled here could mean they can not
* be used for entities like functions or class names. We could
* avoid this by introducing some lexer/parser hacks so that those
* keywords are recognized only in certain contexts (e.g. just after
* the '{' of a class) but that complicates the full parser (note
* also that IMHO it's better to not let the user overload those
* special names). A simpler solution, instead of extending the lexer,
* is to extend the grammar by having a 'ident:' rule that allows
* the regular IDENT as well as those XHP tokens. See parser_php.mly.
*/
XHP_ATTRIBUTE ::= "attribute"
XHP_CHILDREN ::= "children"
XHP_CATEGORY ::= "category"
/* for attribute declarations and Hack first class enums */
ENUM ::= "enum"
/* for children declarations */
XHP_ANY ::= "any"
/* "empty" is already a PHP keyword, see EMPTY */
XHP_PCDATA ::= "pcdata"

PLUS ::= '+'
MINUS ::= '-'
MUL ::= '*'
DIV ::= '/'
MOD ::= '%'
INC ::= "++"
DEC ::= "--"
EQUAL ::= "="
PLUS_EQUAL ::= "+="
MINUS_EQUAL ::= "-="
MUL_EQUAL ::= "*="
DIV_EQUAL ::= "/="
MOD_EQUAL ::= "%="
AND_EQUAL ::= "&="
OR_EQUAL ::= "|="
XOR_EQUAL ::= "^="
SHL_EQUAL ::= "<<="
SHR_EQUAL ::= ">>="
CONCAT_EQUAL ::= ".="
IS_EQUAL ::= "=="
IS_NOT_EQUAL ::= "!="
IS_IDENTICAL ::= "==="
IS_NOT_IDENTICAL ::= "!=="
IS_NOT_EQUAL ::= "<>"
SPACESHIP ::= "<=>"
IS_SMALLER_OR_EQUAL ::= "<="
IS_GREATER_OR_EQUAL ::= ">="
LANGLE ::= "<"
RANGLE ::= ">"
BOOLEAN_AND ::= "&&"
BOOLEAN_OR ::= "||"
PIPE_ANGLE ::= "|>"
SHL ::= "<<"
SHR_PREFIX ::= ">>"
POW ::= "**"
POW_EQUAL ::= "**="
AND ::= "&"
OR ::= "|"
XOR ::= "^"
LOGICAL_OR ::= "OR"
LOGICAL_AND ::= "AND"
LOGICAL_XOR ::= "XOR"
LOGICAL_OR ::= "or"
LOGICAL_AND ::= "and"
LOGICAL_XOR ::= "xor"

CONCAT ::= '.'
COMMA ::= ','
AT ::= '@'

/* was called DOUBLE_ARROW but we actually now have a real ==> */
DOUBLE_ARROW ::= "=>"
TILDE ::= "~"
SEMICOLON ::= ";"
BANG ::= "!"
COLONCOLON ::= "::" /* was called T_PAAMAYIM_NEKUDOTAYIM */
ANTISLASH ::= "\\"  /* was called T_NS_SEPARATOR */

LPAREN ::= '('
RPAREN ::= ')'

LBRACKET ::= '['
RBRACKET ::= ']'

COLON ::= ":"
QUESTION ::= "?"
COLON ::= ":"
QUESTION_QUESTION ::= "??"
QUESTION_QUESTION_EQUAL ::= "??="

/* semantic grep or var args extension */
ELLIPSIS ::= "..."

/* facebook-ext: short lambdas */
LONG_DOUBLE_ARROW ::= "==>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant