kuniri 0.0.1
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.
- 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,45 @@
|
|
|
1
|
+
require_relative '../language/language_factory'
|
|
2
|
+
require_relative '../util/html_logger'
|
|
3
|
+
require_relative '../util/html_logger'
|
|
4
|
+
|
|
5
|
+
# Module responsible for keeping the parser handler
|
|
6
|
+
module Parser
|
|
7
|
+
|
|
8
|
+
# Keep the relationship between languages and project
|
|
9
|
+
class Parser
|
|
10
|
+
|
|
11
|
+
public
|
|
12
|
+
|
|
13
|
+
attr_accessor :language
|
|
14
|
+
attr_reader :fileLanguage
|
|
15
|
+
|
|
16
|
+
def initialize(pFilesPath, pLanguage = "ruby")
|
|
17
|
+
@filesPath = pFilesPath
|
|
18
|
+
@fileLanguage = []
|
|
19
|
+
@log = @settings = Kuniri::Setting.create.log
|
|
20
|
+
@factory = Languages::LanguageFactory.new
|
|
21
|
+
@language = pLanguage
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Start parse in the project.
|
|
25
|
+
def start_parser
|
|
26
|
+
# TODO: handle the case of filePAth is empty
|
|
27
|
+
@log.write_log("Debug: START FIRST PARSER")
|
|
28
|
+
@filesPath.each do |file|
|
|
29
|
+
language = @factory.get_language(@language)
|
|
30
|
+
language.analyse_source(file)
|
|
31
|
+
@fileLanguage.push(language)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
@filesPath
|
|
38
|
+
@log
|
|
39
|
+
@factory
|
|
40
|
+
|
|
41
|
+
# class
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# module
|
|
45
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
require 'nokogiri'
|
|
2
|
+
require_relative '../language/container_data/structured_and_oo/class_data'
|
|
3
|
+
|
|
4
|
+
module Parser
|
|
5
|
+
|
|
6
|
+
# Class responsible for generate xml output
|
|
7
|
+
class XML
|
|
8
|
+
|
|
9
|
+
def initialize(path = "kuniri.xml")
|
|
10
|
+
@log = @settings = Kuniri::Setting.create.log
|
|
11
|
+
set_path(path)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Set path to save the output.
|
|
15
|
+
# @param pPath Output path.
|
|
16
|
+
def set_path(pPath)
|
|
17
|
+
@parser_path = pPath
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Create the xml output file, only saves a single ClassData for now
|
|
21
|
+
# @param class_data [ClassData] Receives the ClassData to save
|
|
22
|
+
def create_class_data(class_data)
|
|
23
|
+
@log.write_log("---- PARSER XML ----")
|
|
24
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
|
25
|
+
generate_class(xml, class_data)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
@builder = builder
|
|
29
|
+
|
|
30
|
+
File.open(@parser_path, 'w') do |file|
|
|
31
|
+
file.write(builder.to_xml)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Create the xml output file, only saves a ClassData for now.
|
|
36
|
+
# @param parser - Receives the parser
|
|
37
|
+
def create_all_data(parser)
|
|
38
|
+
@log.write_log("---- PARSER XML ----")
|
|
39
|
+
|
|
40
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
|
41
|
+
xml.kuniri {
|
|
42
|
+
for elements in parser.fileLanguage do
|
|
43
|
+
if(elements.fileElements[0].classes.length() > 0)
|
|
44
|
+
generate_class(xml, elements.fileElements[0].classes[0])
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
}
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
@builder = builder
|
|
51
|
+
|
|
52
|
+
File.open(@parser_path, 'w') do |file|
|
|
53
|
+
file.write(builder.to_xml)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# returns the builder if create method already executed
|
|
58
|
+
def get_builder
|
|
59
|
+
@builder
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Parse a ClassData to xml
|
|
63
|
+
# @param xml [Nokogiri::XML::Builder] xml builder to edit
|
|
64
|
+
# @param class_data [ClassData] the ClassData to save
|
|
65
|
+
def generate_class(xml, class_data)
|
|
66
|
+
@log.write_log(class_data.name)
|
|
67
|
+
xml.class_data(:name => class_data.name) {
|
|
68
|
+
class_data.methods.each do |o|
|
|
69
|
+
generate_method(xml, o)
|
|
70
|
+
end
|
|
71
|
+
class_data.constructors.each do |c|
|
|
72
|
+
generate_constructor(xml, c)
|
|
73
|
+
end
|
|
74
|
+
class_data.inheritances.each do |i|
|
|
75
|
+
generate_inheritance(xml, i)
|
|
76
|
+
end
|
|
77
|
+
}
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Parse a InheritanceData to xml
|
|
81
|
+
# @param xml builder to edit
|
|
82
|
+
# @param inheritance_data the InheritanceData to save
|
|
83
|
+
def generate_inheritance(xml, inheritance_data)
|
|
84
|
+
xml.inheritance(:name => inheritance_data[0].strip()) {}
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Parse a ConstructorData to xml
|
|
88
|
+
# @param xml xml builder to edit
|
|
89
|
+
# @param constructor_data the ConstructorData to save
|
|
90
|
+
def generate_constructor(xml, constructor_data)
|
|
91
|
+
xml.method_(:name => constructor_data.name) {
|
|
92
|
+
constructor_data.parameters.each do |p|
|
|
93
|
+
generate_parameter(xml, p)
|
|
94
|
+
end
|
|
95
|
+
}
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Parse a MethodData to xml
|
|
99
|
+
# @param xml builder to edit
|
|
100
|
+
# @param method_data the MethodData to save
|
|
101
|
+
def generate_method(xml, method_data)
|
|
102
|
+
xml.method_(:name => method_data.name, :visibility => method_data.visibility) {
|
|
103
|
+
method_data.parameters.each do |p|
|
|
104
|
+
generate_parameter(xml, p)
|
|
105
|
+
end
|
|
106
|
+
}
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Parse a MethodData to xml
|
|
110
|
+
# @param xml builder to edit
|
|
111
|
+
# @param parameter the Attribute to save
|
|
112
|
+
def generate_parameter(xml, parameter)
|
|
113
|
+
if parameter.kind_of?(String)
|
|
114
|
+
xml.parameter(:name => parameter) {}
|
|
115
|
+
else
|
|
116
|
+
# Is a hash parameter=>defaultValue
|
|
117
|
+
for p in parameter do
|
|
118
|
+
xml.parameter(:name => p[0]+'='+p[1]) {}
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
private
|
|
124
|
+
|
|
125
|
+
@log
|
|
126
|
+
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require_relative 'oo_structured_state'
|
|
2
|
+
|
|
3
|
+
module StateMachine
|
|
4
|
+
|
|
5
|
+
module OOStructuredFSM
|
|
6
|
+
|
|
7
|
+
# Class responsible for handling attribute state.
|
|
8
|
+
class AttributeState < OOStructuredState
|
|
9
|
+
|
|
10
|
+
@language
|
|
11
|
+
|
|
12
|
+
def initialize(pLanguage)
|
|
13
|
+
@language = pLanguage
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @see OOStructuredState
|
|
17
|
+
def handle_line(pLine)
|
|
18
|
+
# TODO: YOU HAVE TO HANDLER THE CASE OF SELF REFERENCE
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# @see OOStructuredState
|
|
22
|
+
def class_capture
|
|
23
|
+
@language.rewind_state
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# @see OOStructuredState
|
|
27
|
+
def execute(pElementFile, pLine)
|
|
28
|
+
attributeElement = @language.attributeHandler.get_attribute(pLine)
|
|
29
|
+
|
|
30
|
+
if attributeElement
|
|
31
|
+
# Add attribute to the last class
|
|
32
|
+
lastIndex = pElementFile.classes.length - 1 # We want the index
|
|
33
|
+
attributeElement.each do |attribute|
|
|
34
|
+
attribute.comments = @language.string_comment_to_transfer
|
|
35
|
+
end
|
|
36
|
+
@language.string_comment_to_transfer = ""
|
|
37
|
+
pElementFile.classes[lastIndex].add_attribute(attributeElement)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class_capture
|
|
41
|
+
return pElementFile
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# End class
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# End OOStructuredFSM
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# End StateMachine
|
|
51
|
+
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
require_relative 'oo_structured_state'
|
|
2
|
+
|
|
3
|
+
module StateMachine
|
|
4
|
+
|
|
5
|
+
module OOStructuredFSM
|
|
6
|
+
|
|
7
|
+
# Class responsible for handling class state.
|
|
8
|
+
class ClassState < OOStructuredState
|
|
9
|
+
|
|
10
|
+
@language
|
|
11
|
+
|
|
12
|
+
def initialize (pLanguage)
|
|
13
|
+
@language = pLanguage
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @see OOStructuredState
|
|
17
|
+
def handle_line(pLine)
|
|
18
|
+
if @language.attributeHandler.get_attribute(pLine)
|
|
19
|
+
attribute_capture
|
|
20
|
+
elsif @language.constructorHandler.get_constructor(pLine)
|
|
21
|
+
constructor_capture
|
|
22
|
+
elsif @language.methodHandler.get_function(pLine)
|
|
23
|
+
method_capture
|
|
24
|
+
elsif @language.moduleHandler.get_module(pLine)
|
|
25
|
+
module_capture
|
|
26
|
+
elsif @language.commentHandler.is_single_line_comment?(pLine) ||
|
|
27
|
+
@language.commentHandler.is_multiple_line_comment?(pLine)
|
|
28
|
+
comment_capture
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# @see OOStructuredState
|
|
33
|
+
def method_capture
|
|
34
|
+
@language.set_state(@language.methodState)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# @see OOStructuredState
|
|
38
|
+
def constructor_capture
|
|
39
|
+
@language.set_state(@language.constructorState)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# @see OOStructuredState
|
|
43
|
+
def attribute_capture
|
|
44
|
+
@language.set_state(@language.attributeState)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# @see OOStructuredState
|
|
48
|
+
def module_capture
|
|
49
|
+
@language.rewind_state
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# @see OOStructuredState
|
|
53
|
+
def idle_capture
|
|
54
|
+
@language.rewind_state
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# @see OOStructuredState
|
|
58
|
+
def comment_capture
|
|
59
|
+
@language.set_state(@language.commentState)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# @see OOStructuredState
|
|
63
|
+
def execute(pElementFile, pLine)
|
|
64
|
+
classElement = @language.classHandler.get_class(pLine)
|
|
65
|
+
|
|
66
|
+
if classElement
|
|
67
|
+
classElement.comments = @language.string_comment_to_transfer
|
|
68
|
+
@language.string_comment_to_transfer = ""
|
|
69
|
+
pElementFile.add_class(classElement)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
if @language.endBlockHandler.has_end_of_block?(pLine)
|
|
73
|
+
previous = @language.previousState.last
|
|
74
|
+
|
|
75
|
+
if (previous.is_a? (StateMachine::OOStructuredFSM::IdleState))
|
|
76
|
+
idle_capture
|
|
77
|
+
elsif (previous.is_a? (StateMachine::OOStructuredFSM::ModuleState))
|
|
78
|
+
module_capture
|
|
79
|
+
else
|
|
80
|
+
return pElementFile
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
return pElementFile
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# End class
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# End OOStructuredFSM
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
#
|
|
94
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
require_relative 'oo_structured_state'
|
|
2
|
+
|
|
3
|
+
module StateMachine
|
|
4
|
+
|
|
5
|
+
module OOStructuredFSM
|
|
6
|
+
|
|
7
|
+
# CommentState is responsible for handling comments.
|
|
8
|
+
class CommentState < OOStructuredState
|
|
9
|
+
|
|
10
|
+
@language
|
|
11
|
+
@multipleLineComment
|
|
12
|
+
@enableMultipleLine
|
|
13
|
+
|
|
14
|
+
def initialize(pLanguage)
|
|
15
|
+
@language = pLanguage
|
|
16
|
+
@multipleLineComment = ""
|
|
17
|
+
@enableMultipleLine = false
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def handle_line(pLine)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @see OOStructuredState
|
|
24
|
+
def execute(pElementFile, pLine)
|
|
25
|
+
# Single line
|
|
26
|
+
if @language.commentHandler.is_single_line_comment?(pLine)
|
|
27
|
+
handling_single_line(pLine)
|
|
28
|
+
return pElementFile
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Multiple line
|
|
32
|
+
if @language.commentHandler.is_multiple_line_comment?(pLine)
|
|
33
|
+
@enableMultipleLine = true
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
if @language.commentHandler.is_multiple_line_comment_end?(pLine)
|
|
37
|
+
handling_multiple_line
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
if @enableMultipleLine
|
|
41
|
+
capture_multiple_line_comment(pLine)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
return pElementFile
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
def handling_single_line(pLine)
|
|
51
|
+
comment_string = @language.commentHandler.get_comment(pLine)
|
|
52
|
+
comment_string += "\n"
|
|
53
|
+
@language.string_comment_to_transfer += comment_string
|
|
54
|
+
@language.rewind_state
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def handling_multiple_line
|
|
58
|
+
@enableMultipleLine = false
|
|
59
|
+
@language.string_comment_to_transfer = @multipleLineComment
|
|
60
|
+
@multipleLineComment = ""
|
|
61
|
+
@language.rewind_state
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def capture_multiple_line_comment(pLine)
|
|
65
|
+
comment_string = @language.commentHandler.get_comment(pLine)
|
|
66
|
+
@multipleLineComment += comment_string
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# class
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# module
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# module
|
|
76
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
require_relative 'oo_structured_state'
|
|
2
|
+
|
|
3
|
+
module StateMachine
|
|
4
|
+
|
|
5
|
+
module OOStructuredFSM
|
|
6
|
+
|
|
7
|
+
# Class responsible for handling conditional state.
|
|
8
|
+
class ConditionalState < OOStructuredState
|
|
9
|
+
|
|
10
|
+
@language
|
|
11
|
+
|
|
12
|
+
def initialize(pLanguage)
|
|
13
|
+
@language = pLanguage
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def handle_line(pLine)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# @see OOStructuredState
|
|
20
|
+
def method_capture
|
|
21
|
+
reset_flag
|
|
22
|
+
@language.rewind_state
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# @see OOStructuredState
|
|
26
|
+
def constructor_capture
|
|
27
|
+
reset_flag
|
|
28
|
+
@language.rewind_state
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# @see OOStructuredState
|
|
32
|
+
def function_capture
|
|
33
|
+
reset_flag
|
|
34
|
+
@language.rewind_state
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# @see OOStructuredState
|
|
38
|
+
def add_conditional_element(pFlag, pElementFile, pConditional)
|
|
39
|
+
if pFlag == StateMachine::GLOBAL_FUNCTION_STATE
|
|
40
|
+
pElementFile.global_functions
|
|
41
|
+
.last.add_conditional(pConditional)
|
|
42
|
+
elsif pFlag == StateMachine::METHOD_STATE
|
|
43
|
+
pElementFile.classes.last.methods
|
|
44
|
+
.last.add_conditional(pConditional)
|
|
45
|
+
elsif pFlag == StateMachine::CONSTRUCTOR_STATE
|
|
46
|
+
pElementFile.classes.last.constructors
|
|
47
|
+
.last.add_conditional(pConditional)
|
|
48
|
+
end
|
|
49
|
+
return pElementFile
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# @see OOStructuredState
|
|
53
|
+
def execute(pElementFile, pLine)
|
|
54
|
+
conditional = @language.conditionalHandler.get_conditional(pLine)
|
|
55
|
+
|
|
56
|
+
flag = @language.flagFunctionBehaviour
|
|
57
|
+
|
|
58
|
+
if (conditional)
|
|
59
|
+
pElementFile = add_conditional_element(flag,
|
|
60
|
+
pElementFile, conditional)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
if (@language.endBlockHandler.has_end_of_block?(pLine))
|
|
64
|
+
if (flag == StateMachine::GLOBAL_FUNCTION_STATE)
|
|
65
|
+
function_capture
|
|
66
|
+
elsif (flag == StateMachine::METHOD_STATE)
|
|
67
|
+
method_capture
|
|
68
|
+
elsif (flag == StateMachine::CONSTRUCTOR_STATE)
|
|
69
|
+
constructor_capture
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
return pElementFile
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
private
|
|
78
|
+
|
|
79
|
+
# @see OOStructuredState
|
|
80
|
+
def reset_flag
|
|
81
|
+
@language.flagFunctionBehaviour = StateMachine::NONE_HANDLING_STATE
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
# End class
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# End OOStructuredFSM
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# End StateMachine
|
|
92
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require_relative 'oo_structured_state'
|
|
2
|
+
|
|
3
|
+
module StateMachine
|
|
4
|
+
|
|
5
|
+
module OOStructuredFSM
|
|
6
|
+
|
|
7
|
+
# Class responsible for handling constructor state.
|
|
8
|
+
class ConstructorState < OOStructuredState
|
|
9
|
+
|
|
10
|
+
@language
|
|
11
|
+
|
|
12
|
+
def initialize(pLanguage)
|
|
13
|
+
@language = pLanguage
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @see OOStructuredState
|
|
17
|
+
def handle_line(pLine)
|
|
18
|
+
if @language.conditionalHandler.get_conditional(pLine)
|
|
19
|
+
conditional_capture
|
|
20
|
+
elsif @language.repetitionHandler.get_repetition(pLine)
|
|
21
|
+
repetition_capture
|
|
22
|
+
else
|
|
23
|
+
return
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# @see OOStructuredState
|
|
28
|
+
def class_capture
|
|
29
|
+
@language.rewind_state
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# @see OOStructuredState
|
|
33
|
+
def conditional_capture
|
|
34
|
+
@language.flagFunctionBehaviour = StateMachine::CONSTRUCTOR_STATE
|
|
35
|
+
@language.set_state(@language.conditionalState)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# @see OOStructuredState
|
|
39
|
+
def repetition_capture
|
|
40
|
+
@language.flagFunctionBehaviour = StateMachine::CONSTRUCTOR_STATE
|
|
41
|
+
@language.set_state(@language.repetitionState)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# @see OOStructuredState
|
|
45
|
+
def execute(pElementFile, pLine)
|
|
46
|
+
constructorElement =
|
|
47
|
+
@language.constructorHandler.get_constructor(pLine)
|
|
48
|
+
|
|
49
|
+
if (constructorElement)
|
|
50
|
+
lastIndex = pElementFile.classes.length - 1 # We want the index
|
|
51
|
+
constructorElement.comments = @language.string_comment_to_transfer
|
|
52
|
+
@language.string_comment_to_transfer = ""
|
|
53
|
+
pElementFile.classes[lastIndex].add_constructor(constructorElement)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
if (@language.endBlockHandler.has_end_of_block?(pLine))
|
|
57
|
+
class_capture
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
return pElementFile
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# End class
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# End OOStructuredFSM
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# End StateMachine
|
|
71
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
require_relative 'oo_structured_state'
|
|
2
|
+
require_relative 'module_state'
|
|
3
|
+
require_relative 'token_state_machine'
|
|
4
|
+
|
|
5
|
+
module StateMachine
|
|
6
|
+
|
|
7
|
+
module OOStructuredFSM
|
|
8
|
+
|
|
9
|
+
# Class responsible for handling function state.
|
|
10
|
+
class FunctionState < OOStructuredState
|
|
11
|
+
|
|
12
|
+
@language
|
|
13
|
+
|
|
14
|
+
def initialize(pLanguage)
|
|
15
|
+
@language = pLanguage
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# @see OOStructuredState
|
|
19
|
+
def handle_line(pLine)
|
|
20
|
+
if @language.conditionalHandler.get_conditional(pLine)
|
|
21
|
+
conditional_capture
|
|
22
|
+
elsif @language.repetitionHandler.get_repetition(pLine)
|
|
23
|
+
repetition_capture
|
|
24
|
+
else
|
|
25
|
+
return
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# @see OOStructuredState
|
|
30
|
+
def idle_capture
|
|
31
|
+
@language.rewind_state
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# @see OOStructuredState
|
|
35
|
+
def module_capture
|
|
36
|
+
@language.rewind_state
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# @see OOStructuredState
|
|
40
|
+
def conditional_capture
|
|
41
|
+
@language.flagFunctionBehaviour = StateMachine::GLOBAL_FUNCTION_STATE
|
|
42
|
+
@language.set_state(@language.conditionalState)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# @see OOStructuredState
|
|
46
|
+
def repetition_capture
|
|
47
|
+
@language.flagFunctionBehaviour = StateMachine::GLOBAL_FUNCTION_STATE
|
|
48
|
+
@language.set_state(@language.repetitionState)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# @see OOStructuredState
|
|
52
|
+
def execute(pElementFile, pLine)
|
|
53
|
+
function = @language.functionHandler.get_function(pLine)
|
|
54
|
+
|
|
55
|
+
if function
|
|
56
|
+
function.comments = @language.string_comment_to_transfer
|
|
57
|
+
@language.string_comment_to_transfer = ""
|
|
58
|
+
pElementFile.add_global_function(function)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
if (@language.endBlockHandler.has_end_of_block?(pLine))
|
|
62
|
+
previous = @language.previousState.last
|
|
63
|
+
|
|
64
|
+
if (previous.is_a? (StateMachine::OOStructuredFSM::ModuleState))
|
|
65
|
+
module_capture
|
|
66
|
+
elsif (previous.is_a? (StateMachine::OOStructuredFSM::IdleState))
|
|
67
|
+
idle_capture
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
return pElementFile
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# End class
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# End OOStructuredFSM
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# End StateMachine
|
|
82
|
+
end
|