Пример #1
0
 def test_scan(self):
     s = self.strscan
     assert 0 == s.pos
     s.scan(StringRegexp('world'))
     s.scan(StringRegexp('luo'))
     assert 0 == s.pos
     assert 'hel' == s.scan(StringRegexp('hel'))
     assert 3 == s.pos
Пример #2
0
 def test_search_full(self):
     s = self.strscan
     assert 'he' == s.search_full(StringRegexp('e'))
     assert 2 == s.pos
     assert 'llo' == s.search_full(StringRegexp('lo'),
                                   advance_pointer=False)
     assert 2 == s.pos
     assert 3 == s.search_full(StringRegexp('o'),
                               advance_pointer=False,
                               return_string=False)
Пример #3
0
 def test_scan_full(self):
     s = self.strscan
     assert None == s.scan_full(StringRegexp("l"))
     assert 'he' == s.scan_full(StringRegexp("he"))
     assert 2 == s.pos
     assert 'll' == s.scan_full(StringRegexp('ll'), advance_pointer=False)
     assert 2 == s.pos
     assert 2 == s.scan_full(StringRegexp('ll'),
                             advance_pointer=False,
                             return_string=False)
     assert 2 == s.pos
Пример #4
0
 def test_unscan(self):
     s = self.strscan
     s.skip(StringRegexp('he'))
     assert 'llo' == s.rest
     s.unscan
     assert 0 == s.pos
     assert self.string == s.string
Пример #5
0
    '#',  # Python, Ruby
    '%',  # Tex
]

# Start state on opening token, ignore anything until the closing
# token is reached.
MULTI_LINE_COMMENTS = [
    [r'/*', r'*/'],  # C
    [r'<!--', r'-->'],  # XML
    [r'{-', r'-}'],  # Haskell
    [r'(*', r'*)'],  # Coq
    [r'"""', r'"""'],  # Python
    [r"'''", r"'''"],  # Python
]

MULTI_LINE_COMMENT_DICT = dict([(s, StringRegexp(escape(e)))
                                for s, e in MULTI_LINE_COMMENTS])

START_SINGLE_LINE_COMMENT = StringRegexp('|'.join(
    map(lambda c: '\s*%s ' % escape(c), SINGLE_LINE_COMMENTS)))
START_MULTI_LINE_COMMENT = StringRegexp('|'.join(
    map(lambda c: escape(c[0]), MULTI_LINE_COMMENTS)))

REGEX_SHEBANG = StringRegexp(r'^#!.+')
REGEX_BOL = StringRegexp(r'\n|\Z')
REGEX_DOUBLE_QUOTE = StringRegexp(r'"')
REGEX_SINGLE_QUOTE = StringRegexp(r"'")
REGEX_DOUBLE_END_QUOTE = StringRegexp(r'[^\\]"')
REGEX_SINGLE_END_QUOTE = StringRegexp(r"[^\\]'")
REGEX_NUMBER_LITERALS = StringRegexp(r'(0x)?\d(\d|\.)*')
REGEX_SGML = StringRegexp(r'<[^\s<>][^<>]*>')
Пример #6
0
 def test_pre_match(self):
     s = self.strscan
     assert 2 == s.skip(StringRegexp('he'))
     assert 'll' == s.scan(StringRegexp('ll'))
     assert 'he' == s.pre_match
Пример #7
0
 def test_post_match(self):
     s = self.strscan
     s.skip(StringRegexp('he'))
     s.scan(StringRegexp('ll'))
     assert 'o' == s.post_match
Пример #8
0
 def test_rest(self):
     s = self.strscan
     s.scan(StringRegexp('hel'))
     assert self.string == s.string
Пример #9
0
 def test_matched(self):
     s = self.strscan
     s.scan(StringRegexp('hel'))
     assert 'hel' == s.matched
Пример #10
0
 def test_exist(self):
     s = self.strscan
     assert 3 == s.exists(StringRegexp('l'))
     assert 0 == s.pos
Пример #11
0
 def test_check_until(self):
     s = self.strscan
     assert 'hell' == s.check(StringRegexp('hell'))
     assert 0 == s.pos
Пример #12
0
 def test_skip_unitl(self):
     s = self.strscan
     assert 3 == s.skip_until(StringRegexp('l'))
Пример #13
0
 def test_skip(self):
     s = self.strscan
     assert 3 == s.skip(StringRegexp('hel'))
Пример #14
0
 def test_scan_until(self):
     s = self.strscan
     assert 'hel' == s.scan_until(StringRegexp('el'))
     assert 3 == s.pos