code_junkie

Regular Expression Compiler

Nov 14th, 2011
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. sub at_start { '^'; }
  2. sub at_end { '$'; }
  3. sub any { "."; }
  4. sub zero_or_more { "(?:$_[0])*"; }
  5. sub one_or_more { "(?:$_[0])+"; }
  6. sub optional { "(?:$_[0])?"; }
  7. sub remember { "($_[0])"; }
  8. sub one_of { "(?:" . join("|", @_) . ")"; }
  9. sub in_charset { "[$_[0]]"; } # I know it's broken for ']'...
  10. sub not_in_charset { "[^$_[0]]"; } # I know it's broken for ']'...
  11.  
  12. at_start .
  13. '"' .
  14. zero_or_more(
  15. one_of(
  16. not_in_charset('\\"'), # Yuck, 2 levels of escaping required
  17. '\\' . any
  18. )
  19. ) .
  20. '"'
  21.  
  22. c(a|d)+r
  23.  
  24. <sequence>
  25. <element name="c" type="xs:string"/>
  26. <choice minOccurs="1" maxOccurs="unbounded">
  27. <element name="a" type="xs:string"/>
  28. <element name="d" type="xs:string"/>
  29. </choice>
  30. <element name="r" type="xs:string"/>
  31. <sequence>
Add Comment
Please, Sign In to add comment