Last active
January 25, 2020 17:17
-
-
Save Nullpo/71a333633c72603b29cc2ad88b041047 to your computer and use it in GitHub Desktop.
Gramatica recetapp
This file contains hidden or 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
| Ejemplo: | |
| Merengue. | |
| Porciones: 3.5 | |
| Ingredientes: | |
| - Huevos -- 2.9 unidades | |
| - Almibar | |
| - Pequeña sandia | |
| Preparacion: | |
| - Romper los huevos | |
| - Separar la clara | |
| - Batir la clara a punto de nieve | |
| - Mezclarla con el almibar. | |
| - Hornear la mezcla 20 minutos. | |
| - Colocarle una pequeña sandia, de 2 o 3 Kg. | |
| Gramatica: | |
| receta | |
| = n:nombre inf:porciones i:ingredientes p:preparacion { | |
| return { | |
| nombre: n, | |
| porciones: inf, | |
| ingredientes: i, | |
| preparacion: p | |
| } | |
| } | |
| /**** INFO ****/ | |
| info = r:(porciones) { | |
| return r | |
| } | |
| porciones = "Porciones:"i " "* r:number " "* eol+ { return r; } | |
| /**************/ | |
| nombre = n:untilEol eol { | |
| return n; | |
| } | |
| ingredientes | |
| = "Ingredientes"i ":"? "\s"* eol+ i:ingrediente+ { | |
| return i; | |
| } | |
| ingrediente | |
| = " "* "-" "\s"* i:[^\n-]+ cant:cantidad? eol+ { | |
| return { | |
| elemento: i.join('').trim(), | |
| cantidad: cant | |
| } | |
| } | |
| cantidad | |
| = "--" " "* valor:(number) " "+ unidad:([^\n]+) { | |
| return { valor, unidad: unidad.join('').trim() } | |
| } | |
| number | |
| = r:([0-9]( "." [0-9] )?)+ { return parseFloat(r.join('').trim()); } | |
| preparacion | |
| = "Preparacion"i ":"? eol+ prep:(paso)+ { | |
| return prep; | |
| } | |
| paso | |
| = " "* "-" s:untilEol eol* { | |
| return s; | |
| } | |
| eol= "\n" | |
| untilEol = r:[^\n]+ { | |
| return r.join('').trim(); | |
| } | |
| Resultado: | |
| { | |
| "nombre": "Merengue.", | |
| "porciones": 3, | |
| "ingredientes": [ | |
| { | |
| "elemento": "Huevos", | |
| "cantidad": { | |
| "valor": 2, | |
| "unidad": "unidades" | |
| } | |
| }, | |
| { | |
| "elemento": "Almibar", | |
| "cantidad": null | |
| }, | |
| { | |
| "elemento": "Pequeña sandia", | |
| "cantidad": null | |
| } | |
| ], | |
| "preparacion": [ | |
| "Romper los huevos", | |
| "Separar la clara", | |
| "Batir la clara a punto de nieve", | |
| "Mezclarla con el almibar.", | |
| "Hornear la mezcla 20 minutos.", | |
| "Colocarle una pequeña sandia, de 2 o 3 Kg." | |
| ] | |
| } |
This file contains hidden or 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
| Ejemplo: | |
| nombre: pescado | |
| cantidad: 2 gramos | |
| grasas: 10 | |
| calorias: 10 | |
| carbohidratos: 20 | |
| proteinas: 10.3 | |
| nombre: rabioso | |
| cantidad: 200 metros | |
| calorias: 10 | |
| carbohidratos: 20 | |
| grasas: 10 | |
| proteinas: 10.3 | |
| nombre: al horno | |
| cantidad: 2 hornos | |
| calorias: 10 | |
| carbohidratos: 20 | |
| grasas: 10 | |
| proteinas: 10.3 | |
| Gramatica: | |
| texto = | |
| a: ingredientes | |
| eol* | |
| { | |
| return a | |
| } | |
| ingredientes = | |
| a:ingrediente b:ingredientesRecursivo? { return {...a, ...b} } | |
| ingredientesRecursivo | |
| = eol+ a:ingredientes { return a } | |
| ingrediente | |
| = n:name eol | |
| q:quantity eol | |
| s:chars* { | |
| return {[n]: | |
| s.reduce( | |
| (prev, act) => { | |
| return { | |
| ...prev, | |
| [act.key]: act.value | |
| } | |
| }, {calorias: 0, proteinas:0, grasas: 0, carbohidratos: 0, cantidad: q} | |
| ) | |
| } | |
| } | |
| quantity = "cantidad:" " "* n:number u:untilEol? { return {cantidad: n, unidad:u} } | |
| name = | |
| (" " "\n")* "nombre:" " "* name:untilEol { return name; } | |
| chars = s:(char) eol { return s; } | |
| char = | |
| name:([^\n:])+ ":" " "* x:number { | |
| return { | |
| key: name.join('').trim(), | |
| value: x | |
| }; | |
| } | |
| eol= "\n" | |
| untilEol = r:[^\n]+ { | |
| return r.join('').trim(); | |
| } | |
| number | |
| = r:(integer) x:( "." integer )? { return parseFloat(r + (x? "." + x[1]: "")); } | |
| integer = s:[0-9]+ { return s.join('').trim() } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment