Skip to content

Commit

Permalink
Rework handling of addtask, deltask and addhandler statements
Browse files Browse the repository at this point in the history
Especially the addtask statement is a bit special as the "after" and
"before" tokens should only be recognized as keywords when we are in
the addtask state.

A new lexer state has been introduced to fix this issue.

Signed-off-by: Florian Bezdeka <[email protected]>
  • Loading branch information
fbezdeka committed Aug 5, 2024
1 parent 8941cd5 commit 07cd2d6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}

bitbakeFile ::= item_*
private item_ ::= (variable|bbFunction|bbStatement|bbExportStatement|bbExportFuncStatement|keyword|COMMENT|CRLF)
private item_ ::= (variable|bbFunction|bbStatement|bbAddTaskStatement|bbExportStatement|bbExportFuncStatement|keyword|COMMENT|CRLF)
variable ::= (KEY (OVERRIDE+ | bbFlag)? OPERATOR VALUE)
bbFlag ::= (ALB FLAG ARB)
bbFunction ::= (bbBashFunction | bbPyFunction | bbDefPyFunction)
Expand All @@ -27,5 +27,8 @@ bbDefPyFunction ::= (DEF BB_FUNCTION_NAME LB bbDefParam* RB LBB FB+ RBB)
bbDefParam ::= (BB_FUNCTION_NAME COMMA?)+
keyword ::= (INHERIT|INCLUDE|REQUIRE) INCLUDE_REST
bbStatement ::= (STATEMENT (STATEMENT | STATEMENT_REST))
bbAfterStatement ::= (AFTER BB_FUNCTION_NAME+)
bbBeforeStatement ::= (BEFORE BB_FUNCTION_NAME+)
bbAddTaskStatement ::= (ADD_TASK BB_FUNCTION_NAME bbAfterStatement? bbBeforeStatement? bbAfterStatement?)
bbExportStatement ::= (EXPORT KEY (OPERATOR VALUE)?)
bbExportFuncStatement ::= (EXPORT_FUNC BB_FUNCTION_NAME+)
20 changes: 15 additions & 5 deletions src/main/java/com/github/vitalibo/intellij/bitbake/BitBake.flex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.intellij.psi.TokenType;
%eof}

CRLF = \R
WS = [\ \t\f]
WHITE_SPACE = [\ \n\t\f]
VALUE_CHARACTER = [^\n\f\\\"] | "\\"{CRLF} | "\\".
COMMENT = (("#")[^\r\n]*)
Expand All @@ -30,6 +31,7 @@ VALUE = (("'" {VALUE_CHARACTER}* "'") | (\" {VALUE_CHARACTER}* \"))
%state WAITING_VALUE FUNCTION_NAME PY_FUNCTION_NAME PY_FUNCTION FUNCTION_VALUE INCLUDE_VALUE STATEMENT_VALUE
%state EXPORT_STATEMENT EXPORT_FUNC_STATEMENT
%state LINE_WITH_FLAG FLAG
%state ADD_TASK_STATEMENT

%%

Expand All @@ -38,14 +40,14 @@ VALUE = (("'" {VALUE_CHARACTER}* "'") | (\" {VALUE_CHARACTER}* \"))
<YYINITIAL> ^"require" { yybegin(INCLUDE_VALUE); return BitBakeTypes.REQUIRE; }
<YYINITIAL> ^"export" { yybegin(EXPORT_STATEMENT); return BitBakeTypes.EXPORT; }
<YYINITIAL> ^"EXPORT_FUNCTIONS" { yybegin(EXPORT_FUNC_STATEMENT); return BitBakeTypes.EXPORT_FUNC; }
<YYINITIAL> ^(addtask|deltask|addhandler) { yybegin(STATEMENT_VALUE); return BitBakeTypes.STATEMENT; }
<YYINITIAL> (after|before) { yybegin(STATEMENT_VALUE); return BitBakeTypes.STATEMENT; }
<YYINITIAL> ^"addtask" { yybegin(ADD_TASK_STATEMENT); return BitBakeTypes.ADD_TASK; }
<YYINITIAL> ^("deltask"|"addhandler") { yybegin(STATEMENT_VALUE); return BitBakeTypes.STATEMENT; }

<INCLUDE_VALUE> .+ { yybegin(YYINITIAL); return BitBakeTypes.INCLUDE_REST; }
<STATEMENT_VALUE> {WHITE_SPACE}+ { return TokenType.WHITE_SPACE; }
<STATEMENT_VALUE> [^\ \n\t\f]+ { yybegin(YYINITIAL); return BitBakeTypes.STATEMENT_REST; }

<YYINITIAL> ^((python|fakeroot)\s*)*({FN_TOKEN})?\s*\(\s*\)[\ \t\f]*\{$ { yypushback(yylength()); yybegin(FUNCTION_NAME); }
<YYINITIAL> ^((python|fakeroot)\s*)*({FN_TOKEN})?\s*\(\s*\){WS}*\{$ { yypushback(yylength()); yybegin(FUNCTION_NAME); }
<YYINITIAL> ^(def\s+)([0-9A-Za-z_-]+)(\s*\(.*\)\s*):\s* { yypushback(yylength()); yybegin(PY_FUNCTION_NAME); }
<YYINITIAL> ^({KEY_CHARACTER}+ "[" .* "]" ) { yypushback(yylength()); yybegin(LINE_WITH_FLAG); }

Expand Down Expand Up @@ -87,13 +89,13 @@ VALUE = (("'" {VALUE_CHARACTER}* "'") | (\" {VALUE_CHARACTER}* \"))
{KEY_CHARACTER}+ { return BitBakeTypes.KEY; }
{ASSIGNMENT_OPERATOR} { return BitBakeTypes.OPERATOR; }
{CRLF}+ { yybegin(YYINITIAL); return TokenType.WHITE_SPACE; }
[\ \t\f]+ { return TokenType.WHITE_SPACE; }
{WS}+ { return TokenType.WHITE_SPACE; }
}

<EXPORT_FUNC_STATEMENT> {
[\w\.\-\+\{\}\$]+ { return BitBakeTypes.BB_FUNCTION_NAME; }
{CRLF}+ { yybegin(YYINITIAL); return TokenType.WHITE_SPACE; }
[\ \t\f]+ { return TokenType.WHITE_SPACE; }
{WS}+ { return TokenType.WHITE_SPACE; }
}

<LINE_WITH_FLAG> {
Expand All @@ -107,6 +109,14 @@ VALUE = (("'" {VALUE_CHARACTER}* "'") | (\" {VALUE_CHARACTER}* \"))
\] { yybegin(YYINITIAL); return BitBakeTypes.ARB; }
}

<ADD_TASK_STATEMENT> {
"after" { return BitBakeTypes.AFTER; }
"before" { return BitBakeTypes.BEFORE; }
{KEY_CHARACTER}+ { return BitBakeTypes.BB_FUNCTION_NAME; }
{WS}+ {return TokenType.WHITE_SPACE; }
{CRLF}+ { yybegin(YYINITIAL); return TokenType.WHITE_SPACE; }
}

<YYINITIAL> ^{COMMENT} { return BitBakeTypes.COMMENT; }
<YYINITIAL> ^{KEY_CHARACTER}+ { return BitBakeTypes.KEY; }
<YYINITIAL> {OVERRIDE} { return BitBakeTypes.OVERRIDE; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
tokenType.equals(BitBakeTypes.PYTHON) ||
tokenType.equals(BitBakeTypes.EXPORT) ||
tokenType.equals(BitBakeTypes.EXPORT_FUNC) ||
tokenType.equals(BitBakeTypes.STATEMENT)) {
tokenType.equals(BitBakeTypes.STATEMENT) ||
tokenType.equals(BitBakeTypes.ADD_TASK) ||
tokenType.equals(BitBakeTypes.AFTER) ||
tokenType.equals(BitBakeTypes.BEFORE)) {
return KEYWORD_KEYS;
} else if (tokenType.equals(BitBakeTypes.OVERRIDE)) {
return KEYWORD_KEYS;
Expand Down

0 comments on commit 07cd2d6

Please sign in to comment.