From d7017bebb3d70f3ef39bbe340a3f224ba3d9304c Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Tue, 5 Oct 2021 21:17:13 +0200 Subject: [PATCH] Birb: Fixed class name false positives (#3111) --- components/prism-birb.js | 2 +- components/prism-birb.min.js | 2 +- tests/languages/birb/class-name_feature.test | 63 ++++++++++++++++++++ tests/languages/birb/function_feature.test | 4 +- tests/languages/birb/keyword_feature.test | 62 ++++++++++++------- 5 files changed, 108 insertions(+), 25 deletions(-) create mode 100644 tests/languages/birb/class-name_feature.test diff --git a/components/prism-birb.js b/components/prism-birb.js index 6937117d9f..ff994d8a5d 100644 --- a/components/prism-birb.js +++ b/components/prism-birb.js @@ -7,7 +7,7 @@ Prism.languages.birb = Prism.languages.extend('clike', { /\b[A-Z](?:[\d_]*[a-zA-Z]\w*)?\b/, // matches variable and function return types (parameters as well). - /\b[A-Z]\w*(?=\s+\w+\s*[;,=()])/ + /\b(?:[A-Z]\w*|(?!(?:var|void)\b)[a-z]\w*)(?=\s+\w+\s*[;,=()])/ ], 'keyword': /\b(?:assert|break|case|class|const|default|else|enum|final|follows|for|grab|if|nest|new|next|noSeeb|return|static|switch|throw|var|void|while)\b/, 'operator': /\+\+|--|&&|\|\||<<=?|>>=?|~(?:\/=?)?|[+\-*\/%&^|=!<>]=?|\?|:/, diff --git a/components/prism-birb.min.js b/components/prism-birb.min.js index 660a5401f3..c61079e1ea 100644 --- a/components/prism-birb.min.js +++ b/components/prism-birb.min.js @@ -1 +1 @@ -Prism.languages.birb=Prism.languages.extend("clike",{string:{pattern:/r?("|')(?:\\.|(?!\1)[^\\])*\1/,greedy:!0},"class-name":[/\b[A-Z](?:[\d_]*[a-zA-Z]\w*)?\b/,/\b[A-Z]\w*(?=\s+\w+\s*[;,=()])/],keyword:/\b(?:assert|break|case|class|const|default|else|enum|final|follows|for|grab|if|nest|new|next|noSeeb|return|static|switch|throw|var|void|while)\b/,operator:/\+\+|--|&&|\|\||<<=?|>>=?|~(?:\/=?)?|[+\-*\/%&^|=!<>]=?|\?|:/,variable:/\b[a-z_]\w*\b/}),Prism.languages.insertBefore("birb","function",{metadata:{pattern:/<\w+>/,greedy:!0,alias:"symbol"}}); \ No newline at end of file +Prism.languages.birb=Prism.languages.extend("clike",{string:{pattern:/r?("|')(?:\\.|(?!\1)[^\\])*\1/,greedy:!0},"class-name":[/\b[A-Z](?:[\d_]*[a-zA-Z]\w*)?\b/,/\b(?:[A-Z]\w*|(?!(?:var|void)\b)[a-z]\w*)(?=\s+\w+\s*[;,=()])/],keyword:/\b(?:assert|break|case|class|const|default|else|enum|final|follows|for|grab|if|nest|new|next|noSeeb|return|static|switch|throw|var|void|while)\b/,operator:/\+\+|--|&&|\|\||<<=?|>>=?|~(?:\/=?)?|[+\-*\/%&^|=!<>]=?|\?|:/,variable:/\b[a-z_]\w*\b/}),Prism.languages.insertBefore("birb","function",{metadata:{pattern:/<\w+>/,greedy:!0,alias:"symbol"}}); \ No newline at end of file diff --git a/tests/languages/birb/class-name_feature.test b/tests/languages/birb/class-name_feature.test new file mode 100644 index 0000000000..946c751f70 --- /dev/null +++ b/tests/languages/birb/class-name_feature.test @@ -0,0 +1,63 @@ +class Birb { + String name = "Birb"; + int age = 5; + bool isMale = true; + + String getName() { + return name; + } +} + +List list = ["Seeb", 10, false]; + +---------------------------------------------------- + +[ + ["keyword", "class"], + ["class-name", "Birb"], + ["punctuation", "{"], + + ["class-name", "String"], + ["variable", "name"], + ["operator", "="], + ["string", "\"Birb\""], + ["punctuation", ";"], + + ["class-name", "int"], + ["variable", "age"], + ["operator", "="], + ["number", "5"], + ["punctuation", ";"], + + ["class-name", "bool"], + ["variable", "isMale"], + ["operator", "="], + ["boolean", "true"], + ["punctuation", ";"], + + ["class-name", "String"], + ["function", "getName"], + ["punctuation", "("], + ["punctuation", ")"], + ["punctuation", "{"], + + ["class-name", "return"], + ["variable", "name"], + ["punctuation", ";"], + + ["punctuation", "}"], + + ["punctuation", "}"], + + ["class-name", "List"], + ["variable", "list"], + ["operator", "="], + ["punctuation", "["], + ["string", "\"Seeb\""], + ["punctuation", ","], + ["number", "10"], + ["punctuation", ","], + ["boolean", "false"], + ["punctuation", "]"], + ["punctuation", ";"] +] diff --git a/tests/languages/birb/function_feature.test b/tests/languages/birb/function_feature.test index 9b61b4b65a..ab0b6f823e 100644 --- a/tests/languages/birb/function_feature.test +++ b/tests/languages/birb/function_feature.test @@ -7,7 +7,7 @@ foo(0); ["keyword", "void"], ["function", "foo"], ["punctuation", "("], - ["variable", "int"], + ["class-name", "int"], ["variable", "a"], ["punctuation", ")"], ["punctuation", "{"], @@ -22,4 +22,4 @@ foo(0); ---------------------------------------------------- -Checks for functions. \ No newline at end of file +Checks for functions. diff --git a/tests/languages/birb/keyword_feature.test b/tests/languages/birb/keyword_feature.test index 8d1c1a3777..3105071968 100644 --- a/tests/languages/birb/keyword_feature.test +++ b/tests/languages/birb/keyword_feature.test @@ -1,37 +1,57 @@ -assert break case +assert; +break; +case; class; -const default -else enum -final +const; +default; +else; +enum; +final; follows; -for grab -if nest +for; +grab; +if; +nest; next; new; -noSeeb return -static switch -throw var -void while +noSeeb; +return; +static; +switch; +throw; +var; +void; +while; ---------------------------------------------------- [ - ["keyword", "assert"], ["keyword", "break"], ["keyword", "case"], + ["keyword", "assert"], ["punctuation", ";"], + ["keyword", "break"], ["punctuation", ";"], + ["keyword", "case"], ["punctuation", ";"], ["keyword", "class"], ["punctuation", ";"], - ["keyword", "const"], ["keyword", "default"], - ["keyword", "else"], ["keyword", "enum"], - ["keyword", "final"], + ["keyword", "const"], ["punctuation", ";"], + ["keyword", "default"], ["punctuation", ";"], + ["keyword", "else"], ["punctuation", ";"], + ["keyword", "enum"], ["punctuation", ";"], + ["keyword", "final"], ["punctuation", ";"], ["keyword", "follows"], ["punctuation", ";"], - ["keyword", "for"], ["keyword", "grab"], - ["keyword", "if"], ["keyword", "nest"], + ["keyword", "for"], ["punctuation", ";"], + ["keyword", "grab"], ["punctuation", ";"], + ["keyword", "if"], ["punctuation", ";"], + ["keyword", "nest"], ["punctuation", ";"], ["keyword", "next"], ["punctuation", ";"], ["keyword", "new"], ["punctuation", ";"], - ["keyword", "noSeeb"], ["keyword", "return"], - ["keyword", "static"], ["keyword", "switch"], - ["keyword", "throw"], ["keyword", "var"], - ["keyword", "void"], ["keyword", "while"] + ["keyword", "noSeeb"], ["punctuation", ";"], + ["keyword", "return"], ["punctuation", ";"], + ["keyword", "static"], ["punctuation", ";"], + ["keyword", "switch"], ["punctuation", ";"], + ["keyword", "throw"], ["punctuation", ";"], + ["keyword", "var"], ["punctuation", ";"], + ["keyword", "void"], ["punctuation", ";"], + ["keyword", "while"], ["punctuation", ";"] ] ---------------------------------------------------- -Checks for all keywords. \ No newline at end of file +Checks for all keywords.