Skip to content

Commit

Permalink
Use non-top-level macros to clarify regex macro definitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Jun 27, 2011
1 parent 3c71e4e commit 1f30a71
Showing 1 changed file with 38 additions and 31 deletions.
69 changes: 38 additions & 31 deletions j/regex.j
Original file line number Diff line number Diff line change
Expand Up @@ -133,37 +133,44 @@ Regex(p::String) = Regex(p, 0, true)
# likes so that Julia all the Julia string quoting
# constructs are correctly handled.

macro r_str(p); Regex(p); end
macro ri_str(p); Regex(p, PCRE_CASELESS); end
macro rm_str(p); Regex(p, PCRE_MULTILINE); end
macro rs_str(p); Regex(p, PCRE_DOTALL); end
macro rx_str(p); Regex(p, PCRE_EXTENDED); end
macro rim_str(p); Regex(p, PCRE_CASELESS|PCRE_MULTILINE); end
macro ris_str(p); Regex(p, PCRE_CASELESS|PCRE_DOTALL); end
macro rix_str(p); Regex(p, PCRE_CASELESS|PCRE_EXTENDED); end
macro rms_str(p); Regex(p, PCRE_MULTILINE|PCRE_DOTALL); end
macro rmx_str(p); Regex(p, PCRE_MULTILINE|PCRE_EXTENDED); end
macro rsx_str(p); Regex(p, PCRE_DOTALL|PCRE_EXTENDED); end
macro rims_str(p); Regex(p, PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL); end
macro rimx_str(p); Regex(p, PCRE_CASELESS|PCRE_MULTILINE|PCRE_EXTENDED); end
macro risx_str(p); Regex(p, PCRE_CASELESS|PCRE_DOTALL|PCRE_EXTENDED); end
macro rmsx_str(p); Regex(p, PCRE_MULTILINE|PCRE_DOTALL|PCRE_EXTENDED); end
macro rimsx_str(p); Regex(p, PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL|PCRE_EXTENDED); end

function show(re::Regex)
if (re.options & ~(PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL|PCRE_EXTENDED)) == 0
print('r')
if re.options & PCRE_CASELESS != 0; print('i'); end
if re.options & PCRE_MULTILINE != 0; print('m'); end
if re.options & PCRE_DOTALL != 0; print('s'); end
if re.options & PCRE_EXTENDED != 0; print('x'); end
print_quoted_literal(re.pattern)
else
print("Regex(")
show(re.pattern)
print(',')
show(re.options)
print(')')
begin
local i = PCRE_CASELESS
local m = PCRE_MULTILINE
local s = PCRE_DOTALL
local x = PCRE_EXTENDED

macro r_str(p); Regex(p); end
macro ri_str(p); Regex(p, i); end
macro rm_str(p); Regex(p, m); end
macro rs_str(p); Regex(p, s); end
macro rx_str(p); Regex(p, x); end
macro rim_str(p); Regex(p, i|m); end
macro ris_str(p); Regex(p, i|s); end
macro rix_str(p); Regex(p, i|x); end
macro rms_str(p); Regex(p, m|s); end
macro rmx_str(p); Regex(p, m|x); end
macro rsx_str(p); Regex(p, s|x); end
macro rims_str(p); Regex(p, i|m|s); end
macro rimx_str(p); Regex(p, i|m|x); end
macro risx_str(p); Regex(p, i|s|x); end
macro rmsx_str(p); Regex(p, m|s|x); end
macro rimsx_str(p); Regex(p, i|m|s|x); end

function show(re::Regex)
if (re.options & ~(i|m|s|x)) == 0
print('r')
if re.options & i != 0; print('i'); end
if re.options & m != 0; print('m'); end
if re.options & s != 0; print('s'); end
if re.options & x != 0; print('x'); end
print_quoted_literal(re.pattern)
else
print("Regex(")
show(re.pattern)
print(',')
show(re.options)
print(')')
end
end
end

Expand Down

0 comments on commit 1f30a71

Please sign in to comment.