From d1a5ce30e4d97f5156b1ed0b36c9637785355e38 Mon Sep 17 00:00:00 2001 From: Wei Ting <59229084+hoonweiting@users.noreply.github.com> Date: Mon, 14 Mar 2022 23:48:11 +0800 Subject: [PATCH] VHDL: Add `private`, `view` keywords; Distinguish `attribute` from `keyword` (#3389) --- components/prism-vhdl.js | 7 +- components/prism-vhdl.min.js | 2 +- tests/languages/vhdl/attribute_feature.test | 25 +++++++ tests/languages/vhdl/constant_feature.test | 13 ---- tests/languages/vhdl/keyword_feature.test | 72 +++------------------ 5 files changed, 40 insertions(+), 79 deletions(-) create mode 100644 tests/languages/vhdl/attribute_feature.test delete mode 100644 tests/languages/vhdl/constant_feature.test diff --git a/components/prism-vhdl.js b/components/prism-vhdl.js index c898cc5412..7426fa2ce5 100644 --- a/components/prism-vhdl.js +++ b/components/prism-vhdl.js @@ -11,9 +11,12 @@ Prism.languages.vhdl = { alias: 'function' }, 'string': /"(?:[^\\"\r\n]|\\(?:\r\n|[\s\S]))*"/, - 'constant': /\b(?:library|use)\b/i, + 'attribute': { + pattern: /\b'\w+/, + alias: 'attr-name' + }, // support for predefined attributes included - 'keyword': /\b(?:'active|'ascending|'base|'delayed|'driving|'driving_value|'event|'high|'image|'instance_name|'last_active|'last_event|'last_value|'left|'leftof|'length|'low|'path_name|'pos|'pred|'quiet|'range|'reverse_range|'right|'rightof|'simple_name|'stable|'succ|'transaction|'val|'value|access|after|alias|all|architecture|array|assert|attribute|begin|block|body|buffer|bus|case|component|configuration|constant|disconnect|downto|else|elsif|end|entity|exit|file|for|function|generate|generic|group|guarded|if|impure|in|inertial|inout|is|label|library|linkage|literal|loop|map|new|next|null|of|on|open|others|out|package|port|postponed|procedure|process|pure|range|record|register|reject|report|return|select|severity|shared|signal|subtype|then|to|transport|type|unaffected|units|until|use|variable|wait|when|while|with)\b/i, + 'keyword': /\b(?:access|after|alias|all|architecture|array|assert|attribute|begin|block|body|buffer|bus|case|component|configuration|constant|disconnect|downto|else|elsif|end|entity|exit|file|for|function|generate|generic|group|guarded|if|impure|in|inertial|inout|is|label|library|linkage|literal|loop|map|new|next|null|of|on|open|others|out|package|port|postponed|private|procedure|process|pure|range|record|register|reject|report|return|select|severity|shared|signal|subtype|then|to|transport|type|unaffected|units|until|use|variable|view|wait|when|while|with)\b/i, 'boolean': /\b(?:false|true)\b/i, 'function': /\w+(?=\()/, // decimal, based, physical, and exponential numbers supported diff --git a/components/prism-vhdl.min.js b/components/prism-vhdl.min.js index 01532288e9..17fd67df3d 100644 --- a/components/prism-vhdl.min.js +++ b/components/prism-vhdl.min.js @@ -1 +1 @@ -Prism.languages.vhdl={comment:/--.+/,"vhdl-vectors":{pattern:/\b[oxb]"[\da-f_]+"|"[01uxzwlh-]+"/i,alias:"number"},"quoted-function":{pattern:/"\S+?"(?=\()/,alias:"function"},string:/"(?:[^\\"\r\n]|\\(?:\r\n|[\s\S]))*"/,constant:/\b(?:library|use)\b/i,keyword:/\b(?:'active|'ascending|'base|'delayed|'driving|'driving_value|'event|'high|'image|'instance_name|'last_active|'last_event|'last_value|'left|'leftof|'length|'low|'path_name|'pos|'pred|'quiet|'range|'reverse_range|'right|'rightof|'simple_name|'stable|'succ|'transaction|'val|'value|access|after|alias|all|architecture|array|assert|attribute|begin|block|body|buffer|bus|case|component|configuration|constant|disconnect|downto|else|elsif|end|entity|exit|file|for|function|generate|generic|group|guarded|if|impure|in|inertial|inout|is|label|library|linkage|literal|loop|map|new|next|null|of|on|open|others|out|package|port|postponed|procedure|process|pure|range|record|register|reject|report|return|select|severity|shared|signal|subtype|then|to|transport|type|unaffected|units|until|use|variable|wait|when|while|with)\b/i,boolean:/\b(?:false|true)\b/i,function:/\w+(?=\()/,number:/'[01uxzwlh-]'|\b(?:\d+#[\da-f_.]+#|\d[\d_.]*)(?:e[-+]?\d+)?/i,operator:/[<>]=?|:=|[-+*/&=]|\b(?:abs|and|mod|nand|nor|not|or|rem|rol|ror|sla|sll|sra|srl|xnor|xor)\b/i,punctuation:/[{}[\];(),.:]/}; \ No newline at end of file +Prism.languages.vhdl={comment:/--.+/,"vhdl-vectors":{pattern:/\b[oxb]"[\da-f_]+"|"[01uxzwlh-]+"/i,alias:"number"},"quoted-function":{pattern:/"\S+?"(?=\()/,alias:"function"},string:/"(?:[^\\"\r\n]|\\(?:\r\n|[\s\S]))*"/,attribute:{pattern:/\b'\w+/,alias:"attr-name"},keyword:/\b(?:access|after|alias|all|architecture|array|assert|attribute|begin|block|body|buffer|bus|case|component|configuration|constant|disconnect|downto|else|elsif|end|entity|exit|file|for|function|generate|generic|group|guarded|if|impure|in|inertial|inout|is|label|library|linkage|literal|loop|map|new|next|null|of|on|open|others|out|package|port|postponed|private|procedure|process|pure|range|record|register|reject|report|return|select|severity|shared|signal|subtype|then|to|transport|type|unaffected|units|until|use|variable|view|wait|when|while|with)\b/i,boolean:/\b(?:false|true)\b/i,function:/\w+(?=\()/,number:/'[01uxzwlh-]'|\b(?:\d+#[\da-f_.]+#|\d[\d_.]*)(?:e[-+]?\d+)?/i,operator:/[<>]=?|:=|[-+*/&=]|\b(?:abs|and|mod|nand|nor|not|or|rem|rol|ror|sla|sll|sra|srl|xnor|xor)\b/i,punctuation:/[{}[\];(),.:]/}; \ No newline at end of file diff --git a/tests/languages/vhdl/attribute_feature.test b/tests/languages/vhdl/attribute_feature.test new file mode 100644 index 0000000000..d4df31b4e3 --- /dev/null +++ b/tests/languages/vhdl/attribute_feature.test @@ -0,0 +1,25 @@ +T'BASE +T'IMAGE(X) +A'RANGE +A'RANGE(N) +A'REVERSE_RANGE +A'REVERSE_RANGE(N) +S'DELAYED(t) +E'INSTANCE_NAME + +---------------------------------------------------- + +[ + "T", ["attribute", "'BASE"], + "\r\nT", ["attribute", "'IMAGE"], ["punctuation", "("], "X", ["punctuation", ")"], + "\r\nA", ["attribute", "'RANGE"], + "\r\nA", ["attribute", "'RANGE"], ["punctuation", "("], "N", ["punctuation", ")"], + "\r\nA", ["attribute", "'REVERSE_RANGE"], + "\r\nA", ["attribute", "'REVERSE_RANGE"], ["punctuation", "("], "N", ["punctuation", ")"], + "\r\nS", ["attribute", "'DELAYED"], ["punctuation", "("], "t", ["punctuation", ")"], + "\r\nE", ["attribute", "'INSTANCE_NAME"] +] + +---------------------------------------------------- + +Checks for attributes. diff --git a/tests/languages/vhdl/constant_feature.test b/tests/languages/vhdl/constant_feature.test deleted file mode 100644 index 345bfaa139..0000000000 --- a/tests/languages/vhdl/constant_feature.test +++ /dev/null @@ -1,13 +0,0 @@ -use -library - ----------------------------------------------------- - -[ - ["constant", "use"], - ["constant", "library"] -] - ----------------------------------------------------- - -Checks for constants. \ No newline at end of file diff --git a/tests/languages/vhdl/keyword_feature.test b/tests/languages/vhdl/keyword_feature.test index e67f11ef51..23c5af65a6 100644 --- a/tests/languages/vhdl/keyword_feature.test +++ b/tests/languages/vhdl/keyword_feature.test @@ -1,34 +1,3 @@ -A'active -A'ascending -A'base -A'delayed -A'driving -A'driving_value -A'event -A'high -A'image -A'instance_name -A'last_active -A'last_event -A'last_value -A'left -A'leftof -A'length -A'low -A'path_name -A'pos -A'pred -A'quiet -A'range -A'reverse_range -A'right -A'rightof -A'simple_name -A'stable -A'succ -A'transaction -A'val -A'value access after alias @@ -67,6 +36,7 @@ inertial inout is label +library linkage literal loop @@ -82,6 +52,7 @@ out package port postponed +private procedure process pure @@ -103,7 +74,9 @@ type unaffected units until +use variable +view wait when while @@ -112,37 +85,6 @@ with ---------------------------------------------------- [ - "A", ["keyword", "'active"], - "\r\nA", ["keyword", "'ascending"], - "\r\nA", ["keyword", "'base"], - "\r\nA", ["keyword", "'delayed"], - "\r\nA", ["keyword", "'driving"], - "\r\nA", ["keyword", "'driving_value"], - "\r\nA", ["keyword", "'event"], - "\r\nA", ["keyword", "'high"], - "\r\nA", ["keyword", "'image"], - "\r\nA", ["keyword", "'instance_name"], - "\r\nA", ["keyword", "'last_active"], - "\r\nA", ["keyword", "'last_event"], - "\r\nA", ["keyword", "'last_value"], - "\r\nA", ["keyword", "'left"], - "\r\nA", ["keyword", "'leftof"], - "\r\nA", ["keyword", "'length"], - "\r\nA", ["keyword", "'low"], - "\r\nA", ["keyword", "'path_name"], - "\r\nA", ["keyword", "'pos"], - "\r\nA", ["keyword", "'pred"], - "\r\nA", ["keyword", "'quiet"], - "\r\nA", ["keyword", "'range"], - "\r\nA", ["keyword", "'reverse_range"], - "\r\nA", ["keyword", "'right"], - "\r\nA", ["keyword", "'rightof"], - "\r\nA", ["keyword", "'simple_name"], - "\r\nA", ["keyword", "'stable"], - "\r\nA", ["keyword", "'succ"], - "\r\nA", ["keyword", "'transaction"], - "\r\nA", ["keyword", "'val"], - "\r\nA", ["keyword", "'value"], ["keyword", "access"], ["keyword", "after"], ["keyword", "alias"], @@ -181,6 +123,7 @@ with ["keyword", "inout"], ["keyword", "is"], ["keyword", "label"], + ["keyword", "library"], ["keyword", "linkage"], ["keyword", "literal"], ["keyword", "loop"], @@ -196,6 +139,7 @@ with ["keyword", "package"], ["keyword", "port"], ["keyword", "postponed"], + ["keyword", "private"], ["keyword", "procedure"], ["keyword", "process"], ["keyword", "pure"], @@ -217,7 +161,9 @@ with ["keyword", "unaffected"], ["keyword", "units"], ["keyword", "until"], + ["keyword", "use"], ["keyword", "variable"], + ["keyword", "view"], ["keyword", "wait"], ["keyword", "when"], ["keyword", "while"], @@ -226,4 +172,4 @@ with ---------------------------------------------------- -Checks for all keywords. \ No newline at end of file +Checks for all keywords.