Guest User

Untitled

a guest
Nov 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.71 KB | None | 0 0
  1. #config parser:
  2.  
  3. #syntax:
  4. #  #its a comment
  5. #  x = 7 # comment inside a line
  6. #  x = "string#its not a comment"
  7. #  x =  {
  8. #        item = 2 # its is an item
  9. #        #its an object/dictionary
  10. #  }
  11. # x = @y # its is a reusing of config variables previously declared
  12.  
  13.  
  14. from plex import *
  15.  
  16. #digits
  17. digit = Range('09')
  18. hexa_digit = digit + Range('afAF')
  19. dhexa_digit = hexa_digit + hexa_digit
  20. qhexa_digit = dhexa_digit + dhexa_digit
  21. oct_digit = Range('07')
  22. doct_digit = oct_digit + oct_digit
  23. bin_digit = Range('01')
  24.  
  25. #escapes
  26. esc_quote = Str("\\'")
  27. esc_dquote = Str('\\"')
  28. esc_nline = Str('\\n')
  29. esc_cr = Str('\\r')
  30. esc_table = Str('\\t')
  31. esc_backslash = Str('\\\\')
  32. esc_bell = Str('\\a')
  33. esc_bs = Str('\\b')
  34. esc_vertical = Str('\\v')
  35. esc_question = Str('\\?')
  36. esc_hexa = Str('\\x') + dhexa_digit | qhexa_digit
  37. esc_oct = Str('\\o') + doct_digit
  38. esc_bin = Str('\\b') + Rep(bin_digit)
  39.  
  40. escapes = esc_quote | esc_dquote | esc_nline | esc_cr | esc_table | esc_backslach | esc_bell |\
  41.           esc_bs | esc_vertical | esc_question | esc_hexa | esc_oct | esc_bin
  42.  
  43. #simbols
  44.  
  45. letter = Range("AZaz")
  46. number = Rep1(digit)
  47. hexa = Str('0x') + Rep(hexa_digt)
  48. octa = Str('0') + Rep(oct_digt)
  49. space = Any(" \t\n")
  50. comment = Str("#") + Rep(AnyBut(Eol))
  51. quote = Str("'")
  52. dquote = Str('"')
  53. name = letter + Rep(letter | digit)
  54. getvar = Str('@') + name
  55.  
  56. #mathematics
  57.  
  58. plus = Str('+')
  59. sub = Str('-')
  60. mul = Str('*')
  61. div = Str('/')
  62. mod = Str('%')
  63.  
  64. #lists, dicts
  65. enter_dict = Str('{')
  66. leave_dict = Str('}')
  67. enter_list = Str('[')
  68. leave_list = Str(']')
  69.  
  70.  
  71. str_squote = quote + Rep(AnyBut("'") | escapes)  + quote
  72. str_dquote = dquote + Rep(Anybut('"') | escapes) + dquote
  73. string = rep(space | str_dquote | str_squote)
Add Comment
Please, Sign In to add comment