kuniri 0.0.1 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +9 -7
  4. data/COPYING +160 -656
  5. data/Gemfile +4 -3
  6. data/README.md +57 -27
  7. data/Rakefile +3 -1
  8. data/bin/kuniri +50 -26
  9. data/data/aggregation_lang.rb +33 -0
  10. data/data/attribute_lang.rb +14 -87
  11. data/data/class_lang.rb +19 -41
  12. data/data/comment_lang.rb +52 -0
  13. data/data/conditional_lang.rb +14 -41
  14. data/data/constructor_lang.rb +4 -12
  15. data/data/end_block_lang.rb +7 -6
  16. data/data/extern_requirement_lang.rb +10 -17
  17. data/data/function_behavior_lang.rb +17 -66
  18. data/data/global_function_lang.rb +26 -0
  19. data/data/lang_syntax.rb +82 -49
  20. data/data/method_lang.rb +26 -0
  21. data/data/module_namespace_lang.rb +8 -13
  22. data/data/repetition_lang.rb +19 -32
  23. data/data/token_lang.rb +2 -44
  24. data/data/variable_behaviour_lang.rb +43 -0
  25. data/data/variable_global_lang.rb +13 -72
  26. data/kuniri.gemspec +4 -4
  27. data/lib/kuniri/core/configuration/language_available.rb +2 -2
  28. data/lib/kuniri/core/kuniri.rb +32 -24
  29. data/lib/kuniri/core/setting.rb +51 -85
  30. data/lib/kuniri/error/parser_error.rb +9 -0
  31. data/lib/kuniri/language/abstract_container/structured_and_oo/aggregation.rb +29 -0
  32. data/lib/kuniri/language/abstract_container/structured_and_oo/attribute.rb +0 -40
  33. data/lib/kuniri/language/abstract_container/structured_and_oo/global_tokens.rb +20 -0
  34. data/lib/kuniri/language/abstract_container/structured_and_oo/repetition.rb +9 -1
  35. data/lib/kuniri/language/abstract_container/structured_and_oo/variable_global.rb +0 -35
  36. data/lib/kuniri/language/container_data/structured_and_oo/aggregation_data.rb +23 -0
  37. data/lib/kuniri/language/container_data/structured_and_oo/attribute_data.rb +4 -2
  38. data/lib/kuniri/language/container_data/structured_and_oo/basic_structure.rb +24 -0
  39. data/lib/kuniri/language/container_data/structured_and_oo/class_data.rb +13 -19
  40. data/lib/kuniri/language/container_data/structured_and_oo/conditional_data.rb +2 -13
  41. data/lib/kuniri/language/container_data/structured_and_oo/constructor_data.rb +2 -0
  42. data/lib/kuniri/language/container_data/structured_and_oo/extern_requirement_data.rb +11 -6
  43. data/lib/kuniri/language/container_data/structured_and_oo/{file_element.rb → file_element_data.rb} +11 -9
  44. data/lib/kuniri/language/container_data/structured_and_oo/function_abstract.rb +58 -11
  45. data/lib/kuniri/language/container_data/structured_and_oo/function_data.rb +3 -3
  46. data/lib/kuniri/language/container_data/structured_and_oo/manager_basic_structure_data.rb +55 -0
  47. data/lib/kuniri/language/container_data/structured_and_oo/method_data.rb +5 -4
  48. data/lib/kuniri/language/container_data/structured_and_oo/module_namespace_data.rb +3 -1
  49. data/lib/kuniri/language/container_data/structured_and_oo/repetition_data.rb +2 -13
  50. data/lib/kuniri/language/container_data/structured_and_oo/variable_global_data.rb +2 -0
  51. data/lib/kuniri/language/language.rb +37 -11
  52. data/lib/kuniri/language/metadata.rb +29 -0
  53. data/lib/kuniri/language/ruby/aggregation_ruby.rb +37 -0
  54. data/lib/kuniri/language/ruby/attribute_ruby.rb +23 -38
  55. data/lib/kuniri/language/ruby/class_ruby.rb +2 -10
  56. data/lib/kuniri/language/ruby/conditional_ruby.rb +20 -6
  57. data/lib/kuniri/language/ruby/constructor_ruby.rb +5 -7
  58. data/lib/kuniri/language/ruby/end_block_ruby.rb +1 -1
  59. data/lib/kuniri/language/ruby/function_behavior_ruby.rb +1 -9
  60. data/lib/kuniri/language/ruby/global_function_ruby.rb +32 -0
  61. data/lib/kuniri/language/ruby/method_ruby.rb +33 -0
  62. data/lib/kuniri/language/ruby/repetition_ruby.rb +60 -14
  63. data/lib/kuniri/language/ruby/ruby_syntax.rb +76 -49
  64. data/lib/kuniri/parser/output_factory.rb +29 -0
  65. data/lib/kuniri/parser/output_format.rb +134 -0
  66. data/lib/kuniri/parser/parser.rb +3 -7
  67. data/lib/kuniri/parser/xml_builder_engine.rb +94 -0
  68. data/lib/kuniri/parser/xml_output_format.rb +143 -0
  69. data/lib/kuniri/state_machine/OO_structured_fsm/aggregation_state.rb +45 -0
  70. data/lib/kuniri/state_machine/OO_structured_fsm/attribute_state.rb +0 -1
  71. data/lib/kuniri/state_machine/OO_structured_fsm/basic_structure_state.rb +182 -0
  72. data/lib/kuniri/state_machine/OO_structured_fsm/class_state.rb +12 -3
  73. data/lib/kuniri/state_machine/OO_structured_fsm/conditional_state.rb +11 -68
  74. data/lib/kuniri/state_machine/OO_structured_fsm/constructor_state.rb +7 -52
  75. data/lib/kuniri/state_machine/OO_structured_fsm/function_behaviour_state.rb +86 -0
  76. data/lib/kuniri/state_machine/OO_structured_fsm/include_state.rb +2 -3
  77. data/lib/kuniri/state_machine/OO_structured_fsm/method_state.rb +8 -50
  78. data/lib/kuniri/state_machine/OO_structured_fsm/oo_structured_state.rb +6 -1
  79. data/lib/kuniri/state_machine/OO_structured_fsm/repetition_state.rb +10 -59
  80. data/lib/kuniri/state_machine/OO_structured_fsm/token_state_machine.rb +4 -0
  81. data/lib/kuniri/state_machine/OO_structured_fsm/variable_state.rb +0 -1
  82. data/lib/kuniri/version.rb +1 -1
  83. data/other/analyseFile.asta +0 -0
  84. data/spec/core/kuniri_spec.rb +2 -1
  85. data/spec/core/setting_spec.rb +35 -61
  86. data/spec/language/abstract_container/aggregation_spec.rb +13 -0
  87. data/spec/language/abstract_container/extern_requirement_spec.rb +13 -0
  88. data/spec/language/container_data/structured_and_oo/aggregation_data_spec.rb +29 -0
  89. data/spec/language/container_data/structured_and_oo/attribute_data_spec.rb +9 -2
  90. data/spec/language/container_data/structured_and_oo/class_data_spec.rb +1 -46
  91. data/spec/language/container_data/structured_and_oo/constructor_data_spec.rb +32 -2
  92. data/spec/language/container_data/structured_and_oo/extern_requirement_data_spec.rb +31 -7
  93. data/spec/language/container_data/structured_and_oo/{file_element_spec.rb → file_element_data_spec.rb} +21 -5
  94. data/spec/language/container_data/structured_and_oo/function_abstract_spec.rb +213 -0
  95. data/spec/language/container_data/structured_and_oo/function_data_spec.rb +31 -2
  96. data/spec/language/container_data/structured_and_oo/manager_basic_structure_data_spec.rb +150 -0
  97. data/spec/language/container_data/structured_and_oo/method_data_spec.rb +80 -0
  98. data/spec/language/container_data/structured_and_oo/module_namespace_spec.rb +7 -1
  99. data/spec/language/container_data/structured_and_oo/variable_global_data_spec.rb +9 -0
  100. data/spec/language/language_factory_spec.rb +1 -1
  101. data/spec/language/language_spec.rb +46 -9
  102. data/spec/language/ruby/aggregation_ruby_spec.rb +80 -0
  103. data/spec/language/ruby/class_ruby_spec.rb +66 -6
  104. data/spec/language/ruby/constructor_ruby_spec.rb +1 -1
  105. data/spec/language/ruby/end_block_ruby_spec.rb +11 -0
  106. data/spec/language/ruby/extern_requirement_ruby_spec.rb +59 -0
  107. data/spec/language/ruby/function_behavior_ruby_spec.rb +54 -2
  108. data/spec/language/ruby/global_test/.kuniri.yml +4 -0
  109. data/spec/language/ruby/global_test/complete_class_ruby_spec.rb +161 -0
  110. data/spec/language/ruby/global_test/conditional/.kuniri.yml +4 -0
  111. data/spec/language/ruby/global_test/conditional/.kuniri1.yml +4 -0
  112. data/spec/language/ruby/global_test/conditional/.kuniri2.yml +4 -0
  113. data/spec/language/ruby/global_test/conditional/.kuniri3.yml +4 -0
  114. data/spec/language/ruby/global_test/conditional/.kuniri4.yml +4 -0
  115. data/spec/language/ruby/global_test/conditional/.kuniri5.yml +4 -0
  116. data/spec/language/ruby/global_test/conditional/.kuniri6.yml +4 -0
  117. data/spec/language/ruby/global_test/conditional/a_lot_of_conditionals_spec.rb +92 -0
  118. data/spec/language/ruby/global_test/conditional/constructor_very_mix_conditional_spec.rb +105 -0
  119. data/spec/language/ruby/global_test/conditional/function_with_conditional_spec.rb +94 -0
  120. data/spec/language/ruby/global_test/conditional/function_with_nested_conditional_spec.rb +56 -0
  121. data/spec/language/ruby/global_test/conditional/method_very_mix_conditional_spec.rb +109 -0
  122. data/spec/language/ruby/global_test/conditional/very_deep_conditional_structure_spec.rb +61 -0
  123. data/spec/language/ruby/global_test/conditional/very_mix_conditional_spec.rb +105 -0
  124. data/spec/language/ruby/global_test/conditionalAndRepetition/.kuniri.yml +4 -0
  125. data/spec/language/ruby/global_test/conditionalAndRepetition/mix_conditional_repetition_spec.rb +57 -0
  126. data/spec/language/ruby/global_test/repetition/.kuniri.yml +4 -0
  127. data/spec/language/ruby/global_test/repetition/.kuniri2.yml +4 -0
  128. data/spec/language/ruby/global_test/repetition/.kuniri3.yml +4 -0
  129. data/spec/language/ruby/global_test/repetition/.kuniri4.yml +4 -0
  130. data/spec/language/ruby/global_test/repetition/.kuniri5.yml +4 -0
  131. data/spec/language/ruby/global_test/repetition/.kuniri6.yml +4 -0
  132. data/spec/language/ruby/global_test/repetition/.kuniri7.yml +4 -0
  133. data/spec/language/ruby/global_test/repetition/.kuniri8.yml +4 -0
  134. data/spec/language/ruby/global_test/repetition/complete_class_integrity.rb +41 -0
  135. data/spec/language/ruby/global_test/repetition/complete_class_until_loop_spec.rb +42 -0
  136. data/spec/language/ruby/global_test/repetition/complete_class_while_loop_spec.rb +41 -0
  137. data/spec/language/ruby/global_test/repetition/complete_class_with_repetition_spec.rb +42 -0
  138. data/spec/language/ruby/global_test/repetition/constructor_with_mix_repetition_spec.rb +57 -0
  139. data/spec/language/ruby/global_test/repetition/method_with_mix_repetition_spec.rb +59 -0
  140. data/spec/language/ruby/global_test/repetition/very_mix_repetition_spec.rb +61 -0
  141. data/spec/language/ruby/global_test/repetition/very_nested_repetition_spec.rb +65 -0
  142. data/spec/language/ruby/method_ruby_spec.rb +52 -0
  143. data/spec/language/ruby/repetition_ruby_spec.rb +175 -8
  144. data/spec/language/ruby/ruby_syntax_spec.rb +213 -84
  145. data/spec/parser/output_factory_spec.rb +32 -0
  146. data/spec/parser/output_format_spec.rb +83 -0
  147. data/spec/parser/parser_spec.rb +7 -0
  148. data/spec/parser/xmlSchemaValidate/.kuniri1.yml +3 -0
  149. data/spec/parser/xmlSchemaValidate/.kuniri2.yml +3 -0
  150. data/spec/parser/xmlSchemaValidate/.kuniri3.yml +3 -0
  151. data/spec/parser/xmlSchemaValidate/class_data.xsd +99 -0
  152. data/spec/parser/xmlSchemaValidate/fullCodeTwo.xsd +119 -0
  153. data/spec/parser/xmlSchemaValidate/fullCodeWithComments.xsd +146 -0
  154. data/spec/parser/xmlSchemaValidate/simpleFunction.xsd +25 -0
  155. data/spec/parser/xmlSchemaValidate/validate_xml_spec.rb +52 -0
  156. data/spec/parser/xml_builder_engine_spec.rb +258 -0
  157. data/spec/parser/xml_output_format_spec.rb +274 -0
  158. data/spec/samples/rubySyntaxParts/aggregation/classAggregation.rb +37 -0
  159. data/spec/samples/rubySyntaxParts/aggregation/constructorAggregation.rb +36 -0
  160. data/spec/samples/rubySyntaxParts/aggregation/methodAggregation.rb +36 -0
  161. data/spec/samples/rubySyntaxParts/aggregation/multipleAggregation.rb +59 -0
  162. data/spec/samples/rubySyntaxParts/comment/simple_multiple_line_comment_class.rb +7 -0
  163. data/spec/samples/rubySyntaxParts/comment/simple_single_line_comment_class.rb +2 -1
  164. data/spec/samples/rubySyntaxParts/conditionalStatment/aLotOfConditionals.rb +42 -0
  165. data/spec/samples/rubySyntaxParts/conditionalStatment/commonCasesOfConditionals.rb +47 -0
  166. data/spec/samples/rubySyntaxParts/conditionalStatment/constructorConditional.rb +1 -1
  167. data/spec/samples/rubySyntaxParts/conditionalStatment/constructorMixConditional.rb +41 -0
  168. data/spec/samples/rubySyntaxParts/conditionalStatment/methodMixConditional.rb +41 -0
  169. data/spec/samples/rubySyntaxParts/conditionalStatment/mixConditionalWithRepetition.rb +20 -0
  170. data/spec/samples/rubySyntaxParts/conditionalStatment/nestedConditional.rb +61 -0
  171. data/spec/samples/rubySyntaxParts/conditionalStatment/veryDeepConditionalStructure.rb +48 -0
  172. data/spec/samples/rubySyntaxParts/conditionalStatment/veryMixConditional.rb +37 -0
  173. data/spec/samples/rubySyntaxParts/fullCode/fullCodeTwo.rb +56 -0
  174. data/spec/samples/rubySyntaxParts/fullCode/fullCodeWithComments.rb +64 -0
  175. data/spec/samples/rubySyntaxParts/fullCode/simpleFullCode.rb +9 -1
  176. data/spec/samples/rubySyntaxParts/method/simpleMethod.rb +2 -0
  177. data/spec/samples/rubySyntaxParts/repetition/beginWithWhileLoopInClass.rb +10 -0
  178. data/spec/samples/rubySyntaxParts/repetition/constructorWithMixRepetition.rb +22 -0
  179. data/spec/samples/rubySyntaxParts/repetition/forLoopInClass.rb +7 -0
  180. data/spec/samples/rubySyntaxParts/repetition/methodWithMixRepetition.rb +19 -0
  181. data/spec/samples/rubySyntaxParts/repetition/mixConditionalRepetition.rb +17 -0
  182. data/spec/samples/rubySyntaxParts/repetition/untilLoopInClass.rb +16 -0
  183. data/spec/samples/rubySyntaxParts/repetition/veryMixRepetition.rb +28 -0
  184. data/spec/samples/rubySyntaxParts/repetition/veryNestedRepetition.rb +17 -0
  185. data/spec/samples/rubySyntaxParts/repetition/whileLoopInClass.rb +12 -0
  186. data/spec/state_machine/OO_structured_fsm/aggregation_state_spec.rb +67 -0
  187. data/spec/state_machine/OO_structured_fsm/class_state_spec.rb +15 -0
  188. data/spec/state_machine/OO_structured_fsm/conditional_state_spec.rb +64 -0
  189. data/spec/state_machine/OO_structured_fsm/include_state_spec.rb +3 -3
  190. data/spec/state_machine/OO_structured_fsm/method_state_spec.rb +18 -0
  191. data/spec/state_machine/OO_structured_fsm/repetition_state_spec.rb +27 -0
  192. metadata +195 -28
  193. data/lib/kuniri/core/configuration/monitor_available.rb +0 -13
  194. data/lib/kuniri/language/abstract_container/structured_and_oo/constructor.rb +0 -52
  195. data/lib/kuniri/parser/parser_xml.rb +0 -128
  196. data/spec/language/abstract_container/constructor_spec.rb +0 -13
  197. data/spec/util/html_logger_spec.rb +0 -31
  198. data/spec/util/logger_spec.rb +0 -20
  199. data/spec/util/txt_logger_spec.rb +0 -31
@@ -15,7 +15,6 @@ module StateMachine
15
15
 
16
16
  # @see OOStructuredState
17
17
  def handle_line(pLine)
18
- # TODO: YOU HAVE TO HANDLER THE CASE OF SELF REFERENCE
19
18
  end
20
19
 
21
20
  # @see OOStructuredState
@@ -0,0 +1,182 @@
1
+ require_relative 'oo_structured_state'
2
+ require_relative '../../language/abstract_container/structured_and_oo/global_tokens.rb'
3
+
4
+ module StateMachine
5
+
6
+ module OOStructuredFSM
7
+
8
+ # Class responsible for handling Basic structures state. Understand basic
9
+ # basic structure by conditional and repetitions.
10
+ class BasicStructureState < OOStructuredState
11
+
12
+ @language
13
+
14
+ def initialize(pLanguage)
15
+ @language = pLanguage
16
+ @language.resetNested
17
+ @whoAmI = "the fu@!+ nobody"
18
+ end
19
+
20
+ def handle_line(pLine)
21
+ conditional = @language.conditionalHandler.get_conditional(pLine)
22
+ repetition = @language.repetitionHandler.get_repetition(pLine)
23
+ if conditional
24
+ if isNestedStructure?(conditional.type)
25
+ conditional_capture
26
+ end
27
+ elsif repetition
28
+ if isNestedStructure?(repetition.type)
29
+ repetition_capture
30
+ end
31
+ # aggregation
32
+ end
33
+ end
34
+
35
+ # @see OOStructuredState
36
+ def method_capture
37
+ @language.rewind_state
38
+ end
39
+
40
+ # @see OOStructuredState
41
+ def constructor_capture
42
+ @language.rewind_state
43
+ end
44
+
45
+ # @see OOStructuredState
46
+ def conditional_capture
47
+ @language.moreNested
48
+ @language.set_state(@language.conditionalState)
49
+ end
50
+
51
+ # @see OOStructuredState
52
+ def repetition_capture
53
+ @language.moreNested
54
+ @language.set_state(@language.repetitionState)
55
+ end
56
+
57
+ # @see OOStructuredState
58
+ def function_capture
59
+ @language.rewind_state
60
+ end
61
+
62
+ # @see OOStructuredState
63
+ def aggregation_capture
64
+ @language.set_state(@language.aggregationState)
65
+ end
66
+
67
+ # @see OOStructuredState
68
+ def execute(pElementFile, pLine)
69
+ flag = @language.flagFunctionBehaviour
70
+ classIndex = pElementFile.classes.length - 1 # We want the index
71
+
72
+ addBasicStructure(pLine, flag, classIndex, pElementFile)
73
+
74
+ #if (@language.endBlockHandler.has_end_of_block?(pLine) || singleLine)
75
+ if (@language.endBlockHandler.has_end_of_block?(pLine))
76
+ updateLevel(flag, pElementFile, classIndex)
77
+ end
78
+ return pElementFile
79
+ end
80
+
81
+ protected
82
+
83
+ @whoAmI # !@param whoAmI Used for differentiated child class.
84
+
85
+ # Add conditional or repetition. It is delegate to child class.
86
+ # @param pLine Line to analyse
87
+ # @param pFlag Flag for identify global function, constructor or method
88
+ # @param pClassIndex Element index to add
89
+ # @param pElementFile Element with all data
90
+ def addBasicStructure(pLine, pFlag, pClassIndex, pElementFile)
91
+ raise NotImplementedError
92
+ end
93
+
94
+ # If is a structure which can be nested. It is delegate.
95
+ # @param pType Constant with type description.
96
+ def isNestedStructure?(pType)
97
+ if pType == Languages::WHILE_LABEL ||
98
+ pType == Languages::FOR_LABEL ||
99
+ pType == Languages::DO_WHILE_LABEL ||
100
+ pType == Languages::UNTIL_LABEL ||
101
+ pType == Languages::IF_LABEL ||
102
+ pType == Languages::CASE_LABEL ||
103
+ pType == Languages::UNLESS_LABEL
104
+ return true
105
+ end
106
+ return false
107
+
108
+ end
109
+
110
+ # Add element to correct place, based on the state machine position.
111
+ # @pElement Specific element, e.g, conditional or repetition object.
112
+ # @pElementFile All data.
113
+ # @pFlag Flag with current position in the state machine.
114
+ # @pClassIndex Index of class.
115
+ def addToCorrectElement(pElement, pElementFile, pFlag, pClassIndex)
116
+ elementType = pElement.type
117
+ stringToEval = "classes[#{pClassIndex}]."
118
+ case pFlag
119
+ when StateMachine::GLOBAL_FUNCTION_STATE
120
+ dynamicallyAdd(pElementFile, pElement,
121
+ elementType, "global_functions")
122
+ when StateMachine::METHOD_STATE
123
+ dynamicallyAdd(pElementFile, pElement,
124
+ elementType, stringToEval + "methods")
125
+ when StateMachine::CONSTRUCTOR_STATE
126
+ dynamicallyAdd(pElementFile, pElement,
127
+ elementType, stringToEval + "constructors")
128
+ end
129
+ end
130
+
131
+ # Update nested level in conditional or repetition.
132
+ # @param pFlag
133
+ # @param pElementFile
134
+ # @param pClassIndex
135
+ def updateLevel(pFlag, pElementFile, pClassIndex)
136
+ case pFlag
137
+ when StateMachine::GLOBAL_FUNCTION_STATE
138
+ dynamicLevelUpdate(pElementFile, "global_functions")
139
+ when StateMachine::METHOD_STATE
140
+ stringMethod = "classes[#{pClassIndex}].methods"
141
+ dynamicLevelUpdate(pElementFile, stringMethod)
142
+ when StateMachine::CONSTRUCTOR_STATE
143
+ stringMethod = "classes[#{pClassIndex}].constructors"
144
+ dynamicLevelUpdate(pElementFile, stringMethod)
145
+ end
146
+ @language.rewind_state
147
+ @language.lessNested
148
+ end
149
+
150
+ # Dynamically add based on child class.
151
+ # @param pElementFile All data inside element.
152
+ # @param pToAdd Element to add.
153
+ # @param pType Type of thhe element.
154
+ # @param pElement Element description.
155
+ def dynamicallyAdd(pElementFile, pToAdd, pType, pElement)
156
+ classIndex = pElementFile.classes.length - 1 # We want the index
157
+ index = eval("pElementFile.#{pElement}.length - 1")
158
+ if (@language.isNested? && isNestedStructure?(pType))
159
+ eval("pElementFile.#{pElement}[index]." +
160
+ "managerCondAndLoop.down_level")
161
+ end
162
+ eval("pElementFile.#{pElement}[index].add_#{@whoAmI}(pToAdd)")
163
+ end
164
+
165
+ # Update level of conditional or repetition
166
+ # @param pElementFile Element with all data.
167
+ # @param pElement String name of the element.
168
+ def dynamicLevelUpdate(pElementFile, pElement)
169
+ index = eval("pElementFile.#{pElement}.length - 1")
170
+ if @language.isNested?
171
+ eval("pElementFile.#{pElement}[index].managerCondAndLoop.up_level")
172
+ end
173
+ end
174
+
175
+ # End class
176
+ end
177
+
178
+ # End OOStructuredFSM
179
+ end
180
+
181
+ # End StateMachine
182
+ end
@@ -15,7 +15,9 @@ module StateMachine
15
15
 
16
16
  # @see OOStructuredState
17
17
  def handle_line(pLine)
18
- if @language.attributeHandler.get_attribute(pLine)
18
+ if @language.aggregationHandler.get_aggregation(pLine)
19
+ aggregation_capture
20
+ elsif @language.attributeHandler.get_attribute(pLine)
19
21
  attribute_capture
20
22
  elsif @language.constructorHandler.get_constructor(pLine)
21
23
  constructor_capture
@@ -23,6 +25,8 @@ module StateMachine
23
25
  method_capture
24
26
  elsif @language.moduleHandler.get_module(pLine)
25
27
  module_capture
28
+ elsif @language.aggregationHandler.get_aggregation(pLine)
29
+ aggregation_capture
26
30
  elsif @language.commentHandler.is_single_line_comment?(pLine) ||
27
31
  @language.commentHandler.is_multiple_line_comment?(pLine)
28
32
  comment_capture
@@ -59,6 +63,10 @@ module StateMachine
59
63
  @language.set_state(@language.commentState)
60
64
  end
61
65
 
66
+ def aggregation_capture
67
+ @language.set_state(@language.aggregationState)
68
+ end
69
+
62
70
  # @see OOStructuredState
63
71
  def execute(pElementFile, pLine)
64
72
  classElement = @language.classHandler.get_class(pLine)
@@ -67,8 +75,9 @@ module StateMachine
67
75
  classElement.comments = @language.string_comment_to_transfer
68
76
  @language.string_comment_to_transfer = ""
69
77
  pElementFile.add_class(classElement)
78
+ @language.metadata.allClasses.push(classElement)
70
79
  end
71
-
80
+
72
81
  if @language.endBlockHandler.has_end_of_block?(pLine)
73
82
  previous = @language.previousState.last
74
83
 
@@ -90,5 +99,5 @@ module StateMachine
90
99
  # End OOStructuredFSM
91
100
  end
92
101
 
93
- #
102
+ # End module
94
103
  end
@@ -1,87 +1,30 @@
1
- require_relative 'oo_structured_state'
1
+ require_relative 'basic_structure_state'
2
+ require_relative '../../language/abstract_container/structured_and_oo/global_tokens.rb'
2
3
 
3
4
  module StateMachine
4
5
 
5
6
  module OOStructuredFSM
6
7
 
7
- # Class responsible for handling conditional state.
8
- class ConditionalState < OOStructuredState
8
+ # Class responsible for handling Conditional state.
9
+ class ConditionalState < BasicStructureState
9
10
 
10
11
  @language
11
12
 
12
13
  def initialize(pLanguage)
13
14
  @language = pLanguage
15
+ @whoAmI = "conditional"
14
16
  end
15
17
 
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
18
+ protected
51
19
 
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
20
+ # @see basic_structure_state
21
+ def addBasicStructure(pLine, pFlag, pClassIndex, pElementFile)
22
+ conditional = @language.conditionalHandler.get_conditional(pLine)
23
+ if (conditional)
24
+ addToCorrectElement(conditional, pElementFile, pFlag, pClassIndex)
70
25
  end
71
26
  end
72
27
 
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
28
  # End class
86
29
  end
87
30
 
@@ -1,66 +1,21 @@
1
1
  require_relative 'oo_structured_state'
2
+ require_relative 'function_behaviour_state'
2
3
 
3
4
  module StateMachine
4
5
 
5
6
  module OOStructuredFSM
6
7
 
7
8
  # Class responsible for handling constructor state.
8
- class ConstructorState < OOStructuredState
9
-
10
- @language
9
+ class ConstructorState < FunctionBehaviourState
11
10
 
12
11
  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)
12
+ super(
13
+ pLanguage,
14
+ flagState: StateMachine::CONSTRUCTOR_STATE,
15
+ functionId: StateMachine::CONSTRUCTOR_LABEL
16
+ )
36
17
  end
37
18
 
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
19
  # End class
65
20
  end
66
21
 
@@ -0,0 +1,86 @@
1
+ require_relative 'oo_structured_state'
2
+ require_relative 'token_state_machine'
3
+
4
+ module StateMachine
5
+
6
+ module OOStructuredFSM
7
+
8
+ # Class responsible for handling Method and constructor state.
9
+ class FunctionBehaviourState < OOStructuredState
10
+
11
+ @language
12
+ @flagState
13
+ @functionIdentifier
14
+
15
+ # Constructor responsible for setup the basic configuration.
16
+ # @param pLanguage Reference to language object.
17
+ # @param pParams Dictionary with all element data.
18
+ def initialize(pLanguage, pParams = {})
19
+ @language = pLanguage
20
+ @flagState = pParams[:flagState] || StateMachine::METHOD_STATE
21
+ @functionIdentifier = pParams[:functionId] || MethodState::METHOD_LABEL
22
+ end
23
+
24
+ # @see OOStructuredState
25
+ def handle_line(pLine)
26
+ if @language.conditionalHandler.get_conditional(pLine)
27
+ conditional_capture
28
+ elsif @language.repetitionHandler.get_repetition(pLine)
29
+ repetition_capture
30
+ elsif @language.aggregationHandler.get_aggregation(pLine)
31
+ aggregation_capture
32
+ else
33
+ return
34
+ end
35
+ end
36
+
37
+ # @see OOStructuredState
38
+ def class_capture
39
+ @language.rewind_state
40
+ end
41
+
42
+ # @see OOStructuredState
43
+ def conditional_capture
44
+ @language.flagFunctionBehaviour = @flagState
45
+ @language.set_state(@language.conditionalState)
46
+ end
47
+
48
+ # @see OOStructuredState
49
+ def repetition_capture
50
+ @language.flagFunctionBehaviour = @flagState
51
+ @language.set_state(@language.repetitionState)
52
+ end
53
+
54
+ # @see OOStructuredState
55
+ def aggregation_capture
56
+ @language.set_state(@language.aggregationState)
57
+ end
58
+
59
+ # @see OOStructuredState
60
+ def execute(pElementFile, pLine)
61
+ functionElement = @language.send("#{@functionIdentifier}Handler")
62
+ .send("get_#{@functionIdentifier}", pLine)
63
+
64
+ if (functionElement)
65
+ lastIndex = pElementFile.classes.length - 1 # We want the index
66
+ functionElement.comments = @language.string_comment_to_transfer
67
+ @language.string_comment_to_transfer = ""
68
+ pElementFile.classes[lastIndex].send("add_#{@functionIdentifier}",
69
+ functionElement)
70
+ end
71
+
72
+ if (@language.endBlockHandler.has_end_of_block?(pLine))
73
+ @language.rewind_state
74
+ end
75
+
76
+ return pElementFile
77
+ end
78
+
79
+ # End class
80
+ end
81
+
82
+ # End OOStructuredFSM
83
+ end
84
+
85
+ # End StateMachine
86
+ end