kuniri 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +43 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +18 -0
  5. data/.yardopts +1 -0
  6. data/COPYING +661 -0
  7. data/Gemfile +14 -0
  8. data/Guardfile +8 -0
  9. data/README.md +102 -0
  10. data/Rakefile +114 -0
  11. data/bin/kuniri +53 -0
  12. data/data/attribute_lang.rb +131 -0
  13. data/data/class_lang.rb +77 -0
  14. data/data/conditional_lang.rb +71 -0
  15. data/data/constructor_lang.rb +34 -0
  16. data/data/end_block_lang.rb +30 -0
  17. data/data/extern_requirement_lang.rb +45 -0
  18. data/data/function_behavior_lang.rb +113 -0
  19. data/data/lang_syntax.rb +111 -0
  20. data/data/module_namespace_lang.rb +43 -0
  21. data/data/repetition_lang.rb +62 -0
  22. data/data/token_lang.rb +55 -0
  23. data/data/variable_global_lang.rb +118 -0
  24. data/kuniri.gemspec +24 -0
  25. data/lib/kuniri/core/configuration/language_available.rb +7 -0
  26. data/lib/kuniri/core/configuration/log_available.rb +7 -0
  27. data/lib/kuniri/core/configuration/monitor_available.rb +13 -0
  28. data/lib/kuniri/core/kuniri.rb +78 -0
  29. data/lib/kuniri/core/setting.rb +143 -0
  30. data/lib/kuniri/error/configuration_file_error.rb +12 -0
  31. data/lib/kuniri/error/language_error.rb +12 -0
  32. data/lib/kuniri/language/abstract_container/structured_and_oo/attribute.rb +73 -0
  33. data/lib/kuniri/language/abstract_container/structured_and_oo/class.rb +51 -0
  34. data/lib/kuniri/language/abstract_container/structured_and_oo/comment.rb +57 -0
  35. data/lib/kuniri/language/abstract_container/structured_and_oo/conditional.rb +42 -0
  36. data/lib/kuniri/language/abstract_container/structured_and_oo/constructor.rb +52 -0
  37. data/lib/kuniri/language/abstract_container/structured_and_oo/end_block.rb +27 -0
  38. data/lib/kuniri/language/abstract_container/structured_and_oo/extern_requirement.rb +36 -0
  39. data/lib/kuniri/language/abstract_container/structured_and_oo/function_behavior.rb +55 -0
  40. data/lib/kuniri/language/abstract_container/structured_and_oo/module_namespace.rb +36 -0
  41. data/lib/kuniri/language/abstract_container/structured_and_oo/repetition.rb +42 -0
  42. data/lib/kuniri/language/abstract_container/structured_and_oo/variable_behaviour.rb +53 -0
  43. data/lib/kuniri/language/abstract_container/structured_and_oo/variable_global.rb +67 -0
  44. data/lib/kuniri/language/container_data/structured_and_oo/attribute_data.rb +26 -0
  45. data/lib/kuniri/language/container_data/structured_and_oo/basic_data.rb +18 -0
  46. data/lib/kuniri/language/container_data/structured_and_oo/class_data.rb +77 -0
  47. data/lib/kuniri/language/container_data/structured_and_oo/conditional_data.rb +23 -0
  48. data/lib/kuniri/language/container_data/structured_and_oo/constructor_data.rb +18 -0
  49. data/lib/kuniri/language/container_data/structured_and_oo/extern_requirement_data.rb +26 -0
  50. data/lib/kuniri/language/container_data/structured_and_oo/file_element.rb +77 -0
  51. data/lib/kuniri/language/container_data/structured_and_oo/function_abstract.rb +52 -0
  52. data/lib/kuniri/language/container_data/structured_and_oo/function_data.rb +21 -0
  53. data/lib/kuniri/language/container_data/structured_and_oo/method_data.rb +20 -0
  54. data/lib/kuniri/language/container_data/structured_and_oo/module_namespace_data.rb +18 -0
  55. data/lib/kuniri/language/container_data/structured_and_oo/repetition_data.rb +23 -0
  56. data/lib/kuniri/language/container_data/structured_and_oo/variable_global_data.rb +22 -0
  57. data/lib/kuniri/language/language.rb +222 -0
  58. data/lib/kuniri/language/language_factory.rb +48 -0
  59. data/lib/kuniri/language/ruby/attribute_ruby.rb +134 -0
  60. data/lib/kuniri/language/ruby/class_ruby.rb +83 -0
  61. data/lib/kuniri/language/ruby/comment_ruby.rb +84 -0
  62. data/lib/kuniri/language/ruby/conditional_ruby.rb +77 -0
  63. data/lib/kuniri/language/ruby/constructor_ruby.rb +36 -0
  64. data/lib/kuniri/language/ruby/end_block_ruby.rb +33 -0
  65. data/lib/kuniri/language/ruby/extern_requirement_ruby.rb +49 -0
  66. data/lib/kuniri/language/ruby/function_behavior_ruby.rb +120 -0
  67. data/lib/kuniri/language/ruby/module_namespace_ruby.rb +47 -0
  68. data/lib/kuniri/language/ruby/repetition_ruby.rb +68 -0
  69. data/lib/kuniri/language/ruby/ruby_syntax.rb +117 -0
  70. data/lib/kuniri/language/ruby/token_ruby.rb +59 -0
  71. data/lib/kuniri/language/ruby/variable_behaviour_ruby.rb +83 -0
  72. data/lib/kuniri/language/ruby/variable_global_ruby.rb +123 -0
  73. data/lib/kuniri/parser/parser.rb +45 -0
  74. data/lib/kuniri/parser/parser_xml.rb +128 -0
  75. data/lib/kuniri/state_machine/OO_structured_fsm/attribute_state.rb +51 -0
  76. data/lib/kuniri/state_machine/OO_structured_fsm/class_state.rb +94 -0
  77. data/lib/kuniri/state_machine/OO_structured_fsm/comment_state.rb +76 -0
  78. data/lib/kuniri/state_machine/OO_structured_fsm/conditional_state.rb +92 -0
  79. data/lib/kuniri/state_machine/OO_structured_fsm/constructor_state.rb +71 -0
  80. data/lib/kuniri/state_machine/OO_structured_fsm/function_state.rb +82 -0
  81. data/lib/kuniri/state_machine/OO_structured_fsm/idle_state.rb +80 -0
  82. data/lib/kuniri/state_machine/OO_structured_fsm/include_state.rb +59 -0
  83. data/lib/kuniri/state_machine/OO_structured_fsm/method_state.rb +69 -0
  84. data/lib/kuniri/state_machine/OO_structured_fsm/module_state.rb +79 -0
  85. data/lib/kuniri/state_machine/OO_structured_fsm/oo_structured_state.rb +92 -0
  86. data/lib/kuniri/state_machine/OO_structured_fsm/repetition_state.rb +85 -0
  87. data/lib/kuniri/state_machine/OO_structured_fsm/token_state_machine.rb +8 -0
  88. data/lib/kuniri/state_machine/OO_structured_fsm/variable_state.rb +49 -0
  89. data/lib/kuniri/util/html_logger.rb +41 -0
  90. data/lib/kuniri/util/logger.rb +34 -0
  91. data/lib/kuniri/util/txt_logger.rb +29 -0
  92. data/lib/kuniri/version.rb +3 -0
  93. data/lib/kuniri.rb +5 -0
  94. data/other/analyseFile.asta +0 -0
  95. data/spec/core/kuniri_spec.rb +14 -0
  96. data/spec/core/setting_spec.rb +114 -0
  97. data/spec/language/abstract_container/attribute_spec.rb +13 -0
  98. data/spec/language/abstract_container/class_spec.rb +13 -0
  99. data/spec/language/abstract_container/comment_spec.rb +31 -0
  100. data/spec/language/abstract_container/conditional_spec.rb +13 -0
  101. data/spec/language/abstract_container/constructor_spec.rb +13 -0
  102. data/spec/language/abstract_container/end_block_spec.rb +14 -0
  103. data/spec/language/abstract_container/module_namespace_spec.rb +13 -0
  104. data/spec/language/abstract_container/repetition_spec.rb +13 -0
  105. data/spec/language/container_data/structured_and_oo/attribute_data_spec.rb +32 -0
  106. data/spec/language/container_data/structured_and_oo/class_data_spec.rb +121 -0
  107. data/spec/language/container_data/structured_and_oo/conditional_data_spec.rb +34 -0
  108. data/spec/language/container_data/structured_and_oo/constructor_data_spec.rb +46 -0
  109. data/spec/language/container_data/structured_and_oo/extern_requirement_data_spec.rb +26 -0
  110. data/spec/language/container_data/structured_and_oo/file_element_spec.rb +91 -0
  111. data/spec/language/container_data/structured_and_oo/function_data_spec.rb +22 -0
  112. data/spec/language/container_data/structured_and_oo/module_namespace_spec.rb +20 -0
  113. data/spec/language/container_data/structured_and_oo/repetition_data_spec.rb +34 -0
  114. data/spec/language/container_data/structured_and_oo/variable_global_data_spec.rb +39 -0
  115. data/spec/language/language_factory_spec.rb +64 -0
  116. data/spec/language/language_spec.rb +74 -0
  117. data/spec/language/ruby/attribute_ruby_spec.rb +126 -0
  118. data/spec/language/ruby/class_ruby_spec.rb +102 -0
  119. data/spec/language/ruby/comment_ruby_spec.rb +78 -0
  120. data/spec/language/ruby/conditional_ruby_spec.rb +106 -0
  121. data/spec/language/ruby/constructor_ruby_spec.rb +57 -0
  122. data/spec/language/ruby/end_block_ruby_spec.rb +62 -0
  123. data/spec/language/ruby/function_behavior_ruby_spec.rb +246 -0
  124. data/spec/language/ruby/module_namespace_ruby_spec.rb +55 -0
  125. data/spec/language/ruby/repetition_ruby_spec.rb +33 -0
  126. data/spec/language/ruby/ruby_syntax_spec.rb +482 -0
  127. data/spec/language/ruby/variable_ruby_spec.rb +134 -0
  128. data/spec/parser/parser_spec.rb +25 -0
  129. data/spec/samples/rubySyntaxParts/attribute/simpleAttribute.rb +15 -0
  130. data/spec/samples/rubySyntaxParts/class/simpleClass.rb +19 -0
  131. data/spec/samples/rubySyntaxParts/comment/simple_multiple_line_comment_class.rb +33 -0
  132. data/spec/samples/rubySyntaxParts/comment/simple_multiple_line_comment_global.rb +20 -0
  133. data/spec/samples/rubySyntaxParts/comment/simple_single_line_comment_class.rb +23 -0
  134. data/spec/samples/rubySyntaxParts/comment/simple_single_line_comment_global.rb +16 -0
  135. data/spec/samples/rubySyntaxParts/conditionalStatment/constructorConditional.rb +28 -0
  136. data/spec/samples/rubySyntaxParts/conditionalStatment/methodConditional.rb +42 -0
  137. data/spec/samples/rubySyntaxParts/conditionalStatment/nestedConditional.rb +0 -0
  138. data/spec/samples/rubySyntaxParts/conditionalStatment/simpleConditional.rb +43 -0
  139. data/spec/samples/rubySyntaxParts/constructor/simpleConstructor.rb +27 -0
  140. data/spec/samples/rubySyntaxParts/extern/multipleLineExternRequirement.rb +0 -0
  141. data/spec/samples/rubySyntaxParts/extern/requireRelative.rb +6 -0
  142. data/spec/samples/rubySyntaxParts/extern/simpleExternRequirement.rb +14 -0
  143. data/spec/samples/rubySyntaxParts/fullCode/simpleCodeWithConditional.rb +18 -0
  144. data/spec/samples/rubySyntaxParts/fullCode/simpleFullCode.rb +19 -0
  145. data/spec/samples/rubySyntaxParts/function/simpleFunction.rb +29 -0
  146. data/spec/samples/rubySyntaxParts/method/simpleMethod.rb +13 -0
  147. data/spec/samples/rubySyntaxParts/module/simpleModule.rb +12 -0
  148. data/spec/samples/rubySyntaxParts/repetition/simpleRepetition.rb +28 -0
  149. data/spec/samples/rubySyntaxParts/variable/simpleVariable.rb +13 -0
  150. data/spec/spec_helper.rb +20 -0
  151. data/spec/state_machine/OO_structured_fsm/attribute_state_spec.rb +44 -0
  152. data/spec/state_machine/OO_structured_fsm/class_state_spec.rb +90 -0
  153. data/spec/state_machine/OO_structured_fsm/comment_state_spec.rb +30 -0
  154. data/spec/state_machine/OO_structured_fsm/conditional_state_spec.rb +83 -0
  155. data/spec/state_machine/OO_structured_fsm/constructor_state_spec.rb +48 -0
  156. data/spec/state_machine/OO_structured_fsm/function_state_spec.rb +41 -0
  157. data/spec/state_machine/OO_structured_fsm/idle_state_spec.rb +101 -0
  158. data/spec/state_machine/OO_structured_fsm/include_state_spec.rb +62 -0
  159. data/spec/state_machine/OO_structured_fsm/method_state_spec.rb +42 -0
  160. data/spec/state_machine/OO_structured_fsm/module_state_spec.rb +54 -0
  161. data/spec/state_machine/OO_structured_fsm/oo_structured_state_spec.rb +0 -0
  162. data/spec/state_machine/OO_structured_fsm/repetition_state_spec.rb +83 -0
  163. data/spec/state_machine/OO_structured_fsm/variable_state_spec.rb +40 -0
  164. data/spec/util/html_logger_spec.rb +31 -0
  165. data/spec/util/logger_spec.rb +20 -0
  166. data/spec/util/txt_logger_spec.rb +31 -0
  167. metadata +326 -0
@@ -0,0 +1,113 @@
1
+ require_relative '../abstract_container/structured_and_oo/function_behavior'
2
+ require_relative '../../core/setting'
3
+ require_relative '../container_data/structured_and_oo/function_data'
4
+
5
+ module Languages
6
+
7
+ module {LANG}
8
+
9
+ # Handling {LANG} method
10
+ class FunctionBehavior{LANG} < Languages::FunctionBehavior
11
+
12
+ public
13
+
14
+ def initialize
15
+ @log = @settings = Kuniri::Setting.create.log
16
+ end
17
+
18
+ def get_function(pLine, type = 'globalFunction')
19
+ result = detect_function(pLine)
20
+ return nil unless result
21
+
22
+ @log.write_log("Info: get method")
23
+
24
+ function{LANG} = Languages::FunctionData.new(result)
25
+
26
+ parameters = handling_parameter(pLine)
27
+ if parameters
28
+ parameters.each do |parameter|
29
+ function{LANG}.add_parameters(parameter)
30
+ end
31
+ end
32
+
33
+ @log.write_log("Debug: Method: #{function{LANG}.name}, Parameter:
34
+ #{function{LANG}.parameters}")
35
+
36
+ return function{LANG}
37
+ end
38
+
39
+ protected
40
+
41
+ def detect_function(pLine)
42
+ regexExpression = /^\s*def\b\s*(\w*)\b/
43
+ return nil unless pLine =~ regexExpression
44
+ return pLine.scan(regexExpression)[0].join("")
45
+ end
46
+
47
+ def handling_default_parameter(pLine)
48
+ return pLine unless pLine =~ /=/
49
+
50
+ if pLine =~ /,/
51
+ partialParameters = pLine.split(",")
52
+ else
53
+ partialParameters = [pLine]
54
+ end
55
+
56
+ newList = []
57
+ partialParameters.each do |element|
58
+ if element =~ /=/
59
+ parameter = element.scan(/(\w*)=/).join("")
60
+ value = element.scan(/=(\w*)/).join("")
61
+ defaultParameter = Hash(parameter => value)
62
+ newList.push(defaultParameter)
63
+ next
64
+ end
65
+ newList.push(element)
66
+ end
67
+
68
+ return newList
69
+
70
+ end
71
+
72
+ def remove_unnecessary_information(pLine)
73
+ return pLine.gsub(/\s+|\(|\)/,"") if pLine =~ /\s+|\(|\)/
74
+ return pLine
75
+ end
76
+
77
+ def handling_parameter(pLine)
78
+ # Handling with parenthesis and without it.
79
+ if pLine =~ /\(.+\)/
80
+ partial = get_parameters(pLine, /\(.+\)/)
81
+ elsif pLine =~ /def\s+\w+[\s]+(.+)/
82
+ partial = get_parameters(pLine, /def\s+\w+[\s]+(.+)/)
83
+ else
84
+ return nil
85
+ end
86
+
87
+ return handling_default_parameter(partial) if partial =~ /=/
88
+ return split_string_by_comma(partial)
89
+ end
90
+
91
+ private
92
+
93
+ @log
94
+
95
+ def get_parameters(pLine, pRegex)
96
+ partialParameters = pLine.scan(pRegex).join("")
97
+ partialParameters = remove_unnecessary_information(partialParameters)
98
+ return partialParameters
99
+ end
100
+
101
+ def split_string_by_comma(pString)
102
+ return pString.split(",") if pString =~ /,/
103
+ return [pString]
104
+ end
105
+
106
+ # Class
107
+ end
108
+
109
+ # {LANG}
110
+ end
111
+
112
+ # Language
113
+ end
@@ -0,0 +1,111 @@
1
+ require_relative '../language'
2
+ require_relative '../container_data/structured_and_oo/class_data'
3
+ require_relative '../container_data/structured_and_oo/file_element'
4
+ require_relative 'token_{lang}'
5
+ require_relative 'extern_requirement_{lang}'
6
+ require_relative 'variable_global_{lang}'
7
+ require_relative 'module_namespace_{lang}'
8
+ require_relative 'end_block_{lang}'
9
+ require_relative 'constructor_{lang}'
10
+ require_relative 'class_{lang}'
11
+ require_relative 'conditional_{lang}'
12
+ require_relative 'repetition_{lang}'
13
+ require_relative 'function_behavior_{lang}'
14
+ require_relative 'attribute_{lang}'
15
+
16
+ module Languages
17
+
18
+ # Handling the {LANG} syntax for extract information.
19
+ class {LANG}Syntax < Languages::Language
20
+
21
+ public
22
+
23
+ def initialize
24
+ super
25
+ @externRequirementHandler = Languages::{LANG}::ExternRequirement{LANG}.new
26
+ @variableHandler = Languages::{LANG}::VariableGlobal{LANG}.new
27
+ @functionHandler = Languages::{LANG}::FunctionBehavior{LANG}.new
28
+ @moduleHandler = Languages::{LANG}::ModuleNamespace{LANG}.new
29
+ @classHandler = Languages::{LANG}::Class{LANG}.new
30
+ @attributeHandler = Languages::{LANG}::Attribute{LANG}.new
31
+ @endBlockHandler = Languages::{LANG}::EndBlock{LANG}.new
32
+ @methodHandler = Languages::{LANG}::FunctionBehavior{LANG}.new
33
+ @constructorHandler = Languages::{LANG}::Constructor{LANG}.new
34
+ @conditionalHandler = Languages::{LANG}::Conditional{LANG}.new
35
+ @repetitionHandler = Languages::{LANG}::Repetition{LANG}.new
36
+ @visibility = "public"
37
+ end
38
+
39
+ def analyse_source(pPath)
40
+ @name = File.basename(pPath, ".*")
41
+ @path = File.dirname(pPath)
42
+ analyse_first_step(pPath)
43
+ #self.analyse_second_step
44
+ end
45
+
46
+ # Extract all the comments from the source.
47
+ # @param source [String] Source code to analys.
48
+ def comment_extract
49
+ all_comments = Array.new
50
+ #Find a simple {LANG} comment with '#'
51
+ @source.scan(/#(.*)/).each do |comments|
52
+ all_comments.push(comments[0])
53
+ end
54
+ #Find multiple line comment.
55
+ @source.scan(/^=begin(.*?)^=end/m).each do |comment|
56
+ all_comments.push(comment[0].lstrip)
57
+ end
58
+ return all_comments
59
+ end
60
+
61
+ # Extract all method from the source.
62
+ # @param source [String]
63
+ def method_extract
64
+ return @currentClass.get_methods
65
+ end
66
+
67
+ # Extract all the class declared in the source.
68
+ # @param source [String]
69
+ def class_extract
70
+ return @currentClass
71
+ end
72
+
73
+ # @param source [String]
74
+ def attribute_extract
75
+ return @currentClass.get_attributes
76
+ end
77
+
78
+ # @param source [String]
79
+ def global_variable_extract
80
+ raise NotImplementedError
81
+ end
82
+
83
+ def extern_requirement_extract
84
+ return @externRequirements
85
+ end
86
+
87
+ def get_classes
88
+ end
89
+
90
+ private
91
+
92
+ attr_accessor :visibility
93
+ @source
94
+
95
+ def analyse_first_step(pPath)
96
+ fileElement = Languages::FileElement.new(pPath)
97
+ @source = File.open(pPath, "rb")
98
+ @source.each do |line|
99
+ next if line.gsub(/\s+/,"").size == 0
100
+ # Special token for class
101
+ @state.handle_line(line)
102
+ fileElement = @state.execute(fileElement, line)
103
+ end
104
+ @fileElements.push(fileElement)
105
+ end
106
+
107
+ # {LANG}
108
+ end
109
+
110
+ # Module
111
+ end
@@ -0,0 +1,43 @@
1
+ require_relative '../abstract_container/structured_and_oo/module_namespace'
2
+ require_relative '../container_data/structured_and_oo/module_namespace_data'
3
+
4
+ module Languages
5
+
6
+ module {LANG}
7
+
8
+ # Class for handling {LANG} module
9
+ class ModuleNamespace{LANG} < Languages::ModuleNamespace
10
+
11
+ public
12
+
13
+ def get_module(pLine)
14
+ result = detect_module(pLine)
15
+ return nil unless result
16
+
17
+ result = remove_unnecessary_information(result)
18
+ moduleCaptured = Languages::ModuleNamespaceData.new(result)
19
+
20
+ return moduleCaptured
21
+ end
22
+
23
+ protected
24
+
25
+ def detect_module(pLine)
26
+ regexExpression = /^\s*module\s+(.*)/
27
+ return nil unless pLine =~ regexExpression
28
+ return pLine.scan(regexExpression).join("")
29
+ end
30
+
31
+ def remove_unnecessary_information(pLine)
32
+ return pLine.gsub(/\s/, "") if pLine =~ /\s/
33
+ return pLine
34
+ end
35
+
36
+ # class
37
+ end
38
+
39
+ # {LANG}
40
+ end
41
+
42
+ # module
43
+ end
@@ -0,0 +1,62 @@
1
+ require_relative '../abstract_container/structured_and_oo/repetition.rb'
2
+ require_relative '../container_data/structured_and_oo/repetition_data.rb'
3
+
4
+ module Languages
5
+
6
+ module {LANG}
7
+
8
+ class Repetition{LANG} < Languages::Repetition
9
+
10
+ public
11
+
12
+ def get_repetition(pLine)
13
+ result = detect_repetition(pLine)
14
+ return nil unless result
15
+
16
+ repetitionCaptured = Languages::RepetitionData.new
17
+ repetitionCaptured.type = repetition_type(pLine)
18
+
19
+ repetitionCaptured.expression = get_expression(result)
20
+
21
+ return repetitionCaptured
22
+ end
23
+
24
+ protected
25
+
26
+ def detect_repetition(pLine)
27
+ regexExp = /^\s*while\s+(.*)do/
28
+ return pLine.scan(regexExp)[0].join("") if regexExp =~ pLine
29
+
30
+ regexExp = /^\s*for\s+(.*)/
31
+ return pLine.scan(regexExp)[0].join("") if regexExp =~ pLine
32
+
33
+ regexExp = /^\s*until\s+(.*)do/
34
+ return pLine.scan(regexExp)[0].join("") if regexExp =~ pLine
35
+
36
+ return nil
37
+ end
38
+
39
+ def repetition_type(pString)
40
+ regexExp = /^\s+while|^while/
41
+ return "WHILE" if regexExp =~ pString
42
+
43
+ regexExp = /^\s+for|^for/
44
+ return "FOR" if regexExp =~ pString
45
+
46
+ return nil
47
+ end
48
+
49
+ def get_expression(pString)
50
+ leftStrip = pString.lstrip
51
+ rightStrip = leftStrip.rstrip
52
+ return rightStrip
53
+ end
54
+
55
+ # class
56
+ end
57
+
58
+ # {LANG}
59
+ end
60
+
61
+ # Module
62
+ end
@@ -0,0 +1,55 @@
1
+ module Languages
2
+
3
+ module {LANG}
4
+
5
+ # Token types used to identify keywords
6
+ CLASS_TOKEN ||= 1 # Executes the block passed to the method.
7
+ ATTRIBUTE_TOKEN ||= 2
8
+ DEF_TOKEN ||= 3
9
+ VISIBILITY_TOKEN ||= 4
10
+ END_TOKEN ||= 5 # Code, enclosed in { and }, to run when the program ends.
11
+ IF_TOKEN ||= 6 # Executes code block if true. Closes with end.
12
+ WHILE_TOKEN ||= 7 # Executes the block passed to the method.
13
+ DO_TOKEN ||= 8 # Begins a block and executes code in that block(end)
14
+ BEGIN_TOKEN ||= 9 # Code, enclosed in { and }, to run before the program runs.
15
+ ALIAS_TOKEN ||= 10 # Creates an alias: method, operator, or global variable.
16
+ AND_TOKEN ||= 11 # Logical operator same as && except and has lower precedence.
17
+ BEGIN_DOWN_TOKEN ||= 12 # Begins a code block or group of statements (end).
18
+ BREAK_TOKEN ||= 13 # Terminates a while or until loop or a method.
19
+ CASE_TOKEN ||= 14 # Compares an expression with a matching when clause (end).
20
+ REQUIRE_TOKEN ||= 15 # Extern requirement
21
+ DEFINED_TOKEN ||= 16 # Determines: variable, method, super method, or block.
22
+ ELSE_TOKEN ||= 17 # Executes if previous conditional.
23
+ ELSIF_TOKEN ||= 18 # Executes if previous conditional, in if or elsif.
24
+ ENSURE_TOKEN ||= 19 # Always executes at block termination.
25
+ FALSE_TOKEN ||= 20 # Logical or Boolean false, instance of FalseClass.
26
+ TRUE_TOKEN ||= 21 # Instance of TrueClass.
27
+ FOR_TOKEN ||= 22 # Begins a for loop; used with in.
28
+ MODULE_TOKEN ||= 23 # Defines a module; closes with end.
29
+ NEXT_TOKEN ||= 24 # Jumps before a loop's conditional.
30
+ NIL_TOKEN ||= 25 # Object of NilClass.
31
+ NOT_TOKEN ||= 26 # Logical operator, same as !.
32
+ OR_TOKEN ||= 27 # Logical operator, same as ||.
33
+ REDO_TOKEN ||= 28 # Jumps after a loop's conditional.
34
+ RESCUE_TOKEN ||= 29 # Evaluates an expression after an exception is raised.
35
+ RETRY_TOKEN ||= 30 # Repeats a method call outside of rescue.
36
+ RETURN_TOKEN ||= 31 # Returns a value from a method or block.
37
+ SELF_TOKEN ||= 32 # Current object (invoked by a method).
38
+ SUPER_TOKEN ||= 33 # Calls method of the same name in the superclass.
39
+ THEN_TOKEN ||= 34 # A continuation for if, unless, and when.
40
+ UNDEF_TOKEN ||= 35 # Makes a method in current class undefined.
41
+ UNLESS_TOKEN ||= 36 # Executes code block if conditional statement is false.
42
+ UNTIL_TOKEN ||= 37 # Executes code block while conditional statement is false.
43
+ WHEN_TOKEN ||= 38 # Starts a clause (one or more) under case.
44
+ YIELD_TOKEN ||= 39 # Executes the block passed to the method.
45
+ INTEGER_TOKEN ||= 40
46
+ ARRAY_TOKEN ||= 41
47
+ HASH_TOKEN ||= 42
48
+ OBJECT_TOKEN ||= 43
49
+ CONSTRUCTOR_TOKEN ||= 44
50
+
51
+ # Module
52
+ end
53
+
54
+ # Language
55
+ end
@@ -0,0 +1,118 @@
1
+ require_relative '../abstract_container/structured_and_oo/variable_global'
2
+ require_relative '../container_data/structured_and_oo/variable_global_data'
3
+
4
+ module Languages
5
+
6
+ module {LANG}
7
+
8
+ # @class VariableGlobal{LANG} Handling extern requirements.
9
+ class VariableGlobal{LANG} < Languages::VariableGlobal
10
+
11
+ public
12
+
13
+ def get_variable(pLine)
14
+ result = detect_variable(pLine)
15
+ return nil unless result
16
+
17
+ listOfVariable = []
18
+
19
+ # Separated by comma, equal or the common case
20
+ if result.split(",").size > 1
21
+ listOfVariable = handle_multiple_declaration_with_comma(result)
22
+ elsif result.split("=").size > 1
23
+ listOfVariable = handle_multiple_declaration_with_equal(result)
24
+ else
25
+ listOfVariable = handle_line_declaration(result)
26
+ end
27
+
28
+ return listOfVariable
29
+ end
30
+
31
+ protected
32
+
33
+ def detect_variable(pLine)
34
+ # Check basic case of non variable. Ex.: value x
35
+ pLine.gsub!(/^\s*/, "")
36
+ pLine.gsub!(/\s*$/, "")
37
+ return nil if pLine =~ /end/
38
+ return nil if pLine =~ /^def\s+/
39
+ return pLine if pLine.split(",").size > 1
40
+ return pLine if pLine.split("=").size > 1
41
+
42
+ return nil if pLine.split(" ").size > 1
43
+ return pLine
44
+ end
45
+
46
+ def remove_unnecessary_information(pLine)
47
+ return pLine
48
+ end
49
+
50
+ # Override
51
+ def prepare_final_string(pString)
52
+ if pString =~ /\s+|:|@|=/
53
+ return pString.gsub!(/\s+|:|@|=/,"")
54
+ end
55
+ return pString
56
+ end
57
+
58
+ # Override
59
+ def handle_multiple_declaration_with_comma(pString)
60
+ listOfVariable = []
61
+ pString = pString.split(",")
62
+ pString.each do |variable|
63
+ return nil if variable.split("=").size > 2
64
+
65
+ variable = variable.scan(/.*=/).join("") if variable =~ /.*=/
66
+
67
+ return nil if variable =~ /\./
68
+
69
+ variable = prepare_final_string(variable)
70
+ globalVariable = Languages::VariableGlobalData.new(variable)
71
+ listOfVariable.push(globalVariable)
72
+ end
73
+
74
+ return listOfVariable
75
+ end
76
+
77
+ # Override
78
+ def handle_multiple_declaration_with_equal(pString)
79
+ listOfVariable = []
80
+ pString = pString.split("=")
81
+ pString.each do |variable|
82
+ return nil if variable =~ /\./
83
+
84
+ variable = prepare_final_string(variable)
85
+ globalVariable = Languages::VariableGlobalData.new(variable)
86
+ listOfVariable.push(globalVariable)
87
+ end
88
+ value = listOfVariable.pop
89
+
90
+ return listOfVariable
91
+ end
92
+
93
+ # Override
94
+ def handle_line_declaration(pString)
95
+ listOfVariable = []
96
+ if pString =~ /=/
97
+ pString = pString.scan(/.*=/).join("")
98
+ return nil if pString =~ /\./
99
+ end
100
+
101
+ return nil if pString =~ /\./
102
+
103
+ pString = prepare_final_string(pString)
104
+ globalVariable = Languages::VariableGlobalData.new(pString)
105
+ listOfVariable.push(globalVariable)
106
+
107
+ return listOfVariable
108
+ end
109
+
110
+
111
+ # Class
112
+ end
113
+
114
+ # {LANG}
115
+ end
116
+
117
+ # Module
118
+ end
data/kuniri.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kuniri/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kuniri"
8
+ spec.version = Kuniri::VERSION
9
+ spec.authors = ["Gustavo Jaruga", "Rodrigo Siqueira"]
10
+ spec.email = ["darksshades@hotmail.com", "rodrigosiqueiramelo@gmail.com"]
11
+ spec.summary = %q{Extract class information from code.}
12
+ spec.description = 'Generic parser'
13
+ spec.homepage = "http://kuniri.github.io/kuniri/"
14
+ spec.license = "GPLv3"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = ["kuniri"]
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_runtime_dependency 'nokogiri', '~> 1.6.6'
24
+ end
@@ -0,0 +1,7 @@
1
+ module Configuration
2
+ #Handling the languages available in the system.
3
+ class Language_Available
4
+ public
5
+ LANGUAGES = ["ruby", "python", "c++", "c"] #Put here new language.
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Configuration
2
+ # Configuration for the monitor available.
3
+ class Log_Available
4
+ public
5
+ LOG = ["html", "txt"] #List with log types.
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ # Configuration module keep all the constants for make the system works.
2
+ # | __Configure__ | __Description__ |
3
+ # |---|---|
4
+ # | Monitor | Types of monitoring available. |
5
+ # | Language | Languages available. |
6
+ # | Watchdog | Types of watchdog. |
7
+ module Configuration
8
+ # Configuration for the monitor available.
9
+ class Monitor_Available
10
+ public
11
+ MONITORS = ["uml", "traceability"] #List with monitors types.
12
+ end
13
+ end
@@ -0,0 +1,78 @@
1
+ require_relative '../error/configuration_file_error'
2
+ require_relative '../parser/parser'
3
+ require_relative '../util/logger'
4
+ require_relative 'configuration/language_available'
5
+ require_relative 'configuration/monitor_available'
6
+ require_relative 'configuration/log_available'
7
+ require_relative 'setting'
8
+
9
+ # Kuniri module connect all the elements and use it in the proper sequence.
10
+ module Kuniri
11
+
12
+ # Kuniri class have the reference for all files and settings. Basically this
13
+ # class launch the application.
14
+ class Kuniri
15
+
16
+ public
17
+
18
+ # @param pPath Receives the path of configuration file. If any element
19
+ # is given, it tries to find in the current folder.
20
+ def initialize(pPath = ".kuniri")
21
+ @configurationInfo = {}
22
+ @filesPathProject = []
23
+ @parserFiles = []
24
+ @parser = nil
25
+
26
+ @settings = Setting.create
27
+ @settings.initializate_settings(pPath)
28
+ @log = @settings.log
29
+ @configurationInfo = @settings.configurationInfo
30
+
31
+ @log.write_log("info: Kuniri object successfully created.")
32
+ end
33
+
34
+ # Start Kuniri tasks based on configuration file. After read
35
+ # configuration file, find all files in source directory.
36
+ def run_analysis()
37
+ @log.write_log("info: Start to run analysis.")
38
+ @log.write_log("debug: ConfigurationInfo: #{@configurationInfo}")
39
+
40
+ @filesPathProject = get_project_file(@configurationInfo["source"])
41
+ unless @filesPathProject
42
+ puts "Problem on source path: #{@configurationInfo["source"]}"
43
+ @log.write_log("Prolblem when tried to access source folder.")
44
+ return -1
45
+ end
46
+
47
+ @log.write_log("debug: files: #{@filesPathProject.to_s}")
48
+ @parser = Parser::Parser.new(@filesPathProject)
49
+ @parser.start_parser()
50
+ end
51
+
52
+ def get_parser
53
+ @parser
54
+ end
55
+
56
+ private
57
+
58
+ @configurationInfo # !@attribute Hash with configuration description
59
+ @filesProject # !@attribute Array with object reference of all files
60
+ @parser # !@attribute Execute the parser based on settings.
61
+ @parserFiles # !@attribute Final output from parser.
62
+ @log # !@attribute Log reference.
63
+
64
+ # !@param pPath Relative path of the project.
65
+ # !@param pLanguage Language extension for make the parser.
66
+ def get_project_file(pPath="./", pLanguage="**.rb")
67
+ return nil unless File.exists?(pPath)
68
+
69
+ @log.write_log("Info: Reading all files.")
70
+
71
+ @filesProject = Dir[File.join(pPath, "**", pLanguage)]
72
+ end
73
+
74
+ # Class
75
+ end
76
+
77
+ # Kuniri
78
+ end