Skip to content

Commit

Permalink
Merge pull request #375 from stkw0/master
Browse files Browse the repository at this point in the history
Add support for python3.11
  • Loading branch information
terryyin committed Apr 25, 2024
2 parents e06407d + f44f796 commit 384d0cc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
22 changes: 19 additions & 3 deletions lizard_languages/code_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import re
from copy import copy
from functools import reduce
from operator import or_


class CodeStateMachine(object):
Expand Down Expand Up @@ -112,7 +114,7 @@ def create_token(match):
if not token_class:
token_class = create_token

def _generate_tokens(source, add):
def _generate_tokens(source, add, flags=re.NOFLAG):
# DO NOT put any sub groups in the regex. Good for performance
_until_end = r"(?:\\\n|[^\n])*"
combined_symbols = ["<<=", ">>=", "||", "&&", "===", "!==",
Expand All @@ -136,7 +138,7 @@ def _generate_tokens(source, add):
r"|\\\n" +
r"|\n" +
r"|[^\S\n]+" +
r"|.)", re.M | re.S)
r"|.)", re.M | re.S | flags)
macro = ""
for match in token_pattern.finditer(source):
token = token_class(match)
Expand All @@ -154,7 +156,21 @@ def _generate_tokens(source, add):
if macro:
yield macro

return _generate_tokens(source_code, addition)
flag_dict = {
'a': re.A, # ASCII-only matching
'i': re.I, # Ignore case
'L': re.L, # Locale dependent
'm': re.M, # Multi-line
's': re.S, # Dot matches all
'u': re.U, # Unicode matching
'x': re.X # Verbose
}

pattern = re.compile(r'\(\?[aiLmsux]+\)')
re_flags = ''.join(opt[2:-1] for opt in pattern.findall(addition))
flags = reduce(or_, (flag_dict[flag] for flag in re_flags), re.NOFLAG)

return _generate_tokens(source_code, pattern.sub('', addition), flags=flags)

def __call__(self, tokens, reader):
self.context = reader.context
Expand Down
4 changes: 2 additions & 2 deletions test/testOutputCSV.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_csv_header(self):
options_mock.verbose = True
options_mock.extensions = []
csv_output(AllResult([self.fileSummary]), options_mock)
self.assertRegexpMatches(sys.stdout.stream,
self.assertRegex(sys.stdout.stream,
r"NLOC,CCN,token,PARAM,length,location,file,function,long_name,start,end")

def test_csv_header_with_extension(self):
Expand All @@ -35,7 +35,7 @@ def test_csv_header_with_extension(self):
results = AllResult([self.fileSummary])
results.result[0].function_list[0].exit_count = 1
csv_output(results, options_mock)
self.assertRegexpMatches(sys.stdout.stream,
self.assertRegex(sys.stdout.stream,
r"NLOC,CCN,token,PARAM,length,location,file,function,long_name,start,end,exits")

def test_csv_no_header(self):
Expand Down
3 changes: 1 addition & 2 deletions test/testOutputHTML.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ def setUp(self):

def test_should_have_html_body(self):
html_output([self.fileSummary], self.option, None, AllResult)
self.assertRegexpMatches(sys.stdout.stream,
r"\<html\>")
self.assertRegex(sys.stdout.stream, r"\<html\>")

0 comments on commit 384d0cc

Please sign in to comment.