EFL 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +36 -0
- data/lib/EFL.rb +494 -0
- data/lib/EFL_array.rb +20 -0
- data/lib/EFL_errors.rb +48 -0
- data/lib/EFL_hash.rb +18 -0
- data/lib/EFL_production.rb +49 -0
- data/lib/EFL_regexp.rb +112 -0
- data/lib/EFL_regexp_generator.rb +70 -0
- data/lib/EFL_substitution.rb +221 -0
- data/lib/EFL_syntactic_sugar.rb +67 -0
- data/lib/Hash Doc.doc +0 -0
- data/lib/Limitaciones.txt +3 -0
- data/lib/doc/classes/Generator.html +634 -0
- data/lib/doc/classes/Generator.src/M000008.html +18 -0
- data/lib/doc/classes/Generator.src/M000009.html +18 -0
- data/lib/doc/classes/Generator.src/M000010.html +18 -0
- data/lib/doc/classes/Generator.src/M000011.html +18 -0
- data/lib/doc/classes/Generator.src/M000012.html +18 -0
- data/lib/doc/classes/Generator.src/M000013.html +18 -0
- data/lib/doc/classes/Generator.src/M000014.html +18 -0
- data/lib/doc/classes/Generator.src/M000015.html +18 -0
- data/lib/doc/classes/Generator.src/M000016.html +28 -0
- data/lib/doc/classes/Generator.src/M000017.html +24 -0
- data/lib/doc/classes/Generator.src/M000018.html +157 -0
- data/lib/doc/classes/Generator.src/M000019.html +25 -0
- data/lib/doc/classes/Generator.src/M000020.html +30 -0
- data/lib/doc/classes/Generator.src/M000021.html +32 -0
- data/lib/doc/classes/Generator.src/M000022.html +22 -0
- data/lib/doc/classes/Generator.src/M000023.html +18 -0
- data/lib/doc/classes/Generator.src/M000024.html +27 -0
- data/lib/doc/classes/Generator.src/M000025.html +22 -0
- data/lib/doc/classes/Generator.src/M000026.html +18 -0
- data/lib/doc/classes/Generator.src/M000027.html +27 -0
- data/lib/doc/classes/Regexp.html +271 -0
- data/lib/doc/classes/Regexp.src/M000028.html +37 -0
- data/lib/doc/classes/Regexp.src/M000029.html +29 -0
- data/lib/doc/classes/Regexp.src/M000030.html +32 -0
- data/lib/doc/created.rid +1 -0
- data/lib/doc/files/EFL_rb.html +147 -0
- data/lib/doc/files/EFL_regexp_generator_rb.html +242 -0
- data/lib/doc/files/EFL_regexp_generator_rb.src/M000003.html +27 -0
- data/lib/doc/files/EFL_regexp_generator_rb.src/M000004.html +27 -0
- data/lib/doc/files/EFL_regexp_generator_rb.src/M000005.html +19 -0
- data/lib/doc/files/EFL_regexp_generator_rb.src/M000006.html +20 -0
- data/lib/doc/files/EFL_regexp_generator_rb.src/M000007.html +19 -0
- data/lib/doc/files/EFL_regexp_rb.html +139 -0
- data/lib/doc/files/EFL_syntactic_sugar_rb.html +208 -0
- data/lib/doc/files/EFL_syntactic_sugar_rb.src/M000001.html +29 -0
- data/lib/doc/files/EFL_syntactic_sugar_rb.src/M000002.html +19 -0
- data/lib/doc/fr_class_index.html +28 -0
- data/lib/doc/fr_file_index.html +30 -0
- data/lib/doc/fr_method_index.html +56 -0
- data/lib/doc/index.html +24 -0
- data/tests/Add_Sup_1.rb +223 -0
- data/tests/Add_Sup_1.rb.bak +223 -0
- data/tests/Add_Sup_1_NI.rb +25 -0
- data/tests/Add_Sup_2.rb +142 -0
- data/tests/Add_Sup_2.rb.bak +140 -0
- data/tests/All.rb +2 -0
- data/tests/All_1.rb +7 -0
- data/tests/All_2.rb +7 -0
- data/tests/All_2.rb.bak +5 -0
- data/tests/BeforeAfter.rb +83 -0
- data/tests/Bloques.rb +34 -0
- data/tests/Bloques.rb.bak +34 -0
- data/tests/Complementary.rb +144 -0
- data/tests/ComplementaryZoom.rb +78 -0
- data/tests/Del.rb +126 -0
- data/tests/Dup.rb +55 -0
- data/tests/Dup.rb.bak +54 -0
- data/tests/Error.rb +11 -0
- data/tests/ErrorArgClass.rb +169 -0
- data/tests/ErrorArgClass.rb.bak +158 -0
- data/tests/ErrorCollision.rb +218 -0
- data/tests/ErrorCollision.rb.bak +219 -0
- data/tests/ErrorWithoutDeclaration.rb +60 -0
- data/tests/ErrorWithoutDeclaration.rb.bak +60 -0
- data/tests/Extract.rb +56 -0
- data/tests/ExtractDollar.rb +17 -0
- data/tests/HashTest.rb +54 -0
- data/tests/HashTest.rb.bak +54 -0
- data/tests/Lista Czarnecki/AntiguaInterfaz/List.cpp +75 -0
- data/tests/Lista Czarnecki/AntiguaInterfaz/ListTransformer.rb +69 -0
- data/tests/Lista Czarnecki/AntiguaInterfaz/ListTransformer.rb.bak +100 -0
- data/tests/Lista Czarnecki/AntiguaInterfaz/ejecutame.bat +1 -0
- data/tests/Lista Czarnecki/AntiguaInterfaz/outDir/MyClassList.cpp +75 -0
- data/tests/Lista Czarnecki/AntiguaInterfaz/runme.bat +1 -0
- data/tests/Lista Czarnecki/AntiguaInterfaz/specification1.txt +5 -0
- data/tests/Lista Czarnecki/AntiguaInterfaz/specification2.txt +3 -0
- data/tests/Lista Czarnecki/AntiguaInterfaz/specification3.txt +5 -0
- data/tests/Lista Czarnecki/NuevaInterfaz/List.cpp +75 -0
- data/tests/Lista Czarnecki/NuevaInterfaz/ListTransformer.rb +58 -0
- data/tests/Lista Czarnecki/NuevaInterfaz/ListTransformer.rb.bak +57 -0
- data/tests/Lista Czarnecki/NuevaInterfaz/ejecutame.bat +1 -0
- data/tests/Lista Czarnecki/NuevaInterfaz/outDir/MyClassList.cpp +75 -0
- data/tests/Lista Czarnecki/NuevaInterfaz/outDir/NewClassList.cpp +75 -0
- data/tests/Lista Czarnecki/NuevaInterfaz/specification1.txt +5 -0
- data/tests/Lista Czarnecki/NuevaInterfaz/specification1.txt.bak +5 -0
- data/tests/Lista Czarnecki/NuevaInterfaz/specification2.txt +3 -0
- data/tests/Lista Czarnecki/NuevaInterfaz/specification3.txt +5 -0
- data/tests/Minus.rb +89 -0
- data/tests/Plus.rb.bak +48 -0
- data/tests/REVit.rb +84 -0
- data/tests/RenameTest.rb +46 -0
- data/tests/RenameTest.rb.bak +46 -0
- data/tests/SubCrash.rb +26 -0
- data/tests/SubList.rb.bak +43 -0
- data/tests/archAuxiliares/1.txt +328 -0
- data/tests/archAuxiliares/2.txt +328 -0
- data/tests/archAuxiliares/Bloques/s1.txt +328 -0
- data/tests/archAuxiliares/Copia de Matriz.java +19 -0
- data/tests/archAuxiliares/Gen/Tesis_156_1.lgi +10 -0
- data/tests/archAuxiliares/Gen/Tesis_156_2.lgi +10 -0
- data/tests/archAuxiliares/Gen/t01.txt +328 -0
- data/tests/archAuxiliares/Gen/t01.txt.bak +328 -0
- data/tests/archAuxiliares/Gen/t02.txt +328 -0
- data/tests/archAuxiliares/Gen/t02.txt.bak +328 -0
- data/tests/archAuxiliares/Gen/t03.txt +328 -0
- data/tests/archAuxiliares/Gen/t03.txt.bak +328 -0
- data/tests/archAuxiliares/Gen/t04.txt +328 -0
- data/tests/archAuxiliares/Gen/t04.txt.bak +328 -0
- data/tests/archAuxiliares/Gen/t1.txt +328 -0
- data/tests/archAuxiliares/Gen/t1.txt.bak +328 -0
- data/tests/archAuxiliares/Gen/t2.txt +328 -0
- data/tests/archAuxiliares/Gen/t2.txt.bak +328 -0
- data/tests/archAuxiliares/Gen/t5.txt +328 -0
- data/tests/archAuxiliares/Gen/t9.txt +328 -0
- data/tests/archAuxiliares/Gen/t9.txt.bak +328 -0
- data/tests/archAuxiliares/GenTesis_156_1.lgi +10 -0
- data/tests/archAuxiliares/Matriz.java +74 -0
- data/tests/archAuxiliares/MatrizOut.java +74 -0
- data/tests/archAuxiliares/MatrizOut10.java +68 -0
- data/tests/archAuxiliares/MatrizOut11.java +86 -0
- data/tests/archAuxiliares/MatrizOut2.java +74 -0
- data/tests/archAuxiliares/MatrizOut3.java +74 -0
- data/tests/archAuxiliares/MatrizOut4.java +74 -0
- data/tests/archAuxiliares/MatrizOut5.java +21 -0
- data/tests/archAuxiliares/MatrizOut6.java +21 -0
- data/tests/archAuxiliares/MatrizOut7.java +21 -0
- data/tests/archAuxiliares/MatrizOut8.java +16 -0
- data/tests/archAuxiliares/MatrizOut9.java +86 -0
- data/tests/archAuxiliares/MatrizOut_9.java +86 -0
- data/tests/archAuxiliares/Matriz_1.java +74 -0
- data/tests/archAuxiliares/Matriz_10.java +68 -0
- data/tests/archAuxiliares/Matriz_11.java +86 -0
- data/tests/archAuxiliares/Matriz_2.java +74 -0
- data/tests/archAuxiliares/Matriz_3.java +74 -0
- data/tests/archAuxiliares/Matriz_4.java +74 -0
- data/tests/archAuxiliares/Matriz_5.java +21 -0
- data/tests/archAuxiliares/Matriz_6.java +21 -0
- data/tests/archAuxiliares/Matriz_7.java +21 -0
- data/tests/archAuxiliares/Matriz_8.java +16 -0
- data/tests/archAuxiliares/Matriz_9.java +86 -0
- data/tests/archAuxiliares/Matriz_N_1.java +21 -0
- data/tests/archAuxiliares/Matriz_N_2.java +91 -0
- data/tests/archAuxiliares/N1.txt +18 -0
- data/tests/archAuxiliares/N1_EXPECTED.txt +18 -0
- data/tests/archAuxiliares/N1_OUT.txt +18 -0
- data/tests/archAuxiliares/N2_EXPECTED.txt +18 -0
- data/tests/archAuxiliares/N2_OUT.txt +18 -0
- data/tests/archAuxiliares/N3.txt +23 -0
- data/tests/archAuxiliares/N3_EXPECTED.txt +22 -0
- data/tests/archAuxiliares/N3_OUT.txt +22 -0
- data/tests/archAuxiliares/N4_EXPECTED.txt +10 -0
- data/tests/archAuxiliares/N4_OUT.txt +10 -0
- data/tests/archAuxiliares/N5_OUT.txt +18 -0
- data/tests/archAuxiliares/N6_OUT.txt +18 -0
- data/tests/archAuxiliares/PedidorTerceroWS.jsp +142 -0
- data/tests/archAuxiliares/Tesis_156.lgi +7 -0
- data/tests/archAuxiliares/aspectgen.rb +328 -0
- data/tests/archAuxiliares/aspectgenCopy.rb +328 -0
- data/tests/archAuxiliares/extract_dollar.txt +1 -0
- data/tests/archAuxiliares/minus.txt +26 -0
- data/tests/archAuxiliares/minus_expected_1.txt +26 -0
- data/tests/archAuxiliares/minus_expected_2.txt +26 -0
- data/tests/archAuxiliares/minus_out_1.txt +26 -0
- data/tests/archAuxiliares/minus_out_2.txt +26 -0
- data/tests/archAuxiliares/p1.txt +328 -0
- data/tests/archAuxiliares/p2.txt +328 -0
- data/tests/archAuxiliares/s1.txt +328 -0
- data/tests/archAuxiliares/s2.txt +328 -0
- data/tests/archAuxiliares/s3.txt +328 -0
- data/tests/archAuxiliares/s4.txt +328 -0
- data/tests/archAuxiliares/s5.txt +328 -0
- data/tests/archAuxiliares/s7.txt +328 -0
- data/tests/archAuxiliares/s8.txt +328 -0
- data/tests/archAuxiliares/s9.txt +328 -0
- data/tests/archAuxiliares/text.txt +1 -0
- data/tests/delay.rb +33 -0
- data/tests/delay.rb.bak +33 -0
- data/tests/satisfy.rb +44 -0
- data/tests/satisfy.rb.bak +34 -0
- metadata +252 -0
data/lib/EFL_array.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# <em>Copyright � 2007 by Ruben Heradio Gil, Jose Antonio Cerrada Somolinos, Jose Ramon Coz Fernandez and Jose Carlos Lopez Ruiz.</em>
|
2
|
+
# <em>This file is part of <b>EFL-A Ruby implementation of the Exemplar Flexibilization Language.</b></em>
|
3
|
+
# <em>EFL is distributed under the terms of the GNU Lesser General Public License (LGPL).</em>
|
4
|
+
# <em>EFL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.</em>
|
5
|
+
# <em>EFL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.</em>
|
6
|
+
# <em>You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.</em>
|
7
|
+
# <em>Contact Information: Ruben Heradio Gil (rheradio@issi.uned.es). Phone number: 00 34 91 398 8242, Postal address: Dpto. de Ingenier�a de SW y Sistemas Inform�ticos. E.T.S.I. Inform�tica, UNED. C/ Juan del Rosal, 16. 28040 Madrid.</em>
|
8
|
+
|
9
|
+
class Array #:nodoc: all
|
10
|
+
|
11
|
+
def oneOnRest
|
12
|
+
0.upto(length-2) {|i|
|
13
|
+
(i+1).upto(length-1) {|j|
|
14
|
+
return true if yield(at(i), at(j))
|
15
|
+
} #j
|
16
|
+
} #i
|
17
|
+
return false
|
18
|
+
end #oneOnRest
|
19
|
+
|
20
|
+
end #Array
|
data/lib/EFL_errors.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# <em>Copyright � 2007 by Ruben Heradio Gil, Jose Antonio Cerrada Somolinos, Jose Ramon Coz Fernandez and Jose Carlos Lopez Ruiz.</em>
|
2
|
+
# <em>This file is part of <b>EFL-A Ruby implementation of the Exemplar Flexibilization Language.</b></em>
|
3
|
+
# <em>EFL is distributed under the terms of the GNU Lesser General Public License (LGPL).</em>
|
4
|
+
# <em>EFL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.</em>
|
5
|
+
# <em>EFL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.</em>
|
6
|
+
# <em>You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.</em>
|
7
|
+
# <em>Contact Information: Ruben Heradio Gil (rheradio@issi.uned.es). Phone number: 00 34 91 398 8242, Postal address: Dpto. de Ingenier�a de SW y Sistemas Inform�ticos. E.T.S.I. Inform�tica, UNED. C/ Juan del Rosal, 16. 28040 Madrid.</em>
|
8
|
+
|
9
|
+
module Error #:nodoc: all
|
10
|
+
|
11
|
+
def Error.arg_class(*args)
|
12
|
+
code = ""
|
13
|
+
args.each {|a|
|
14
|
+
code += "
|
15
|
+
if !#{a.at(0)}.kind_of?(#{a.at(1)}) && #{a.at(0)}
|
16
|
+
raise 'argument number #{args.index(a) + 1} ' +
|
17
|
+
'should be of class #{a.at(1)}'
|
18
|
+
end"
|
19
|
+
}
|
20
|
+
return code
|
21
|
+
end #Error.arg_class
|
22
|
+
|
23
|
+
def Error.without_declaration(element)
|
24
|
+
# Un elemento de una lista (pasada como parametro) no existe en la tabla hash correspondiente
|
25
|
+
<<-CODE
|
26
|
+
#{element}_list.each {|e|
|
27
|
+
if !@#{element}_hash.include?(e)
|
28
|
+
raise "\#\{e\} needs a prior declaration"
|
29
|
+
end
|
30
|
+
}
|
31
|
+
CODE
|
32
|
+
end #Error.without_declaration
|
33
|
+
|
34
|
+
def Error.collision(receiver)
|
35
|
+
c = {
|
36
|
+
'prod' => [['i_file', 'o_file', 'sub_list'], 'Substitution'],
|
37
|
+
'gen' => [['prod_list'], 'Production'],
|
38
|
+
'add' => [['generator'], 'Generator'],
|
39
|
+
'sup' => [['generator'], 'Generator']
|
40
|
+
}
|
41
|
+
<<-CODE
|
42
|
+
if !#{receiver}?(#{c[receiver].at(0).join(', ')})
|
43
|
+
raise "Collision between #{c[receiver].at(1)}s"
|
44
|
+
end
|
45
|
+
CODE
|
46
|
+
end #Error.collision
|
47
|
+
|
48
|
+
end #Error
|
data/lib/EFL_hash.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# <em>Copyright � 2007 by Ruben Heradio Gil, Jose Antonio Cerrada Somolinos, Jose Ramon Coz Fernandez and Jose Carlos Lopez Ruiz.</em>
|
2
|
+
# <em>This file is part of <b>EFL-A Ruby implementation of the Exemplar Flexibilization Language.</b></em>
|
3
|
+
# <em>EFL is distributed under the terms of the GNU Lesser General Public License (LGPL).</em>
|
4
|
+
# <em>EFL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.</em>
|
5
|
+
# <em>EFL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.</em>
|
6
|
+
# <em>You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.</em>
|
7
|
+
# <em>Contact Information: Ruben Heradio Gil (rheradio@issi.uned.es). Phone number: 00 34 91 398 8242, Postal address: Dpto. de Ingenier�a de SW y Sistemas Inform�ticos. E.T.S.I. Inform�tica, UNED. C/ Juan del Rosal, 16. 28040 Madrid.</em>
|
8
|
+
|
9
|
+
class Hash #:nodoc: all
|
10
|
+
def my_collect
|
11
|
+
result = {}
|
12
|
+
each {|key, value|
|
13
|
+
new_key, new_value = yield(key, value.dup)
|
14
|
+
result[new_key] = new_value
|
15
|
+
}
|
16
|
+
return result
|
17
|
+
end
|
18
|
+
end #Hash
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# <em>Copyright � 2007 by Ruben Heradio Gil, Jose Antonio Cerrada Somolinos, Jose Ramon Coz Fernandez and Jose Carlos Lopez Ruiz.</em>
|
2
|
+
# <em>This file is part of <b>EFL-A Ruby implementation of the Exemplar Flexibilization Language.</b></em>
|
3
|
+
# <em>EFL is distributed under the terms of the GNU Lesser General Public License (LGPL).</em>
|
4
|
+
# <em>EFL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.</em>
|
5
|
+
# <em>EFL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.</em>
|
6
|
+
# <em>You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.</em>
|
7
|
+
# <em>Contact Information: Ruben Heradio Gil (rheradio@issi.uned.es). Phone number: 00 34 91 398 8242, Postal address: Dpto. de Ingenier�a de SW y Sistemas Inform�ticos. E.T.S.I. Inform�tica, UNED. C/ Juan del Rosal, 16. 28040 Madrid.</em>
|
8
|
+
|
9
|
+
class Production #:nodoc: all
|
10
|
+
attr_accessor :i_file, :o_file, :sub_list
|
11
|
+
def initialize(i_file, o_file, sub_list)
|
12
|
+
@i_file = i_file
|
13
|
+
@o_file = o_file
|
14
|
+
@sub_list = sub_list
|
15
|
+
end
|
16
|
+
|
17
|
+
def dup
|
18
|
+
return Production.new(@i_file.dup, @o_file.dup, @sub_list.dup)
|
19
|
+
end
|
20
|
+
|
21
|
+
def crash?(sub_hash, production = nil)
|
22
|
+
return crashSelf?(sub_hash) unless production
|
23
|
+
if @o_file != production.o_file
|
24
|
+
return false
|
25
|
+
else
|
26
|
+
if @i_file != production.i_file
|
27
|
+
return true
|
28
|
+
else
|
29
|
+
return Production.new(@i_file, @o_file,
|
30
|
+
(@sub_list + production.sub_list)).crashSelf?(sub_hash)
|
31
|
+
end #if
|
32
|
+
end #if
|
33
|
+
end #crash?
|
34
|
+
|
35
|
+
#####################################################
|
36
|
+
# <crash? auxiliar method>
|
37
|
+
#####################################################
|
38
|
+
|
39
|
+
def crashSelf?(sub_hash)
|
40
|
+
@sub_list.oneOnRest {|s1, s2|
|
41
|
+
sub_hash[s1].crash?(sub_hash[s2], @i_file)
|
42
|
+
}
|
43
|
+
end #crashSelf?
|
44
|
+
|
45
|
+
#####################################################
|
46
|
+
# </crash? auxiliar method>
|
47
|
+
#####################################################
|
48
|
+
|
49
|
+
end #Production
|
data/lib/EFL_regexp.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
# <em>Copyright � 2007 by Ruben Heradio Gil, Jose Antonio Cerrada Somolinos, Jose Ramon Coz Fernandez and Jose Carlos Lopez Ruiz.</em>
|
2
|
+
# <em>This file is part of <b>EFL-A Ruby implementation of the Exemplar Flexibilization Language.</b></em>
|
3
|
+
# <em>EFL is distributed under the terms of the GNU Lesser General Public License (LGPL).</em>
|
4
|
+
# <em>EFL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.</em>
|
5
|
+
# <em>EFL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.</em>
|
6
|
+
# <em>You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.</em>
|
7
|
+
# <em>Contact Information: Ruben Heradio Gil (rheradio@issi.uned.es). Phone number: 00 34 91 398 8242, Postal address: Dpto. de Ingenier�a de SW y Sistemas Inform�ticos. E.T.S.I. Inform�tica, UNED. C/ Juan del Rosal, 16. 28040 Madrid.</em>
|
8
|
+
#
|
9
|
+
# = Extensions of the Ruby regular expressions
|
10
|
+
#
|
11
|
+
# The next operators are included:
|
12
|
+
# * zoom Regexp#>
|
13
|
+
# * complement Regexp#o
|
14
|
+
# * minus Regexp#-
|
15
|
+
|
16
|
+
class Regexp
|
17
|
+
|
18
|
+
attr_accessor :zoom_list #:nodoc:
|
19
|
+
attr_accessor :minus_list #:nodoc:
|
20
|
+
attr_accessor :complemented #:nodoc:
|
21
|
+
|
22
|
+
|
23
|
+
# Using the "zoom operator", regular expressions can be chained to specify progressively a text pattern.
|
24
|
+
#
|
25
|
+
# For example:
|
26
|
+
# <tt>regular_expression_1 > regular_expression_2 > regular_expression_3 > ... regular_expression_N</tt>
|
27
|
+
#
|
28
|
+
# runs the <tt>regular_expression_2</tt> over the selection made by the <tt>regular_expression_1</tt>,
|
29
|
+
#
|
30
|
+
# the <tt>regular_expression_3</tt> over the selection made by the <tt>regular_expression_2</tt>, etcetera
|
31
|
+
|
32
|
+
def > (zoom_regular_expression)
|
33
|
+
op2 = zoom_regular_expression.dup
|
34
|
+
if !op2.zoom_list then
|
35
|
+
op2.zoom_list = [op2]
|
36
|
+
end
|
37
|
+
|
38
|
+
op1 = self.dup
|
39
|
+
if op1.minus_list && (op1.minus_list !=[]) then #due '-' has major precedence than '>', this error is detected here
|
40
|
+
raise "erroooor minus"
|
41
|
+
end
|
42
|
+
if op1.zoom_list
|
43
|
+
op1.zoom_list = op1.zoom_list + op2.zoom_list
|
44
|
+
else
|
45
|
+
op1.zoom_list = [op1] + op2.zoom_list
|
46
|
+
end
|
47
|
+
|
48
|
+
op1.minus_list = [] unless op1.minus_list
|
49
|
+
op1.zoom_list.each {|e|
|
50
|
+
op1.minus_list = op1.minus_list + e.minus_list unless !e.minus_list
|
51
|
+
}
|
52
|
+
return op1
|
53
|
+
end # >
|
54
|
+
|
55
|
+
|
56
|
+
# Using the "minus operator", regular expressions can be refined by deleting specific patterns.
|
57
|
+
# For example, let suppose we have the text: <tt>text_1, text_2, text_3, text_4</tt>.
|
58
|
+
#
|
59
|
+
# The matching of the regular expression <tt>/text_[0-9]/</tt> is <tt>['text_1', 'text_2', 'text_3', 'text_4']</tt>.
|
60
|
+
#
|
61
|
+
# Applying the <tt>-</tt> operator: <tt>/text_[0-9]/ - /text_1/ - /text_3/</tt>, the matching will be refined to <tt>['text_2', 'text_4']</tt>.
|
62
|
+
#
|
63
|
+
# Note that:
|
64
|
+
# * <tt>re1 - re2</tt> deletes the <tt>re2</tt> matchings in the context of <tt>re1</tt>.
|
65
|
+
# That is, <tt>re_1 > re_2 > ... > re_n - re_minus</tt> it would be equivalent to
|
66
|
+
# <tt>re_1 > re_2 > ... > re_n - (re_1 > re_2 > ... > re_n > re_minus)</tt>
|
67
|
+
# * To avoid inconsistent expressions, on the right side of the <tt>-</tt> operator is not permitted the use of the <tt>></tt> operator.
|
68
|
+
|
69
|
+
def - (minus_regular_expression)
|
70
|
+
op2 = minus_regular_expression.dup
|
71
|
+
if !op2.minus_list then
|
72
|
+
op2.minus_list = [op2]
|
73
|
+
end
|
74
|
+
|
75
|
+
op1 = self.dup
|
76
|
+
if op1.minus_list
|
77
|
+
op1.minus_list = op1.minus_list + op2.minus_list
|
78
|
+
else
|
79
|
+
op1.minus_list = op2.minus_list
|
80
|
+
end
|
81
|
+
return op1
|
82
|
+
end # -
|
83
|
+
|
84
|
+
|
85
|
+
# Complements a regular expression.
|
86
|
+
# For example:
|
87
|
+
# <tt>regular_expression_1.o > regular_expression_2</tt>
|
88
|
+
# matchs <tt>regular_expression_2</tt> outside the text matched by <tt>regular_expression_1</tt>
|
89
|
+
#
|
90
|
+
# Note that:
|
91
|
+
# * <tt>regular_expresion.o.o = regular_expresion</tt>
|
92
|
+
# * <tt>(regular_expression_1 > regular_expression_2 > ... > regular_expression_N).o = regular_expression_1 > regular_expression_2 > ... > regular_expresion_N.o</tt>
|
93
|
+
|
94
|
+
def o
|
95
|
+
result = self.dup
|
96
|
+
if result.zoom_list then
|
97
|
+
if not result.zoom_list.last.complemented then
|
98
|
+
result.zoom_list.last.complemented = true
|
99
|
+
else
|
100
|
+
result.zoom_list.last.complemented = false
|
101
|
+
end
|
102
|
+
else
|
103
|
+
if not result.complemented then
|
104
|
+
result.complemented = true
|
105
|
+
else
|
106
|
+
result.complemented = false
|
107
|
+
end
|
108
|
+
end
|
109
|
+
return result
|
110
|
+
end # o
|
111
|
+
|
112
|
+
end # Regexp
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# <em>Copyright � 2007 by Ruben Heradio Gil, Jose Antonio Cerrada Somolinos, Jose Ramon Coz Fernandez and Jose Carlos Lopez Ruiz.</em>
|
2
|
+
# <em>This file is part of <b>EFL-A Ruby implementation of the Exemplar Flexibilization Language.</b></em>
|
3
|
+
# <em>EFL is distributed under the terms of the GNU Lesser General Public License (LGPL).</em>
|
4
|
+
# <em>EFL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.</em>
|
5
|
+
# <em>EFL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.</em>
|
6
|
+
# <em>You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.</em>
|
7
|
+
# <em>Contact Information: Ruben Heradio Gil (rheradio@issi.uned.es). Phone number: 00 34 91 398 8242, Postal address: Dpto. de Ingenier�a de SW y Sistemas Inform�ticos. E.T.S.I. Inform�tica, UNED. C/ Juan del Rosal, 16. 28040 Madrid.</em>
|
8
|
+
#
|
9
|
+
# = Regular expression generators and facilities
|
10
|
+
|
11
|
+
#Returns a Regular Expression who matches nested symbols.
|
12
|
+
#By default, 10 is the maximum possible nested levels.
|
13
|
+
#
|
14
|
+
#Example:
|
15
|
+
# y = '( 1 + (3 + 9 - (45 + 9) ) ) (89(14))'
|
16
|
+
# y =~ nestedSymbols( '(' , ')' )
|
17
|
+
# puts $&
|
18
|
+
# ------------>
|
19
|
+
# 1 + (3 + 9 - (45 + 9) )
|
20
|
+
def nested_symbols(beginSymbol, endSymbol, levels=10)
|
21
|
+
eval('@level0 = "[' + beginSymbol + ']([^' + beginSymbol + endSymbol + '])*[' + endSymbol + ']"')
|
22
|
+
(1..(levels-2)).reject {|i|
|
23
|
+
eval("@level#{i}" + '= "[' + beginSymbol + ']([^' + beginSymbol + endSymbol +'] | #{@level' + "#{i-1}" + '} )*[' + endSymbol + ']"')
|
24
|
+
}
|
25
|
+
if levels > 1 then
|
26
|
+
eval("@level#{levels-1}" + '= /[' + beginSymbol + ']([^' + beginSymbol + endSymbol +'] | #{@level' + "#{levels-2}" + '} )*[' + endSymbol + ']/mx')
|
27
|
+
eval "return @level#{levels-1}"
|
28
|
+
else
|
29
|
+
eval "return /#{@level0}/mx"
|
30
|
+
end
|
31
|
+
end #nested_symbols
|
32
|
+
|
33
|
+
#Returns a Regular Expression who matches nested symbols.
|
34
|
+
#By default, 10 is the maximum possible nested levels.
|
35
|
+
#
|
36
|
+
#Example:
|
37
|
+
# puts nested_symbol('=', 2)
|
38
|
+
# ------------>
|
39
|
+
# (?mx-i:[=]([^=] | [=]([^=])*[=] )*[=])
|
40
|
+
def nested_symbol(symbol, levels=10)
|
41
|
+
eval('@level0 = "[' + symbol + ']([^' + symbol + '])*[' + symbol + ']"')
|
42
|
+
(1..(levels-2)).reject {|i|
|
43
|
+
eval("@level#{i}" + '= "[' + symbol + ']([^' + symbol +'] | #{@level' + "#{i-1}" + '} )*[' + symbol + ']"')
|
44
|
+
}
|
45
|
+
if levels > 1 then
|
46
|
+
eval("@level#{levels-1}" + '= /[' + symbol + ']([^' + symbol +'] | #{@level' + "#{levels-2}" + '} )*[' + symbol + ']/mx')
|
47
|
+
eval "return @level#{levels-1}"
|
48
|
+
else
|
49
|
+
eval "return /#{@level0}/mx"
|
50
|
+
end
|
51
|
+
end #nested_symbol
|
52
|
+
|
53
|
+
def regexp2string(reg_exp)
|
54
|
+
reg_exp.to_s =~ /:(.*?)[)]$/mx
|
55
|
+
return $1
|
56
|
+
end
|
57
|
+
|
58
|
+
#Returns a Regular Expression who matches nested quotes ("..."..."...").
|
59
|
+
#By default, 10 is the maximum possible nested levels.
|
60
|
+
def nested_quotes(levels=10)
|
61
|
+
nq_regexp = nested_symbol('\"', levels)
|
62
|
+
nq_string = regexp2string(nq_regexp).gsub(/\\/, '')
|
63
|
+
return /#{nq_string}/mx
|
64
|
+
end
|
65
|
+
|
66
|
+
def inside_nested_symbols(beginSymbol, endSymbol, levels=50)
|
67
|
+
quit_begin_and_end_symbols = /[^#{beginSymbol}].*(?=#{endSymbol})/xm
|
68
|
+
return (nested_symbols(beginSymbol, endSymbol, levels) > quit_begin_and_end_symbols)
|
69
|
+
end #nestedSymbols
|
70
|
+
|
@@ -0,0 +1,221 @@
|
|
1
|
+
# <em>Copyright � 2007 by Ruben Heradio Gil, Jose Antonio Cerrada Somolinos, Jose Ramon Coz Fernandez and Jose Carlos Lopez Ruiz.</em>
|
2
|
+
# <em>This file is part of <b>EFL-A Ruby implementation of the Exemplar Flexibilization Language.</b></em>
|
3
|
+
# <em>EFL is distributed under the terms of the GNU Lesser General Public License (LGPL).</em>
|
4
|
+
# <em>EFL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.</em>
|
5
|
+
# <em>EFL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.</em>
|
6
|
+
# <em>You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.</em>
|
7
|
+
# <em>Contact Information: Ruben Heradio Gil (rheradio@issi.uned.es). Phone number: 00 34 91 398 8242, Postal address: Dpto. de Ingenier�a de SW y Sistemas Inform�ticos. E.T.S.I. Inform�tica, UNED. C/ Juan del Rosal, 16. 28040 Madrid.</em>
|
8
|
+
|
9
|
+
class Substitution #:nodoc: all
|
10
|
+
attr_accessor :reg_exp, :text, :scope, :match_hash
|
11
|
+
|
12
|
+
def initialize(reg_exp, text, scope)
|
13
|
+
@reg_exp = reg_exp
|
14
|
+
@text = text
|
15
|
+
@scope = scope
|
16
|
+
@match_hash = {}
|
17
|
+
end
|
18
|
+
|
19
|
+
#####################################################
|
20
|
+
# <matching>
|
21
|
+
#####################################################
|
22
|
+
|
23
|
+
#####################################################
|
24
|
+
# <complemented regular expressions matching>
|
25
|
+
#####################################################
|
26
|
+
|
27
|
+
def local_o(str, array)
|
28
|
+
if array == [] then
|
29
|
+
return [ [0, str.length-1] ]
|
30
|
+
else
|
31
|
+
if array[0][0] == 0 then
|
32
|
+
array_complemented = []
|
33
|
+
else
|
34
|
+
array_complemented = [ [0, array[0][0]-1] ]
|
35
|
+
end
|
36
|
+
array_complemented << [array[0][1]+1, str.length-1]
|
37
|
+
return array_complemented
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def global_o(str, array)
|
42
|
+
if array == [] then
|
43
|
+
return [ [0, str.length-1] ]
|
44
|
+
else
|
45
|
+
if array[0][0] == 0 then
|
46
|
+
array_complemented = []
|
47
|
+
else
|
48
|
+
array_complemented = [ [0, array[0][0]-1] ]
|
49
|
+
end
|
50
|
+
i = -1
|
51
|
+
for i in 0..array.length-2
|
52
|
+
array_complemented << [array[i][1]+1, array[i+1][0]-1]
|
53
|
+
end
|
54
|
+
array_complemented << [array[i+1][1]+1, str.length-1]
|
55
|
+
return array_complemented
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
#####################################################
|
60
|
+
# </complemented regular expressions matching>
|
61
|
+
#####################################################
|
62
|
+
|
63
|
+
def match_pos(str, reg_exp, scope)
|
64
|
+
pos =[]
|
65
|
+
aux_str = str.dup
|
66
|
+
while aux_str != nil
|
67
|
+
m = reg_exp.match(aux_str)
|
68
|
+
if m
|
69
|
+
range = m.offset(0)
|
70
|
+
range[1] = range[1] - 1
|
71
|
+
pos << range.dup
|
72
|
+
if pos.length > 1
|
73
|
+
pos[pos.length - 1][0] = pos[pos.length-2][1] +
|
74
|
+
pos[pos.length - 1][0] + 1
|
75
|
+
pos[pos.length - 1][1] = pos[pos.length-2][1] +
|
76
|
+
pos[pos.length - 1][1] + 1
|
77
|
+
end
|
78
|
+
aux_str = aux_str[range[1] + 1, aux_str.length-1]
|
79
|
+
else
|
80
|
+
aux_str = nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
if reg_exp.complemented then
|
84
|
+
if /local/ =~ scope then
|
85
|
+
pos = local_o(str, pos)
|
86
|
+
else #/global/ =~ scope
|
87
|
+
pos = global_o(str, pos)
|
88
|
+
end
|
89
|
+
else
|
90
|
+
return pos
|
91
|
+
end
|
92
|
+
end #match_pos
|
93
|
+
|
94
|
+
def format_array(array)
|
95
|
+
a1 = array.dup
|
96
|
+
a1.flatten!
|
97
|
+
i = 0
|
98
|
+
a2 = []
|
99
|
+
while i<a1.length
|
100
|
+
a2 << [a1[i], a1[i+1]]
|
101
|
+
i += 2
|
102
|
+
end
|
103
|
+
return a2
|
104
|
+
end
|
105
|
+
|
106
|
+
def get_match_pos(str, reg_exp, scope)
|
107
|
+
|
108
|
+
############################
|
109
|
+
# zoom matching
|
110
|
+
############################
|
111
|
+
reg_exp.zoom_list = [reg_exp.dup] unless reg_exp.zoom_list
|
112
|
+
pos1 = match_pos(str, reg_exp.zoom_list[0], scope)
|
113
|
+
pos2, pos3 = [], []
|
114
|
+
i = 1
|
115
|
+
while i<reg_exp.zoom_list.length
|
116
|
+
j = 0
|
117
|
+
pos1.each {|aux|
|
118
|
+
pos2 = match_pos(str[aux[0], aux[1]-aux[0]+1], reg_exp.zoom_list[i], scope)
|
119
|
+
pos2.map! {|e|
|
120
|
+
e[0] = e[0] + pos1[j][0]
|
121
|
+
e[1] = e[1] + pos1[j][0]
|
122
|
+
e
|
123
|
+
}
|
124
|
+
pos3 << pos2.dup
|
125
|
+
j += 1
|
126
|
+
}
|
127
|
+
pos1 = format_array(pos3)
|
128
|
+
pos3 = []
|
129
|
+
i += 1
|
130
|
+
end #while
|
131
|
+
|
132
|
+
############################
|
133
|
+
# minus matching
|
134
|
+
############################
|
135
|
+
if reg_exp.minus_list then
|
136
|
+
pos2, pos3 = [], []
|
137
|
+
i = 0
|
138
|
+
while i<reg_exp.minus_list.length
|
139
|
+
j = 0
|
140
|
+
pos1.each {|aux|
|
141
|
+
pos2 = match_pos(str[aux[0], aux[1]-aux[0]+1], reg_exp.minus_list[i], scope)
|
142
|
+
pos2.map! {|e|
|
143
|
+
e[0] = e[0] + pos1[j][0]
|
144
|
+
e[1] = e[1] + pos1[j][0]
|
145
|
+
e
|
146
|
+
}
|
147
|
+
pos3 << pos2.dup
|
148
|
+
j += 1
|
149
|
+
}
|
150
|
+
i += 1
|
151
|
+
end #while
|
152
|
+
pos3 = format_array(pos3)
|
153
|
+
return pos1 - pos3
|
154
|
+
else
|
155
|
+
return pos1
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
#####################################################
|
160
|
+
# </matching>
|
161
|
+
#####################################################
|
162
|
+
|
163
|
+
def crash?(substitution, i_file)
|
164
|
+
|
165
|
+
i_string = ''
|
166
|
+
File.open(i_file) { |f| i_string = f.read }
|
167
|
+
|
168
|
+
self.match_hash[i_file] = get_match_pos(i_string, self.reg_exp, self.scope) unless self.match_hash[i_file]
|
169
|
+
|
170
|
+
substitution.match_hash[i_file] = get_match_pos(i_string, substitution.reg_exp, substitution.scope) unless substitution.match_hash[i_file]
|
171
|
+
|
172
|
+
crash = false
|
173
|
+
|
174
|
+
if (/before/ =~ self.scope) or (/after/ =~ self.scope) or
|
175
|
+
(/before/ =~ substitution.scope) or (/after/ =~ substitution.scope)
|
176
|
+
return false
|
177
|
+
|
178
|
+
elsif (/local/ =~ self.scope) and (/local/ =~ substitution.scope)
|
179
|
+
crash = crash_one_on_one?(self, 0, substitution, 0, i_file)
|
180
|
+
|
181
|
+
elsif (/local/ =~ self.scope) and (/global/ =~ substitution.scope)
|
182
|
+
index_2 = 0
|
183
|
+
while !crash and index_2 < substitution.match_hash[i_file].length - 1 do
|
184
|
+
crash = crash_one_on_one?(self, 0, substitution, index_2, i_file)
|
185
|
+
index_2 += 1
|
186
|
+
end
|
187
|
+
|
188
|
+
elsif (/global/ =~ self.scope) and (/local/ =~ substitution.scope)
|
189
|
+
index_1 = 0
|
190
|
+
while !crash and index_1 < self.match_hash[i_file].length - 1 do
|
191
|
+
crash = crash_one_on_one?(self, index_1, substitution, 0, i_file)
|
192
|
+
index_1 += 1
|
193
|
+
end
|
194
|
+
|
195
|
+
else #if (/global/ =~ self.scope) and (/global/ =~ substitution.scope)
|
196
|
+
index_1 = 0
|
197
|
+
while !crash and index_1 < self.match_hash[i_file].length - 1 do
|
198
|
+
index_2 = 0
|
199
|
+
while !crash and index_2 < substitution.match_hash[i_file].length - 1 do
|
200
|
+
crash = crash_one_on_one?(self, index_1, substitution, index_2, i_file)
|
201
|
+
index_2 += 1
|
202
|
+
end
|
203
|
+
index_1 += 1
|
204
|
+
end
|
205
|
+
end #if
|
206
|
+
|
207
|
+
return crash
|
208
|
+
|
209
|
+
end #crash?
|
210
|
+
|
211
|
+
def crash_one_on_one?(substitution1, index_1, substitution2, index_2, i_file)
|
212
|
+
return false if (substitution1.match_hash[i_file] == nil) or (substitution2.match_hash[i_file] ==nil)
|
213
|
+
if substitution1.match_hash[i_file][index_1][0] <= substitution2.match_hash[i_file][index_2][0]
|
214
|
+
return true if substitution1.match_hash[i_file][index_1][1] >= substitution2.match_hash[i_file][index_2][0]
|
215
|
+
else
|
216
|
+
return true if substitution2.match_hash[i_file][index_2][1] >= substitution1.match_hash[i_file][index_1][0]
|
217
|
+
end #if
|
218
|
+
return false
|
219
|
+
end #crash_one_on_one?
|
220
|
+
|
221
|
+
end #Substitution
|