Added support for Cooklang (#3337)

Co-authored-by: Michael Schmidt <msrd0000@gmail.com>
This commit is contained in:
ahue 2022-02-19 13:29:43 +01:00 committed by GitHub
parent 703881e14b
commit 4eb928c33e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 580 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@ -299,6 +299,10 @@
"title": "Content-Security-Policy",
"owner": "ScottHelme"
},
"cooklang": {
"title": "Cooklang",
"owner": "ahue"
},
"coq": {
"title": "Coq",
"owner": "RunDevelopment"

View File

@ -0,0 +1,146 @@
(function (Prism) {
// see https://github.com/cooklang/spec/blob/main/EBNF.md
var single_token_suffix = /(?:(?!\s)[\d$+<=a-zA-Z\x80-\uFFFF])+/.source;
var multi_token_infix = /[^{}@#]+/.source;
var multi_token_suffix = /\{[^}#@]*\}/.source;
var multi_token = multi_token_infix + multi_token_suffix;
var timer_units = /(?:h|hours|hrs|m|min|minutes)/.source;
var amount_group_impl = {
pattern: /\{[^{}]*\}/,
inside: {
'amount': {
pattern: /([\{|])[^{}|*%]+/,
lookbehind: true,
alias: 'number',
},
'unit': {
pattern: /(%)[^}]+/,
lookbehind: true,
alias: 'symbol',
},
'servings-scaler': {
pattern: /\*/,
alias: 'operator',
},
'servings-alternative-separator': {
pattern: /\|/,
alias: 'operator',
},
'unit-separator': {
pattern: /(?:%|(\*)%)/,
lookbehind: true,
alias: 'operator',
},
'punctuation': /[{}]/,
}
};
Prism.languages.cooklang = {
'comment': {
// [- comment -]
// -- comment
pattern: /\[-[\s\S]*?-\]|--.*/,
greedy: true,
},
'meta': { // >> key: value
pattern: />>.*:.*/,
inside: {
'property': { // key:
pattern: /(>>\s*)[^\s:](?:[^:]*[^\s:])?/,
lookbehind: true,
}
}
},
'cookware-group': { // #...{...}, #...
pattern: new RegExp('#(?:'
+ multi_token
+ '|'
+ single_token_suffix
+ ')'
),
inside: {
'cookware': {
pattern: new RegExp('(^#)(?:'
+ multi_token_infix
+ ')'
),
lookbehind: true,
alias: 'variable',
},
'cookware-keyword': {
pattern: /^#/,
alias: 'keyword',
},
'quantity-group': {
pattern: new RegExp(/\{[^{}@#]*\}/),
inside: {
'quantity': {
pattern: new RegExp(/(^\{)/.source + multi_token_infix),
lookbehind: true,
alias: 'number',
},
'punctuation': /[{}]/,
}
}
},
},
'ingredient-group': { // @...{...}, @...
pattern: new RegExp('@(?:'
+ multi_token
+ '|'
+ single_token_suffix
+ ')'),
inside: {
'ingredient': {
pattern: new RegExp('(^@)(?:'
+ multi_token_infix
+ ')'),
lookbehind: true,
alias: 'variable',
},
'ingredient-keyword': {
pattern: /^@/,
alias: 'keyword',
},
'amount-group': amount_group_impl,
}
},
'timer-group': { // ~timer{...}
// eslint-disable-next-line regexp/sort-alternatives
pattern: /~(?!\s)[^@#~{}]*\{[^{}]*\}/,
inside: {
'timer': {
pattern: /(^~)[^{]+/,
lookbehind: true,
alias: 'variable',
},
'duration-group': { // {...}
pattern: /\{[^{}]*\}/,
inside: {
'punctuation': /[{}]/,
'unit': {
pattern: new RegExp(/(%\s*)/.source + timer_units + /\b/.source),
lookbehind: true,
alias: 'symbol',
},
'operator': /%/,
'duration': {
pattern: /\d+/,
alias: 'number',
},
}
},
'timer-keyword': {
pattern: /^~/,
alias: 'keyword',
},
}
}
};
}(Prism));

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

@ -0,0 +1 @@
!function(e){var a="(?:(?!\\s)[\\d$+<=a-zA-Z\\x80-\\uFFFF])+",t="[^{}@#]+",n=t+"\\{[^}#@]*\\}";Prism.languages.cooklang={comment:{pattern:/\[-[\s\S]*?-\]|--.*/,greedy:!0},meta:{pattern:/>>.*:.*/,inside:{property:{pattern:/(>>\s*)[^\s:](?:[^:]*[^\s:])?/,lookbehind:!0}}},"cookware-group":{pattern:new RegExp("#(?:"+n+"|"+a+")"),inside:{cookware:{pattern:new RegExp("(^#)(?:"+t+")"),lookbehind:!0,alias:"variable"},"cookware-keyword":{pattern:/^#/,alias:"keyword"},"quantity-group":{pattern:new RegExp(/\{[^{}@#]*\}/),inside:{quantity:{pattern:new RegExp("(^\\{)"+t),lookbehind:!0,alias:"number"},punctuation:/[{}]/}}}},"ingredient-group":{pattern:new RegExp("@(?:"+n+"|"+a+")"),inside:{ingredient:{pattern:new RegExp("(^@)(?:"+t+")"),lookbehind:!0,alias:"variable"},"ingredient-keyword":{pattern:/^@/,alias:"keyword"},"amount-group":{pattern:/\{[^{}]*\}/,inside:{amount:{pattern:/([\{|])[^{}|*%]+/,lookbehind:!0,alias:"number"},unit:{pattern:/(%)[^}]+/,lookbehind:!0,alias:"symbol"},"servings-scaler":{pattern:/\*/,alias:"operator"},"servings-alternative-separator":{pattern:/\|/,alias:"operator"},"unit-separator":{pattern:/(?:%|(\*)%)/,lookbehind:!0,alias:"operator"},punctuation:/[{}]/}}}},"timer-group":{pattern:/~(?!\s)[^@#~{}]*\{[^{}]*\}/,inside:{timer:{pattern:/(^~)[^{]+/,lookbehind:!0,alias:"variable"},"duration-group":{pattern:/\{[^{}]*\}/,inside:{punctuation:/[{}]/,unit:{pattern:new RegExp("(%\\s*)(?:h|hours|hrs|m|min|minutes)\\b"),lookbehind:!0,alias:"symbol"},operator:/%/,duration:{pattern:/\d+/,alias:"number"}}},"timer-keyword":{pattern:/^~/,alias:"keyword"}}}}}();

View File

@ -0,0 +1,41 @@
<h2>Comments</h2>
<pre><code>
-- This is a single line comment
[- this
is
a multi line comment -]
</code></pre>
<h2>Meta</h2>
<pre><code>
>> servings: 3
>> source: https://cooklang.org/docs/spec
>> any key: any value
</code></pre>
<h2>Ingredients</h2>
<pre><code>
@salt without amount
@egg{1}
@milk{1%l}
@milk{1|2%l}
@egg{1|2}
@egg{1*}
@milk{2*%l}
</code></pre>
<h2>Cookware</h2>
<pre><code>
#spoon without amount
#spoon{10%pair}
#spoon{1|2}
#spoon{1*%pair}
#spoon{1|2%pair}
#spoon{1*}
</code></pre>
<h2>Timer</h2>
<pre><code>
~{25%minutes} without name
~named timer{1%hours}
</code></pre>

View File

@ -0,0 +1,20 @@
-- a single line comment
[- a multi line comment on a single line -]
[- a multi
line comment 1 -]
[- a multi
line comment 2
-]
[-
a multi
line comment 3 -]
----------------------------------------------------
[
["comment", "-- a single line comment"],
["comment", "[- a multi line comment on a single line -]"],
["comment", "[- a multi\r\nline comment 1 -]"],
["comment", "[- a multi\r\nline comment 2 \r\n-]"],
["comment", "[- \r\na multi\r\nline comment 3 -]"]
]

View File

@ -0,0 +1,131 @@
#spoon
#spoon and more #spoon
#spoon is good but more #spoon are better
#more spoon{}
#even more spoon{1}
#spoon{1%set}
#spoon{2*%kg}
#spoon{3|1%set}
#spoon{3*set}
#spoon{3|set}
#spoon{3%*set}
#spoon{3%*%set}
----------------------------------------------------
[
["cookware-group", [
["cookware-keyword", "#"],
["cookware", "spoon"]
]],
["cookware-group", [
["cookware-keyword", "#"],
["cookware", "spoon"]
]],
" and more ",
["cookware-group", [
["cookware-keyword", "#"],
["cookware", "spoon"]
]],
["cookware-group", [
["cookware-keyword", "#"],
["cookware", "spoon"]
]],
" is good but more ",
["cookware-group", [
["cookware-keyword", "#"],
["cookware", "spoon"]
]],
" are better\r\n",
["cookware-group", [
["cookware-keyword", "#"],
["cookware", "more spoon"],
["quantity-group", [
["punctuation", "{"],
["punctuation", "}"]
]]
]],
["cookware-group", [
["cookware-keyword", "#"],
["cookware", "even more spoon"],
["quantity-group", [
["punctuation", "{"],
["quantity", "1"],
["punctuation", "}"]
]]
]],
["cookware-group", [
["cookware-keyword", "#"],
["cookware", "spoon"],
["quantity-group", [
["punctuation", "{"],
["quantity", "1%set"],
["punctuation", "}"]
]]
]],
["cookware-group", [
["cookware-keyword", "#"],
["cookware", "spoon"],
["quantity-group", [
["punctuation", "{"],
["quantity", "2*%kg"],
["punctuation", "}"]
]]
]],
["cookware-group", [
["cookware-keyword", "#"],
["cookware", "spoon"],
["quantity-group", [
["punctuation", "{"],
["quantity", "3|1%set"],
["punctuation", "}"]
]]
]],
["cookware-group", [
["cookware-keyword", "#"],
["cookware", "spoon"],
["quantity-group", [
["punctuation", "{"],
["quantity", "3*set"],
["punctuation", "}"]
]]
]],
["cookware-group", [
["cookware-keyword", "#"],
["cookware", "spoon"],
["quantity-group", [
["punctuation", "{"],
["quantity", "3|set"],
["punctuation", "}"]
]]
]],
["cookware-group", [
["cookware-keyword", "#"],
["cookware", "spoon"],
["quantity-group", [
["punctuation", "{"],
["quantity", "3%*set"],
["punctuation", "}"]
]]
]],
["cookware-group", [
["cookware-keyword", "#"],
["cookware", "spoon"],
["quantity-group", [
["punctuation", "{"],
["quantity", "3%*%set"],
["punctuation", "}"]
]]
]]
]

View File

@ -0,0 +1,149 @@
@milk
@milk and more @milk
@milk is good but more @milk is better
@more milk{}
@even more milk{1}
@milk{1%l}
@milk{2*%kg}
@milk{3|1%L}
@milk{3*L} must not match amount-group
@milk{3|L}
@milk{3%*L}
@milk{3%*%L}
----------------------------------------------------
[
["ingredient-group", [
["ingredient-keyword", "@"],
["ingredient", "milk"]
]],
["ingredient-group", [
["ingredient-keyword", "@"],
["ingredient", "milk"]
]],
" and more ",
["ingredient-group", [
["ingredient-keyword", "@"],
["ingredient", "milk"]
]],
["ingredient-group", [
["ingredient-keyword", "@"],
["ingredient", "milk"]
]],
" is good but more ",
["ingredient-group", [
["ingredient-keyword", "@"],
["ingredient", "milk"]
]],
" is better\r\n",
["ingredient-group", [
["ingredient-keyword", "@"],
["ingredient", "more milk"],
["amount-group", [
["punctuation", "{"],
["punctuation", "}"]
]]
]],
["ingredient-group", [
["ingredient-keyword", "@"],
["ingredient", "even more milk"],
["amount-group", [
["punctuation", "{"],
["amount", "1"],
["punctuation", "}"]
]]
]],
["ingredient-group", [
["ingredient-keyword", "@"],
["ingredient", "milk"],
["amount-group", [
["punctuation", "{"],
["amount", "1"],
["unit-separator", "%"],
["unit", "l"],
["punctuation", "}"]
]]
]],
["ingredient-group", [
["ingredient-keyword", "@"],
["ingredient", "milk"],
["amount-group", [
["punctuation", "{"],
["amount", "2"],
["servings-scaler", "*"],
["unit-separator", "%"],
["unit", "kg"],
["punctuation", "}"]
]]
]],
["ingredient-group", [
["ingredient-keyword", "@"],
["ingredient", "milk"],
["amount-group", [
["punctuation", "{"],
["amount", "3"],
["servings-alternative-separator", "|"],
["amount", "1"],
["unit-separator", "%"],
["unit", "L"],
["punctuation", "}"]
]]
]],
["ingredient-group", [
["ingredient-keyword", "@"],
["ingredient", "milk"],
["amount-group", [
["punctuation", "{"],
["amount", "3"],
["servings-scaler", "*"],
"L",
["punctuation", "}"]
]]
]],
" must not match amount-group\r\n",
["ingredient-group", [
["ingredient-keyword", "@"],
["ingredient", "milk"],
["amount-group", [
["punctuation", "{"],
["amount", "3"],
["servings-alternative-separator", "|"],
["amount", "L"],
["punctuation", "}"]
]]
]],
["ingredient-group", [
["ingredient-keyword", "@"],
["ingredient", "milk"],
["amount-group", [
["punctuation", "{"],
["amount", "3"],
["unit-separator", "%"],
["unit", "*L"],
["punctuation", "}"]
]]
]],
["ingredient-group", [
["ingredient-keyword", "@"],
["ingredient", "milk"],
["amount-group", [
["punctuation", "{"],
["amount", "3"],
["unit-separator", "%"],
["unit", "*%L"],
["punctuation", "}"]
]]
]]
]

View File

@ -0,0 +1,19 @@
>> servings: 1|2|3
>> servings: 3
>> meta without colon must not match
----------------------------------------------------
[
["meta", [
">> ",
["property", "servings"],
": 1|2|3"
]],
["meta", [
">> ",
["property", "servings"],
": 3"
]],
"\r\n>> meta without colon must not match"
]

View File

@ -0,0 +1,68 @@
~{25%minutes}
~eggs{25%minutes}
~{abc%minutes} must not match
~eggs{2%hours}
~eggs{2%h}
----------------------------------------------------
[
["timer-group", [
["timer-keyword", "~"],
["duration-group", [
["punctuation", "{"],
["duration", "25"],
["operator", "%"],
["unit", "minutes"],
["punctuation", "}"]
]]
]],
["timer-group", [
["timer-keyword", "~"],
["timer", "eggs"],
["duration-group", [
["punctuation", "{"],
["duration", "25"],
["operator", "%"],
["unit", "minutes"],
["punctuation", "}"]
]]
]],
["timer-group", [
["timer-keyword", "~"],
["duration-group", [
["punctuation", "{"],
"abc",
["operator", "%"],
["unit", "minutes"],
["punctuation", "}"]
]]
]],
" must not match\r\n",
["timer-group", [
["timer-keyword", "~"],
["timer", "eggs"],
["duration-group", [
["punctuation", "{"],
["duration", "2"],
["operator", "%"],
["unit", "hours"],
["punctuation", "}"]
]]
]],
["timer-group", [
["timer-keyword", "~"],
["timer", "eggs"],
["duration-group", [
["punctuation", "{"],
["duration", "2"],
["operator", "%"],
["unit", "h"],
["punctuation", "}"]
]]
]]
]