rx		: "rx" (":" modifier)* body
		| "m" (":" modifier)* body

modifier	: "e" | "each"
		| "x" "(" digit+ ")"
		| digit+ "x"
		| digit+ letter+
		| "nth" "(" ( digit+ | identifier ) ")"
		| "p5" | "perl5"
		| "w" | "word"
		| "any"
		| "u0" | "u1" | "u2" | "u3"
		| "i"

body		: delimiter expression? delimiter
		| " " letter expression letter
		| "[" expression? "]"
		| "{" expression? "}"
		| "(" expression? ")"
		| "<" expression? ">"

delimiter	: "/" | "!" | "?" | "=" | "]" | "}" | ")" | ">" | "#"

expression	: term ( "|" term )*
term		: factor factor*
factor		: "(" expression ")"
		| "[" expression "]"
		| "<[" character_class "]>"
		| "<" identifier ">"
		| "#" character_not_newline*
		| metacharacter
		| identifier
#		| "<" perl_expression ">"
		|				# Will break stuff...

character_not_newline :	# Not going to enumerate this...

identifier	: sigil(?) letter ( letter | digit )*
# This needs to be rethought... And it's likely that it will break.
		| digit | "-" | "&" | "_" | "." | "+" | ","

sigil		: "$" | "@" | "%"

# Ranges aren't standard BNF

regular_char	: "a"..."z" | "A"..."Z" | "0"..."9"

special_char	: "\0" octal_digit+
		| "\x" hex_digit+
		| "\x" "{" hex_digit+ "}"
		| ( "\p" | "\P" ) "{" identifier "}"

metacharacter	: "+" | "*" | "?" | "^" | "^^" | "$" | "$$"
		| "\" ( "c" | "s" | "S" | "d" | "D" | "w" | "W" )
		| "\[" | "\]"
		| "\(" | "\)"
		| "\{" | "\}"
		| "\<" | "\>"
		| special_char
		| ":"+

# Ranges aren't standard BNF
digit		: "0"..."9"
letter		: "a"..."z" | "A"..."Z"
