Last active
December 16, 2019 17:47
-
-
Save radgeRayden/87c2b1669228a757f6027b5a1ac5659d 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
let number-regexp = | |
do | |
hex-digit := "[0-9a-fA-F]" | |
bin-digit := "[01]" | |
oct-digit := "[0-7]" | |
fn re-or (...) | |
let result = | |
.. "(" | |
va-lifold "" | |
inline (index _. value computed-result) | |
if (index < ((va-countof ...) - 1)) | |
.. computed-result value "|" | |
else | |
.. computed-result value | |
... | |
")" | |
fn number-dot-number (prefix class) | |
let class+ = (class .. "+") | |
.. prefix (re-or (class+ .. "\\.") ("\\." .. class+) (.. class+ "\\." class+)) | |
let number-regexp = | |
.. "^[+-]?" | |
re-or | |
# no fractional part | |
(.. | |
(re-or | |
"\\d+" | |
(.. "0b" bin-digit "+") | |
(.. "0o" oct-digit "+") | |
(.. "0x" hex-digit "+")) | |
"(\\:" | |
(re-or | |
("f" .. (re-or "32" "64")) | |
("[ui]" .. (re-or "8" "16" "32" "64")) | |
"usize") ")?") | |
# floats with fractional part | |
(.. | |
(re-or | |
(number-dot-number "" "\\d") | |
(number-dot-number "0b" bin-digit) | |
(number-dot-number "0o" oct-digit) | |
(number-dot-number "0x" hex-digit)) | |
"([eE][+-]\\d+)?" | |
(re-or ":f32" ":f64") "?") | |
# token interrupting characters | |
"(?=[,'()\\[\\]{} \\n]|$)" | |
# output: | |
^[+-]?((\d+|0b[01]+|0o[0-7]+|0x[0-9a-fA-F]+)(\:(f(32|64)|[ui](8|16|32|64)|usize))?|((\d+\.|\.\d+|\d+\.\d+)|0b([01]+\.|\.[01]+|[01]+\.[01]+)|0o([0-7]+\.|\.[0-7]+|[0-7]+\.[0-7]+)|0x([0-9a-fA-F]+\.|\.[0-9a-fA-F]+|[ | |
0-9a-fA-F]+\.[0-9a-fA-F]+))([eE][+-]\d+)?(:f32|:f64)?)(?=[,'()\[\]{} \n]|$) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment