Skip to content

Commit

Permalink
Added support for Nevod (#2798)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-surkov authored Mar 18, 2021
1 parent e32e043 commit f84c49c
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,10 @@
"title": "NEON",
"owner": "nette"
},
"nevod": {
"title": "Nevod",
"owner": "nezaboodka"
},
"nginx": {
"title": "nginx",
"owner": "volado"
Expand Down
125 changes: 125 additions & 0 deletions components/prism-nevod.js
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions components/prism-nevod.min.js

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

59 changes: 59 additions & 0 deletions examples/prism-nevod.html
Original file line number Diff line number Diff line change
@@ -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>
6 changes: 6 additions & 0 deletions tests/identifier-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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[]>} */
Expand Down
20 changes: 20 additions & 0 deletions tests/languages/nevod/comment_feature.test
Original file line number Diff line number Diff line change
@@ -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.
15 changes: 15 additions & 0 deletions tests/languages/nevod/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -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.
25 changes: 25 additions & 0 deletions tests/languages/nevod/operator_feature.test
Original file line number Diff line number Diff line change
@@ -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.
27 changes: 27 additions & 0 deletions tests/languages/nevod/string_feature.test
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit f84c49c

Please sign in to comment.