Skip to content

Commit

Permalink
Merge branch 'master' into refa-v0.7.0-update
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Mar 5, 2021
2 parents 993ce35 + 42d24fa commit 97e27e5
Show file tree
Hide file tree
Showing 18 changed files with 526 additions and 101 deletions.
23 changes: 22 additions & 1 deletion components/prism-cpp.js
@@ -1,6 +1,7 @@
(function (Prism) {

var keyword = /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char8_t|char16_t|char32_t|class|compl|concept|const|consteval|constexpr|constinit|const_cast|continue|co_await|co_return|co_yield|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|float|for|friend|goto|if|inline|int|int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|long|mutable|namespace|new|noexcept|nullptr|operator|private|protected|public|register|reinterpret_cast|requires|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/;
var keyword = /\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char8_t|char16_t|char32_t|class|compl|concept|const|consteval|constexpr|constinit|const_cast|continue|co_await|co_return|co_yield|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|final|float|for|friend|goto|if|import|inline|int|int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|long|module|mutable|namespace|new|noexcept|nullptr|operator|override|private|protected|public|register|reinterpret_cast|requires|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/;
var modName = /\b(?!<keyword>)\w+(?:\s*\.\s*\w+)*\b/.source.replace(/<keyword>/g, function () { return keyword.source; })

Prism.languages.cpp = Prism.languages.extend('c', {
'class-name': [
Expand Down Expand Up @@ -31,6 +32,26 @@
});

Prism.languages.insertBefore('cpp', 'string', {
'module': {
// https://en.cppreference.com/w/cpp/language/modules
pattern: RegExp(
/(\b(?:module|import)\s+)/.source +
'(?:' +
// header-name
/"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|<[^<>\r\n]*>/.source +
'|' +
// module name or partition or both
/<mod-name>(?:\s*:\s*<mod-name>)?|:\s*<mod-name>/.source.replace(/<mod-name>/g, function () { return modName; }) +
')'
),
lookbehind: true,
greedy: true,
inside: {
'string': /^[<"][\s\S]+/,
'operator': /:/,
'punctuation': /\./
}
},
'raw-string': {
pattern: /R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,
alias: 'string',
Expand Down
2 changes: 1 addition & 1 deletion components/prism-cpp.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 17 additions & 20 deletions components/prism-elixir.js
@@ -1,5 +1,15 @@
Prism.languages.elixir = {
'comment': /#.*/m,
'doc': {
pattern: /@(?:doc|moduledoc)\s+(?:("""|''')[\s\S]*?\1|("|')(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2)/,
inside: {
'attribute': /^@\w+/,
'string': /['"][\s\S]+/
}
},
'comment': {
pattern: /#.*/m,
greedy: true
},
// ~r"""foo""" (multi-line), ~r'''foo''' (multi-line), ~r/foo/, ~r|foo|, ~r"foo", ~r'foo', ~r(foo), ~r[foo], ~r{foo}, ~r<foo>
'regex': {
pattern: /~[rR](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([\/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|[^\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[uismxfr]*/,
Expand Down Expand Up @@ -36,14 +46,12 @@ Prism.languages.elixir = {
lookbehind: true,
alias: 'symbol'
},
'module': {
pattern: /\b[A-Z]\w*\b/,
alias: 'class-name'
},
// Look-ahead prevents bad highlighting of the :: operator
'attr-name': /\w+\??:(?!:)/,
'capture': {
// Look-behind prevents bad highlighting of the && operator
pattern: /(^|[^&])&(?:[^&\s\d()][^\s()]*|(?=\())/,
lookbehind: true,
alias: 'function'
},
'argument': {
// Look-behind prevents bad highlighting of the && operator
pattern: /(^|[^&])&\d+/,
Expand All @@ -54,8 +62,9 @@ Prism.languages.elixir = {
pattern: /@\w+/,
alias: 'variable'
},
'function': /\b[_a-zA-Z]\w*[?!]?(?:(?=\s*(?:\.\s*)?\()|(?=\/\d+))/,
'number': /\b(?:0[box][a-f\d_]+|\d[\d_]*)(?:\.[\d_]+)?(?:e[+-]?[\d_]+)?\b/i,
'keyword': /\b(?:after|alias|and|case|catch|cond|def(?:callback|exception|impl|module|p|protocol|struct|delegate)?|do|else|end|fn|for|if|import|not|or|require|rescue|try|unless|use|when)\b/,
'keyword': /\b(?:after|alias|and|case|catch|cond|def(?:callback|exception|impl|module|p|protocol|struct|delegate)?|do|else|end|fn|for|if|import|not|or|raise|require|rescue|try|unless|use|when)\b/,
'boolean': /\b(?:true|false|nil)\b/,
'operator': [
/\bin\b|&&?|\|[|>]?|\\\\|::|\.\.\.?|\+\+?|-[->]?|<[-=>]|>=|!==?|\B!|=(?:==?|[>~])?|[*\/^]/,
Expand All @@ -73,18 +82,6 @@ Prism.languages.elixir = {
'punctuation': /<<|>>|[.,%\[\]{}()]/
};

Prism.languages.insertBefore('elixir', 'keyword', {
'module': {
pattern: /\b(defmodule\s)[A-Z][\w.\\]+/,
lookbehind: true,
alias: 'class-name'
},
'function': {
pattern: /\b(defp?\s)[\w.\\]+/,
lookbehind: true
}
});

Prism.languages.elixir.string.forEach(function(o) {
o.inside = {
'interpolation': {
Expand Down
2 changes: 1 addition & 1 deletion components/prism-elixir.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 38 additions & 7 deletions components/prism-ini.js
@@ -1,11 +1,42 @@
Prism.languages.ini= {
'comment': /^[ \t]*[;#].*$/m,
'selector': /^[ \t]*\[.*?\]/m,
'constant': /^[ \t]*[^\s=]+?(?=[ \t]*=)/m,
'attr-value': {
pattern: /=.*/,

/**
* The component mimics the behavior of the Win32 API parser.
*
* @see {@link https://github.com/PrismJS/prism/issues/2775#issuecomment-787477723}
*/

'comment': {
pattern: /(^[ \f\t\v]*)[#;][^\n\r]*/m,
lookbehind: true
},
'header': {
pattern: /(^[ \f\t\v]*)\[[^\n\r\]]*\]?/m,
lookbehind: true,
inside: {
'punctuation': /^[=]/
'section-name': {
pattern: /(^\[[ \f\t\v]*)[^ \f\t\v\]]+(?:[ \f\t\v]+[^ \f\t\v\]]+)*/,
lookbehind: true,
alias: 'selector'
},
'punctuation': /\[|\]/
}
}
},
'key': {
pattern: /(^[ \f\t\v]*)[^ \f\n\r\t\v=]+(?:[ \f\t\v]+[^ \f\n\r\t\v=]+)*(?=[ \f\t\v]*=)/m,
lookbehind: true,
alias: 'attr-name'
},
'value': {
pattern: /(=[ \f\t\v]*)[^ \f\n\r\t\v]+(?:[ \f\t\v]+[^ \f\n\r\t\v]+)*/,
lookbehind: true,
alias: 'attr-value',
inside: {
'inner-value': {
pattern: /^("|').+(?=\1$)/,
lookbehind: true
}
}
},
'punctuation': /=/
};
2 changes: 1 addition & 1 deletion components/prism-ini.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tests/languages/cpp/keyword_feature.test
Expand Up @@ -33,20 +33,24 @@ enum;
explicit
export
extern
final
float
for
friend
goto
if
import;
inline
int
long
module;
mutable
namespace
new
noexcept
nullptr
operator
override
private
protected
public
Expand Down Expand Up @@ -125,20 +129,24 @@ uint64_t
["keyword", "explicit"],
["keyword", "export"],
["keyword", "extern"],
["keyword", "final"],
["keyword", "float"],
["keyword", "for"],
["keyword", "friend"],
["keyword", "goto"],
["keyword", "if"],
["keyword", "import"], ["punctuation", ";"],
["keyword", "inline"],
["keyword", "int"],
["keyword", "long"],
["keyword", "module"], ["punctuation", ";"],
["keyword", "mutable"],
["keyword", "namespace"],
["keyword", "new"],
["keyword", "noexcept"],
["keyword", "nullptr"],
["keyword", "operator"],
["keyword", "override"],
["keyword", "private"],
["keyword", "protected"],
["keyword", "public"],
Expand Down
116 changes: 116 additions & 0 deletions tests/languages/cpp/module_feature.test
@@ -0,0 +1,116 @@
export module speech;

export const char* get_phrase_en() {
return "Hello, world!";
}

export module speech;

export import :english;
export import :spanish;

export module speech:english;

import speech;
import :PrivWidget;

import <iostream>;
import <cstdlib>;
import "foo.h";
import <baz.h>;

module : private;

----------------------------------------------------

[
["keyword", "export"],
["keyword", "module"],
["module", ["speech"]],
["punctuation", ";"],

["keyword", "export"],
["keyword", "const"],
["keyword", "char"],
["operator", "*"],
["function", "get_phrase_en"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", "{"],

["keyword", "return"],
["string", "\"Hello, world!\""],
["punctuation", ";"],

["punctuation", "}"],

["keyword", "export"],
["keyword", "module"],
["module", ["speech"]],
["punctuation", ";"],

["keyword", "export"],
["keyword", "import"],
["module", [
["operator", ":"],
"english"
]],
["punctuation", ";"],

["keyword", "export"],
["keyword", "import"],
["module", [
["operator", ":"],
"spanish"
]],
["punctuation", ";"],

["keyword", "export"],
["keyword", "module"],
["module", [
"speech",
["operator", ":"],
"english"
]],
["punctuation", ";"],

["keyword", "import"],
["module", ["speech"]],
["punctuation", ";"],

["keyword", "import"],
["module", [
["operator", ":"],
"PrivWidget"
]],
["punctuation", ";"],

["keyword", "import"],
["module", [
["string", "<iostream>"]
]],
["punctuation", ";"],

["keyword", "import"],
["module", [
["string", "<cstdlib>"]
]],
["punctuation", ";"],

["keyword", "import"],
["module", [
["string", "\"foo.h\""]
]],
["punctuation", ";"],

["keyword", "import"],
["module", [
["string", "<baz.h>"]
]],
["punctuation", ";"],

["keyword", "module"],
["operator", ":"],
["keyword", "private"],
["punctuation", ";"]
]
6 changes: 2 additions & 4 deletions tests/languages/elixir/attribute_feature.test
Expand Up @@ -8,12 +8,10 @@ foobar

[
["attribute", "@vsn"], ["number", "2"],
["attribute", "@moduledoc"], ["string", [
"\"\"\"\r\nfoobar\r\n\"\"\""
]],
["doc", [ ["attribute", "@moduledoc" ], [ "string", "\"\"\"\r\nfoobar\r\n\"\"\"" ] ] ],
["attribute", "@tag"], ["atom", ":external"]
]

----------------------------------------------------

Checks for module attributes.
Checks for module attributes.

0 comments on commit 97e27e5

Please sign in to comment.