Last active
August 29, 2015 13:57
-
-
Save acook/9719190 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
| REBOL [] | |
| string "say 'hello world!'" | |
| action-rule: [ some alphanumer ] | |
| action-coerce: func [match][ to-lit-word match ] ;; coercion function to apply to match | |
| action: [ action-rule action-coerce ] | |
| apostext: [ delim "'" ] | |
| tokens: tokenize string [ | |
| save/coerce action ;; expects second word in block to be a coercion function | |
| space | |
| save/annotate apostext ;; wraps match in block with name of rule prefixed | |
| ] | |
| print mold tokens | |
| ;;== ['say ['apostext "hello world!"]] |
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
| REBOL [] | |
| string "say 'hello world!'" | |
| word: [ some alphanumer ] ;; alphanumer is a built in TOKENIZE charset | |
| apostext: [ delim "'" ] ;; delim is a TOKENIZE function that matches everything between given delimiter, which can be any valid PARSE rule | |
| tokens: tokenize string [ | |
| save word | |
| space | |
| save apostext | |
| ] | |
| print mold tokens | |
| ;;== ["say" "hello world!"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment