source: proto/charsetcompiler/charset_def.py @ 3903

Last change on this file since 3903 was 915, checked in by ksherdy, 8 years ago

Modularize charset compiler and character set definitions.

File size: 1.0 KB
Line 
1# -*- coding: utf-8 -*-
2#
3#  Character sets are defined as lists of items that
4#  are either individual characters or ranges of contiguous
5#  characters.
6#
7class CharSetDef:
8    """Definitions of character sets.   Examples:
9    CharSetDef('alpha_', ['a-z', 'A-Z', '_'])
10    CharDef('semicolon', ';') (equiv. to CharSetDef('semicolon', [';']))
11    """
12    def __init__(self, name, items, invert = False):
13        self.name = name
14        self.items = items
15        self.complemented = invert
16    def show(self): 
17        if self.complemented:
18            return "CharSetDef(%s, %s, True)" % (self.name, self.items)
19        else: return "CharSetDef(%s, %s)" % (self.name, self.items)
20
21       
22class CharDef(CharSetDef):
23    def __init__(self, name, char, invert = False):
24        self.name = name
25        self.items = [char]
26        self.complemented = invert
27    def show(self): 
28        if self.complemented:
29            return "CharDef(%s, '\\%X', True)" % (self.name, ord(self.items[0]))
30        else: return "CharDef(%s, '\\%X')" % (self.name, ord(self.items[0]))
31
32
Note: See TracBrowser for help on using the repository browser.