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
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)
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
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
'#', # 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<>][^<>]*>')
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
def test_post_match(self): s = self.strscan s.skip(StringRegexp('he')) s.scan(StringRegexp('ll')) assert 'o' == s.post_match
def test_rest(self): s = self.strscan s.scan(StringRegexp('hel')) assert self.string == s.string
def test_matched(self): s = self.strscan s.scan(StringRegexp('hel')) assert 'hel' == s.matched
def test_exist(self): s = self.strscan assert 3 == s.exists(StringRegexp('l')) assert 0 == s.pos
def test_check_until(self): s = self.strscan assert 'hell' == s.check(StringRegexp('hell')) assert 0 == s.pos
def test_skip_unitl(self): s = self.strscan assert 3 == s.skip_until(StringRegexp('l'))
def test_skip(self): s = self.strscan assert 3 == s.skip(StringRegexp('hel'))
def test_scan_until(self): s = self.strscan assert 'hel' == s.scan_until(StringRegexp('el')) assert 3 == s.pos