-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Michael Schmidt <msrd0000@gmail.com>
- Loading branch information
1 parent
703881e
commit 4eb928c
Showing
10 changed files
with
580 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 -]"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", "}"] | ||
]] | ||
]] | ||
] |
Oops, something went wrong.