Skip to content

Instantly share code, notes, and snippets.

@acook
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save acook/9719190 to your computer and use it in GitHub Desktop.

Select an option

Save acook/9719190 to your computer and use it in GitHub Desktop.
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!"]]
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