kuniri 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +43 -0
- data/.rspec +2 -0
- data/.travis.yml +18 -0
- data/.yardopts +1 -0
- data/COPYING +661 -0
- data/Gemfile +14 -0
- data/Guardfile +8 -0
- data/README.md +102 -0
- data/Rakefile +114 -0
- data/bin/kuniri +53 -0
- data/data/attribute_lang.rb +131 -0
- data/data/class_lang.rb +77 -0
- data/data/conditional_lang.rb +71 -0
- data/data/constructor_lang.rb +34 -0
- data/data/end_block_lang.rb +30 -0
- data/data/extern_requirement_lang.rb +45 -0
- data/data/function_behavior_lang.rb +113 -0
- data/data/lang_syntax.rb +111 -0
- data/data/module_namespace_lang.rb +43 -0
- data/data/repetition_lang.rb +62 -0
- data/data/token_lang.rb +55 -0
- data/data/variable_global_lang.rb +118 -0
- data/kuniri.gemspec +24 -0
- data/lib/kuniri/core/configuration/language_available.rb +7 -0
- data/lib/kuniri/core/configuration/log_available.rb +7 -0
- data/lib/kuniri/core/configuration/monitor_available.rb +13 -0
- data/lib/kuniri/core/kuniri.rb +78 -0
- data/lib/kuniri/core/setting.rb +143 -0
- data/lib/kuniri/error/configuration_file_error.rb +12 -0
- data/lib/kuniri/error/language_error.rb +12 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/attribute.rb +73 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/class.rb +51 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/comment.rb +57 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/conditional.rb +42 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/constructor.rb +52 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/end_block.rb +27 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/extern_requirement.rb +36 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/function_behavior.rb +55 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/module_namespace.rb +36 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/repetition.rb +42 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/variable_behaviour.rb +53 -0
- data/lib/kuniri/language/abstract_container/structured_and_oo/variable_global.rb +67 -0
- data/lib/kuniri/language/container_data/structured_and_oo/attribute_data.rb +26 -0
- data/lib/kuniri/language/container_data/structured_and_oo/basic_data.rb +18 -0
- data/lib/kuniri/language/container_data/structured_and_oo/class_data.rb +77 -0
- data/lib/kuniri/language/container_data/structured_and_oo/conditional_data.rb +23 -0
- data/lib/kuniri/language/container_data/structured_and_oo/constructor_data.rb +18 -0
- data/lib/kuniri/language/container_data/structured_and_oo/extern_requirement_data.rb +26 -0
- data/lib/kuniri/language/container_data/structured_and_oo/file_element.rb +77 -0
- data/lib/kuniri/language/container_data/structured_and_oo/function_abstract.rb +52 -0
- data/lib/kuniri/language/container_data/structured_and_oo/function_data.rb +21 -0
- data/lib/kuniri/language/container_data/structured_and_oo/method_data.rb +20 -0
- data/lib/kuniri/language/container_data/structured_and_oo/module_namespace_data.rb +18 -0
- data/lib/kuniri/language/container_data/structured_and_oo/repetition_data.rb +23 -0
- data/lib/kuniri/language/container_data/structured_and_oo/variable_global_data.rb +22 -0
- data/lib/kuniri/language/language.rb +222 -0
- data/lib/kuniri/language/language_factory.rb +48 -0
- data/lib/kuniri/language/ruby/attribute_ruby.rb +134 -0
- data/lib/kuniri/language/ruby/class_ruby.rb +83 -0
- data/lib/kuniri/language/ruby/comment_ruby.rb +84 -0
- data/lib/kuniri/language/ruby/conditional_ruby.rb +77 -0
- data/lib/kuniri/language/ruby/constructor_ruby.rb +36 -0
- data/lib/kuniri/language/ruby/end_block_ruby.rb +33 -0
- data/lib/kuniri/language/ruby/extern_requirement_ruby.rb +49 -0
- data/lib/kuniri/language/ruby/function_behavior_ruby.rb +120 -0
- data/lib/kuniri/language/ruby/module_namespace_ruby.rb +47 -0
- data/lib/kuniri/language/ruby/repetition_ruby.rb +68 -0
- data/lib/kuniri/language/ruby/ruby_syntax.rb +117 -0
- data/lib/kuniri/language/ruby/token_ruby.rb +59 -0
- data/lib/kuniri/language/ruby/variable_behaviour_ruby.rb +83 -0
- data/lib/kuniri/language/ruby/variable_global_ruby.rb +123 -0
- data/lib/kuniri/parser/parser.rb +45 -0
- data/lib/kuniri/parser/parser_xml.rb +128 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/attribute_state.rb +51 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/class_state.rb +94 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/comment_state.rb +76 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/conditional_state.rb +92 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/constructor_state.rb +71 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/function_state.rb +82 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/idle_state.rb +80 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/include_state.rb +59 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/method_state.rb +69 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/module_state.rb +79 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/oo_structured_state.rb +92 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/repetition_state.rb +85 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/token_state_machine.rb +8 -0
- data/lib/kuniri/state_machine/OO_structured_fsm/variable_state.rb +49 -0
- data/lib/kuniri/util/html_logger.rb +41 -0
- data/lib/kuniri/util/logger.rb +34 -0
- data/lib/kuniri/util/txt_logger.rb +29 -0
- data/lib/kuniri/version.rb +3 -0
- data/lib/kuniri.rb +5 -0
- data/other/analyseFile.asta +0 -0
- data/spec/core/kuniri_spec.rb +14 -0
- data/spec/core/setting_spec.rb +114 -0
- data/spec/language/abstract_container/attribute_spec.rb +13 -0
- data/spec/language/abstract_container/class_spec.rb +13 -0
- data/spec/language/abstract_container/comment_spec.rb +31 -0
- data/spec/language/abstract_container/conditional_spec.rb +13 -0
- data/spec/language/abstract_container/constructor_spec.rb +13 -0
- data/spec/language/abstract_container/end_block_spec.rb +14 -0
- data/spec/language/abstract_container/module_namespace_spec.rb +13 -0
- data/spec/language/abstract_container/repetition_spec.rb +13 -0
- data/spec/language/container_data/structured_and_oo/attribute_data_spec.rb +32 -0
- data/spec/language/container_data/structured_and_oo/class_data_spec.rb +121 -0
- data/spec/language/container_data/structured_and_oo/conditional_data_spec.rb +34 -0
- data/spec/language/container_data/structured_and_oo/constructor_data_spec.rb +46 -0
- data/spec/language/container_data/structured_and_oo/extern_requirement_data_spec.rb +26 -0
- data/spec/language/container_data/structured_and_oo/file_element_spec.rb +91 -0
- data/spec/language/container_data/structured_and_oo/function_data_spec.rb +22 -0
- data/spec/language/container_data/structured_and_oo/module_namespace_spec.rb +20 -0
- data/spec/language/container_data/structured_and_oo/repetition_data_spec.rb +34 -0
- data/spec/language/container_data/structured_and_oo/variable_global_data_spec.rb +39 -0
- data/spec/language/language_factory_spec.rb +64 -0
- data/spec/language/language_spec.rb +74 -0
- data/spec/language/ruby/attribute_ruby_spec.rb +126 -0
- data/spec/language/ruby/class_ruby_spec.rb +102 -0
- data/spec/language/ruby/comment_ruby_spec.rb +78 -0
- data/spec/language/ruby/conditional_ruby_spec.rb +106 -0
- data/spec/language/ruby/constructor_ruby_spec.rb +57 -0
- data/spec/language/ruby/end_block_ruby_spec.rb +62 -0
- data/spec/language/ruby/function_behavior_ruby_spec.rb +246 -0
- data/spec/language/ruby/module_namespace_ruby_spec.rb +55 -0
- data/spec/language/ruby/repetition_ruby_spec.rb +33 -0
- data/spec/language/ruby/ruby_syntax_spec.rb +482 -0
- data/spec/language/ruby/variable_ruby_spec.rb +134 -0
- data/spec/parser/parser_spec.rb +25 -0
- data/spec/samples/rubySyntaxParts/attribute/simpleAttribute.rb +15 -0
- data/spec/samples/rubySyntaxParts/class/simpleClass.rb +19 -0
- data/spec/samples/rubySyntaxParts/comment/simple_multiple_line_comment_class.rb +33 -0
- data/spec/samples/rubySyntaxParts/comment/simple_multiple_line_comment_global.rb +20 -0
- data/spec/samples/rubySyntaxParts/comment/simple_single_line_comment_class.rb +23 -0
- data/spec/samples/rubySyntaxParts/comment/simple_single_line_comment_global.rb +16 -0
- data/spec/samples/rubySyntaxParts/conditionalStatment/constructorConditional.rb +28 -0
- data/spec/samples/rubySyntaxParts/conditionalStatment/methodConditional.rb +42 -0
- data/spec/samples/rubySyntaxParts/conditionalStatment/nestedConditional.rb +0 -0
- data/spec/samples/rubySyntaxParts/conditionalStatment/simpleConditional.rb +43 -0
- data/spec/samples/rubySyntaxParts/constructor/simpleConstructor.rb +27 -0
- data/spec/samples/rubySyntaxParts/extern/multipleLineExternRequirement.rb +0 -0
- data/spec/samples/rubySyntaxParts/extern/requireRelative.rb +6 -0
- data/spec/samples/rubySyntaxParts/extern/simpleExternRequirement.rb +14 -0
- data/spec/samples/rubySyntaxParts/fullCode/simpleCodeWithConditional.rb +18 -0
- data/spec/samples/rubySyntaxParts/fullCode/simpleFullCode.rb +19 -0
- data/spec/samples/rubySyntaxParts/function/simpleFunction.rb +29 -0
- data/spec/samples/rubySyntaxParts/method/simpleMethod.rb +13 -0
- data/spec/samples/rubySyntaxParts/module/simpleModule.rb +12 -0
- data/spec/samples/rubySyntaxParts/repetition/simpleRepetition.rb +28 -0
- data/spec/samples/rubySyntaxParts/variable/simpleVariable.rb +13 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/state_machine/OO_structured_fsm/attribute_state_spec.rb +44 -0
- data/spec/state_machine/OO_structured_fsm/class_state_spec.rb +90 -0
- data/spec/state_machine/OO_structured_fsm/comment_state_spec.rb +30 -0
- data/spec/state_machine/OO_structured_fsm/conditional_state_spec.rb +83 -0
- data/spec/state_machine/OO_structured_fsm/constructor_state_spec.rb +48 -0
- data/spec/state_machine/OO_structured_fsm/function_state_spec.rb +41 -0
- data/spec/state_machine/OO_structured_fsm/idle_state_spec.rb +101 -0
- data/spec/state_machine/OO_structured_fsm/include_state_spec.rb +62 -0
- data/spec/state_machine/OO_structured_fsm/method_state_spec.rb +42 -0
- data/spec/state_machine/OO_structured_fsm/module_state_spec.rb +54 -0
- data/spec/state_machine/OO_structured_fsm/oo_structured_state_spec.rb +0 -0
- data/spec/state_machine/OO_structured_fsm/repetition_state_spec.rb +83 -0
- data/spec/state_machine/OO_structured_fsm/variable_state_spec.rb +40 -0
- data/spec/util/html_logger_spec.rb +31 -0
- data/spec/util/logger_spec.rb +20 -0
- data/spec/util/txt_logger_spec.rb +31 -0
- metadata +326 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative '../abstract_container/structured_and_oo/end_block'
|
2
|
+
|
3
|
+
module Languages
|
4
|
+
|
5
|
+
module Ruby
|
6
|
+
|
7
|
+
# Class responsible for handling Ruby end of block.
|
8
|
+
class EndBlockRuby < Languages::EndBlock
|
9
|
+
|
10
|
+
public
|
11
|
+
|
12
|
+
# Verify Ruby end of block.
|
13
|
+
# @see EndBlock
|
14
|
+
def has_end_of_block?(pLine)
|
15
|
+
return detect_end(pLine)
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def detect_end(pLine)
|
21
|
+
#TODO: EXTREMELY SIMPLE HANDLING, IT HAVE TO BE IMPROVED!
|
22
|
+
return true if pLine =~ /^\s+end|^end/
|
23
|
+
return false
|
24
|
+
end
|
25
|
+
|
26
|
+
# Class
|
27
|
+
end
|
28
|
+
|
29
|
+
# Module
|
30
|
+
end
|
31
|
+
|
32
|
+
# Module
|
33
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative '../abstract_container/structured_and_oo/extern_requirement'
|
2
|
+
require_relative '../container_data/structured_and_oo/extern_requirement_data'
|
3
|
+
|
4
|
+
module Languages
|
5
|
+
|
6
|
+
module Ruby
|
7
|
+
|
8
|
+
# ExternRequirement Handling extern requirements.
|
9
|
+
class ExternRequirementRuby < Languages::ExternRequirement
|
10
|
+
|
11
|
+
public
|
12
|
+
|
13
|
+
# Get Ruby requirement.
|
14
|
+
# @see ExternRequirement
|
15
|
+
def get_requirement(pLine)
|
16
|
+
detectExpression = detect_extern_requirement(pLine)
|
17
|
+
return nil unless detectExpression
|
18
|
+
|
19
|
+
detectExpression = remove_unnecessary_information(detectExpression)
|
20
|
+
# @requirement = detectExpression
|
21
|
+
name = File.basename(detectExpression, ".*")
|
22
|
+
externReference = ExternRequirementData.new(name)
|
23
|
+
return externReference
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
# Override
|
29
|
+
def detect_extern_requirement(pLine)
|
30
|
+
regexExpression = /^\s*require(?:_relative)?\s+('|")(.*)\1/
|
31
|
+
return nil unless pLine =~ regexExpression
|
32
|
+
return pLine.scan(regexExpression).join("")
|
33
|
+
end
|
34
|
+
|
35
|
+
# Override
|
36
|
+
def remove_unnecessary_information(pLine)
|
37
|
+
regexClean = /\s+|"|'/
|
38
|
+
return pLine.gsub!(regexClean, "") if pLine =~ regexClean
|
39
|
+
return pLine
|
40
|
+
end
|
41
|
+
|
42
|
+
# Class
|
43
|
+
end
|
44
|
+
|
45
|
+
# Module
|
46
|
+
end
|
47
|
+
|
48
|
+
# Module
|
49
|
+
end
|
@@ -0,0 +1,120 @@
|
|
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 Ruby
|
8
|
+
|
9
|
+
# Handling Ruby method
|
10
|
+
class FunctionBehaviorRuby < Languages::FunctionBehavior
|
11
|
+
|
12
|
+
public
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@log = @settings = Kuniri::Setting.create.log
|
16
|
+
end
|
17
|
+
|
18
|
+
# Get Ruby function.
|
19
|
+
def get_function(pLine, type = 'globalFunction')
|
20
|
+
result = detect_function(pLine)
|
21
|
+
return nil unless result
|
22
|
+
|
23
|
+
@log.write_log("Info: get method")
|
24
|
+
|
25
|
+
functionRuby = Languages::FunctionData.new(result)
|
26
|
+
|
27
|
+
parameters = handling_parameter(pLine)
|
28
|
+
if parameters
|
29
|
+
parameters.each do |parameter|
|
30
|
+
functionRuby.add_parameters(parameter)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
@log.write_log("Debug: Method: #{functionRuby.name}, Parameter:
|
35
|
+
#{functionRuby.parameters}")
|
36
|
+
|
37
|
+
return functionRuby
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
|
42
|
+
# Override
|
43
|
+
def detect_function(pLine)
|
44
|
+
regexExpression = /^\s*def\b\s*(\w*)\b/
|
45
|
+
return nil unless pLine =~ regexExpression
|
46
|
+
return pLine.scan(regexExpression)[0].join("")
|
47
|
+
end
|
48
|
+
|
49
|
+
# Override
|
50
|
+
def handling_default_parameter(pLine)
|
51
|
+
return pLine unless pLine =~ /=/
|
52
|
+
|
53
|
+
if pLine =~ /,/
|
54
|
+
partialParameters = pLine.split(",")
|
55
|
+
else
|
56
|
+
partialParameters = [pLine]
|
57
|
+
end
|
58
|
+
|
59
|
+
newList = []
|
60
|
+
partialParameters.each do |element|
|
61
|
+
if element =~ /=/
|
62
|
+
parameter = element.scan(/(\w*)=/).join("")
|
63
|
+
value = element.scan(/=(\w*)/).join("")
|
64
|
+
defaultParameter = Hash(parameter => value)
|
65
|
+
newList.push(defaultParameter)
|
66
|
+
next
|
67
|
+
end
|
68
|
+
newList.push(element)
|
69
|
+
end
|
70
|
+
|
71
|
+
return newList
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
# Override
|
76
|
+
def remove_unnecessary_information(pLine)
|
77
|
+
return pLine.gsub(/\s+|\(|\)/,"") if pLine =~ /\s+|\(|\)/
|
78
|
+
return pLine
|
79
|
+
end
|
80
|
+
|
81
|
+
# Override
|
82
|
+
def handling_parameter(pLine)
|
83
|
+
# Handling with parenthesis and without it.
|
84
|
+
if pLine =~ /\(.+\)/
|
85
|
+
partial = get_parameters(pLine, /\(.+\)/)
|
86
|
+
elsif pLine =~ /def\s+\w+[\s]+(.+)/
|
87
|
+
partial = get_parameters(pLine, /def\s+\w+[\s]+(.+)/)
|
88
|
+
else
|
89
|
+
return nil
|
90
|
+
end
|
91
|
+
|
92
|
+
return handling_default_parameter(partial) if partial =~ /=/
|
93
|
+
return split_string_by_comma(partial)
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
@log
|
99
|
+
|
100
|
+
# Override
|
101
|
+
def get_parameters(pLine, pRegex)
|
102
|
+
partialParameters = pLine.scan(pRegex).join("")
|
103
|
+
partialParameters = remove_unnecessary_information(partialParameters)
|
104
|
+
return partialParameters
|
105
|
+
end
|
106
|
+
|
107
|
+
# Override
|
108
|
+
def split_string_by_comma(pString)
|
109
|
+
return pString.split(",") if pString =~ /,/
|
110
|
+
return [pString]
|
111
|
+
end
|
112
|
+
|
113
|
+
# Class
|
114
|
+
end
|
115
|
+
|
116
|
+
# Ruby
|
117
|
+
end
|
118
|
+
|
119
|
+
# Language
|
120
|
+
end
|
@@ -0,0 +1,47 @@
|
|
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 Ruby
|
7
|
+
|
8
|
+
# Class for handling ruby module
|
9
|
+
class ModuleNamespaceRuby < Languages::ModuleNamespace
|
10
|
+
|
11
|
+
public
|
12
|
+
|
13
|
+
# Get Ruby module.
|
14
|
+
# @see Languages::ModuleNamespace
|
15
|
+
def get_module(pLine)
|
16
|
+
result = detect_module(pLine)
|
17
|
+
return nil unless result
|
18
|
+
|
19
|
+
result = remove_unnecessary_information(result)
|
20
|
+
moduleCaptured = Languages::ModuleNamespaceData.new(result)
|
21
|
+
|
22
|
+
return moduleCaptured
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
# Override
|
28
|
+
def detect_module(pLine)
|
29
|
+
regexExpression = /^\s*module\s+(.*)/
|
30
|
+
return nil unless pLine =~ regexExpression
|
31
|
+
return pLine.scan(regexExpression).join("")
|
32
|
+
end
|
33
|
+
|
34
|
+
# Override
|
35
|
+
def remove_unnecessary_information(pLine)
|
36
|
+
return pLine.gsub(/\s/, "") if pLine =~ /\s/
|
37
|
+
return pLine
|
38
|
+
end
|
39
|
+
|
40
|
+
# class
|
41
|
+
end
|
42
|
+
|
43
|
+
# module
|
44
|
+
end
|
45
|
+
|
46
|
+
# module
|
47
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require_relative '../abstract_container/structured_and_oo/repetition'
|
2
|
+
require_relative '../container_data/structured_and_oo/repetition_data'
|
3
|
+
|
4
|
+
module Languages
|
5
|
+
|
6
|
+
module Ruby
|
7
|
+
|
8
|
+
# Class responsible for handling Ruby repetition data structures.
|
9
|
+
class RepetitionRuby < Languages::Repetition
|
10
|
+
|
11
|
+
public
|
12
|
+
|
13
|
+
# Get Ruby repetition structure.
|
14
|
+
# @see Languages::Repetition
|
15
|
+
def get_repetition(pLine)
|
16
|
+
result = detect_repetition(pLine)
|
17
|
+
return nil unless result
|
18
|
+
|
19
|
+
repetitionCaptured = Languages::RepetitionData.new
|
20
|
+
repetitionCaptured.type = repetition_type(pLine)
|
21
|
+
|
22
|
+
repetitionCaptured.expression = get_expression(result)
|
23
|
+
|
24
|
+
return repetitionCaptured
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
# Override
|
30
|
+
def detect_repetition(pLine)
|
31
|
+
regexExp = /^\s*while\s+(.*)do/
|
32
|
+
return pLine.scan(regexExp)[0].join("") if regexExp =~ pLine
|
33
|
+
|
34
|
+
regexExp = /^\s*for\s+(.*)/
|
35
|
+
return pLine.scan(regexExp)[0].join("") if regexExp =~ pLine
|
36
|
+
|
37
|
+
regexExp = /^\s*until\s+(.*)do/
|
38
|
+
return pLine.scan(regexExp)[0].join("") if regexExp =~ pLine
|
39
|
+
|
40
|
+
return nil
|
41
|
+
end
|
42
|
+
|
43
|
+
# Override
|
44
|
+
def repetition_type(pString)
|
45
|
+
regexExp = /^\s+while|^while/
|
46
|
+
return "WHILE" if regexExp =~ pString
|
47
|
+
|
48
|
+
regexExp = /^\s+for|^for/
|
49
|
+
return "FOR" if regexExp =~ pString
|
50
|
+
|
51
|
+
return nil
|
52
|
+
end
|
53
|
+
|
54
|
+
# Override
|
55
|
+
def get_expression(pString)
|
56
|
+
leftStrip = pString.lstrip
|
57
|
+
rightStrip = leftStrip.rstrip
|
58
|
+
return rightStrip
|
59
|
+
end
|
60
|
+
|
61
|
+
# class
|
62
|
+
end
|
63
|
+
|
64
|
+
# Module
|
65
|
+
end
|
66
|
+
|
67
|
+
# Module
|
68
|
+
end
|
@@ -0,0 +1,117 @@
|
|
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_ruby'
|
5
|
+
require_relative 'extern_requirement_ruby'
|
6
|
+
require_relative 'variable_global_ruby'
|
7
|
+
require_relative 'module_namespace_ruby'
|
8
|
+
require_relative 'end_block_ruby'
|
9
|
+
require_relative 'constructor_ruby'
|
10
|
+
require_relative 'class_ruby'
|
11
|
+
require_relative 'conditional_ruby'
|
12
|
+
require_relative 'repetition_ruby'
|
13
|
+
require_relative 'function_behavior_ruby'
|
14
|
+
require_relative 'attribute_ruby'
|
15
|
+
require_relative 'comment_ruby'
|
16
|
+
|
17
|
+
module Languages
|
18
|
+
|
19
|
+
# Handling the ruby syntax for extract information.
|
20
|
+
class RubySyntax < Languages::Language
|
21
|
+
|
22
|
+
public
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
super
|
26
|
+
@externRequirementHandler = Languages::Ruby::ExternRequirementRuby.new
|
27
|
+
@variableHandler = Languages::Ruby::VariableGlobalRuby.new
|
28
|
+
@functionHandler = Languages::Ruby::FunctionBehaviorRuby.new
|
29
|
+
@moduleHandler = Languages::Ruby::ModuleNamespaceRuby.new
|
30
|
+
@classHandler = Languages::Ruby::ClassRuby.new
|
31
|
+
@attributeHandler = Languages::Ruby::AttributeRuby.new
|
32
|
+
@endBlockHandler = Languages::Ruby::EndBlockRuby.new
|
33
|
+
@methodHandler = Languages::Ruby::FunctionBehaviorRuby.new
|
34
|
+
@constructorHandler = Languages::Ruby::ConstructorRuby.new
|
35
|
+
@conditionalHandler = Languages::Ruby::ConditionalRuby.new
|
36
|
+
@repetitionHandler = Languages::Ruby::RepetitionRuby.new
|
37
|
+
@commentHandler = Languages::Ruby::CommentRuby.new
|
38
|
+
@visibility = "public"
|
39
|
+
end
|
40
|
+
|
41
|
+
# Analyse source code.
|
42
|
+
# @param pPath Path of file to be analysed.
|
43
|
+
def analyse_source(pPath)
|
44
|
+
@name = File.basename(pPath, ".*")
|
45
|
+
@path = File.dirname(pPath)
|
46
|
+
analyse_first_step(pPath)
|
47
|
+
#self.analyse_second_step
|
48
|
+
end
|
49
|
+
|
50
|
+
# TODO: remove it.
|
51
|
+
def comment_extract
|
52
|
+
all_comments = Array.new
|
53
|
+
#Find a simple Ruby comment with '#'
|
54
|
+
@source.scan(/#(.*)/).each do |comments|
|
55
|
+
all_comments.push(comments[0])
|
56
|
+
end
|
57
|
+
#Find multiple line comment.
|
58
|
+
@source.scan(/^=begin(.*?)^=end/m).each do |comment|
|
59
|
+
all_comments.push(comment[0].lstrip)
|
60
|
+
end
|
61
|
+
return all_comments
|
62
|
+
end
|
63
|
+
|
64
|
+
# TODO: remove it.
|
65
|
+
def method_extract
|
66
|
+
return @currentClass.get_methods
|
67
|
+
end
|
68
|
+
|
69
|
+
# TODO: remove it.
|
70
|
+
def class_extract
|
71
|
+
return @currentClass
|
72
|
+
end
|
73
|
+
|
74
|
+
# TODO: remove it.
|
75
|
+
def attribute_extract
|
76
|
+
return @currentClass.get_attributes
|
77
|
+
end
|
78
|
+
|
79
|
+
# TODO: remove it.
|
80
|
+
def global_variable_extract
|
81
|
+
raise NotImplementedError
|
82
|
+
end
|
83
|
+
|
84
|
+
# TODO: remove it.
|
85
|
+
def extern_requirement_extract
|
86
|
+
return @externRequirements
|
87
|
+
end
|
88
|
+
|
89
|
+
# TODO: remove it.
|
90
|
+
def get_classes
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
attr_accessor :visibility
|
96
|
+
@source
|
97
|
+
|
98
|
+
# First step for analyse code, it is responsible for get only basic
|
99
|
+
# informations.
|
100
|
+
# @param pPath Path of file to be analysed.
|
101
|
+
def analyse_first_step(pPath)
|
102
|
+
fileElement = Languages::FileElement.new(pPath)
|
103
|
+
@source = File.open(pPath, "rb")
|
104
|
+
@source.each do |line|
|
105
|
+
next if line.gsub(/\s+/,"").size == 0
|
106
|
+
|
107
|
+
@state.handle_line(line)
|
108
|
+
fileElement = @state.execute(fileElement, line)
|
109
|
+
end
|
110
|
+
@fileElements.push(fileElement)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Class
|
114
|
+
end
|
115
|
+
|
116
|
+
# Module
|
117
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#reference:
|
2
|
+
# http://www.java2s.com/Code/Ruby/Language-Basics/Rubysreservedwords.htm
|
3
|
+
|
4
|
+
module Languages
|
5
|
+
|
6
|
+
# Module responsible for handling ruby syntax.
|
7
|
+
module Ruby
|
8
|
+
|
9
|
+
# Token types used to identify keywords
|
10
|
+
CLASS_TOKEN ||= 1 # Executes the block passed to the method.
|
11
|
+
ATTRIBUTE_TOKEN ||= 2
|
12
|
+
DEF_TOKEN ||= 3
|
13
|
+
VISIBILITY_TOKEN ||= 4
|
14
|
+
END_TOKEN ||= 5 # Code, enclosed in { and }, to run when the program ends.
|
15
|
+
IF_TOKEN ||= 6 # Executes code block if true. Closes with end.
|
16
|
+
WHILE_TOKEN ||= 7 # Executes the block passed to the method.
|
17
|
+
DO_TOKEN ||= 8 # Begins a block and executes code in that block(end)
|
18
|
+
BEGIN_TOKEN ||= 9 # Code, enclosed in { and }, to run before the program runs.
|
19
|
+
ALIAS_TOKEN ||= 10 # Creates an alias: method, operator, or global variable.
|
20
|
+
AND_TOKEN ||= 11 # Logical operator same as && except and has lower precedence.
|
21
|
+
BEGIN_DOWN_TOKEN ||= 12 # Begins a code block or group of statements (end).
|
22
|
+
BREAK_TOKEN ||= 13 # Terminates a while or until loop or a method.
|
23
|
+
CASE_TOKEN ||= 14 # Compares an expression with a matching when clause (end).
|
24
|
+
REQUIRE_TOKEN ||= 15 # Extern requirement
|
25
|
+
DEFINED_TOKEN ||= 16 # Determines: variable, method, super method, or block.
|
26
|
+
ELSE_TOKEN ||= 17 # Executes if previous conditional.
|
27
|
+
ELSIF_TOKEN ||= 18 # Executes if previous conditional, in if or elsif.
|
28
|
+
ENSURE_TOKEN ||= 19 # Always executes at block termination.
|
29
|
+
FALSE_TOKEN ||= 20 # Logical or Boolean false, instance of FalseClass.
|
30
|
+
TRUE_TOKEN ||= 21 # Instance of TrueClass.
|
31
|
+
FOR_TOKEN ||= 22 # Begins a for loop; used with in.
|
32
|
+
MODULE_TOKEN ||= 23 # Defines a module; closes with end.
|
33
|
+
NEXT_TOKEN ||= 24 # Jumps before a loop's conditional.
|
34
|
+
NIL_TOKEN ||= 25 # Object of NilClass.
|
35
|
+
NOT_TOKEN ||= 26 # Logical operator, same as !.
|
36
|
+
OR_TOKEN ||= 27 # Logical operator, same as ||.
|
37
|
+
REDO_TOKEN ||= 28 # Jumps after a loop's conditional.
|
38
|
+
RESCUE_TOKEN ||= 29 # Evaluates an expression after an exception is raised.
|
39
|
+
RETRY_TOKEN ||= 30 # Repeats a method call outside of rescue.
|
40
|
+
RETURN_TOKEN ||= 31 # Returns a value from a method or block.
|
41
|
+
SELF_TOKEN ||= 32 # Current object (invoked by a method).
|
42
|
+
SUPER_TOKEN ||= 33 # Calls method of the same name in the superclass.
|
43
|
+
THEN_TOKEN ||= 34 # A continuation for if, unless, and when.
|
44
|
+
UNDEF_TOKEN ||= 35 # Makes a method in current class undefined.
|
45
|
+
UNLESS_TOKEN ||= 36 # Executes code block if conditional statement is false.
|
46
|
+
UNTIL_TOKEN ||= 37 # Executes code block while conditional statement is false.
|
47
|
+
WHEN_TOKEN ||= 38 # Starts a clause (one or more) under case.
|
48
|
+
YIELD_TOKEN ||= 39 # Executes the block passed to the method.
|
49
|
+
INTEGER_TOKEN ||= 40
|
50
|
+
ARRAY_TOKEN ||= 41
|
51
|
+
HASH_TOKEN ||= 42
|
52
|
+
OBJECT_TOKEN ||= 43
|
53
|
+
CONSTRUCTOR_TOKEN ||= 44
|
54
|
+
|
55
|
+
# Module
|
56
|
+
end
|
57
|
+
|
58
|
+
# Language
|
59
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require_relative '../abstract_container/structured_and_oo/variable_behaviour'
|
2
|
+
|
3
|
+
module Languages
|
4
|
+
|
5
|
+
module Ruby
|
6
|
+
|
7
|
+
# Ruby Handling Ruby attributes
|
8
|
+
class VariableBehaviourRuby < Languages::VariableBehaviour
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
# Override
|
13
|
+
def remove_unnecessary_information(pString)
|
14
|
+
return pString.gsub!(/\(.*\)/,"") if pString =~ /\(.*\)/
|
15
|
+
return pString
|
16
|
+
end
|
17
|
+
|
18
|
+
# Override
|
19
|
+
def prepare_final_string(pString)
|
20
|
+
if pString =~ /\s+|:|@|=/
|
21
|
+
return pString.gsub!(/\s+|:|@|=/,"")
|
22
|
+
end
|
23
|
+
return pString
|
24
|
+
end
|
25
|
+
|
26
|
+
# Override
|
27
|
+
def handle_multiple_declaration_with_comma(pString)
|
28
|
+
listOfAttributes = []
|
29
|
+
pString = pString.split(",")
|
30
|
+
pString.each do |variable|
|
31
|
+
return nil if variable.scan(/=/).count > 1
|
32
|
+
|
33
|
+
variable = variable.scan(/.*=/).join("") if variable =~ /.*=/
|
34
|
+
|
35
|
+
return nil if variable =~ /\./
|
36
|
+
|
37
|
+
variable = prepare_final_string(variable)
|
38
|
+
finalVariableElement = yield(variable)
|
39
|
+
listOfAttributes.push(finalVariableElement)
|
40
|
+
end
|
41
|
+
|
42
|
+
return listOfAttributes
|
43
|
+
end
|
44
|
+
|
45
|
+
# Override
|
46
|
+
def handle_multiple_declaration_with_equal(pString)
|
47
|
+
listOfAttributes = []
|
48
|
+
pString = pString.split("=")
|
49
|
+
pString.each do |variable|
|
50
|
+
return nil if variable =~ /\./
|
51
|
+
|
52
|
+
variable = prepare_final_string(variable)
|
53
|
+
attribute = yield(variable)
|
54
|
+
listOfAttributes.push(attribute)
|
55
|
+
end
|
56
|
+
|
57
|
+
return listOfAttributes
|
58
|
+
end
|
59
|
+
|
60
|
+
# Override
|
61
|
+
def handle_line_declaration(pString)
|
62
|
+
listOfAttributes = []
|
63
|
+
if pString =~ /=/
|
64
|
+
pString = pString.scan(/.*=/).join("")
|
65
|
+
return nil if pString =~ /\./
|
66
|
+
end
|
67
|
+
|
68
|
+
return nil if pString =~ /\./
|
69
|
+
|
70
|
+
pString = prepare_final_string(pString)
|
71
|
+
attribute = yield(pString)
|
72
|
+
listOfAttributes.push(attribute)
|
73
|
+
|
74
|
+
return listOfAttributes
|
75
|
+
end
|
76
|
+
|
77
|
+
#Class
|
78
|
+
end
|
79
|
+
|
80
|
+
# Ruby
|
81
|
+
end
|
82
|
+
#Language
|
83
|
+
end
|
@@ -0,0 +1,123 @@
|
|
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 Ruby
|
7
|
+
|
8
|
+
# VariableGlobalRuby Handling extern requirements.
|
9
|
+
class VariableGlobalRuby < Languages::VariableGlobal
|
10
|
+
|
11
|
+
public
|
12
|
+
|
13
|
+
# Get Ruby variable.
|
14
|
+
# @see Languages::VariableGlobal
|
15
|
+
def get_variable(pLine)
|
16
|
+
result = detect_variable(pLine)
|
17
|
+
return nil unless result
|
18
|
+
|
19
|
+
listOfVariable = []
|
20
|
+
|
21
|
+
# Separated by comma, equal or the common case
|
22
|
+
if result.split(",").size > 1
|
23
|
+
listOfVariable = handle_multiple_declaration_with_comma(result)
|
24
|
+
elsif result.split("=").size > 1
|
25
|
+
listOfVariable = handle_multiple_declaration_with_equal(result)
|
26
|
+
else
|
27
|
+
listOfVariable = handle_line_declaration(result)
|
28
|
+
end
|
29
|
+
|
30
|
+
return listOfVariable
|
31
|
+
end
|
32
|
+
|
33
|
+
protected
|
34
|
+
|
35
|
+
# Override
|
36
|
+
def detect_variable(pLine)
|
37
|
+
# Check basic case of non variable. Ex.: value x
|
38
|
+
pLine.gsub!(/^\s*/, "")
|
39
|
+
pLine.gsub!(/\s*$/, "")
|
40
|
+
return nil if pLine =~ /end/
|
41
|
+
return nil if pLine =~ /^def\s+/
|
42
|
+
return nil if pLine =~ /=begin/
|
43
|
+
return pLine if pLine.split(",").size > 1
|
44
|
+
return pLine if pLine.split("=").size > 1
|
45
|
+
|
46
|
+
return nil if pLine.split(" ").size > 1
|
47
|
+
return pLine
|
48
|
+
end
|
49
|
+
|
50
|
+
# Override
|
51
|
+
def remove_unnecessary_information(pLine)
|
52
|
+
return pLine
|
53
|
+
end
|
54
|
+
|
55
|
+
# Override
|
56
|
+
def prepare_final_string(pString)
|
57
|
+
if pString =~ /\s+|:|@|=/
|
58
|
+
return pString.gsub!(/\s+|:|@|=/,"")
|
59
|
+
end
|
60
|
+
return pString
|
61
|
+
end
|
62
|
+
|
63
|
+
# Override
|
64
|
+
def handle_multiple_declaration_with_comma(pString)
|
65
|
+
listOfVariable = []
|
66
|
+
pString = pString.split(",")
|
67
|
+
pString.each do |variable|
|
68
|
+
return nil if variable.split("=").size > 2
|
69
|
+
|
70
|
+
variable = variable.scan(/.*=/).join("") if variable =~ /.*=/
|
71
|
+
|
72
|
+
return nil if variable =~ /\./
|
73
|
+
|
74
|
+
variable = prepare_final_string(variable)
|
75
|
+
globalVariable = Languages::VariableGlobalData.new(variable)
|
76
|
+
listOfVariable.push(globalVariable)
|
77
|
+
end
|
78
|
+
|
79
|
+
return listOfVariable
|
80
|
+
end
|
81
|
+
|
82
|
+
# Override
|
83
|
+
def handle_multiple_declaration_with_equal(pString)
|
84
|
+
listOfVariable = []
|
85
|
+
pString = pString.split("=")
|
86
|
+
pString.each do |variable|
|
87
|
+
return nil if variable =~ /\./
|
88
|
+
|
89
|
+
variable = prepare_final_string(variable)
|
90
|
+
globalVariable = Languages::VariableGlobalData.new(variable)
|
91
|
+
listOfVariable.push(globalVariable)
|
92
|
+
end
|
93
|
+
value = listOfVariable.pop
|
94
|
+
|
95
|
+
return listOfVariable
|
96
|
+
end
|
97
|
+
|
98
|
+
# Override
|
99
|
+
def handle_line_declaration(pString)
|
100
|
+
listOfVariable = []
|
101
|
+
if pString =~ /=/
|
102
|
+
pString = pString.scan(/.*=/).join("")
|
103
|
+
return nil if pString =~ /\./
|
104
|
+
end
|
105
|
+
|
106
|
+
return nil if pString =~ /\./
|
107
|
+
|
108
|
+
pString = prepare_final_string(pString)
|
109
|
+
globalVariable = Languages::VariableGlobalData.new(pString)
|
110
|
+
listOfVariable.push(globalVariable)
|
111
|
+
|
112
|
+
return listOfVariable
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
# Class
|
117
|
+
end
|
118
|
+
|
119
|
+
# Module
|
120
|
+
end
|
121
|
+
|
122
|
+
# Module
|
123
|
+
end
|