Skip to content

Commit

Permalink
Handle punctuation in single word cookware/ingredients (#15)
Browse files Browse the repository at this point in the history
Add tests for singleword punctation
  • Loading branch information
RottenFishbone authored May 18, 2023
1 parent d459df0 commit 3e2f98f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const metadata = /^>>\s*(?<key>.+?):\s*(?<value>.+)/;

const multiwordIngredient = /@(?<mIngredientName>[^@#~[]+?){(?<mIngredientQuantity>[^]*?)(?:%(?<mIngredientUnits>[^}]+?))?}/;
const singleWordIngredient = /@(?<sIngredientName>[^\s]+)/;
const multiwordIngredient = /@(?<mIngredientName>[^@#~[]+?)\{(?<mIngredientQuantity>[^]*?)(?:%(?<mIngredientUnits>[^}]+?))?\}/;
const singleWordIngredient = /@(?<sIngredientName>[^\s\t\p{Zs}\p{P}]+)/;

const multiwordCookware = /#(?<mCookwareName>[^@#~[]+?){(?<mCookwareQuantity>.*?)}/;
const singleWordCookware = /#(?<sCookwareName>[^\s]+)/;
const multiwordCookware = /#(?<mCookwareName>[^@#~[]+?)\{(?<mCookwareQuantity>.*?)\}/;
const singleWordCookware = /#(?<sCookwareName>[^\s\t\p{Zs}\p{P}]+)/;

const timer = /~(?<timerName>.*?)(?:{(?<timerQuantity>.*?)(?:%(?<timerUnits>.+?))?})/;
const timer = /~(?<timerName>.*?)(?:\{(?<timerQuantity>.*?)(?:%(?<timerUnits>.+?))?\})/;

export const comment = /--.*/g;
export const blockComment = /\s*\[\-.*?\-\]\s*/g;

export const shoppingList = /\[(?<name>.+)\]\n(?<items>[^]*?)(?:\n\n|$)/g;
export const tokens = new RegExp([metadata, multiwordIngredient, singleWordIngredient, multiwordCookware, singleWordCookware, timer].map(r => r.source).join('|'), 'g');
export const tokens = new RegExp([metadata, multiwordIngredient, singleWordIngredient, multiwordCookware, singleWordCookware, timer].map(r => r.source).join('|'), 'gu');
26 changes: 26 additions & 0 deletions tests/custom.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ tests:
name: "ingredient with spaces"
metadata: []

testSingleWordIngredientFollowedByPunctuation:
source: |
@ingredient, then step.
result:
steps:
-
- type: ingredient
quantity: "some"
units: ""
name: "ingredient"
- type: text
value: ", then step."
metadata: []

testMultiWordFollowingSingleWordCookware:
source: |
Expand All @@ -75,6 +88,19 @@ tests:
quantity: 1
metadata: []

testSingleWordCookwareFollowedByPunctuation:
source: |
#pan, then step.
result:
steps:
-
- type: cookware
name: "pan"
quantity: 1
- type: text
value: ", then step."
metadata: []


testMultiWordFollowingSingleWordCookwareAndIngredient:
source: |
Expand Down

0 comments on commit 3e2f98f

Please sign in to comment.