From 04c1c193260079008614d93c4c87d3810bbf4a36 Mon Sep 17 00:00:00 2001 From: Ziwei Wang Date: Thu, 12 Oct 2023 15:42:05 -0400 Subject: [PATCH 1/2] Chore: Update grammar rule regex 1. Use boundary anchor 2. Add python keywords --- client/syntaxes/bitbake.tmLanguage.json | 49 +++++++++++++------------ 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/client/syntaxes/bitbake.tmLanguage.json b/client/syntaxes/bitbake.tmLanguage.json index 85fe371f..91ea849e 100644 --- a/client/syntaxes/bitbake.tmLanguage.json +++ b/client/syntaxes/bitbake.tmLanguage.json @@ -17,9 +17,6 @@ "end": "(?=\\])", "name": "source.python" }, - { - "include": "#boolean" - }, { "include": "#numeric" }, @@ -49,7 +46,7 @@ "keywords": { "patterns": [ { - "match": "\\s*(include|from|import|require|inherit|addtask|deltask|after|before|export|echo|if|fi|else|return|unset|print|or|fakeroot|EXPORT_FUNCTIONS|INHERIT)(?=\\s+|\\s*:)", + "match": "\\b(include|require|inherit|addtask|deltask|after|before|export|echo|if|fi|unset|print|fakeroot|EXPORT_FUNCTIONS|INHERIT)\\b", "captures": { "1": { "name": "keyword.control.bb" @@ -57,7 +54,10 @@ } }, { - "match": "\\s*(def)(?=\\s+)", + "include": "#python-keywords" + }, + { + "match": "\\s*(python)(?=\\s+|\\s*\\()", "captures": { "1": { "name": "storage.type.function.python.bb" @@ -65,30 +65,40 @@ } }, { - "match": "\\s*(python)(?=\\s+|\\s*\\()", + "match": "\\b(bbplain|bb|self)\\b(?=\\s+|\\.)", "captures": { "1": { - "name": "storage.type.function.python.bb" + "name": "support.class.built-in-object.bb" } } }, { - "match": "(bbplain|bb|self)(?=\\s+|\\.)", + "match": "(?<=(import|inherit|from)\\s+)([a-zA-Z_][\\w_]*)(?=\\s+)", + "name": "support.class.bb" + } + ] + }, + "python-keywords": { + "patterns": [ + { + "match": "\\b(if|elif|else|for|while|break|continue|return|yield|try|except|finally|raise|assert|import|from|as|pass|del|with|async|await)\\b", "captures": { "1": { - "name": "support.class.built-in-object.bb" + "name": "keyword.control.bb" } } }, { - "begin": "(?<=import|inherit)(?=\\s+)", - "end": "\\n", - "name": "support.class.bb", - "patterns": [ - { - "include": "#variable-reference" + "match": "\\b(def|class|global|nonlocal|and|or|not|in|is|lambda)\\b", + "captures": { + "1": { + "name": "storage.type.function.python.bb" } - ] + } + }, + { + "match": "\\b(True|False)\\b", + "name": "constant.language.python.bb" } ] }, @@ -175,9 +185,6 @@ { "include": "#keywords" }, - { - "include": "#boolean" - }, { "match": "(\\[)", "name": "meta.embedded.brackets.begin.bb" @@ -232,10 +239,6 @@ "parenthesis-close": { "match": "\\)", "name": "meta.embedded.parenthesis.close.bb" - }, - "boolean": { - "match": "(? Date: Thu, 12 Oct 2023 15:42:55 -0400 Subject: [PATCH 2/2] Chore: Update test cases for grammar rule changes --- client/test/grammars/snaps/keywords.bb | 94 +++++++-- client/test/grammars/test-cases/keywords.bb | 179 ++++++++++++++---- .../grammars/test-cases/nested-patterns.bb | 4 +- client/test/grammars/test-cases/strings.bb | 10 +- 4 files changed, 231 insertions(+), 56 deletions(-) diff --git a/client/test/grammars/snaps/keywords.bb b/client/test/grammars/snaps/keywords.bb index 92b89469..ab956e56 100644 --- a/client/test/grammars/snaps/keywords.bb +++ b/client/test/grammars/snaps/keywords.bb @@ -1,4 +1,82 @@ -from foo1 import bar1 +# Keywords (Should target bitbake keywords only and exclude python and shell keywords) + +python do_foo(){ + from foo1 import bar1 + + if + + whatif + + ifnot + + elif + + else + + for + + while + + break + + continue + + return + + yield + + try + + except + + finally + + raise + + assert + + import + + from + + as + + pass + + del + + with + + async + + await + + def + + class + + global + + nonlocal + + and + + or + + not + + in + + is + + lambda + + self + + True + + False +} require foo2 @@ -16,24 +94,14 @@ EXPORT_FUNCTIONS functionname INHERIT += "autotools pkgconfig" -fakeroot python foo() {} - bbplain bb -self +fakeroot python foo() {} def bar3(): pass -python bar4(){} - - -True - -False - -def bar2(var1 = True): - pass +python (){} diff --git a/client/test/grammars/test-cases/keywords.bb b/client/test/grammars/test-cases/keywords.bb index 9a8fa42a..8022d052 100644 --- a/client/test/grammars/test-cases/keywords.bb +++ b/client/test/grammars/test-cases/keywords.bb @@ -1,61 +1,168 @@ -# SYNTAX TEST "source.bb" "keywords" +# SYNTAX TEST "source.bb" "bitbake-keywords" ->from foo import bar -#^^^^ source.bb keyword.control.bb -# ^^^^^^ source.bb keyword.control.bb - ->require foo +># BitBake Keywords +#^ source.bb comment.line.bb comment.line.number-sign.bb +# ^^^^^^^^^^^^^^^^^ source.bb comment.line.bb comment.line.text.bb + +>python do_foo(){ +#^^^^^^ source.bb storage.type.function.python.bb +> from foo1 import bar1 +# ^^^^ source.bb keyword.control.bb +# ^^^^^^ source.bb keyword.control.bb + +> if +# ^^ source.bb keyword.control.bb + +> whatif +# ^^ - keyword.control.bb + +> ifnot +# ^^ - keyword.control.bb + +> elif +# ^^^^ source.bb keyword.control.bb + +> else +# ^^^^ source.bb keyword.control.bb + +> for +# ^^^ source.bb keyword.control.bb + +> while +# ^^^^^ source.bb keyword.control.bb + +> break +# ^^^^^ source.bb keyword.control.bb + +> continue +# ^^^^^^^^ source.bb keyword.control.bb + +> return +# ^^^^^^ source.bb keyword.control.bb + +> yield +# ^^^^^ source.bb keyword.control.bb + +> try +# ^^^ source.bb keyword.control.bb + +> except +# ^^^^^^ source.bb keyword.control.bb + +> finally +# ^^^^^^^ source.bb keyword.control.bb + +> raise +# ^^^^^ source.bb keyword.control.bb + +> assert +# ^^^^^^ source.bb keyword.control.bb + +> import +# ^^^^^^ source.bb keyword.control.bb + +> from +# ^^^^ source.bb keyword.control.bb + +> as +# ^^ source.bb keyword.control.bb + +> pass +# ^^^^ source.bb keyword.control.bb + +> del +# ^^^ source.bb keyword.control.bb + +> with +# ^^^^ source.bb keyword.control.bb + +> async +# ^^^^^ source.bb keyword.control.bb + +> await +# ^^^^^ source.bb keyword.control.bb + +> def +# ^^^ source.bb storage.type.function.python.bb + +> class +# ^^^^^ source.bb storage.type.function.python.bb + +> global +# ^^^^^^ source.bb storage.type.function.python.bb + +> nonlocal +# ^^^^^^^^ source.bb storage.type.function.python.bb + +> and +# ^^^ source.bb storage.type.function.python.bb + +> or +# ^^ source.bb storage.type.function.python.bb + +> not +# ^^^ source.bb storage.type.function.python.bb + +> in +# ^^ source.bb storage.type.function.python.bb + +> is +# ^^ source.bb storage.type.function.python.bb + +> lambda +# ^^^^^^ source.bb storage.type.function.python.bb + +> self +# ^^^^ source.bb support.class.built-in-object.bb + +> True +# ^^^^ source.bb constant.language.python.bb + +> False +# ^^^^^ source.bb constant.language.python.bb +>} + +>require foo2 #^^^^^^^ source.bb keyword.control.bb - ->inherit foo + +>inherit fo3 #^^^^^^^ source.bb keyword.control.bb - + >addtask printdate after do_fetch before do_build #^^^^^^^ source.bb keyword.control.bb # ^^^^^ source.bb keyword.control.bb # ^^^^^^ source.bb keyword.control.bb - + >deltask printdate #^^^^^^^ source.bb keyword.control.bb - + >export BB_ENV_PASSTHROUGH_ADDITIONS="$BB_ENV_PASSTHROUGH_ADDITIONS CCACHE_DIR" #^^^^^^ source.bb keyword.control.bb - + >unset DATE #^^^^^ source.bb keyword.control.bb - + >EXPORT_FUNCTIONS functionname #^^^^^^^^^^^^^^^^ source.bb keyword.control.bb - + >INHERIT += "autotools pkgconfig" #^^^^^^^ source.bb keyword.control.bb - ->fakeroot python foo() {} -#^^^^^^^^ source.bb keyword.control.bb >bbplain #^^^^^^^ source.bb support.class.built-in-object.bb - ->bb -#^^ source.bb support.class.built-in-object.bb - ->self -#^^^^ source.bb support.class.built-in-object.bb - + +>bb +#^^ support.class.built-in-object.bb + +>fakeroot python foo() {} +#^^^^^^^^ source.bb keyword.control.bb +# ^^^^^^ source.bb storage.type.function.python.bb + >def bar3(): #^^^ source.bb storage.type.function.python.bb > pass +# ^^^^ source.bb keyword.control.bb ->python bar4(){} +>python (){} #^^^^^^ source.bb storage.type.function.python.bb - ->True -#^^^^ source.bb constant.language.python.bb - ->False -#^^^^^ source.bb constant.language.python.bb - ->def bar2(var1 = True): -# ^^^^ source.bb constant.language.python.bb -> pass - \ No newline at end of file + diff --git a/client/test/grammars/test-cases/nested-patterns.bb b/client/test/grammars/test-cases/nested-patterns.bb index d490b564..55018b3a 100644 --- a/client/test/grammars/test-cases/nested-patterns.bb +++ b/client/test/grammars/test-cases/nested-patterns.bb @@ -31,7 +31,7 @@ # ^ source.bb string.quoted.double.bb constant.numeric.bb # ^ source.bb string.quoted.double.bb meta.embedded.brackets.end.bb # ^ source.bb string.quoted.double.bb -# ^^ source.bb string.quoted.double.bb keyword.control.bb +# ^^ source.bb string.quoted.double.bb storage.type.function.python.bb # ^ source.bb string.quoted.double.bb # ^ source.bb string.quoted.double.bb string.quoted.single.bb # ^^^^^^^^^^^^^^ source.bb string.quoted.double.bb string.quoted.single.bb @@ -77,7 +77,7 @@ # ^^^^^ source.bb variable.other.names.bb # ^ source.bb # ^^^^^^ source.bb keyword.control.bb -# ^^^^^^^^ source.bb support.class.bb +# ^^^^^^^ source.bb support.class.bb > print("The name of the Event is %s" % getName(e)) #^^^^ source.bb # ^^^^^ source.bb entity.name.function.python.bb diff --git a/client/test/grammars/test-cases/strings.bb b/client/test/grammars/test-cases/strings.bb index 87a2e0ee..f53bde1c 100644 --- a/client/test/grammars/test-cases/strings.bb +++ b/client/test/grammars/test-cases/strings.bb @@ -112,11 +112,11 @@ #^ source.bb >inherit ${@ 'classname' if condition else ''} -# ^ source.bb support.class.bb string.quoted.single.bb -# ^^^^^^^^^ source.bb support.class.bb string.quoted.single.bb -# ^ source.bb support.class.bb string.quoted.single.bb -# ^ source.bb support.class.bb string.quoted.single.bb -# ^ source.bb support.class.bb string.quoted.single.bb +# ^ source.bb string.quoted.single.bb +# ^^^^^^^^^ source.bb string.quoted.single.bb +# ^ source.bb string.quoted.single.bb +# ^ source.bb string.quoted.single.bb +# ^ source.bb string.quoted.single.bb >INHERIT += "autotools pkgconfig" # ^ source.bb string.quoted.double.bb