Skip to content

Instantly share code, notes, and snippets.

@toomasv
Created November 26, 2019 05:20
Show Gist options
  • Select an option

  • Save toomasv/3e55bafe2a6e736a2a5b1a4bddc4b482 to your computer and use it in GitHub Desktop.

Select an option

Save toomasv/3e55bafe2a6e736a2a5b1a4bddc4b482 to your computer and use it in GitHub Desktop.
Example of letting refinements loose
Red []
system/lexer/pre-load: func [src][
ws: charset reduce [space tab newline]
ws+: [some ws]
dig: charset "0123456789"
num: [some dig]
parse src [any [
"myfunc" s: ws+ 2 [num ws+]
any [i: ["/r3" | "/r4"] ws+ num ws+ (
move/part i s 3
s: skip s 3
)]
| skip]]
]
myfunc: func [one two /r3 three /r4 four][
case/all [
r3 [print ["three ->" three]]
r4 [print ["four ->" four]]
true [print ["args ->" one two]]
]
]
myfunc 1 2 /r3 3
;three -> 3
;args -> 1 2
myfunc 1 2 /r3 3 /r4 4
;three -> 3
;four -> 4
;args -> 1 2
myfunc 1 2
;args -> 1 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment