aboutsummaryrefslogtreecommitdiffstats
path: root/hg_keywords.py
blob: 778c514119232b37922c25fab2559cd5ecaaa2aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import re

keyword_rx = re.compile('^\$(\w+)\:\s+(\W+)\s*\$$')

# returns tuple (key, value)
# returns None if kwstring is not a keyword expansion
def extract_keyvalue(kwstring):
    mo = keyword_rx.match(kwstring)
    if mo is None: return None

    try:
        return mo.group(1,2)
    except IndexError:
        return None


    
def keywords(*kwstrings):
    dict([extract_kwvalue(kws) for kws in kwstrings])