Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #config parser:
- #syntax:
- # #its a comment
- # x = 7 # comment inside a line
- # x = "string#its not a comment"
- # x = {
- # item = 2 # its is an item
- # #its an object/dictionary
- # }
- # x = @y # its is a reusing of config variables previously declared
- from plex import *
- #digits
- digit = Range('09')
- hexa_digit = digit + Range('afAF')
- dhexa_digit = hexa_digit + hexa_digit
- qhexa_digit = dhexa_digit + dhexa_digit
- oct_digit = Range('07')
- doct_digit = oct_digit + oct_digit
- bin_digit = Range('01')
- #escapes
- esc_quote = Str("\\'")
- esc_dquote = Str('\\"')
- esc_nline = Str('\\n')
- esc_cr = Str('\\r')
- esc_table = Str('\\t')
- esc_backslash = Str('\\\\')
- esc_bell = Str('\\a')
- esc_bs = Str('\\b')
- esc_vertical = Str('\\v')
- esc_question = Str('\\?')
- esc_hexa = Str('\\x') + dhexa_digit | qhexa_digit
- esc_oct = Str('\\o') + doct_digit
- esc_bin = Str('\\b') + Rep(bin_digit)
- escapes = esc_quote | esc_dquote | esc_nline | esc_cr | esc_table | esc_backslach | esc_bell |\
- esc_bs | esc_vertical | esc_question | esc_hexa | esc_oct | esc_bin
- #simbols
- letter = Range("AZaz")
- number = Rep1(digit)
- hexa = Str('0x') + Rep(hexa_digt)
- octa = Str('0') + Rep(oct_digt)
- space = Any(" \t\n")
- comment = Str("#") + Rep(AnyBut(Eol))
- quote = Str("'")
- dquote = Str('"')
- name = letter + Rep(letter | digit)
- getvar = Str('@') + name
- #mathematics
- plus = Str('+')
- sub = Str('-')
- mul = Str('*')
- div = Str('/')
- mod = Str('%')
- #lists, dicts
- enter_dict = Str('{')
- leave_dict = Str('}')
- enter_list = Str('[')
- leave_list = Str(']')
- str_squote = quote + Rep(AnyBut("'") | escapes) + quote
- str_dquote = dquote + Rep(Anybut('"') | escapes) + dquote
- string = rep(space | str_dquote | str_squote)
Add Comment
Please, Sign In to add comment