Guest User

Regex alternative

a guest
Jun 21st, 2015
673
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. pattern source_code =
  2. {
  3. lines = (any, ['\n'])|repeat =>
  4.  
  5. tokens = any of
  6. (
  7. private whitespace = (any of ' \t\r')|repeat
  8. symbol = (any of '~`!@#$%^&*+-=;:\'",.?/\\|')|repeat
  9. brackets = any of '(){}[]<>'
  10. invalid = (any < 32 except whitespace)|repeat
  11. literal = any of
  12. (
  13. number = any of
  14. (
  15. decimal = any of
  16. (
  17. private nonnegative_int = (any of '0123456789')|repeat
  18. int = ['-'], nonnegative_int
  19. float = ([int], '.', [nonnegative_int]).mask > 0, ['e'|nocase, int]
  20. )
  21. hex = {
  22. int = ['-'], '0x', (any of '0123456789ABCDEF'|nocase)|repeat
  23. }
  24. )
  25. string = any of (
  26. single_quoted = '\'', any eat '\\\'', '\''
  27. double_quoted = '"', any eat '\\"', '"'
  28. )
  29. )
  30.  
  31. word = any left
  32. )|repeat =>
  33.  
  34. objects =
  35. (
  36. pattern class_path = [(word|lowercase, ['.', word|lowercase])|repeat]
  37. pattern class_name = word{0|uppercase}, any
  38. pattern full_class_name = [class_path, '.'], class_name
  39. pattern var_name = word
  40. pattern function_name = word
  41. pattern operator = symbol
  42. pattern type_name = class_name
  43. pattern arguments_list = (var_name, [':', type_name]), [',', arguments_list]
  44. pattern block = any of ((expression, ';'), '{', content == block|repeat, '}')
  45.  
  46. pattern expression = any of
  47. (
  48. var_name
  49. literal
  50. '('
  51. content = expression
  52. ')'
  53. ), [operator, expression]
  54.  
  55. package = 'package', [class_path], ';'
  56. imports = any of
  57. (
  58. import = 'import', class_path, ['.*'], ';'
  59. using = 'using', class_path, ';'
  60. )|repeat
  61.  
  62. pattern class =
  63. (
  64. 'class', name = class_name, ['extends', full_class_name], [('implements', full_class_name)|repeat]
  65. '{'
  66. content == any of
  67. (
  68. var = [any of ('public', 'private', 'static', 'inline')|repeat once], 'var', name = var_name, ['=', expression], ';'
  69. function =
  70. (
  71. attribs = [any of ('public', 'private', 'static', 'inline')|repeat once]
  72. 'function'
  73. name = function_name
  74. args = '(', content == [arguments_list], ')'
  75. block = block
  76. )
  77. )|repeat
  78. '}'
  79. )
  80.  
  81. definitions = (class)|repeat
  82. )
  83. }
Advertisement
Add Comment
Please, Sign In to add comment