lizard 1.17.15__py2.py3-none-any.whl → 1.17.17__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {lizard-1.17.15.dist-info → lizard-1.17.17.dist-info}/METADATA +9 -1
- {lizard-1.17.15.dist-info → lizard-1.17.17.dist-info}/RECORD +15 -15
- lizard.py +32 -2
- lizard_ext/version.py +1 -1
- lizard_languages/csharp.py +43 -1
- lizard_languages/java.py +99 -1
- lizard_languages/javascript.py +2 -6
- lizard_languages/jsx.py +17 -3
- lizard_languages/ruby.py +3 -2
- lizard_languages/tsx.py +1 -2
- lizard_languages/typescript.py +9 -5
- {lizard-1.17.15.dist-info → lizard-1.17.17.dist-info}/LICENSE.txt +0 -0
- {lizard-1.17.15.dist-info → lizard-1.17.17.dist-info}/WHEEL +0 -0
- {lizard-1.17.15.dist-info → lizard-1.17.17.dist-info}/entry_points.txt +0 -0
- {lizard-1.17.15.dist-info → lizard-1.17.17.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: lizard
|
|
3
|
-
Version: 1.17.
|
|
3
|
+
Version: 1.17.17
|
|
4
4
|
Summary: A code analyzer without caring the C/C++ header files. It works with Java, C/C++, JavaScript, Python, Ruby, Swift, Objective C. Metrics includes cyclomatic complexity number etc.
|
|
5
5
|
Home-page: http://www.lizard.ws
|
|
6
6
|
Download-URL: https://pypi.python.org/lizard/
|
|
@@ -29,6 +29,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
29
29
|
Classifier: Programming Language :: Python :: 3.11
|
|
30
30
|
License-File: LICENSE.txt
|
|
31
31
|
Requires-Dist: pygments
|
|
32
|
+
Requires-Dist: pathspec
|
|
32
33
|
|
|
33
34
|
|Web Site| Lizard
|
|
34
35
|
=================
|
|
@@ -138,6 +139,13 @@ Exclude anything in the tests folder:
|
|
|
138
139
|
|
|
139
140
|
lizard mySource/ -x"./tests/*"
|
|
140
141
|
|
|
142
|
+
Use .gitignore file:
|
|
143
|
+
|
|
144
|
+
::
|
|
145
|
+
|
|
146
|
+
lizard mySource/
|
|
147
|
+
|
|
148
|
+
If there is a .gitignore file in the given path, lizard will automatically use it as an additional filter to exclude files that match the gitignore patterns. This is useful when you want to analyze only the tracked files in your git repository.
|
|
141
149
|
|
|
142
150
|
Options
|
|
143
151
|
~~~~~~~
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
lizard.py,sha256=
|
|
1
|
+
lizard.py,sha256=m-wnNDtLaug8yvK65Ex1IMRTubo6uFQAfdcdRN9x5Mg,39927
|
|
2
2
|
lizard_ext/__init__.py,sha256=Cz0pvH6QHyadK-rAeeEhQVsm0hW5M-fBQgV4FBaX9zk,500
|
|
3
3
|
lizard_ext/auto_open.py,sha256=byD_RbeVhvSUhR2bJMRitvA3zcKEapFwv0-XaDJ6GFo,1096
|
|
4
4
|
lizard_ext/csvoutput.py,sha256=43fhmo8kB85qcdujCwySGNuTC4FkKUPLqIApPeljPnA,2663
|
|
@@ -25,28 +25,28 @@ lizard_ext/lizardns.py,sha256=8pztUoRS_UWN24MawwxeHEJgYh49id5PWODUBb6O72U,4184
|
|
|
25
25
|
lizard_ext/lizardoutside.py,sha256=FGm2tbBZ17-2OCgmQlD-vobUCfQKb0FAygf86eM3xuM,336
|
|
26
26
|
lizard_ext/lizardstatementcount.py,sha256=xYk6ixSIItSE1BWQXzrWmduFgGhA3VR817SNKLffyVQ,1182
|
|
27
27
|
lizard_ext/lizardwordcount.py,sha256=2QYXD7-AtkkgAbi9VSidunMbSsGQ7MKYb6IT-bS-cok,7575
|
|
28
|
-
lizard_ext/version.py,sha256=
|
|
28
|
+
lizard_ext/version.py,sha256=cbYsAY5IfG5fvQB3OIb0eEsfLnAzIrG_UpN--BDcwLk,182
|
|
29
29
|
lizard_ext/xmloutput.py,sha256=-cbh0he4O_X-wX56gkv9AnSPNN0qvR7FACqlBeezUS4,5609
|
|
30
30
|
lizard_languages/__init__.py,sha256=2mvrPWMJVCq981kMjoAPEi2O07C8vo-vUWOG_wp7vKQ,1473
|
|
31
31
|
lizard_languages/clike.py,sha256=Lnwkma-jEu8FNVEPqTAKPkz1Hi0T_dP7H9Jyq0Bd0kQ,10725
|
|
32
32
|
lizard_languages/code_reader.py,sha256=P0PkE4QZBWOEj6cFHA4hj3hcLZLcGnqH31EmtltxlaE,6240
|
|
33
|
-
lizard_languages/csharp.py,sha256=
|
|
33
|
+
lizard_languages/csharp.py,sha256=EfFAIOIcJXUUhXTlZApXGSlzG34NZvHM9OSe6m7hpv0,2141
|
|
34
34
|
lizard_languages/erlang.py,sha256=7YJS2cMyXDKEV_kpH8DzBARxFCFcjKuTOPSQ3K52auU,3860
|
|
35
35
|
lizard_languages/fortran.py,sha256=KATDsnfjob5W3579A_VxbwrbTkK7Rx3p0eXdBgjx25I,8973
|
|
36
36
|
lizard_languages/gdscript.py,sha256=KwlGoODilQnFgXvODpq_XlA6fV3hGbN9fd7bsiEUn78,637
|
|
37
37
|
lizard_languages/go.py,sha256=dSbWxtWve7KSRW5i9w4DxhODtJ72EcBNrgp-7Xhn0Sg,465
|
|
38
38
|
lizard_languages/golike.py,sha256=vRIfjTVvc0VmJf27lTOLht55ZF1AQ9wn0Fvu-9WabWk,2858
|
|
39
|
-
lizard_languages/java.py,sha256=
|
|
40
|
-
lizard_languages/javascript.py,sha256=
|
|
39
|
+
lizard_languages/java.py,sha256=O-RAQIFCFJ2VnlpF2sE5xave8n56bnuZl32AZZ42oDs,4929
|
|
40
|
+
lizard_languages/javascript.py,sha256=qqxocZbZ6ivchhswRBBSjEJKiTClnm9ScOy4nlX4JKA,318
|
|
41
41
|
lizard_languages/js_style_language_states.py,sha256=Ie0eA15rd0gfahdNzUlSkQa-o_j5idTIB82JU32c378,4165
|
|
42
42
|
lizard_languages/js_style_regex_expression.py,sha256=Xgyogch4xElYtCG4EnBKvalHTl3tjRPcIIcIQRRd61I,1970
|
|
43
|
-
lizard_languages/jsx.py,sha256=
|
|
43
|
+
lizard_languages/jsx.py,sha256=KA9tDZ8kRSey8RefeC6DJg36yLBi6AEbm5JmVB-TQMU,3951
|
|
44
44
|
lizard_languages/kotlin.py,sha256=v_o2orEzA5gB9vM_0h-E4QXjrc5Yum-0K6W6_laOThc,2844
|
|
45
45
|
lizard_languages/lua.py,sha256=3nqBcunBzJrhv4Iqaf8xvbyqxZy3aSxJ-IiHimHFlac,1573
|
|
46
46
|
lizard_languages/objc.py,sha256=2a1teLdaXZBtCeFiIZer1j_sVx9LZ1CbF2XfnqlvLmk,2319
|
|
47
47
|
lizard_languages/php.py,sha256=8OufyR2TIWyf3bXuTmp37Vwf_tEPF4YV5M3i5_jnguA,1377
|
|
48
48
|
lizard_languages/python.py,sha256=5MwhyuzUqbUkhNyzeo_YsTRp4onMUVC19t61lLnDyjc,3761
|
|
49
|
-
lizard_languages/ruby.py,sha256=
|
|
49
|
+
lizard_languages/ruby.py,sha256=HL1ZckeuUUJU3QSVAOPsG_Zsl0C6X2PX5_VaWqclzkM,2277
|
|
50
50
|
lizard_languages/rubylike.py,sha256=dAGZ2wqW8nqaESMU8HkeR9gwQ-q9fmZqE6AANvVZD1Q,3426
|
|
51
51
|
lizard_languages/rust.py,sha256=DG2RkR9JWwcD6gIw-BPzg-Yo_lxQtSvfgHioFWIQm9o,610
|
|
52
52
|
lizard_languages/scala.py,sha256=6Jr_TG945VYqB3o5weD7jN7S4beHt4aVj3r-fmKeMAM,1316
|
|
@@ -54,14 +54,14 @@ lizard_languages/script_language.py,sha256=UUO3Wjkoa-ZqwwvcwvhOr5tg1rVavcrEYx3dN
|
|
|
54
54
|
lizard_languages/solidity.py,sha256=Z0GD7U5bI5eUikdy7m_iKWeFD5yXRYq4r3zycscOhJQ,553
|
|
55
55
|
lizard_languages/swift.py,sha256=p8S2OAkQOx9YQ02yhoVXFkr7pMqUH1Nb3RVXPHRU_9M,2450
|
|
56
56
|
lizard_languages/tnsdl.py,sha256=pGcalA_lHY362v2wwPS86seYBOOBBjvmU6vd4Yy3A9g,2803
|
|
57
|
-
lizard_languages/tsx.py,sha256=
|
|
57
|
+
lizard_languages/tsx.py,sha256=pzScdziLmFkD1c0LfwUNyC64C0HFmqt16QtsANu0UJ8,639
|
|
58
58
|
lizard_languages/ttcn.py,sha256=ygjw_raBmPF-4mgoM8m6CAdyEMpTI-n1kZJK1RL4Vxo,2131
|
|
59
|
-
lizard_languages/typescript.py,sha256=
|
|
59
|
+
lizard_languages/typescript.py,sha256=jXN3q01g46tWVb9jXjsmwypcAXx0t-vpK3UFQ-SHw9U,3645
|
|
60
60
|
lizard_languages/vue.py,sha256=KXUBUo2R1zNF8Pffrz_KsQEN44m5XFRMoGXylxKUeT0,1038
|
|
61
61
|
lizard_languages/zig.py,sha256=NX1iyBstBuJFeAGBOAIaRfrmeBREne2HX6Pt4fXZZTQ,586
|
|
62
|
-
lizard-1.17.
|
|
63
|
-
lizard-1.17.
|
|
64
|
-
lizard-1.17.
|
|
65
|
-
lizard-1.17.
|
|
66
|
-
lizard-1.17.
|
|
67
|
-
lizard-1.17.
|
|
62
|
+
lizard-1.17.17.dist-info/LICENSE.txt,sha256=05ZjgQ8Cl1dD9p0BhW-Txzkc5rhCogGJVEuf1GT2Y_M,1303
|
|
63
|
+
lizard-1.17.17.dist-info/METADATA,sha256=nPb0Zzq86TmFrDJhfPKOSD4dK3KkKUrVA3yuq3T0JC0,15745
|
|
64
|
+
lizard-1.17.17.dist-info/WHEEL,sha256=Kh9pAotZVRFj97E15yTA4iADqXdQfIVTHcNaZTjxeGM,110
|
|
65
|
+
lizard-1.17.17.dist-info/entry_points.txt,sha256=ZBqPhu-J3NoGGW5vn2Gfyoo0vdVlgBgM-wlNm0SGYUQ,39
|
|
66
|
+
lizard-1.17.17.dist-info/top_level.txt,sha256=5NTrTaOLhHuTzXaGcZPKfuaOgUv7WafNGe0Zl5aycpg,35
|
|
67
|
+
lizard-1.17.17.dist-info/RECORD,,
|
lizard.py
CHANGED
|
@@ -896,14 +896,43 @@ def md5_hash_file(full_path_name):
|
|
|
896
896
|
def get_all_source_files(paths, exclude_patterns, lans):
|
|
897
897
|
'''
|
|
898
898
|
Function counts md5 hash for the given file and checks if it isn't a
|
|
899
|
-
duplicate using set of hashes for previous files
|
|
899
|
+
duplicate using set of hashes for previous files.
|
|
900
|
+
|
|
901
|
+
If a .gitignore file is found in any of the given paths, it will be used
|
|
902
|
+
to filter out files that match the gitignore patterns.
|
|
903
|
+
'''
|
|
900
904
|
hash_set = set()
|
|
905
|
+
gitignore_spec = None
|
|
906
|
+
base_path = None
|
|
907
|
+
|
|
908
|
+
def _load_gitignore():
|
|
909
|
+
nonlocal gitignore_spec, base_path
|
|
910
|
+
try:
|
|
911
|
+
import pathspec
|
|
912
|
+
for path in paths:
|
|
913
|
+
gitignore_path = os.path.join(path, '.gitignore')
|
|
914
|
+
if os.path.exists(gitignore_path):
|
|
915
|
+
with open(gitignore_path, 'r') as gitignore_file:
|
|
916
|
+
# Read lines and strip whitespace and empty lines
|
|
917
|
+
patterns = [line.strip() for line in gitignore_file.readlines()]
|
|
918
|
+
patterns = [p for p in patterns if p and not p.startswith('#')]
|
|
919
|
+
gitignore_spec = pathspec.PathSpec.from_lines('gitwildmatch', patterns)
|
|
920
|
+
base_path = path
|
|
921
|
+
break
|
|
922
|
+
except ImportError:
|
|
923
|
+
pass
|
|
901
924
|
|
|
902
925
|
def _support(reader):
|
|
903
926
|
return not lans or set(lans).intersection(
|
|
904
927
|
reader.language_names)
|
|
905
928
|
|
|
906
929
|
def _validate_file(pathname):
|
|
930
|
+
if gitignore_spec is not None and base_path is not None:
|
|
931
|
+
rel_path = os.path.relpath(pathname, base_path)
|
|
932
|
+
# Normalize path separators for consistent matching
|
|
933
|
+
rel_path = rel_path.replace(os.sep, '/')
|
|
934
|
+
if gitignore_spec.match_file(rel_path):
|
|
935
|
+
return False
|
|
907
936
|
return (
|
|
908
937
|
pathname in paths or (
|
|
909
938
|
get_reader_for(pathname) and
|
|
@@ -926,6 +955,7 @@ def get_all_source_files(paths, exclude_patterns, lans):
|
|
|
926
955
|
for filename in files:
|
|
927
956
|
yield os.path.join(root, filename)
|
|
928
957
|
|
|
958
|
+
_load_gitignore()
|
|
929
959
|
return filter(_validate_file, all_listed_files(paths))
|
|
930
960
|
|
|
931
961
|
|
|
@@ -967,7 +997,7 @@ def parse_args(argv):
|
|
|
967
997
|
if inferred_printer:
|
|
968
998
|
if not opt.printer:
|
|
969
999
|
opt.printer = inferred_printer
|
|
970
|
-
|
|
1000
|
+
elif opt.printer != inferred_printer:
|
|
971
1001
|
msg = "Warning: overriding output file extension.\n"
|
|
972
1002
|
sys.stderr.write(msg)
|
|
973
1003
|
return opt
|
lizard_ext/version.py
CHANGED
lizard_languages/csharp.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Language parser for C Sharp
|
|
3
3
|
'''
|
|
4
4
|
|
|
5
|
-
from .clike import CLikeReader
|
|
5
|
+
from .clike import CLikeReader, CLikeStates, CLikeNestingStackStates
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class CSharpReader(CLikeReader):
|
|
@@ -14,7 +14,49 @@ class CSharpReader(CLikeReader):
|
|
|
14
14
|
_conditions = set(['if', 'for', 'while', '&&', '||', '?', 'catch',
|
|
15
15
|
'case', '??'])
|
|
16
16
|
|
|
17
|
+
def __init__(self, context):
|
|
18
|
+
super(CSharpReader, self).__init__(context)
|
|
19
|
+
self.parallel_states = [
|
|
20
|
+
CSharpStates(context),
|
|
21
|
+
CLikeNestingStackStates(context)
|
|
22
|
+
]
|
|
23
|
+
|
|
17
24
|
@staticmethod
|
|
18
25
|
def generate_tokens(source_code, addition='', token_class=None):
|
|
19
26
|
return CLikeReader.generate_tokens(
|
|
20
27
|
source_code, r"|(?:\?\?)", token_class)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class CSharpStates(CLikeStates):
|
|
31
|
+
def __init__(self, context):
|
|
32
|
+
super(CSharpStates, self).__init__(context)
|
|
33
|
+
self.in_primary_constructor = False
|
|
34
|
+
self.class_name = None
|
|
35
|
+
|
|
36
|
+
def try_new_function(self, name):
|
|
37
|
+
if not self.in_primary_constructor:
|
|
38
|
+
super(CSharpStates, self).try_new_function(name)
|
|
39
|
+
if self.class_name and self.context.current_function:
|
|
40
|
+
self.context.current_function.name = f"{self.class_name}::{name}"
|
|
41
|
+
|
|
42
|
+
def _state_global(self, token):
|
|
43
|
+
if token in ("class", "struct", "record"):
|
|
44
|
+
self.class_name = None
|
|
45
|
+
self._state = self._state_class_declaration
|
|
46
|
+
else:
|
|
47
|
+
super(CSharpStates, self)._state_global(token)
|
|
48
|
+
|
|
49
|
+
def _state_class_declaration(self, token):
|
|
50
|
+
if token == '(': # Primary constructor
|
|
51
|
+
self.in_primary_constructor = True
|
|
52
|
+
self._state = self._state_primary_constructor
|
|
53
|
+
elif token == '{':
|
|
54
|
+
self._state = self._state_global
|
|
55
|
+
elif token[0].isalpha():
|
|
56
|
+
if not self.class_name: # Only set class name if not already set
|
|
57
|
+
self.class_name = token
|
|
58
|
+
|
|
59
|
+
@CLikeStates.read_inside_brackets_then("()", "_state_class_declaration")
|
|
60
|
+
def _state_primary_constructor(self, _):
|
|
61
|
+
"""Skip primary constructor parameters without counting them as a function"""
|
|
62
|
+
self.in_primary_constructor = False
|
lizard_languages/java.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Language parser for Java
|
|
3
3
|
'''
|
|
4
4
|
|
|
5
|
+
from lizard_languages.code_reader import CodeStateMachine
|
|
5
6
|
from .clike import CLikeReader, CLikeStates, CLikeNestingStackStates
|
|
6
7
|
|
|
7
8
|
|
|
@@ -19,19 +20,48 @@ class JavaReader(CLikeReader):
|
|
|
19
20
|
|
|
20
21
|
|
|
21
22
|
class JavaStates(CLikeStates): # pylint: disable=R0903
|
|
23
|
+
def __init__(self, context):
|
|
24
|
+
super(JavaStates, self).__init__(context)
|
|
25
|
+
self.class_name = None
|
|
26
|
+
self.is_record = False
|
|
27
|
+
self.in_record_constructor = False
|
|
28
|
+
|
|
22
29
|
def _state_old_c_params(self, token):
|
|
23
30
|
if token == '{':
|
|
24
31
|
self._state_dec_to_imp(token)
|
|
25
32
|
|
|
33
|
+
def _state_imp(self, token):
|
|
34
|
+
def callback():
|
|
35
|
+
self.next(self._state_global)
|
|
36
|
+
self.sub_state(JavaFunctionBodyStates(self.context), callback, token)
|
|
37
|
+
|
|
26
38
|
def try_new_function(self, name):
|
|
39
|
+
# Don't create a function for record compact constructor
|
|
40
|
+
if self.is_record and name == self.class_name:
|
|
41
|
+
self.in_record_constructor = True
|
|
42
|
+
self._state = self._state_record_compact_constructor
|
|
43
|
+
return
|
|
27
44
|
self.context.try_new_function(name)
|
|
28
45
|
self._state = self._state_function
|
|
46
|
+
if self.class_name and self.context.current_function:
|
|
47
|
+
self.context.current_function.name = f"{self.class_name}::{name}"
|
|
48
|
+
|
|
49
|
+
def _try_start_a_class(self, token):
|
|
50
|
+
if token in ("class", "record", "enum"):
|
|
51
|
+
self.class_name = None
|
|
52
|
+
self.is_record = token == "record"
|
|
53
|
+
self.in_record_constructor = False
|
|
54
|
+
self._state = self._state_class_declaration
|
|
55
|
+
return True
|
|
29
56
|
|
|
30
57
|
def _state_global(self, token):
|
|
31
58
|
if token == '@':
|
|
32
59
|
self._state = self._state_decorator
|
|
33
60
|
return
|
|
34
|
-
|
|
61
|
+
if self._try_start_a_class(token):
|
|
62
|
+
return
|
|
63
|
+
if not self.in_record_constructor: # Only process as potential function if not in record constructor
|
|
64
|
+
super(JavaStates, self)._state_global(token)
|
|
35
65
|
|
|
36
66
|
def _state_decorator(self, _):
|
|
37
67
|
self._state = self._state_post_decorator
|
|
@@ -42,3 +72,71 @@ class JavaStates(CLikeStates): # pylint: disable=R0903
|
|
|
42
72
|
else:
|
|
43
73
|
self._state = self._state_global
|
|
44
74
|
self._state(token)
|
|
75
|
+
|
|
76
|
+
def _state_class_declaration(self, token):
|
|
77
|
+
if token == '{':
|
|
78
|
+
def callback():
|
|
79
|
+
self._state = self._state_global
|
|
80
|
+
self.sub_state(JavaClassBodyStates(self.class_name, self.is_record, self.context), callback, token)
|
|
81
|
+
elif token == '(': # Record parameters
|
|
82
|
+
self._state = self._state_record_parameters
|
|
83
|
+
elif token[0].isalpha():
|
|
84
|
+
if not self.class_name: # Only set class name if not already set
|
|
85
|
+
self.class_name = token
|
|
86
|
+
|
|
87
|
+
def _state_record_parameters(self, token):
|
|
88
|
+
if token == ')':
|
|
89
|
+
self._state = self._state_class_declaration
|
|
90
|
+
|
|
91
|
+
def _state_record_compact_constructor(self, token):
|
|
92
|
+
if token == '{':
|
|
93
|
+
self._state = self._state_record_constructor_body
|
|
94
|
+
return
|
|
95
|
+
self._state = self._state_global
|
|
96
|
+
self._state(token)
|
|
97
|
+
|
|
98
|
+
def _state_record_constructor_body(self, token):
|
|
99
|
+
if token == '}':
|
|
100
|
+
self.in_record_constructor = False
|
|
101
|
+
self._state = self._state_global
|
|
102
|
+
|
|
103
|
+
class JavaFunctionBodyStates(JavaStates):
|
|
104
|
+
def __init__(self, context):
|
|
105
|
+
super(JavaFunctionBodyStates, self).__init__(context)
|
|
106
|
+
|
|
107
|
+
@CodeStateMachine.read_inside_brackets_then("{}", "_state_dummy")
|
|
108
|
+
@CodeStateMachine.read_inside_brackets_then("()", "_state_dummy")
|
|
109
|
+
def _state_global(self, token):
|
|
110
|
+
if token == "new":
|
|
111
|
+
self.next(self._state_new)
|
|
112
|
+
self._try_start_a_class(token)
|
|
113
|
+
if self.br_count == 0:
|
|
114
|
+
self.statemachine_return()
|
|
115
|
+
|
|
116
|
+
def _state_dummy(self, _):
|
|
117
|
+
pass
|
|
118
|
+
|
|
119
|
+
def _state_new(self, token):
|
|
120
|
+
self.next(self._state_new_parameters)
|
|
121
|
+
|
|
122
|
+
def _state_new_parameters(self, token):
|
|
123
|
+
if token == "(":
|
|
124
|
+
self.sub_state(JavaFunctionBodyStates(self.context), None, token)
|
|
125
|
+
return
|
|
126
|
+
if token == "{":
|
|
127
|
+
def callback():
|
|
128
|
+
self.next(self._state_global)
|
|
129
|
+
self.sub_state(JavaClassBodyStates("(anonymous)", False, self.context), callback, token)
|
|
130
|
+
return
|
|
131
|
+
self.next(self._state_global)
|
|
132
|
+
|
|
133
|
+
class JavaClassBodyStates(JavaStates):
|
|
134
|
+
def __init__(self, class_name, is_record, context):
|
|
135
|
+
super(JavaClassBodyStates, self).__init__(context)
|
|
136
|
+
self.class_name = class_name
|
|
137
|
+
self.is_record = is_record
|
|
138
|
+
|
|
139
|
+
def _state_global(self, token):
|
|
140
|
+
super()._state_global(token)
|
|
141
|
+
if token == '}':
|
|
142
|
+
self.statemachine_return()
|
lizard_languages/javascript.py
CHANGED
|
@@ -2,17 +2,13 @@
|
|
|
2
2
|
Language parser for JavaScript
|
|
3
3
|
'''
|
|
4
4
|
|
|
5
|
-
from .
|
|
6
|
-
from .clike import CCppCommentsMixin
|
|
7
|
-
from .js_style_regex_expression import js_style_regex_expression
|
|
8
|
-
from .js_style_language_states import JavaScriptStyleLanguageStates
|
|
9
|
-
from .typescript import TypeScriptReader, JSTokenizer
|
|
5
|
+
from .typescript import TypeScriptReader
|
|
10
6
|
|
|
11
7
|
|
|
12
8
|
class JavaScriptReader(TypeScriptReader):
|
|
13
9
|
# pylint: disable=R0903
|
|
14
10
|
|
|
15
|
-
ext = ['js']
|
|
11
|
+
ext = ['js', 'cjs', 'mjs']
|
|
16
12
|
language_names = ['javascript', 'js']
|
|
17
13
|
|
|
18
14
|
def __init__(self, context):
|
lizard_languages/jsx.py
CHANGED
|
@@ -8,6 +8,20 @@ from .code_reader import CodeReader
|
|
|
8
8
|
from .js_style_regex_expression import js_style_regex_expression
|
|
9
9
|
|
|
10
10
|
|
|
11
|
+
class TSXTokenizer(JSTokenizer):
|
|
12
|
+
def __init__(self):
|
|
13
|
+
super().__init__()
|
|
14
|
+
|
|
15
|
+
def process_token(self, token):
|
|
16
|
+
if token == "<":
|
|
17
|
+
from .jsx import XMLTagWithAttrTokenizer # Import only when needed
|
|
18
|
+
self.sub_tokenizer = XMLTagWithAttrTokenizer()
|
|
19
|
+
return
|
|
20
|
+
|
|
21
|
+
for tok in super().process_token(token):
|
|
22
|
+
yield tok
|
|
23
|
+
|
|
24
|
+
|
|
11
25
|
class JSXMixin:
|
|
12
26
|
'''Base mixin class for JSX/TSX shared functionality'''
|
|
13
27
|
@staticmethod
|
|
@@ -17,7 +31,7 @@ class JSXMixin:
|
|
|
17
31
|
r"|(?:\$\w+)" + \
|
|
18
32
|
r"|(?:\<\/\w+\>)" + \
|
|
19
33
|
r"|`.*?`"
|
|
20
|
-
js_tokenizer =
|
|
34
|
+
js_tokenizer = TSXTokenizer()
|
|
21
35
|
for token in CodeReader.generate_tokens(
|
|
22
36
|
source_code, addition, token_class):
|
|
23
37
|
for tok in js_tokenizer(token):
|
|
@@ -102,7 +116,7 @@ class XMLTagWithAttrTokenizer(Tokenizer):
|
|
|
102
116
|
self.state = self._after_tag
|
|
103
117
|
elif token == "{":
|
|
104
118
|
self.cache.append("}")
|
|
105
|
-
self.sub_tokenizer =
|
|
119
|
+
self.sub_tokenizer = TSXTokenizer()
|
|
106
120
|
self.state = self._after_tag
|
|
107
121
|
|
|
108
122
|
def _body(self, token):
|
|
@@ -116,7 +130,7 @@ class XMLTagWithAttrTokenizer(Tokenizer):
|
|
|
116
130
|
return self.flush()
|
|
117
131
|
|
|
118
132
|
if token == '{':
|
|
119
|
-
self.sub_tokenizer =
|
|
133
|
+
self.sub_tokenizer = TSXTokenizer()
|
|
120
134
|
return self.flush()
|
|
121
135
|
|
|
122
136
|
|
lizard_languages/ruby.py
CHANGED
|
@@ -9,11 +9,12 @@ from .script_language import ScriptLanguageMixIn
|
|
|
9
9
|
|
|
10
10
|
class MyToken(str):
|
|
11
11
|
def __new__(cls, value, *_):
|
|
12
|
-
|
|
12
|
+
val = value.group(0) if hasattr(value, 'group') else value
|
|
13
|
+
return super(MyToken, cls).__new__(cls, val)
|
|
13
14
|
|
|
14
15
|
def __init__(self, value):
|
|
15
16
|
super(MyToken, self).__init__()
|
|
16
|
-
self.begin = value.start()
|
|
17
|
+
self.begin = value.start() if hasattr(value, 'start') else 0
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
class RubyReader(RubylikeReader):
|
lizard_languages/tsx.py
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
Language parser for TSX
|
|
3
3
|
'''
|
|
4
4
|
|
|
5
|
-
from .typescript import TypeScriptReader
|
|
5
|
+
from .typescript import TypeScriptReader
|
|
6
6
|
from .jsx import JSXMixin
|
|
7
|
-
from .code_reader import CodeReader
|
|
8
7
|
from .js_style_regex_expression import js_style_regex_expression
|
|
9
8
|
|
|
10
9
|
|
lizard_languages/typescript.py
CHANGED
|
@@ -37,10 +37,6 @@ class JSTokenizer(Tokenizer):
|
|
|
37
37
|
self.depth = 1
|
|
38
38
|
|
|
39
39
|
def process_token(self, token):
|
|
40
|
-
if token == "<":
|
|
41
|
-
from .jsx import XMLTagWithAttrTokenizer # Import only when needed
|
|
42
|
-
self.sub_tokenizer = XMLTagWithAttrTokenizer()
|
|
43
|
-
return
|
|
44
40
|
if token == "{":
|
|
45
41
|
self.depth += 1
|
|
46
42
|
elif token == "}":
|
|
@@ -115,10 +111,18 @@ class TypeScriptTypeAnnotationStates(CodeStateMachine):
|
|
|
115
111
|
self.next(self._state_simple_type, token)
|
|
116
112
|
|
|
117
113
|
def _state_simple_type(self, token):
|
|
118
|
-
|
|
114
|
+
print(token)
|
|
115
|
+
if token == '<':
|
|
116
|
+
print(token)
|
|
117
|
+
self.next(self._state_generic_type, token)
|
|
118
|
+
elif token in '{=;':
|
|
119
119
|
self.saved_token = token
|
|
120
120
|
self.statemachine_return()
|
|
121
121
|
|
|
122
122
|
@CodeStateMachine.read_inside_brackets_then("{}")
|
|
123
123
|
def _inline_type_annotation(self, _):
|
|
124
124
|
self.statemachine_return()
|
|
125
|
+
|
|
126
|
+
@CodeStateMachine.read_inside_brackets_then("<>")
|
|
127
|
+
def _state_generic_type(self, token):
|
|
128
|
+
self.statemachine_return()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|