aaronp-zomg 1.0.2.20080827232412

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. data/History.txt +25 -0
  2. data/Manifest.txt +238 -0
  3. data/README.txt +59 -0
  4. data/Rakefile +43 -0
  5. data/bin/omfg +56 -0
  6. data/lib/scanner.rex +169 -0
  7. data/lib/yacc.y +861 -0
  8. data/lib/zomg.rb +22 -0
  9. data/lib/zomg/idl.rb +14 -0
  10. data/lib/zomg/idl/nodes/attribute.rb +15 -0
  11. data/lib/zomg/idl/nodes/binary.rb +19 -0
  12. data/lib/zomg/idl/nodes/constant.rb +15 -0
  13. data/lib/zomg/idl/nodes/interface.rb +13 -0
  14. data/lib/zomg/idl/nodes/interface_header.rb +14 -0
  15. data/lib/zomg/idl/nodes/member.rb +14 -0
  16. data/lib/zomg/idl/nodes/node.rb +54 -0
  17. data/lib/zomg/idl/nodes/operation.rb +17 -0
  18. data/lib/zomg/idl/nodes/parameter.rb +18 -0
  19. data/lib/zomg/idl/nodes/typedef.rb +13 -0
  20. data/lib/zomg/idl/nodes/union.rb +14 -0
  21. data/lib/zomg/idl/parser.rb +54 -0
  22. data/lib/zomg/idl/visitable.rb +15 -0
  23. data/lib/zomg/idl/visitors/duhr.rb +24 -0
  24. data/lib/zomg/idl/visitors/ruby_sexp.rb +204 -0
  25. data/lib/zomg/idl/visitors/sexp.rb +274 -0
  26. data/lib/zomg/version.rb +3 -0
  27. data/test/assets/array/array1.idl +60 -0
  28. data/test/assets/array/array2.idl +38 -0
  29. data/test/assets/array/array3.idl +8 -0
  30. data/test/assets/array/array4.idl +7 -0
  31. data/test/assets/array/array5.idl +80 -0
  32. data/test/assets/attribute/grid_0attribs_2methods.idl +16 -0
  33. data/test/assets/attribute/grid_1ROattribs_1attribs_0methods.idl +19 -0
  34. data/test/assets/attribute/grid_1ROattribs_1attribs_1methods.idl +19 -0
  35. data/test/assets/attribute/grid_1ROattribs_1attribs_2methods.idl +17 -0
  36. data/test/assets/attribute/grid_1ROattribs_1methods.idl +16 -0
  37. data/test/assets/attribute/grid_1ROattribs_2methods.idl +16 -0
  38. data/test/assets/attribute/grid_1attribs_1methods.idl +17 -0
  39. data/test/assets/attribute/grid_1attribs_2methods.idl +17 -0
  40. data/test/assets/attribute/grid_2ROattribs_0methods.idl +16 -0
  41. data/test/assets/attribute/grid_2ROattribs_1methods.idl +16 -0
  42. data/test/assets/attribute/grid_2ROattribs_2methods.idl +16 -0
  43. data/test/assets/attribute/grid_2attribs_0methods.idl +19 -0
  44. data/test/assets/attribute/grid_2attribs_1methods.idl +19 -0
  45. data/test/assets/attribute/grid_2attribs_2methods.idl +19 -0
  46. data/test/assets/comment/c_style_comments.idl +63 -0
  47. data/test/assets/comment/comment1.idl +57 -0
  48. data/test/assets/comment/cpp_style_comments.idl +168 -0
  49. data/test/assets/comment/shortform.idl +0 -0
  50. data/test/assets/complex/TestCodeSets.idl +10 -0
  51. data/test/assets/complex/TestIntfContext.idl +13 -0
  52. data/test/assets/complex/TestIntfLongLong.idl +51 -0
  53. data/test/assets/complex/TestIntfWChar.idl +52 -0
  54. data/test/assets/complex/any1.idl +22 -0
  55. data/test/assets/complex/complex1.idl +495 -0
  56. data/test/assets/complex/complex2.idl +730 -0
  57. data/test/assets/complex/complex3.idl +181 -0
  58. data/test/assets/complex/complex4.idl +181 -0
  59. data/test/assets/complex/interop_wchar.idl +60 -0
  60. data/test/assets/constant/constant1.idl +37 -0
  61. data/test/assets/constant/constant2.idl +29 -0
  62. data/test/assets/constant/constant3.idl +50 -0
  63. data/test/assets/constant/constant4.idl +21 -0
  64. data/test/assets/constant/constant5.idl +65 -0
  65. data/test/assets/constant/constant6.idl +144 -0
  66. data/test/assets/constant/constant7.idl +30 -0
  67. data/test/assets/enum/enum1.idl +13 -0
  68. data/test/assets/exception/TestIntfExceptions.idl +69 -0
  69. data/test/assets/exception/TestIntfExceptionsExt_2_0.idl +34 -0
  70. data/test/assets/exception/TestIntfExceptionsExt_2_3.idl +24 -0
  71. data/test/assets/exception/ex1.idl +6 -0
  72. data/test/assets/exception/ex2.idl +18 -0
  73. data/test/assets/exception/ex3.idl +10 -0
  74. data/test/assets/exception/ex4.idl +20 -0
  75. data/test/assets/exception/sc.idl +0 -0
  76. data/test/assets/exception/simple1.idl +18 -0
  77. data/test/assets/exception/simple2.idl +25 -0
  78. data/test/assets/factory/factory1.idl +77 -0
  79. data/test/assets/factory/objref.idl +25 -0
  80. data/test/assets/forward/forward.idl +15 -0
  81. data/test/assets/forward/forward1.idl +13 -0
  82. data/test/assets/forward/fwd_incl1.idl +6 -0
  83. data/test/assets/forward/fwd_incl2.idl +7 -0
  84. data/test/assets/include/a.idl +23 -0
  85. data/test/assets/include/b.idl +16 -0
  86. data/test/assets/include/employee.idl +12 -0
  87. data/test/assets/include/include1.idl +10 -0
  88. data/test/assets/include/include2.idl +5 -0
  89. data/test/assets/include/manager.idl +10 -0
  90. data/test/assets/include/pragma.idl +41 -0
  91. data/test/assets/include/rookie.idl +13 -0
  92. data/test/assets/include/rookiemanager.idl +15 -0
  93. data/test/assets/include/sample.idl +58 -0
  94. data/test/assets/include/sample_incl.idl +406 -0
  95. data/test/assets/inherit/IDL1.idl +18 -0
  96. data/test/assets/inherit/IDL2.idl +18 -0
  97. data/test/assets/inherit/IDL3.idl +18 -0
  98. data/test/assets/inherit/IDL4.idl +17 -0
  99. data/test/assets/inherit/diamond_inheritance.idl +31 -0
  100. data/test/assets/inherit/inherit.idl +27 -0
  101. data/test/assets/limit/longidentifiers.idl +25 -0
  102. data/test/assets/limit/namelens.idl +26 -0
  103. data/test/assets/limit/tpztest.idl +21 -0
  104. data/test/assets/module/module1.idl +29 -0
  105. data/test/assets/module/module2.idl +34 -0
  106. data/test/assets/module/module3.idl +20 -0
  107. data/test/assets/module/module4.idl +15 -0
  108. data/test/assets/nested/nested1.idl +5 -0
  109. data/test/assets/nested/nested2.idl +11 -0
  110. data/test/assets/operations/Benchmark.idl +331 -0
  111. data/test/assets/operations/CCS.idl +82 -0
  112. data/test/assets/operations/TestIntf.idl +40 -0
  113. data/test/assets/operations/TestIntfBasic.idl +653 -0
  114. data/test/assets/operations/atomic.idl +40 -0
  115. data/test/assets/operations/dif2.idl +48 -0
  116. data/test/assets/operations/interface1.idl +16 -0
  117. data/test/assets/operations/parameters.idl +111 -0
  118. data/test/assets/operations/perf.idl +84 -0
  119. data/test/assets/operations/timer.idl +104 -0
  120. data/test/assets/preprocess/base_for_diamond_inheritance_with_macros.idl +17 -0
  121. data/test/assets/preprocess/basic_macro_marshalling.idl +54 -0
  122. data/test/assets/preprocess/diamond_inheritance_with_macros.idl +74 -0
  123. data/test/assets/preprocess/macro1.idl +52 -0
  124. data/test/assets/preprocess/preprocess1.idl +246 -0
  125. data/test/assets/preprocess/preprocess2.idl +3 -0
  126. data/test/assets/recursion/loop.idl +28 -0
  127. data/test/assets/recursion/recursion1.idl +47 -0
  128. data/test/assets/recursion/recursion2.idl +74 -0
  129. data/test/assets/scenarios/filestat.idl +69 -0
  130. data/test/assets/scenarios/gateway.idl +176 -0
  131. data/test/assets/scenarios/library.idl +20 -0
  132. data/test/assets/scenarios/phone.idl +24 -0
  133. data/test/assets/scenarios/ticketservice.idl +118 -0
  134. data/test/assets/scope/scope01.idl +58 -0
  135. data/test/assets/scope/scope02.idl +25 -0
  136. data/test/assets/scope/scope03.idl +22 -0
  137. data/test/assets/scope/scope04.idl +27 -0
  138. data/test/assets/scope/scope05.idl +30 -0
  139. data/test/assets/scope/scope06.idl +51 -0
  140. data/test/assets/scope/scope07.idl +20 -0
  141. data/test/assets/scope/scope08.idl +88 -0
  142. data/test/assets/scope/scope09.idl +21 -0
  143. data/test/assets/scope/scope10.idl +95 -0
  144. data/test/assets/scope/scope11.idl +62 -0
  145. data/test/assets/scope/scope12.idl +117 -0
  146. data/test/assets/scope/scope13.idl +117 -0
  147. data/test/assets/scope/scope14.idl +117 -0
  148. data/test/assets/scope/scope15.idl +117 -0
  149. data/test/assets/scope/scope16.idl +117 -0
  150. data/test/assets/scope/scope17.idl +117 -0
  151. data/test/assets/scope/scope18.idl +117 -0
  152. data/test/assets/scope/scope19.idl +117 -0
  153. data/test/assets/scope/scope20.idl +215 -0
  154. data/test/assets/scope/scope21.idl +215 -0
  155. data/test/assets/scope/scope22.idl +205 -0
  156. data/test/assets/scope/scope23.idl +261 -0
  157. data/test/assets/scope/scope24.idl +376 -0
  158. data/test/assets/scope/scope25.idl +266 -0
  159. data/test/assets/scope/scope26.idl +180 -0
  160. data/test/assets/scope/scope27.idl +184 -0
  161. data/test/assets/scope/scope28.idl +182 -0
  162. data/test/assets/scope/scope29.idl +182 -0
  163. data/test/assets/scope/scope30.idl +40 -0
  164. data/test/assets/scope/scope31.idl +33 -0
  165. data/test/assets/scope/scope32.idl +37 -0
  166. data/test/assets/scope/scope33.idl +50 -0
  167. data/test/assets/scope/scope34.idl +97 -0
  168. data/test/assets/scope/scope35.idl +72 -0
  169. data/test/assets/scope/scope36.idl +167 -0
  170. data/test/assets/scope/scope37.idl +57 -0
  171. data/test/assets/scope/scope38.idl +38 -0
  172. data/test/assets/scope/scope39.idl +38 -0
  173. data/test/assets/scope/scope40.idl +38 -0
  174. data/test/assets/scope/scope41.idl +24 -0
  175. data/test/assets/scope/scope42.idl +64 -0
  176. data/test/assets/scope/scope43.idl +66 -0
  177. data/test/assets/scope/scope44.idl +52 -0
  178. data/test/assets/sequence/sequence1.idl +24 -0
  179. data/test/assets/sequence/sequence2.idl +9 -0
  180. data/test/assets/simple/basictypes1.idl +80 -0
  181. data/test/assets/simple/basictypes2.idl +197 -0
  182. data/test/assets/simple/basictypes3.idl +23 -0
  183. data/test/assets/simple/basictypes4.idl +73 -0
  184. data/test/assets/simple/basictypes5.idl +29 -0
  185. data/test/assets/simple/basictypes6.idl +63 -0
  186. data/test/assets/simple/simple1.idl +45 -0
  187. data/test/assets/simple/simple2.idl +61 -0
  188. data/test/assets/simple/simple3.idl +36 -0
  189. data/test/assets/string/string1.idl +11 -0
  190. data/test/assets/string/string2.idl +29 -0
  191. data/test/assets/struct/struct1.idl +20 -0
  192. data/test/assets/struct/struct2.idl +21 -0
  193. data/test/assets/struct/struct3.idl +42 -0
  194. data/test/assets/struct/struct4.idl +57 -0
  195. data/test/assets/struct/struct5.idl +71 -0
  196. data/test/assets/typecode/orb.idl +0 -0
  197. data/test/assets/typecode/pseudo.idl +25 -0
  198. data/test/assets/typedef/shorthand_typedef_struct_insideIF.idl +17 -0
  199. data/test/assets/typedef/shorthand_typedef_struct_insideIF_noMO.idl +16 -0
  200. data/test/assets/typedef/shorthand_typedef_struct_insideMO.idl +17 -0
  201. data/test/assets/typedef/shorthand_typedef_struct_outsideMO.idl +17 -0
  202. data/test/assets/typedef/typedef1.idl +8 -0
  203. data/test/assets/typedef/typedef2.idl +22 -0
  204. data/test/assets/typedef/typedef_struct_insideIF.idl +18 -0
  205. data/test/assets/typedef/typedef_struct_insideMO.idl +18 -0
  206. data/test/assets/typedef/typedef_struct_outsideMO.idl +18 -0
  207. data/test/assets/union/union1.idl +31 -0
  208. data/test/assets/union/union2.idl +22 -0
  209. data/test/assets/union/union3.idl +26 -0
  210. data/test/conversions/test_attribute.rb +46 -0
  211. data/test/conversions/test_enum.rb +25 -0
  212. data/test/conversions/test_exception.rb +24 -0
  213. data/test/conversions/test_forward_declaration.rb +22 -0
  214. data/test/conversions/test_interface.rb +30 -0
  215. data/test/conversions/test_module.rb +24 -0
  216. data/test/conversions/test_struct.rb +25 -0
  217. data/test/conversions/test_typedef.rb +22 -0
  218. data/test/conversions/test_union.rb +27 -0
  219. data/test/conversions/test_value_box_dcl.rb +22 -0
  220. data/test/helper.rb +23 -0
  221. data/test/simple/test_basictypes1.rb +87 -0
  222. data/test/simple/test_basictypes2.rb +18 -0
  223. data/test/simple/test_basictypes3.rb +32 -0
  224. data/test/simple/test_basictypes4.rb +25 -0
  225. data/test/simple/test_basictypes5.rb +17 -0
  226. data/test/simple/test_basictypes6.rb +19 -0
  227. data/test/simple/test_simple1.rb +40 -0
  228. data/test/simple/test_simple2.rb +48 -0
  229. data/test/simple/test_simple3.rb +20 -0
  230. data/test/test_array.rb +22 -0
  231. data/test/test_assets.rb +33 -0
  232. data/test/test_complex.rb +17 -0
  233. data/test/test_node.rb +16 -0
  234. data/test/test_parser.rb +17 -0
  235. data/test/test_scanner.rb +234 -0
  236. metadata +334 -0
@@ -0,0 +1,40 @@
1
+ require 'helper'
2
+
3
+ class Simple1Test < ZOMG::Test
4
+ def setup
5
+ @tree = ZOMG::IDL::Parser.parse_file(simple('simple1.idl'))
6
+ end
7
+
8
+ def test_parse_simple1
9
+ assert_instance_of(Specification, @tree)
10
+ assert_equal(1, @tree.children.length)
11
+
12
+ idl_module = @tree.children.first
13
+ assert_instance_of(Module, idl_module)
14
+ assert_equal('OneWaySimpleTest', idl_module.name)
15
+
16
+ assert_equal(1, idl_module.children.length)
17
+ idl_interface = idl_module.children.first
18
+ assert_instance_of(Interface, idl_interface)
19
+ assert_equal('sim1wcor', idl_interface.header.name)
20
+
21
+ assert_equal(1, idl_interface.children.length)
22
+ idl_op_decl = idl_interface.children.first
23
+ assert_equal('OneWayMethod', idl_op_decl.name)
24
+ assert_equal(:void, idl_op_decl.returns.to_sexp)
25
+ assert_equal('oneway', idl_op_decl.attribute)
26
+
27
+ assert_equal(2, idl_op_decl.children.length)
28
+
29
+ idl_op_decl.children.each do |child|
30
+ assert_instance_of(Parameter, child)
31
+ assert_equal(:in, child.attribute.to_sexp)
32
+ end
33
+
34
+ in_str = idl_op_decl.children.first
35
+ in_long = idl_op_decl.children[1]
36
+
37
+ assert_equal('inStr', in_str.name)
38
+ assert_equal('inLong', in_long.name)
39
+ end
40
+ end
@@ -0,0 +1,48 @@
1
+ require 'helper'
2
+
3
+ class Simple2Test < ZOMG::Test
4
+ def setup
5
+ @tree = ZOMG::IDL::Parser.parse_file(simple('simple2.idl'))
6
+ end
7
+
8
+ def test_parse_simple2
9
+ assert_instance_of(Specification, @tree)
10
+ assert_equal(1, @tree.children.length)
11
+
12
+ idl_module = @tree.children.first
13
+ assert_instance_of(Module, idl_module)
14
+ assert_equal('TwoWaySimpleTest', idl_module.name)
15
+
16
+ assert_equal(2, idl_module.children.length)
17
+ exception = idl_module.children[0]
18
+ assert_instance_of(Exception, exception)
19
+ assert_equal('SimpleEx', exception.name)
20
+
21
+ idl_interface = idl_module.children[1]
22
+ assert_instance_of(Interface, idl_interface)
23
+ assert_equal('sim2wcor', idl_interface.header.name)
24
+
25
+ assert_equal(1, idl_interface.children.length)
26
+ idl_op_decl = idl_interface.children.first
27
+ assert_equal('TwoWayMethod', idl_op_decl.name)
28
+ assert_instance_of(String, idl_op_decl.returns)
29
+ assert_nil(idl_op_decl.attribute)
30
+ assert_equal(1, idl_op_decl.raises.length)
31
+ assert_equal('SimpleEx', idl_op_decl.raises.first.name)
32
+
33
+ assert_equal(3, idl_op_decl.children.length)
34
+ idl_op_decl.children.each do |child|
35
+ assert_instance_of(Parameter, child)
36
+ end
37
+ assert_equal([:in, :in_out, :out], idl_op_decl.children.map { |x|
38
+ x.attribute.to_sexp
39
+ })
40
+ assert_equal( [String, Long, UnsignedShort],
41
+ idl_op_decl.children.map { |x|
42
+ x.type.class
43
+ })
44
+ assert_equal(%w{ inStr inoutLong outUShort }, idl_op_decl.children.map { |x|
45
+ x.name
46
+ })
47
+ end
48
+ end
@@ -0,0 +1,20 @@
1
+ require 'helper'
2
+
3
+ class Simple3Test < ZOMG::Test
4
+ def setup
5
+ @tree = ZOMG::IDL::Parser.parse_file(simple('simple3.idl'))
6
+ end
7
+
8
+ def test_parse_tree
9
+ assert_equal(1, @tree.children.length)
10
+ idl_module = @tree.children.first
11
+ assert_equal(1, idl_module.children.length)
12
+
13
+ interface = idl_module.children.first
14
+ assert_equal(1, interface.children.length)
15
+ attribute = interface.children.first
16
+ assert_instance_of(Attribute, attribute)
17
+ assert_equal(1, attribute.children.length)
18
+ assert_equal('test', attribute.children.first.name)
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ require 'helper'
2
+
3
+ class Array1Test < ZOMG::Test
4
+ def setup
5
+ @tree = ZOMG::IDL::Parser.parse_file(array('array1.idl'))
6
+ end
7
+
8
+ def test_string_sequence
9
+ assert_sexp(
10
+ [:typedef, [:sequence, [[:scoped_name, "arr", []], [:int, 2]]], [[:decl, "arrseq"]]], @tree.duhr.Typedef[7])
11
+ end
12
+
13
+ def test_forward_declaration
14
+ assert_sexp([:forward_decl, 'foo'], @tree.duhr.ForwardDeclaration[0])
15
+ end
16
+
17
+ def test_to_sexp
18
+ assert_nothing_raised {
19
+ @tree.to_sexp
20
+ }
21
+ end
22
+ end
@@ -0,0 +1,33 @@
1
+ require 'helper'
2
+
3
+ module ZOMG
4
+ module AssetTests
5
+ end
6
+ end
7
+
8
+ Dir[File.join(ZOMG::Test::ASSETS, '*')].each do |dir|
9
+ next unless File.directory?(dir)
10
+ klass = Class.new(ZOMG::Test) {
11
+ Dir[File.join(dir, '*.idl')].each do |file|
12
+ name = File.basename(file)
13
+ define_method(:setup) do
14
+ @tree = ZOMG::IDL::Parser.parse_file(file)
15
+ end
16
+
17
+ define_method(:"test_#{name.gsub('.', '_')}_to_sexp") do
18
+ assert_nothing_raised {
19
+ @tree.to_sexp
20
+ }
21
+ end
22
+
23
+ define_method(:"test_#{name.gsub('.', '_')}_to_ruby") do
24
+ ruby = nil
25
+ assert_nothing_raised { ruby = @tree.to_ruby }
26
+ x = Module.new
27
+ assert_nothing_raised { x.module_eval(ruby) }
28
+ end
29
+ end
30
+ }
31
+ test_name = File.basename(dir)
32
+ ZOMG::AssetTests.const_set(:"#{test_name.capitalize}Test", klass)
33
+ end
@@ -0,0 +1,17 @@
1
+ require 'helper'
2
+
3
+ class ComplexTest < ZOMG::Test
4
+ COMPLEX = File.join(ASSETS, 'complex')
5
+
6
+ def test_constant_sexp
7
+ tree = ZOMG::IDL::Parser.parse_file(complex('complex4.idl'))
8
+ assert_sexp([:const, [:scoped_name, "longT", []], "long_c", [:int, 1]],
9
+ tree.duhr.Constant[0])
10
+ end
11
+
12
+ def test_context_sexp
13
+ tree = ZOMG::IDL::Parser.parse_file(complex('TestIntfContext.idl'))
14
+ operation = tree.duhr.Module[0].Interface[0].Operation[0].tree
15
+ assert_sexp([:context, [[:string_lit, ["\"A*\""]], [:string_lit, ["\"C*\""]], [:string_lit, ["\"X\""]], [:string_lit, ["\"Z\""]]]], operation.context)
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ require 'helper'
2
+
3
+ class NodeTest < ZOMG::Test
4
+ def setup
5
+ @tree = ZOMG::IDL::Parser.parse_file(array('array1.idl'))
6
+ end
7
+
8
+ def test_to_ruby
9
+ assert_nothing_raised {
10
+ @tree.to_ruby
11
+ }
12
+ ruby_with_prefix = @tree.to_ruby('A::B')
13
+ assert_match(/module A/, ruby_with_prefix)
14
+ assert_match(/module B/, ruby_with_prefix)
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ require 'helper'
2
+
3
+ class ParserTest < ZOMG::Test
4
+ def setup
5
+ @parser = ZOMG::IDL::Parser.new
6
+ end
7
+
8
+ def test_valuetype
9
+ tree = @parser.parse(<<-eoidl)
10
+ module dom
11
+ {
12
+ valuetype DOMString sequence<unsigned short>;
13
+ };
14
+ eoidl
15
+ assert_nothing_raised { tree.to_sexp }
16
+ end
17
+ end
@@ -0,0 +1,234 @@
1
+ require 'helper'
2
+
3
+ class ScannerTest < ZOMG::Test
4
+ def setup
5
+ @scanner = ZOMG::IDL::Scanner.new
6
+ end
7
+
8
+ def test_load_file
9
+ @scanner.load_file(simple('simple1.idl'))
10
+ tokens = []
11
+ while token = @scanner.next_token
12
+ tokens << token
13
+ end
14
+ assert tokens.length > 0
15
+ end
16
+
17
+ def test_typedef_object
18
+ assert_tokens([
19
+ [:T_TYPEDEF, "typedef"],
20
+ [:T_OBJECT, "Object"],
21
+ [:T_IDENTIFIER, "ObjectAlias"],
22
+ ], 'typedef Object ObjectAlias;')
23
+ end
24
+
25
+ def test_const_long
26
+ assert_tokens([
27
+ [:T_CONST, "const"],
28
+ [:T_LONG, "long"],
29
+ [:T_IDENTIFIER, "ConstLong"],
30
+ [:T_EQUAL, "="],
31
+ [:T_MINUS_SIGN, "-"],
32
+ ], 'const long ConstLong = -1234;')
33
+ end
34
+
35
+ def test_escaped_string
36
+ assert_tokens([
37
+ [:T_CONST, "const"],
38
+ [:T_CHAR, "char"],
39
+ [:T_IDENTIFIER, "ConstChar5"],
40
+ [:T_EQUAL, "="],
41
+ [:T_CHARACTER_LITERAL, "'\\''"],
42
+ ], 'const char ConstChar5 = \'\\\'\'')
43
+ end
44
+
45
+ def test_vertical_pipe
46
+ assert_tokens([
47
+ [:T_CONST, "const"],
48
+ [:T_LONG, "long"],
49
+ [:T_IDENTIFIER, "ConstLong"],
50
+ [:T_EQUAL, "="],
51
+ [:T_LEFT_PARANTHESIS, "("],
52
+ [:T_INTEGER_LITERAL, "0xf"],
53
+ [:T_VERTICAL_LINE, "|"],
54
+ ], "const long ConstLong = (0xf | 0xf000) & 0xfffe")
55
+ end
56
+
57
+ def test_instr
58
+ assert_tokens([
59
+ [:T_IN, "in"],
60
+ [:T_STRING, "string"],
61
+ [:T_IDENTIFIER, "inStr"],
62
+ ], "in string inStr")
63
+ end
64
+
65
+ def test_comment
66
+ assert_tokens([[:T_COMMENT, "// boner"]], "// boner")
67
+ assert_tokens([[:T_COMMENT, "/* boner */"]], "/* boner */")
68
+ end
69
+
70
+ def test_pragma
71
+ assert_tokens([[:T_PRAGMA, "#pragma awesome\n"]], "#pragma awesome\n")
72
+ end
73
+
74
+ def test_preprocessor_directive
75
+ assert_tokens([[:T_PREPROCESSOR, "#awesome\n"]], "#awesome\n")
76
+ end
77
+
78
+ def test_curlies
79
+ assert_tokens([[:T_LEFT_CURLY_BRACKET, "{"]], "{")
80
+ assert_tokens([[:T_RIGHT_CURLY_BRACKET, "}"]], "}")
81
+ assert_tokens([
82
+ [:T_LEFT_CURLY_BRACKET, "{"],
83
+ [:T_RIGHT_CURLY_BRACKET, "}"]
84
+ ], "{ }\n")
85
+ end
86
+
87
+ def test_squares
88
+ assert_tokens([[:T_LEFT_SQUARE_BRACKET, "["]], "[")
89
+ assert_tokens([[:T_RIGHT_SQUARE_BRACKET, "]"]], "]")
90
+ assert_tokens([
91
+ [:T_LEFT_SQUARE_BRACKET, "["],
92
+ [:T_RIGHT_SQUARE_BRACKET, "]"]
93
+ ], " [ ] \n")
94
+ end
95
+
96
+ def test_parens
97
+ assert_tokens([[:T_LEFT_PARANTHESIS, "("]], "(")
98
+ assert_tokens([[:T_RIGHT_PARANTHESIS, ")"]], ")")
99
+ assert_tokens([
100
+ [:T_LEFT_PARANTHESIS, "("],
101
+ [:T_RIGHT_PARANTHESIS, ")"]
102
+ ], " ( ) \n")
103
+ end
104
+
105
+ # Test literals
106
+ {
107
+ :const => [:T_CONST, 'const'],
108
+ :typedef => [:T_TYPEDEF, 'typedef'],
109
+ :float => [:T_FLOAT, 'float'],
110
+ :double => [:T_DOUBLE, 'double'],
111
+ :char => [:T_CHAR, 'char'],
112
+ :wchar => [:T_WCHAR, 'wchar'],
113
+ :fixed => [:T_FIXED, 'fixed'],
114
+ :boolean => [:T_BOOLEAN, 'boolean'],
115
+ :string => [:T_STRING, 'string'],
116
+ :wstring => [:T_WSTRING, 'wstring'],
117
+ :void => [:T_VOID, 'void'],
118
+ :unsigned => [:T_UNSIGNED, 'unsigned'],
119
+ :long => [:T_LONG, 'long'],
120
+ :short => [:T_SHORT, 'short'],
121
+ :struct => [:T_STRUCT, 'struct'],
122
+ :union => [:T_UNION, 'union'],
123
+ :switch => [:T_SWITCH, 'switch'],
124
+ :case => [:T_CASE, 'case'],
125
+ :default => [:T_DEFAULT, 'default'],
126
+ :enum => [:T_ENUM, 'enum'],
127
+ :in => [:T_IN, 'in'],
128
+ :out => [:T_OUT, 'out'],
129
+ :interface => [:T_INTERFACE, 'interface'],
130
+ :abstract => [:T_ABSTRACT, 'abstract'],
131
+ :valuetype => [:T_VALUETYPE, 'valuetype'],
132
+ :truncatable => [:T_TRUNCATABLE, 'truncatable'],
133
+ :supports => [:T_SUPPORTS, 'supports'],
134
+ :custom => [:T_CUSTOM, 'custom'],
135
+ :public => [:T_PUBLIC, 'public'],
136
+ :private => [:T_PRIVATE, 'private'],
137
+ :factory => [:T_FACTORY, 'factory'],
138
+ :native => [:T_NATIVE, 'native'],
139
+ :module => [:T_MODULE, 'module'],
140
+ :octet => [:T_OCTET, 'octet'],
141
+ :any => [:T_ANY, 'any'],
142
+ :sequence => [:T_SEQUENCE, 'sequence'],
143
+ :readonly => [:T_READONLY, 'readonly'],
144
+ :attribute => [:T_ATTRIBUTE, 'attribute'],
145
+ :exception => [:T_EXCEPTION, 'exception'],
146
+ :oneway => [:T_ONEWAY, 'oneway'],
147
+ :inout => [:T_INOUT, 'inout'],
148
+ :raises => [:T_RAISES, 'raises'],
149
+ :context => [:T_CONTEXT, 'context'],
150
+ }.each do |type, token|
151
+ define_method(:"test_#{type}") do
152
+ parse_text = token.length == 3 ? token.pop : token.last
153
+ assert_tokens([token], parse_text)
154
+ assert_tokens([
155
+ [:T_LEFT_SQUARE_BRACKET, "["],
156
+ token,
157
+ [:T_RIGHT_SQUARE_BRACKET, "]"]
158
+ ], " [\n#{parse_text}] \n")
159
+ assert_tokens([
160
+ [:T_IN, "in"],
161
+ [:T_STRING, "string"],
162
+ [:T_IDENTIFIER, "#{parse_text}Str"],
163
+ ], "in string #{parse_text}Str")
164
+ end
165
+ end
166
+
167
+ {
168
+ :minus => [:T_MINUS_SIGN, '-'],
169
+ :plus => [:T_PLUS_SIGN, '+'],
170
+ :shift_left => [:T_SHIFTLEFT, '<<'],
171
+ :shift_right => [:T_SHIFTRIGHT, '>>'],
172
+ :equal => [:T_EQUAL, '='],
173
+ :semicolon => [:T_SEMICOLON, ';'],
174
+ :comma => [:T_COMMA, ','],
175
+ :colon => [:T_COLON, ':'],
176
+ :asterisk => [:T_ASTERISK, '*'],
177
+ :solidus => [:T_SOLIDUS, '/'],
178
+ :percent => [:T_PERCENT_SIGN, '%'],
179
+ :tilde => [:T_TILDE, '~'],
180
+ :pipe => [:T_VERTICAL_LINE, '|'],
181
+ :caret => [:T_CIRCUMFLEX, '^'],
182
+ :ampersand => [:T_AMPERSAND, '&'],
183
+ :less_than => [:T_LESS_THAN_SIGN, '<'],
184
+ :greater_than => [:T_GREATER_THAN_SIGN, '>'],
185
+ :FALSE => [:T_FALSE, 'FALSE'],
186
+ :TRUE => [:T_TRUE, 'TRUE'],
187
+ :ValueBase => [:T_VALUEBASE, 'ValueBase'],
188
+ :scope => [:T_SCOPE, '::'],
189
+ :object => [:T_OBJECT, 'Object'],
190
+ :principal => [:T_PRINCIPAL, 'Principal'],
191
+ :identifier => [:T_IDENTIFIER, 'hello'],
192
+ :float_lit_1 => [:T_FLOATING_PT_LITERAL, '123.2e10'],
193
+ :float_lit_11 => [:T_FLOATING_PT_LITERAL, '123.2E10'],
194
+ :float_lit_2 => [:T_FLOATING_PT_LITERAL, '123.0E-5', '123.E-5'],
195
+ :float_lit_3 => [:T_FLOATING_PT_LITERAL, '123e10'],
196
+ :float_lit_31 => [:T_FLOATING_PT_LITERAL, '123E+10'],
197
+ :float_lit_4 => [:T_FLOATING_PT_LITERAL, '12.2'],
198
+ :float_lit_5 => [:T_FLOATING_PT_LITERAL, '12.0', '12.'],
199
+ :float_lit_6 => [:T_FLOATING_PT_LITERAL, '0.12e10', '.12e10'],
200
+ :float_lit_61 => [:T_FLOATING_PT_LITERAL, '0.12e+10', '.12e+10'],
201
+ :float_lit_7 => [:T_FLOATING_PT_LITERAL, '0.12', '.12'],
202
+ :fixed_lit_1 => [:T_FIXED_PT_LITERAL, '123', '123d'],
203
+ :fixed_lit_2 => [:T_FIXED_PT_LITERAL, '123', '123.d'],
204
+ :fixed_lit_21 => [:T_FIXED_PT_LITERAL, '123', '123.D'],
205
+ :fixed_lit_3 => [:T_FIXED_PT_LITERAL, '0.123', '.123d'],
206
+ :fixed_lit_31 => [:T_FIXED_PT_LITERAL, '0.123', '.123D'],
207
+ :fixed_lit_4 => [:T_FIXED_PT_LITERAL, '0.123', '0.123d'],
208
+ :fixed_lit_41 => [:T_FIXED_PT_LITERAL, '0.123', '0.123D'],
209
+ :hex_lit => [:T_INTEGER_LITERAL, '0x23'],
210
+ :hex_lit_1 => [:T_INTEGER_LITERAL, '0X23'],
211
+ :oct_lit => [:T_INTEGER_LITERAL, '023'],
212
+ :int_lit => [:T_INTEGER_LITERAL, '23'],
213
+ :char_lit => [:T_CHARACTER_LITERAL, "'a'"],
214
+ :string_lit => [:T_STRING_LITERAL, '"abc"'],
215
+ :unknown => [:T_UNKNOWN, '.'],
216
+ }.each do |type, token|
217
+ define_method(:"test_#{type}") do
218
+ parse_text = token.length == 3 ? token.pop : token.last
219
+ assert_tokens([token], parse_text)
220
+ assert_tokens([
221
+ [:T_LEFT_SQUARE_BRACKET, "["],
222
+ token,
223
+ [:T_RIGHT_SQUARE_BRACKET, "]"]
224
+ ], " [\n#{parse_text}] \n")
225
+ end
226
+ end
227
+
228
+ def assert_tokens(tokens, string)
229
+ @scanner.scan_evaluate(string)
230
+ tokens.each do |token|
231
+ assert_equal(token, @scanner.next_token)
232
+ end
233
+ end
234
+ end