lizard 1.17.14__tar.gz → 1.17.15__tar.gz

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.
Files changed (102) hide show
  1. {lizard-1.17.14 → lizard-1.17.15}/PKG-INFO +2 -1
  2. {lizard-1.17.14 → lizard-1.17.15}/README.rst +1 -0
  3. {lizard-1.17.14 → lizard-1.17.15}/lizard.egg-info/PKG-INFO +2 -1
  4. {lizard-1.17.14 → lizard-1.17.15}/lizard.egg-info/SOURCES.txt +1 -0
  5. {lizard-1.17.14 → lizard-1.17.15}/lizard.py +5 -10
  6. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/csvoutput.py +11 -25
  7. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/version.py +1 -1
  8. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/__init__.py +2 -0
  9. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/code_reader.py +2 -1
  10. lizard-1.17.15/lizard_languages/javascript.py +19 -0
  11. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/js_style_language_states.py +20 -21
  12. lizard-1.17.15/lizard_languages/js_style_regex_expression.py +53 -0
  13. lizard-1.17.14/lizard_languages/javascript.py → lizard-1.17.15/lizard_languages/jsx.py +21 -47
  14. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/script_language.py +1 -1
  15. lizard-1.17.15/lizard_languages/tsx.py +24 -0
  16. lizard-1.17.15/lizard_languages/typescript.py +124 -0
  17. lizard-1.17.15/lizard_languages/vue.py +34 -0
  18. lizard-1.17.14/lizard_languages/js_style_regex_expression.py +0 -23
  19. lizard-1.17.14/lizard_languages/jsx.py +0 -27
  20. lizard-1.17.14/lizard_languages/tsx.py +0 -44
  21. lizard-1.17.14/lizard_languages/typescript.py +0 -75
  22. {lizard-1.17.14 → lizard-1.17.15}/LICENSE.txt +0 -0
  23. {lizard-1.17.14 → lizard-1.17.15}/lizard.egg-info/dependency_links.txt +0 -0
  24. {lizard-1.17.14 → lizard-1.17.15}/lizard.egg-info/entry_points.txt +0 -0
  25. {lizard-1.17.14 → lizard-1.17.15}/lizard.egg-info/requires.txt +0 -0
  26. {lizard-1.17.14 → lizard-1.17.15}/lizard.egg-info/top_level.txt +0 -0
  27. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/__init__.py +0 -0
  28. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/auto_open.py +0 -0
  29. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/default_ordered_dict.py +0 -0
  30. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/extension_base.py +0 -0
  31. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/htmloutput.py +0 -0
  32. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/keywords.py +0 -0
  33. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/lizardboolcount.py +0 -0
  34. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/lizardcomplextags.py +0 -0
  35. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/lizardcpre.py +0 -0
  36. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/lizarddependencycount.py +0 -0
  37. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/lizarddumpcomments.py +0 -0
  38. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/lizardduplicate.py +0 -0
  39. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/lizardduplicated_param_list.py +0 -0
  40. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/lizardexitcount.py +0 -0
  41. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/lizardgotocount.py +0 -0
  42. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/lizardignoreassert.py +0 -0
  43. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/lizardio.py +0 -0
  44. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/lizardmccabe.py +0 -0
  45. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/lizardmodified.py +0 -0
  46. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/lizardnd.py +0 -0
  47. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/lizardnonstrict.py +0 -0
  48. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/lizardns.py +0 -0
  49. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/lizardoutside.py +0 -0
  50. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/lizardstatementcount.py +0 -0
  51. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/lizardwordcount.py +0 -0
  52. {lizard-1.17.14 → lizard-1.17.15}/lizard_ext/xmloutput.py +0 -0
  53. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/clike.py +0 -0
  54. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/csharp.py +0 -0
  55. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/erlang.py +0 -0
  56. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/fortran.py +0 -0
  57. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/gdscript.py +0 -0
  58. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/go.py +0 -0
  59. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/golike.py +0 -0
  60. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/java.py +0 -0
  61. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/kotlin.py +0 -0
  62. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/lua.py +0 -0
  63. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/objc.py +0 -0
  64. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/php.py +0 -0
  65. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/python.py +0 -0
  66. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/ruby.py +0 -0
  67. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/rubylike.py +0 -0
  68. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/rust.py +0 -0
  69. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/scala.py +0 -0
  70. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/solidity.py +0 -0
  71. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/swift.py +0 -0
  72. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/tnsdl.py +0 -0
  73. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/ttcn.py +0 -0
  74. {lizard-1.17.14 → lizard-1.17.15}/lizard_languages/zig.py +0 -0
  75. {lizard-1.17.14 → lizard-1.17.15}/setup.cfg +0 -0
  76. {lizard-1.17.14 → lizard-1.17.15}/setup.py +0 -0
  77. {lizard-1.17.14 → lizard-1.17.15}/test/testApplication.py +0 -0
  78. {lizard-1.17.14 → lizard-1.17.15}/test/testAssertionExtension.py +0 -0
  79. {lizard-1.17.14 → lizard-1.17.15}/test/testBasicFunctionInfo.py +0 -0
  80. {lizard-1.17.14 → lizard-1.17.15}/test/testCOutsideComplexity.py +0 -0
  81. {lizard-1.17.14 → lizard-1.17.15}/test/testCPreprocessorExtension.py +0 -0
  82. {lizard-1.17.14 → lizard-1.17.15}/test/testCommentOptions.py +0 -0
  83. {lizard-1.17.14 → lizard-1.17.15}/test/testCyclomaticComplexity.py +0 -0
  84. {lizard-1.17.14 → lizard-1.17.15}/test/testExtension.py +0 -0
  85. {lizard-1.17.14 → lizard-1.17.15}/test/testFilesFilter.py +0 -0
  86. {lizard-1.17.14 → lizard-1.17.15}/test/testFunctionDependencyCount.py +0 -0
  87. {lizard-1.17.14 → lizard-1.17.15}/test/testFunctionExitCount.py +0 -0
  88. {lizard-1.17.14 → lizard-1.17.15}/test/testFunctionGotoCount.py +0 -0
  89. {lizard-1.17.14 → lizard-1.17.15}/test/testFunctionStatementCount.py +0 -0
  90. {lizard-1.17.14 → lizard-1.17.15}/test/testHelpers.py +0 -0
  91. {lizard-1.17.14 → lizard-1.17.15}/test/testLanguages.py +0 -0
  92. {lizard-1.17.14 → lizard-1.17.15}/test/testMcCabe.py +0 -0
  93. {lizard-1.17.14 → lizard-1.17.15}/test/testNestedStructures.py +0 -0
  94. {lizard-1.17.14 → lizard-1.17.15}/test/testNestingDepth.py +0 -0
  95. {lizard-1.17.14 → lizard-1.17.15}/test/testOutput.py +0 -0
  96. {lizard-1.17.14 → lizard-1.17.15}/test/testOutputCSV.py +0 -0
  97. {lizard-1.17.14 → lizard-1.17.15}/test/testOutputFile.py +0 -0
  98. {lizard-1.17.14 → lizard-1.17.15}/test/testOutputHTML.py +0 -0
  99. {lizard-1.17.14 → lizard-1.17.15}/test/testTokenizer.py +0 -0
  100. {lizard-1.17.14 → lizard-1.17.15}/test/test_analyzer.py +0 -0
  101. {lizard-1.17.14 → lizard-1.17.15}/test/test_auto_open.py +0 -0
  102. {lizard-1.17.14 → lizard-1.17.15}/test/test_options.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lizard
3
- Version: 1.17.14
3
+ Version: 1.17.15
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/
@@ -53,6 +53,7 @@ A list of supported languages:
53
53
  - C# (C Sharp)
54
54
  - JavaScript (With ES6 and JSX)
55
55
  - TypeScript (With TSX)
56
+ - VueJS
56
57
  - Objective-C
57
58
  - Swift
58
59
  - Python
@@ -22,6 +22,7 @@ A list of supported languages:
22
22
  - C# (C Sharp)
23
23
  - JavaScript (With ES6 and JSX)
24
24
  - TypeScript (With TSX)
25
+ - VueJS
25
26
  - Objective-C
26
27
  - Swift
27
28
  - Python
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lizard
3
- Version: 1.17.14
3
+ Version: 1.17.15
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/
@@ -53,6 +53,7 @@ A list of supported languages:
53
53
  - C# (C Sharp)
54
54
  - JavaScript (With ES6 and JSX)
55
55
  - TypeScript (With TSX)
56
+ - VueJS
56
57
  - Objective-C
57
58
  - Swift
58
59
  - Python
@@ -67,6 +67,7 @@ lizard_languages/tnsdl.py
67
67
  lizard_languages/tsx.py
68
68
  lizard_languages/ttcn.py
69
69
  lizard_languages/typescript.py
70
+ lizard_languages/vue.py
70
71
  lizard_languages/zig.py
71
72
  test/testApplication.py
72
73
  test/testAssertionExtension.py
@@ -298,8 +298,7 @@ class FunctionInfo(Nesting): # pylint: disable=R0902
298
298
  return self.name.split('::')[-1]
299
299
 
300
300
  location = property(lambda self:
301
- " %(name)s@%(start_line)s-%(end_line)s@%(filename)s"
302
- % self.__dict__)
301
+ f" {self.name}@{self.start_line}-{self.end_line}@{self.filename}")
303
302
 
304
303
  parameter_count = property(lambda self: len(self.parameters))
305
304
 
@@ -723,17 +722,13 @@ class OutputScheme(object):
723
722
  if e.get("avg_caption", None)])
724
723
 
725
724
  def clang_warning_format(self):
726
- return (
727
- "{f.filename}:{f.start_line}: warning: {f.name} has " +
728
- ", ".join([
729
- "{{f.{ext[value]}}} {caption}"
730
- .format(ext=e, caption=e['caption'].strip())
731
- for e in self.items[:-1]
732
- ]))
725
+ return ("{f.filename}:{f.start_line}: warning: {f.name} has {f.nloc} NLOC, "
726
+ "{f.cyclomatic_complexity} CCN, {f.token_count} token, {f.parameter_count} PARAM, "
727
+ "{f.length} length, {f.max_nesting_depth} ND")
733
728
 
734
729
  def msvs_warning_format(self):
735
730
  return (
736
- "{f.filename}({f.start_line}): warning: {f.name} has " +
731
+ "{f.filename}({f.start_line}): warning: {f.name} ({f.long_name}) has " +
737
732
  ", ".join([
738
733
  "{{f.{ext[value]}}} {caption}"
739
734
  .format(ext=e, caption=e['caption'].strip())
@@ -36,9 +36,9 @@ def csv_output(result, options):
36
36
  if options.verbose:
37
37
  extension_caption = ""
38
38
  for caption in extension_captions:
39
- extension_caption = "{},{}".format(extension_caption, caption)
40
- print("NLOC,CCN,token,PARAM,length,location,file,function," +
41
- "long_name,start,end{}".format(extension_caption))
39
+ extension_caption = f"{extension_caption},{caption}"
40
+ print(f"NLOC,CCN,token,PARAM,length,location,file,function," +
41
+ f"long_name,start,end{extension_caption}")
42
42
 
43
43
  for source_file in result:
44
44
  if source_file:
@@ -46,25 +46,11 @@ def csv_output(result, options):
46
46
  if source_function:
47
47
  extension_string = ''
48
48
  for variable in extension_variables:
49
- extension_string = '{},{}'.\
50
- format(extension_string,
51
- source_function.__getattribute__(variable))
52
- print('{},{},{},{},{},"{}","{}","{}","{}",{},{}{}'.format(
53
- source_function.nloc,
54
- source_function.cyclomatic_complexity,
55
- source_function.token_count,
56
- len(source_function.parameters),
57
- source_function.length,
58
- "{}@{}-{}@{}".format(
59
- source_function.name.replace("\"", "'"),
60
- source_function.start_line,
61
- source_function.end_line,
62
- source_file.filename
63
- ),
64
- source_file.filename,
65
- source_function.name.replace("\"", "'"),
66
- source_function.long_name.replace("\"", "'"),
67
- source_function.start_line,
68
- source_function.end_line,
69
- extension_string
70
- ))
49
+ extension_string = f"{extension_string},{source_function.__getattribute__(variable)}"
50
+ print(f"{source_function.nloc},{source_function.cyclomatic_complexity},"
51
+ f"{source_function.token_count},{len(source_function.parameters)},"
52
+ f'{source_function.length},"{source_function.name.replace(chr(34), chr(39))}@'
53
+ f'{source_function.start_line}-{source_function.end_line}@{source_file.filename}",'
54
+ f'"{source_file.filename}","{source_function.name.replace(chr(34), chr(39))}",'
55
+ f'"{source_function.long_name.replace(chr(34), chr(39))}",'
56
+ f"{source_function.start_line},{source_function.end_line}{extension_string}")
@@ -3,4 +3,4 @@
3
3
  #
4
4
  # pylint: disable=missing-docstring,invalid-name
5
5
 
6
- version = "1.17.14"
6
+ version = "1.17.15"
@@ -23,6 +23,7 @@ from .fortran import FortranReader
23
23
  from .solidity import SolidityReader
24
24
  from .jsx import JSXReader
25
25
  from .tsx import TSXReader
26
+ from .vue import VueReader
26
27
 
27
28
 
28
29
  def languages():
@@ -50,6 +51,7 @@ def languages():
50
51
  ZigReader,
51
52
  JSXReader,
52
53
  TSXReader,
54
+ VueReader,
53
55
  ]
54
56
 
55
57
 
@@ -8,7 +8,7 @@ from functools import reduce
8
8
  from operator import or_
9
9
 
10
10
 
11
- class CodeStateMachine(object):
11
+ class CodeStateMachine:
12
12
  """ the state machine """
13
13
  # pylint: disable=R0903
14
14
  # pylint: disable=R0902
@@ -50,6 +50,7 @@ class CodeStateMachine(object):
50
50
  self.next(self.saved_state)
51
51
  if self.callback:
52
52
  self.callback()
53
+ self.callback = None
53
54
  self.last_token = token
54
55
  if self.to_exit:
55
56
  return True
@@ -0,0 +1,19 @@
1
+ '''
2
+ Language parser for JavaScript
3
+ '''
4
+
5
+ from .code_reader import CodeReader
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
10
+
11
+
12
+ class JavaScriptReader(TypeScriptReader):
13
+ # pylint: disable=R0903
14
+
15
+ ext = ['js']
16
+ language_names = ['javascript', 'js']
17
+
18
+ def __init__(self, context):
19
+ super(JavaScriptReader, self).__init__(context)
@@ -11,8 +11,18 @@ class JavaScriptStyleLanguageStates(CodeStateMachine): # pylint: disable=R0903
11
11
  self.last_tokens = ''
12
12
  self.function_name = ''
13
13
  self.started_function = None
14
+ self.as_object = False
14
15
 
15
16
  def _state_global(self, token):
17
+ if self.as_object:
18
+ if token == ':':
19
+ self.function_name = self.last_tokens
20
+ return
21
+ elif token == '(':
22
+ self._function(self.last_tokens)
23
+ self.next(self._function, token)
24
+ return
25
+
16
26
  if token in '.':
17
27
  self._state = self._field
18
28
  self.last_tokens += token
@@ -29,11 +39,11 @@ class JavaScriptStyleLanguageStates(CodeStateMachine): # pylint: disable=R0903
29
39
  self.function_name = self.last_tokens
30
40
  elif token == "(":
31
41
  self.sub_state(
32
- JavaScriptStyleLanguageStates(self.context))
42
+ self.__class__(self.context))
33
43
  elif token in '{':
34
44
  if self.started_function:
35
45
  self.sub_state(
36
- JavaScriptStyleLanguageStates(self.context),
46
+ self.__class__(self.context),
37
47
  self._pop_function_from_stack)
38
48
  else:
39
49
  self.read_object()
@@ -46,7 +56,12 @@ class JavaScriptStyleLanguageStates(CodeStateMachine): # pylint: disable=R0903
46
56
  self.last_tokens = token
47
57
 
48
58
  def read_object(self):
49
- self.sub_state(ES6ObjectStates(self.context))
59
+ def callback():
60
+ self.next(self._state_global)
61
+
62
+ object_reader = self.__class__(self.context)
63
+ object_reader.as_object = True
64
+ self.sub_state(object_reader, callback)
50
65
 
51
66
  def statemachine_before_return(self):
52
67
  self._pop_function_from_stack()
@@ -63,16 +78,14 @@ class JavaScriptStyleLanguageStates(CodeStateMachine): # pylint: disable=R0903
63
78
  return
64
79
 
65
80
  self.sub_state(
66
- JavaScriptStyleLanguageStates(self.context),
67
- callback)
81
+ self.__class__(self.context), callback)
68
82
 
69
83
  def _expecting_statement_or_block(self, token):
70
84
  def callback():
71
85
  self.next(self._state_global)
72
86
  if token == "{":
73
87
  self.sub_state(
74
- JavaScriptStyleLanguageStates(self.context),
75
- callback)
88
+ self.__class__(self.context), callback)
76
89
  else:
77
90
  self.next(self._state_global, token)
78
91
 
@@ -116,17 +129,3 @@ class JavaScriptStyleLanguageStates(CodeStateMachine): # pylint: disable=R0903
116
129
  if token != '{':
117
130
  self.started_function = None
118
131
  self.next(self._state_global, token)
119
-
120
-
121
- class ES6ObjectStates(JavaScriptStyleLanguageStates): # pylint: disable=R0903
122
- def __init__(self, context):
123
- super(ES6ObjectStates, self).__init__(context)
124
-
125
- def _state_global(self, token):
126
- if token == ':':
127
- self.function_name = self.last_tokens
128
- elif token == '(':
129
- self._function(self.last_tokens)
130
- self.next(self._function, token)
131
- else:
132
- super(ES6ObjectStates, self)._state_global(token)
@@ -0,0 +1,53 @@
1
+ '''
2
+ generate token with javascript style regular expression.
3
+ '''
4
+
5
+ import re
6
+
7
+
8
+ def js_style_regex_expression(func):
9
+ def generate_tokens_with_regex(source_code, addition='', token_class=None):
10
+ regx_regx = r"\/(\S*?[^\s\\]\/)+?(igm)*"
11
+ regx_pattern = re.compile(regx_regx)
12
+ tokens = list(func(source_code, addition, token_class))
13
+ result = []
14
+ i = 0
15
+ while i < len(tokens):
16
+ token = tokens[i]
17
+ if token == '/':
18
+ # Check if this could be a regex pattern
19
+ is_regex = False
20
+ if i == 0:
21
+ is_regex = True
22
+ elif i > 0:
23
+ prev_token = tokens[i-1].strip()
24
+ if prev_token and prev_token[-1] in '=,({[?:!&|;':
25
+ is_regex = True
26
+
27
+ if is_regex:
28
+ # This is likely a regex pattern start
29
+ regex_tokens = [token]
30
+ i += 1
31
+ while i < len(tokens) and not tokens[i].endswith('/'):
32
+ regex_tokens.append(tokens[i])
33
+ i += 1
34
+ if i < len(tokens):
35
+ regex_tokens.append(tokens[i])
36
+ i += 1
37
+ # Check for regex flags
38
+ if i < len(tokens) and re.match(r'^[igm]+$', tokens[i]):
39
+ regex_tokens.append(tokens[i])
40
+ i += 1
41
+ combined = ''.join(regex_tokens)
42
+ if regx_pattern.match(combined):
43
+ result.append(combined)
44
+ else:
45
+ result.extend(regex_tokens)
46
+ else:
47
+ # This is a division operator
48
+ result.append(token)
49
+ else:
50
+ result.append(token)
51
+ i += 1
52
+ return result
53
+ return generate_tokens_with_regex
@@ -1,24 +1,21 @@
1
1
  '''
2
- Language parser for JavaScript
2
+ Language parser for JSX
3
3
  '''
4
4
 
5
+ from .javascript import JavaScriptReader
6
+ from .typescript import JSTokenizer, Tokenizer
5
7
  from .code_reader import CodeReader
6
- from .clike import CCppCommentsMixin
7
8
  from .js_style_regex_expression import js_style_regex_expression
8
- from .js_style_language_states import JavaScriptStyleLanguageStates
9
9
 
10
10
 
11
- class JavaScriptReader(CodeReader, CCppCommentsMixin):
12
- # pylint: disable=R0903
13
-
14
- ext = ['js']
15
- language_names = ['javascript', 'js']
16
-
11
+ class JSXMixin:
12
+ '''Base mixin class for JSX/TSX shared functionality'''
17
13
  @staticmethod
18
14
  @js_style_regex_expression
19
15
  def generate_tokens(source_code, addition='', token_class=None):
20
16
  addition = addition +\
21
17
  r"|(?:\$\w+)" + \
18
+ r"|(?:\<\/\w+\>)" + \
22
19
  r"|`.*?`"
23
20
  js_tokenizer = JSTokenizer()
24
21
  for token in CodeReader.generate_tokens(
@@ -26,50 +23,27 @@ class JavaScriptReader(CodeReader, CCppCommentsMixin):
26
23
  for tok in js_tokenizer(token):
27
24
  yield tok
28
25
 
29
- def __init__(self, context):
30
- super(JavaScriptReader, self).__init__(context)
31
- self.parallel_states = [JavaScriptStyleLanguageStates(context)]
32
-
33
-
34
- class Tokenizer(object):
35
- def __init__(self):
36
- self.sub_tokenizer = None
37
- self._ended = False
38
-
39
- def __call__(self, token):
40
- if self.sub_tokenizer:
41
- for tok in self.sub_tokenizer(token):
42
- yield tok
43
- if self.sub_tokenizer._ended:
44
- self.sub_tokenizer = None
26
+ def _expecting_func_opening_bracket(self, token):
27
+ if token == '<':
28
+ self.next(self._expecting_jsx)
45
29
  return
46
- for tok in self.process_token(token):
47
- yield tok
30
+ super()._expecting_func_opening_bracket(token)
48
31
 
49
- def stop(self):
50
- self._ended = True
32
+ def _expecting_jsx(self, token):
33
+ if token == '>':
34
+ self.next(self._expecting_func_opening_bracket)
51
35
 
52
- def process_token(self, token):
53
- pass
54
36
 
37
+ class JSXReader(JavaScriptReader, JSXMixin):
38
+ # pylint: disable=R0903
55
39
 
56
- class JSTokenizer(Tokenizer):
57
- def __init__(self):
58
- super(JSTokenizer, self).__init__()
59
- self.depth = 1
40
+ ext = ['jsx']
41
+ language_names = ['jsx']
60
42
 
61
- def process_token(self, token):
62
- if token == "<":
63
- self.sub_tokenizer = XMLTagWithAttrTokenizer()
64
- return
65
- if token == "{":
66
- self.depth += 1
67
- elif token == "}":
68
- self.depth -= 1
69
- if self.depth == 0:
70
- self.stop()
71
- return
72
- yield token
43
+ @staticmethod
44
+ @js_style_regex_expression
45
+ def generate_tokens(source_code, addition='', token_class=None):
46
+ return JSXMixin.generate_tokens(source_code, addition, token_class)
73
47
 
74
48
 
75
49
  class XMLTagWithAttrTokenizer(Tokenizer):
@@ -4,7 +4,7 @@ Common behaviours of script languages
4
4
  from .code_reader import CodeReader
5
5
 
6
6
 
7
- class ScriptLanguageMixIn(object):
7
+ class ScriptLanguageMixIn:
8
8
  # pylint: disable=R0903
9
9
 
10
10
  @staticmethod
@@ -0,0 +1,24 @@
1
+ '''
2
+ Language parser for TSX
3
+ '''
4
+
5
+ from .typescript import TypeScriptReader, TypeScriptStates, JSTokenizer
6
+ from .jsx import JSXMixin
7
+ from .code_reader import CodeReader
8
+ from .js_style_regex_expression import js_style_regex_expression
9
+
10
+
11
+ class TSXReader(TypeScriptReader, JSXMixin):
12
+ # pylint: disable=R0903
13
+
14
+ ext = ['tsx']
15
+ language_names = ['tsx']
16
+
17
+ @staticmethod
18
+ @js_style_regex_expression
19
+ def generate_tokens(source_code, addition='', token_class=None):
20
+ return JSXMixin.generate_tokens(source_code, addition, token_class)
21
+
22
+ def __init__(self, context):
23
+ super(TSXReader, self).__init__(context)
24
+ # No need for parallel states since JSX handling is in the mixin
@@ -0,0 +1,124 @@
1
+ '''
2
+ Language parser for JavaScript
3
+ '''
4
+
5
+ import re
6
+ from .code_reader import CodeReader, CodeStateMachine
7
+ from .clike import CCppCommentsMixin
8
+ from .js_style_language_states import JavaScriptStyleLanguageStates
9
+ from .js_style_regex_expression import js_style_regex_expression
10
+
11
+
12
+ class Tokenizer(object):
13
+ def __init__(self):
14
+ self.sub_tokenizer = None
15
+ self._ended = False
16
+
17
+ def __call__(self, token):
18
+ if self.sub_tokenizer:
19
+ for tok in self.sub_tokenizer(token):
20
+ yield tok
21
+ if self.sub_tokenizer._ended:
22
+ self.sub_tokenizer = None
23
+ return
24
+ for tok in self.process_token(token):
25
+ yield tok
26
+
27
+ def stop(self):
28
+ self._ended = True
29
+
30
+ def process_token(self, token):
31
+ pass
32
+
33
+
34
+ class JSTokenizer(Tokenizer):
35
+ def __init__(self):
36
+ super().__init__()
37
+ self.depth = 1
38
+
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
+ if token == "{":
45
+ self.depth += 1
46
+ elif token == "}":
47
+ self.depth -= 1
48
+ if self.depth == 0:
49
+ self.stop()
50
+ return
51
+ yield token
52
+
53
+
54
+ class TypeScriptReader(CodeReader, CCppCommentsMixin):
55
+ # pylint: disable=R0903
56
+
57
+ ext = ['ts']
58
+ language_names = ['typescript', 'ts']
59
+ _conditions = set(['if', 'elseif', 'for', 'while', '&&', '||', '?',
60
+ 'catch', 'case'])
61
+
62
+ def __init__(self, context):
63
+ super().__init__(context)
64
+ self.parallel_states = [TypeScriptStates(context)]
65
+
66
+ @staticmethod
67
+ @js_style_regex_expression
68
+ def generate_tokens(source_code, addition='', token_class=None):
69
+ addition = addition +\
70
+ r"|(?:\$\w+)" + \
71
+ r"|(?:\w+\?)" + \
72
+ r"|`.*?`"
73
+ js_tokenizer = JSTokenizer()
74
+ for token in CodeReader.generate_tokens(
75
+ source_code, addition, token_class):
76
+ for tok in js_tokenizer(token):
77
+ yield tok
78
+
79
+
80
+ class TypeScriptStates(JavaScriptStyleLanguageStates):
81
+ def __init__(self, context):
82
+ super().__init__(context)
83
+
84
+ def _state_global(self, token):
85
+ if not self.as_object:
86
+ if token == ':':
87
+ self._consume_type_annotation()
88
+ return
89
+ super()._state_global(token)
90
+
91
+ def _expecting_func_opening_bracket(self, token):
92
+ if token == ':':
93
+ self._consume_type_annotation()
94
+ else:
95
+ super()._expecting_func_opening_bracket(token)
96
+
97
+ def _consume_type_annotation(self):
98
+ typeStates = TypeScriptTypeAnnotationStates(self.context)
99
+
100
+ def callback():
101
+ if typeStates.saved_token:
102
+ self(typeStates.saved_token)
103
+ self.sub_state(typeStates, callback)
104
+
105
+
106
+ class TypeScriptTypeAnnotationStates(CodeStateMachine):
107
+ def __init__(self, context):
108
+ super().__init__(context)
109
+ self.saved_token = None
110
+
111
+ def _state_global(self, token):
112
+ if token == '{':
113
+ self.next(self._inline_type_annotation, token)
114
+ else:
115
+ self.next(self._state_simple_type, token)
116
+
117
+ def _state_simple_type(self, token):
118
+ if token in '{=;':
119
+ self.saved_token = token
120
+ self.statemachine_return()
121
+
122
+ @CodeStateMachine.read_inside_brackets_then("{}")
123
+ def _inline_type_annotation(self, _):
124
+ self.statemachine_return()
@@ -0,0 +1,34 @@
1
+ '''
2
+ Language parser for Vue.js files
3
+ '''
4
+
5
+ from .code_reader import CodeReader, CodeStateMachine
6
+ from .typescript import TypeScriptReader
7
+
8
+
9
+ class VueReader(TypeScriptReader):
10
+ # pylint: disable=R0903
11
+
12
+ ext = ['vue']
13
+ language_names = ['vue', 'vuejs']
14
+
15
+ def __init__(self, context):
16
+ super(VueReader, self).__init__(context)
17
+
18
+ @staticmethod
19
+ def generate_tokens(source_code, addition='', token_class=None):
20
+ # Use the base token generator but ensure we capture Vue block tags
21
+ addition = addition + r"|(?:\<\/?\w+.*?\>)"
22
+ return TypeScriptReader.generate_tokens(source_code, addition, token_class)
23
+
24
+ def preprocess(self, tokens):
25
+ current_block = None
26
+
27
+ for token in tokens:
28
+ if token.startswith('<script'):
29
+ current_block = 'script'
30
+ elif token.startswith('</script'):
31
+ current_block = None
32
+ elif current_block == 'script':
33
+ if not token.isspace() or token == '\n':
34
+ yield token
@@ -1,23 +0,0 @@
1
- '''
2
- generate token with javascript style regular expression.
3
- '''
4
-
5
- import re
6
-
7
-
8
- def js_style_regex_expression(func):
9
- def generate_tokens_with_regex(source_code, _=""):
10
- regx_regx = r"\/(\S*?[^\s\\]\/)+?(igm)*"
11
- regx_pattern = re.compile(regx_regx)
12
- word_pattern = re.compile(r'\w+')
13
- tokens = func(source_code, r"|"+regx_regx)
14
- leading_by_word = False
15
- for token in tokens:
16
- if leading_by_word and regx_pattern.match(token):
17
- for subtoken in func(token, _):
18
- yield subtoken
19
- else:
20
- yield token
21
- if not token.isspace():
22
- leading_by_word = word_pattern.match(token)
23
- return generate_tokens_with_regex
@@ -1,27 +0,0 @@
1
- '''
2
- Language parser for JSX
3
- '''
4
-
5
- from .javascript import JavaScriptReader, JSTokenizer, XMLTagWithAttrTokenizer, isidentifier
6
- from .code_reader import CodeReader
7
- from .js_style_regex_expression import js_style_regex_expression
8
-
9
-
10
- class JSXReader(JavaScriptReader):
11
- # pylint: disable=R0903
12
-
13
- ext = ['jsx']
14
- language_names = ['jsx']
15
-
16
- @staticmethod
17
- @js_style_regex_expression
18
- def generate_tokens(source_code, addition='', token_class=None):
19
- addition = addition +\
20
- r"|(?:\$\w+)" + \
21
- r"|(?:\<\/\w+\>)" + \
22
- r"|`.*?`"
23
- js_tokenizer = JSTokenizer()
24
- for token in CodeReader.generate_tokens(
25
- source_code, addition, token_class):
26
- for tok in js_tokenizer(token):
27
- yield tok
@@ -1,44 +0,0 @@
1
- '''
2
- Language parser for TSX
3
- '''
4
-
5
- from .typescript import TypeScriptReader, TypeScriptStates
6
- from .javascript import JSTokenizer, XMLTagWithAttrTokenizer, isidentifier
7
- from .code_reader import CodeReader
8
- from .js_style_regex_expression import js_style_regex_expression
9
-
10
-
11
- class TSXReader(TypeScriptReader):
12
- # pylint: disable=R0903
13
-
14
- ext = ['tsx']
15
- language_names = ['tsx']
16
-
17
- @staticmethod
18
- @js_style_regex_expression
19
- def generate_tokens(source_code, addition='', token_class=None):
20
- addition = addition +\
21
- r"|(?:\$\w+)" + \
22
- r"|(?:\<\/\w+\>)" + \
23
- r"|`.*?`"
24
- js_tokenizer = JSTokenizer()
25
- for token in CodeReader.generate_tokens(
26
- source_code, addition, token_class):
27
- for tok in js_tokenizer(token):
28
- yield tok
29
-
30
- def __init__(self, context):
31
- super(TSXReader, self).__init__(context)
32
- self.parallel_states = [TSXStates(context)]
33
-
34
-
35
- class TSXStates(TypeScriptStates):
36
- def _expecting_func_opening_bracket(self, token):
37
- if token == '<':
38
- self.next(self._expecting_jsx)
39
- return
40
- super(TSXStates, self)._expecting_func_opening_bracket(token)
41
-
42
- def _expecting_jsx(self, token):
43
- if token == '>':
44
- self.next(self._expecting_func_opening_bracket)
@@ -1,75 +0,0 @@
1
- '''
2
- Language parser for JavaScript
3
- '''
4
-
5
- import re
6
- from .code_reader import CodeReader
7
- from .clike import CCppCommentsMixin
8
- from .js_style_language_states import JavaScriptStyleLanguageStates
9
- from .js_style_regex_expression import js_style_regex_expression
10
-
11
-
12
- class TypeScriptReader(CodeReader, CCppCommentsMixin):
13
- # pylint: disable=R0903
14
-
15
- ext = ['ts']
16
- language_names = ['typescript', 'ts']
17
- _conditions = set(['if', 'elseif', 'for', 'while', '&&', '||', '?',
18
- 'catch', 'case'])
19
-
20
- def __init__(self, context):
21
- super(TypeScriptReader, self).__init__(context)
22
- self.parallel_states = [TypeScriptStates(context)]
23
-
24
- @staticmethod
25
- @js_style_regex_expression
26
- def generate_tokens(source_code, addition='', token_class=None):
27
- addition = addition +\
28
- r"|(?:\w+\?)"
29
- return CodeReader.generate_tokens(source_code, addition, token_class)
30
-
31
-
32
- class TypeScriptStates(JavaScriptStyleLanguageStates):
33
-
34
- def _state_global(self, token):
35
- if token == ':':
36
- # When we see a type annotation in global state, store the last tokens
37
- # but don't treat it as a function name yet
38
- self._potential_name = self.last_tokens
39
- self.next(self._type_annotation)
40
- return
41
- if token == '=>':
42
- # For arrow functions, we want to treat them as anonymous
43
- self.function_name = ''
44
- self._state = self._arrow_function
45
- return
46
- super(TypeScriptStates, self)._state_global(token)
47
-
48
- def _type_annotation(self, token):
49
- if token == '=':
50
- # We're back to an assignment, restore the potential name
51
- if hasattr(self, '_potential_name'):
52
- self.last_tokens = self._potential_name
53
- delattr(self, '_potential_name')
54
- self.next(self._state_global, token)
55
- else:
56
- self.next(self._type_annotation)
57
-
58
- def _expecting_func_opening_bracket(self, token):
59
- if token == ':':
60
- self.next(self._expecting_default)
61
- return
62
- super(TypeScriptStates, self)._expecting_func_opening_bracket(token)
63
-
64
- def _expecting_default(self, token):
65
- self.next(self._function_return_type)
66
- if token == '{':
67
- self.read_object()
68
-
69
- def _function_return_type(self, token):
70
- if token == ';':
71
- self.next(self._state_global)
72
- elif token == '{':
73
- self.next(self._expecting_func_opening_bracket, token)
74
- elif token == '=':
75
- self.next(self._state_global, token)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes