Skip to content

Commit

Permalink
Merge pull request #8 from fbezdeka/bitbake2.0
Browse files Browse the repository at this point in the history
Allow bitbake 2.0 override syntax
  • Loading branch information
vitalibo authored Aug 9, 2024
2 parents c78645f + 07cd2d6 commit e99f932
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 34 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build

on:
push:

jobs:
gradle:
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: 7.4

- name: Execute Gradle build
run: gradle build -Pversion=$(git describe --dirty --tags --always)

- name: Upload build artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: Intellij Plugin
path: build/libs
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
id 'org.jetbrains.intellij' version '1.7.0'
id 'org.jetbrains.intellij' version '1.13.0'
id 'org.jetbrains.grammarkit' version '2021.2.2'
}

Expand Down Expand Up @@ -64,4 +64,8 @@ tasks {
purgeOldFiles = true
}

buildSearchableOptions {
enabled = false
}

}
18 changes: 12 additions & 6 deletions src/main/java/com/github/vitalibo/intellij/bitbake/BitBake.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@
}

bitbakeFile ::= item_*
private item_ ::= (variable|bbFunction|bbStatement|keyword|COMMENT|CRLF)
variable ::= (EXPORT? KEY OPERATOR VALUE)
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)
bbBashFunction ::= (BB_FUNCTION_NAME LB RB LBB FB+ RBB)
bbPyFunction ::= (PYTHON BB_FUNCTION_NAME? LB RB LBB FB+ RBB)
bbBashFunction ::= (FAKEROOT? BB_FUNCTION_NAME OVERRIDE* LB RB LBB FB+ RBB)
bbPyFunction ::= (FAKEROOT? PYTHON (BB_FUNCTION_NAME OVERRIDE*)? LB RB LBB FB+ RBB)
bbDefPyFunction ::= (DEF BB_FUNCTION_NAME LB bbDefParam* RB LBB FB+ RBB)
bbDefParam ::= (BB_FUNCTION_NAME COMMA?)+
keyword ::= (INHERIT|INCLUDE|REQUIRE|EXPORT) INCLUDE_REST
bbStatement ::= (STATEMENT (STATEMENT | STATEMENT_REST))
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+)
89 changes: 66 additions & 23 deletions src/main/java/com/github/vitalibo/intellij/bitbake/BitBake.flex
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,49 @@ import com.intellij.psi.TokenType;
%eof{ return;
%eof}

CRLF=\R
WHITE_SPACE=[\ \n\t\f]
STR_START_CHAR=\"|\'
VALUE_CHARACTER=[^\n\f\\\"] | "\\"{CRLF} | "\\".
END_OF_LINE_COMMENT= (("#")[^\r\n]*)
ASSIGNMENT_OPERATOR=("="|"?="|"??="|":="|"+="|"=+"|".="|"=.")
KEY_CHARACTER=[^?=:+.\ \n\t\f\\\(\)] | "\\ "
CRLF = \R
WS = [\ \t\f]
WHITE_SPACE = [\ \n\t\f]
VALUE_CHARACTER = [^\n\f\\\"] | "\\"{CRLF} | "\\".
COMMENT = (("#")[^\r\n]*)
ASSIGNMENT_OPERATOR = ("="|"?="|"??="|":="|"+="|"=+"|".="|"=.")
KEY_CHARACTER = [^?=:+.\ \n\t\f\\\(\)\[\]] | "\\ "
OVERRIDE = (":" {KEY_CHARACTER}+)
BROKEN_OVERRIDE = (":"+ {KEY_CHARACTER}+)
FN_NAME = ([\w\.\-\+\{\}\$]+)
FN_TOKEN = ({FN_NAME} {BROKEN_OVERRIDE}*)
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

%%

<YYINITIAL> "inherit" { yybegin(INCLUDE_VALUE); return BitBakeTypes.INHERIT; }
<YYINITIAL> "include" { yybegin(INCLUDE_VALUE); return BitBakeTypes.INCLUDE; }
<YYINITIAL> "require" { yybegin(INCLUDE_VALUE); return BitBakeTypes.REQUIRE; }
<YYINITIAL> "export" { return BitBakeTypes.EXPORT; }
<YYINITIAL> "EXPORT_FUNCTIONS" { yybegin(INCLUDE_VALUE); return BitBakeTypes.EXPORT; }
<YYINITIAL> addtask|addhandler|after|before { yybegin(STATEMENT_VALUE); return BitBakeTypes.STATEMENT; }
<YYINITIAL> ^"inherit" { yybegin(INCLUDE_VALUE); return BitBakeTypes.INHERIT; }
<YYINITIAL> ^"include" { yybegin(INCLUDE_VALUE); return BitBakeTypes.INCLUDE; }
<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" { 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*)*([\w\.\-\+\{\}\$]+)?\s*\(\s*\)\s*\{$ { 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); }

<FUNCTION_NAME> {
"python" { return BitBakeTypes.PYTHON; }
"fakeroot" { return BitBakeTypes.FAKEROOT; }
"(" { return BitBakeTypes.LB; }
")" { return BitBakeTypes.RB; }
"{" { yybegin(FUNCTION_VALUE); return BitBakeTypes.LBB; }
{OVERRIDE} { return BitBakeTypes.OVERRIDE; }
[\w\.\-\+\{\}\$]+ { return BitBakeTypes.BB_FUNCTION_NAME; }
{WHITE_SPACE}+ { return TokenType.WHITE_SPACE; }
}
Expand All @@ -62,6 +74,8 @@ KEY_CHARACTER=[^?=:+.\ \n\t\f\\\(\)] | "\\ "

<PY_FUNCTION> {
\n\n+ { yybegin(YYINITIAL); return BitBakeTypes.RBB; }
<<EOF>> { yybegin(YYINITIAL); return BitBakeTypes.RBB; }
{CRLF} | {WHITE_SPACE}+ { return TokenType.WHITE_SPACE; }
[^] { return BitBakeTypes.FB; }
}

Expand All @@ -70,16 +84,45 @@ KEY_CHARACTER=[^?=:+.\ \n\t\f\\\(\)] | "\\ "
[^] { return BitBakeTypes.FB; }
}

<YYINITIAL> {KEY_CHARACTER}+ { return BitBakeTypes.KEY; }
<YYINITIAL> {ASSIGNMENT_OPERATOR} { yybegin(WAITING_VALUE); return BitBakeTypes.OPERATOR; }
<WAITING_VALUE> {WHITE_SPACE}+ { return TokenType.WHITE_SPACE; }
<WAITING_VALUE> {STR_START_CHAR}{VALUE_CHARACTER}*{STR_START_CHAR} { yybegin(YYINITIAL); return BitBakeTypes.VALUE; }
<EXPORT_STATEMENT> {
{VALUE} { yybegin(YYINITIAL); return BitBakeTypes.VALUE; }
{KEY_CHARACTER}+ { return BitBakeTypes.KEY; }
{ASSIGNMENT_OPERATOR} { return BitBakeTypes.OPERATOR; }
{CRLF}+ { yybegin(YYINITIAL); return TokenType.WHITE_SPACE; }
{WS}+ { return TokenType.WHITE_SPACE; }
}

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

<YYINITIAL> {END_OF_LINE_COMMENT} { yybegin(YYINITIAL); return BitBakeTypes.COMMENT; }
({CRLF}|{WHITE_SPACE})+ { return TokenType.WHITE_SPACE; }
<LINE_WITH_FLAG> {
{KEY_CHARACTER}+ { return BitBakeTypes.KEY; }
{WHITE_SPACE}+ { return TokenType.BAD_CHARACTER; }
\[ { yybegin(FLAG); return BitBakeTypes.ALB; }
}

<FLAG> {
[\w\.\-\+]+ { return BitBakeTypes.FLAG; }
\] { 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; }
<YYINITIAL> {ASSIGNMENT_OPERATOR} { yybegin(WAITING_VALUE); return BitBakeTypes.OPERATOR; }
<YYINITIAL> {CRLF} | {WHITE_SPACE}+ { return TokenType.WHITE_SPACE; }
<WAITING_VALUE> {WHITE_SPACE}+ { return TokenType.WHITE_SPACE; }
<WAITING_VALUE> {VALUE} { yybegin(YYINITIAL); return BitBakeTypes.VALUE; }

[^] { return TokenType.BAD_CHARACTER; }
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host, @NotNul
return;
}
final Language language = ((LanguageFileType) fileType).getLanguage();
injectionPlacesRegistrar.addPlace(language, new TextRange(0, host.getText().length()), "\n", "\n");
String text = host.getText();
injectionPlacesRegistrar.addPlace(language, new TextRange(text.indexOf('{') + 2, text.lastIndexOf('}')), "\n", "\n");

} else if ((host instanceof BitBakeNativePythonFunctionImpl) || (host instanceof BitBakePythonFunctionImpl)) {

Expand All @@ -46,7 +47,7 @@ public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host, @NotNul
injectionPlacesRegistrar.addPlace(language, new TextRange(0, host.getText().length()), "import oe\nimport bb\nimport os\n\n", "\n");
} else if (host instanceof BitBakePythonFunctionImpl) {
String text = host.getText();
injectionPlacesRegistrar.addPlace(language, new TextRange(text.indexOf('{') + 2, text.lastIndexOf('}')), "import oe\nimport bb\nimport os\n\ndef name(d):", "\n");
injectionPlacesRegistrar.addPlace(language, new TextRange(text.indexOf('{') + 2, text.lastIndexOf('}')), "import oe\nimport bb\nimport os\n\ndef name(d):\n", "\n");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,23 @@ public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
return COMMENT_KEYS;
} else if (tokenType.equals(BitBakeTypes.BB_FUNCTION_NAME)) {
return FUNCTION_NAME_KEYS;
} else if (tokenType.equals(BitBakeTypes.INCLUDE) || tokenType.equals(BitBakeTypes.INHERIT) || tokenType.equals(BitBakeTypes.REQUIRE)
|| tokenType.equals(BitBakeTypes.PYTHON) || tokenType.equals(BitBakeTypes.EXPORT) || tokenType.equals(BitBakeTypes.STATEMENT)) {
} else if (tokenType.equals(BitBakeTypes.INCLUDE) ||
tokenType.equals(BitBakeTypes.INHERIT) ||
tokenType.equals(BitBakeTypes.REQUIRE) ||
tokenType.equals(BitBakeTypes.PYTHON) ||
tokenType.equals(BitBakeTypes.EXPORT) ||
tokenType.equals(BitBakeTypes.EXPORT_FUNC) ||
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;
} else if (tokenType.equals(BitBakeTypes.FAKEROOT)) {
return KEYWORD_KEYS;
} else if (tokenType.equals(BitBakeTypes.FLAG)) {
return VARIABLE_VALUE_KEYS;
} else if (tokenType.equals(TokenType.BAD_CHARACTER)) {
return BAD_CHAR_KEYS;
} else {
Expand Down

0 comments on commit e99f932

Please sign in to comment.