Added support for Nevod (#2798)

This commit is contained in:
Dmitry Surkov 2021-03-18 16:54:08 +03:00 committed by GitHub
parent e32e043bf0
commit f84c49c5ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 283 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@ -807,6 +807,10 @@
"title": "NEON",
"owner": "nette"
},
"nevod": {
"title": "Nevod",
"owner": "nezaboodka"
},
"nginx": {
"title": "nginx",
"owner": "volado"

125
components/prism-nevod.js Normal file
View File

@ -0,0 +1,125 @@
Prism.languages.nevod = {
'comment': /\/\/.*|(?:\/\*[\s\S]*?(?:\*\/|$))/,
'string': {
pattern: /(?:"(?:""|[^"])*"(?!")|'(?:''|[^'])*'(?!'))!?\*?/,
greedy: true,
inside: {
'string-attrs': /!$|!\*$|\*$/,
},
},
'namespace': {
pattern: /(@namespace\s+)[a-zA-Z0-9\-.]+(?=\s*{)/,
lookbehind: true,
},
'pattern': {
pattern: /(@pattern\s+)?#?[a-zA-Z0-9\-.]+(?:\s*[(]\s*(?:~\s*)?[a-zA-Z0-9\-.]+\s*(?:,\s*(?:~\s*)?[a-zA-Z0-9\-.]*)*[)])?(?=\s*=)/,
lookbehind: true,
inside: {
'pattern-name': {
pattern: /^#?[a-zA-Z0-9\-.]+/,
alias: 'class-name',
},
'fields': {
pattern: /\(.*\)/,
inside: {
'field-name': {
pattern: /[a-zA-Z0-9\-.]+/,
alias: 'variable',
},
'punctuation': /[,()]/,
'operator': {
pattern: /~/,
alias: 'field-hidden-mark',
},
},
},
},
},
'search': {
pattern: /(@search\s+|#)[a-zA-Z0-9\-.]+(?:\.\*)?(?=\s*;)/,
alias: 'function',
lookbehind: true,
},
'keyword': /@(?:require|namespace|pattern|search|inside|outside|having|where)\b/,
'standard-pattern': {
pattern: /\b(?:Word|Punct|Symbol|Space|LineBreak|Start|End|Alpha|AlphaNum|Num|NumAlpha|Blank|WordBreak|Any)(?:\([a-zA-Z0-9\-.,\s+]*\))?/,
inside: {
'standard-pattern-name': {
pattern: /^[a-zA-Z0-9\-.]+/,
alias: 'builtin',
},
'quantifier': {
pattern: /\b\d+(?:\s*\+|\s*-\s*\d+)?(?!\w)/,
alias: 'number',
},
'standard-pattern-attr': {
pattern: /[a-zA-Z0-9\-.]+/,
alias: 'builtin',
},
'punctuation': /[,()]/,
},
},
'quantifier': {
pattern: /\b\d+(?:\s*\+|\s*-\s*\d+)?(?!\w)/,
alias: 'number',
},
'operator': [
{
pattern: /=/,
alias: 'pattern-def',
},
{
pattern: /&/,
alias: 'conjunction',
},
{
pattern: /~/,
alias: 'exception',
},
{
pattern: /\?/,
alias: 'optionality',
},
{
pattern: /[[\]]/,
alias: 'repetition',
},
{
pattern: /[{}]/,
alias: 'variation',
},
{
pattern: /[+_]/,
alias: 'sequence',
},
{
pattern: /\.{2,3}/,
alias: 'span',
},
],
'field-capture': [
{
pattern: /([a-zA-Z0-9\-.]+\s*\()\s*[a-zA-Z0-9\-.]+\s*:\s*[a-zA-Z0-9\-.]+(?:\s*,\s*[a-zA-Z0-9\-.]+\s*:\s*[a-zA-Z0-9\-.]+)*(?=\s*\))/,
lookbehind: true,
inside: {
'field-name': {
pattern: /[a-zA-Z0-9\-.]+/,
alias: 'variable',
},
'colon': /:/,
},
},
{
pattern: /[a-zA-Z0-9\-.]+\s*:/,
inside: {
'field-name': {
pattern: /[a-zA-Z0-9\-.]+/,
alias: 'variable',
},
'colon': /:/,
},
},
],
'punctuation': /[:;,()]/,
'name': /[a-zA-Z0-9\-.]+/
}

1
components/prism-nevod.min.js vendored Normal file
View File

@ -0,0 +1 @@
Prism.languages.nevod={comment:/\/\/.*|(?:\/\*[\s\S]*?(?:\*\/|$))/,string:{pattern:/(?:"(?:""|[^"])*"(?!")|'(?:''|[^'])*'(?!'))!?\*?/,greedy:!0,inside:{"string-attrs":/!$|!\*$|\*$/}},namespace:{pattern:/(@namespace\s+)[a-zA-Z0-9\-.]+(?=\s*{)/,lookbehind:!0},pattern:{pattern:/(@pattern\s+)?#?[a-zA-Z0-9\-.]+(?:\s*[(]\s*(?:~\s*)?[a-zA-Z0-9\-.]+\s*(?:,\s*(?:~\s*)?[a-zA-Z0-9\-.]*)*[)])?(?=\s*=)/,lookbehind:!0,inside:{"pattern-name":{pattern:/^#?[a-zA-Z0-9\-.]+/,alias:"class-name"},fields:{pattern:/\(.*\)/,inside:{"field-name":{pattern:/[a-zA-Z0-9\-.]+/,alias:"variable"},punctuation:/[,()]/,operator:{pattern:/~/,alias:"field-hidden-mark"}}}}},search:{pattern:/(@search\s+|#)[a-zA-Z0-9\-.]+(?:\.\*)?(?=\s*;)/,alias:"function",lookbehind:!0},keyword:/@(?:require|namespace|pattern|search|inside|outside|having|where)\b/,"standard-pattern":{pattern:/\b(?:Word|Punct|Symbol|Space|LineBreak|Start|End|Alpha|AlphaNum|Num|NumAlpha|Blank|WordBreak|Any)(?:\([a-zA-Z0-9\-.,\s+]*\))?/,inside:{"standard-pattern-name":{pattern:/^[a-zA-Z0-9\-.]+/,alias:"builtin"},quantifier:{pattern:/\b\d+(?:\s*\+|\s*-\s*\d+)?(?!\w)/,alias:"number"},"standard-pattern-attr":{pattern:/[a-zA-Z0-9\-.]+/,alias:"builtin"},punctuation:/[,()]/}},quantifier:{pattern:/\b\d+(?:\s*\+|\s*-\s*\d+)?(?!\w)/,alias:"number"},operator:[{pattern:/=/,alias:"pattern-def"},{pattern:/&/,alias:"conjunction"},{pattern:/~/,alias:"exception"},{pattern:/\?/,alias:"optionality"},{pattern:/[[\]]/,alias:"repetition"},{pattern:/[{}]/,alias:"variation"},{pattern:/[+_]/,alias:"sequence"},{pattern:/\.{2,3}/,alias:"span"}],"field-capture":[{pattern:/([a-zA-Z0-9\-.]+\s*\()\s*[a-zA-Z0-9\-.]+\s*:\s*[a-zA-Z0-9\-.]+(?:\s*,\s*[a-zA-Z0-9\-.]+\s*:\s*[a-zA-Z0-9\-.]+)*(?=\s*\))/,lookbehind:!0,inside:{"field-name":{pattern:/[a-zA-Z0-9\-.]+/,alias:"variable"},colon:/:/}},{pattern:/[a-zA-Z0-9\-.]+\s*:/,inside:{"field-name":{pattern:/[a-zA-Z0-9\-.]+/,alias:"variable"},colon:/:/}}],punctuation:/[:;,()]/,name:/[a-zA-Z0-9\-.]+/};

59
examples/prism-nevod.html Normal file
View File

@ -0,0 +1,59 @@
<h2>Comment</h2>
<pre><code>/* This is
multi-line
comment */
// This is single-line comment</code></pre>
<h2>String</h2>
<pre><code>"text in double quotes"
'text in single quotes'
'case-sensitive text'!
'text ''Nevod'' in quotes'
"text ""Nevod"" in double quotes"
'text prefix'*
'case-sensitive text prefix'!*</code></pre>
<h2>Keyword</h2>
<pre><code>@inside
@outside
@having
@search
@where</code></pre>
<h2>Package Import</h2>
<pre><code>@require "Common/DateTime.np"
@require "Common/Url.np"</code></pre>
<h2>Namespace</h2>
<pre><code>@namespace My { }
@namespace My.Domain { }</code></pre>
<h2>Pattern</h2>
<pre><code>@pattern #Percentage = Num + ?Space + {'%', 'pct.', 'pct', 'percent'};
@pattern #GUID = Word(8) + [3 '-' + Word(4)] + '-' + Word(12);
@pattern #HashTag = '#' + {AlphaNum, Alpha, '_'} + [0+ {Word, '_'}];</code></pre>
<h2>Full Example</h2>
<pre><code>@namespace Common
{
@search @pattern Url(Domain, Path, Query, Anchor) =
Method + Domain:Url.Domain + ?Port + ?Path:Url.Path +
?Query:Url.Query + ?Anchor:Url.Anchor
@where
{
Method = {'http', 'https' , 'ftp', 'mailto', 'file', 'data', 'irc'} + '://';
Domain = Word + [1+ '.' + Word + [0+ {Word, '_', '-'}]];
Port = ':' + Num;
Path = ?'/' + [0+ {Word, '/', '_', '+', '-', '%', '.'}];
Query = '?' + ?(Param + [0+ '&' + Param])
@where
{
Param = Identifier + '=' + Identifier
@where
{
Identifier = {Alpha, AlphaNum, '_'} + [0+ {Word, '_'}];
};
};
Anchor(Value) = '#' + Value:{Word};
};
}</code></pre>

View File

@ -46,6 +46,12 @@ const testOptions = {
number: false,
template: false,
},
// Nevod uses underscore symbol as operator and allows hyphen to be part of identifier
'nevod': {
word: false,
template: false,
},
};
/** @type {Record<keyof IdentifierTestOptions, string[]>} */

View File

@ -0,0 +1,20 @@
/* Comment */
/* Multi-line
comment */
/**/
//
// Single-line comment
----------------------------------------------------
[
["comment", "/* Comment */"],
["comment", "/* Multi-line\r\ncomment */"],
["comment", "/**/"],
["comment", "//"],
["comment", "// Single-line comment"]
]
----------------------------------------------------
Checks for comments.

View File

@ -0,0 +1,15 @@
@require @namespace @pattern @search
@inside @outside @having
@where
----------------------------------------------------
[
["keyword", "@require"], ["keyword", "@namespace"], ["keyword", "@pattern"], ["keyword", "@search"],
["keyword", "@inside"], ["keyword", "@outside"], ["keyword", "@having"],
["keyword", "@where"]
]
----------------------------------------------------
Checks for all keywords.

View File

@ -0,0 +1,25 @@
( , ) ;
+ _
.. ...
[ 0-5 ]
&
~
?
{}
----------------------------------------------------
[
["punctuation", "("], ["punctuation", ","], ["punctuation", ")"], ["punctuation", ";"],
["operator", "+"], ["operator", "_"],
["operator", ".."], ["operator", "..."],
["operator", "["], ["quantifier", "0-5"], ["operator", "]"],
["operator", "&"],
["operator", "~"],
["operator", "?"],
["operator", "{"], ["operator", "}"]
]
----------------------------------------------------
Checks for operators.

View File

@ -0,0 +1,27 @@
"text in double quotes"
""
'text in single quotes'
'case-sensitive text'!
'text ''Nevod'' in quotes'
"text ""Nevod"" in double quotes"
'text prefix'*
'case-sensitive text prefix'!*
''
----------------------------------------------------
[
["string", ["\"text in double quotes\""]],
["string", ["\"\""]],
["string", ["'text in single quotes'"]],
["string", ["'case-sensitive text'", ["string-attrs", "!"]]],
["string", ["'text ''Nevod'' in quotes'"]],
["string", ["\"text \"\"Nevod\"\" in double quotes\""]],
["string", ["'text prefix'", ["string-attrs", "*"]]],
["string", ["'case-sensitive text prefix'", ["string-attrs", "!*"]]],
["string", ["''"]]
]
----------------------------------------------------
Checks for various text strings.