Skip to content

Commit

Permalink
PHPParser: Handle PHP Attributes (#3392)
Browse files Browse the repository at this point in the history
This adds very basic parsing of PHP Attributes. Nothing about the
content of the attribute is understood or retained, this is just enough
to not encounter a parser errors for files that contain non-backwards
compatible attributes.
  • Loading branch information
AJenbo authored Jun 3, 2024
1 parent f36b2a9 commit 65537f5
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions CodeLite/PhpLexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ extern "C" int yywrap(void*) { return 1; }
return x;\
}

int bracket_count = 0;

%}

/* regex and modes */
Expand All @@ -55,6 +57,7 @@ extern "C" int yywrap(void*) { return 1; }
%x HEREDOC
%x DSTRING
%x SINGLE_STRING
%x ATTRIBUTE

identifier [a-zA-Z_][0-9a-zA-Z_]*

Expand Down Expand Up @@ -196,6 +199,24 @@ horizontal_white [ ]|{h_tab}
userData->AppendToComment(yytext[0]);
}
}
<PHP>"#[" {
BEGIN(ATTRIBUTE);
bracket_count = 1;
}
<ATTRIBUTE>"[" {
bracket_count++;
}
<ATTRIBUTE>"]" {
bracket_count--;
if (bracket_count == 0) {
BEGIN(PHP);
return ATTRIBUTE;
}
}
<ATTRIBUTE>"\n" {
}
<ATTRIBUTE>. {
}

<PHP>"//"|"#" {
BEGIN(CPP_COMMENT);
Expand Down

0 comments on commit 65537f5

Please sign in to comment.