-
-
Save Enome/4381288 to your computer and use it in GitHub Desktop.
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
%lex | |
%% | |
\n+ { process.stdout.write('[ENDLINE(S)]\n'); return 'ENDLINE'; } | |
<<EOF>> { process.stdout.write('[EOF]'); return 'EOF'; } | |
(.*?)":" { process.stdout.write('[KEY]'); return 'KEY'; } | |
\s { process.stdout.write('[SPACE]'); return 'SPACE'; } | |
[^\Z|\n]+ { process.stdout.write('[VALUE]'); return 'VALUE'; } | |
/lex | |
%% | |
start | |
: KEY SPACE VALUE ENDLINE | |
| VALUE ENDLINE | |
| KEY SPACE VALUE EOF | |
; |
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
var input = 'amount: 200 ml \n' + | |
'size:300\n' + | |
'\n' + | |
'This is just a comment I made.\n' + | |
'temp: 20celsius'; | |
var output = [ | |
[ | |
{ key: 'amount', value: '200 ml' }, | |
{ key: 'size', value: '300 ml' }, | |
], | |
'\n', | |
'This is a comment', | |
'\n', | |
[ | |
{ key: 'temp', value: '20celsius' }, | |
], | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment