webidl 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.
Files changed (74) hide show
  1. data/.autotest +9 -0
  2. data/.document +5 -0
  3. data/.gitignore +5 -0
  4. data/LICENSE +20 -0
  5. data/README.rdoc +31 -0
  6. data/Rakefile +65 -0
  7. data/VERSION +1 -0
  8. data/bin/webidl2ruby +13 -0
  9. data/examples/html5.rb +6 -0
  10. data/lib/webidl.rb +47 -0
  11. data/lib/webidl/ast/argument.rb +25 -0
  12. data/lib/webidl/ast/attribute.rb +29 -0
  13. data/lib/webidl/ast/const.rb +17 -0
  14. data/lib/webidl/ast/exception.rb +15 -0
  15. data/lib/webidl/ast/extended_attribute.rb +14 -0
  16. data/lib/webidl/ast/field.rb +14 -0
  17. data/lib/webidl/ast/implements_statement.rb +14 -0
  18. data/lib/webidl/ast/interface.rb +24 -0
  19. data/lib/webidl/ast/module.rb +17 -0
  20. data/lib/webidl/ast/node.rb +29 -0
  21. data/lib/webidl/ast/operation.rb +43 -0
  22. data/lib/webidl/ast/scoped_name.rb +28 -0
  23. data/lib/webidl/ast/type.rb +20 -0
  24. data/lib/webidl/ast/typedef.rb +15 -0
  25. data/lib/webidl/extensions/string.rb +22 -0
  26. data/lib/webidl/extensions/syntax_node.rb +5 -0
  27. data/lib/webidl/generator.rb +38 -0
  28. data/lib/webidl/generator/ruby_sexp_visitor.rb +118 -0
  29. data/lib/webidl/parse_tree/absolute_scoped_name.rb +11 -0
  30. data/lib/webidl/parse_tree/argument.rb +20 -0
  31. data/lib/webidl/parse_tree/argument_list.rb +14 -0
  32. data/lib/webidl/parse_tree/attribute.rb +17 -0
  33. data/lib/webidl/parse_tree/const.rb +9 -0
  34. data/lib/webidl/parse_tree/definitions.rb +25 -0
  35. data/lib/webidl/parse_tree/exception.rb +15 -0
  36. data/lib/webidl/parse_tree/exception_field.rb +11 -0
  37. data/lib/webidl/parse_tree/extended_attributes.rb +41 -0
  38. data/lib/webidl/parse_tree/implements_statement.rb +20 -0
  39. data/lib/webidl/parse_tree/interface.rb +21 -0
  40. data/lib/webidl/parse_tree/interface_inheritance.rb +11 -0
  41. data/lib/webidl/parse_tree/interface_members.rb +21 -0
  42. data/lib/webidl/parse_tree/module.rb +15 -0
  43. data/lib/webidl/parse_tree/nullable_type.rb +11 -0
  44. data/lib/webidl/parse_tree/operation.rb +30 -0
  45. data/lib/webidl/parse_tree/relative_scoped_name.rb +15 -0
  46. data/lib/webidl/parse_tree/scoped_name_list.rb +16 -0
  47. data/lib/webidl/parse_tree/specials.rb +17 -0
  48. data/lib/webidl/parse_tree/stringifier_attribute_or_operation.rb +16 -0
  49. data/lib/webidl/parse_tree/typedef.rb +11 -0
  50. data/lib/webidl/parser/debug_helper.rb +17 -0
  51. data/lib/webidl/parser/idl.treetop +369 -0
  52. data/spec/ast_spec.rb +218 -0
  53. data/spec/fixtures/empty_interface.idl +3 -0
  54. data/spec/fixtures/empty_module.idl +3 -0
  55. data/spec/fixtures/framework.idl +48 -0
  56. data/spec/fixtures/html5.idl +1440 -0
  57. data/spec/fixtures/interface_with_attribute.idl +7 -0
  58. data/spec/fixtures/interface_with_inheritance.idl +9 -0
  59. data/spec/fixtures/interface_with_members.idl +5 -0
  60. data/spec/fixtures/interface_with_stringifiers.idl +5 -0
  61. data/spec/fixtures/module_with_exception.idl +13 -0
  62. data/spec/fixtures/module_with_implements_statement.idl +6 -0
  63. data/spec/fixtures/module_with_typedef.idl +4 -0
  64. data/spec/fixtures/module_with_xattr_ident.idl +4 -0
  65. data/spec/fixtures/module_with_xattr_named_args.idl +5 -0
  66. data/spec/fixtures/module_with_xattr_no_arg.idl +5 -0
  67. data/spec/fixtures/module_with_xattr_scoped.idl +4 -0
  68. data/spec/fixtures/module_with_xattr_two_args.idl +4 -0
  69. data/spec/fixtures/nested.idl +4 -0
  70. data/spec/fixtures/websocket.idl +19 -0
  71. data/spec/generator_spec.rb +92 -0
  72. data/spec/parser_spec.rb +64 -0
  73. data/spec/spec_helper.rb +45 -0
  74. metadata +161 -0
@@ -0,0 +1,7 @@
1
+ interface foo {
2
+ // Attribute identifier: "const"
3
+ attribute boolean _const;
4
+
5
+ // Attribute identifier: "value"
6
+ attribute DOMString? _value;
7
+ };
@@ -0,0 +1,9 @@
1
+ interface foo {
2
+ // Attribute identifier: "const"
3
+ attribute boolean _const;
4
+
5
+ // Attribute identifier: "value"
6
+ attribute DOMString? _value;
7
+ };
8
+
9
+ interface bar : foo {};
@@ -0,0 +1,5 @@
1
+ interface System {
2
+ // Operation identifier: "createObject"
3
+ // Operation argument identifier: "interface"
4
+ Object createObject(in string _interface);
5
+ };
@@ -0,0 +1,5 @@
1
+ interface System {
2
+ stringifier attribute DOMString href;
3
+ stringifier DOMString ();
4
+ };
5
+
@@ -0,0 +1,13 @@
1
+ module framework {
2
+ // Exception identifier: "FrameworkException"
3
+ // Qualified name: "::framework::FrameworkException"
4
+ exception FrameworkException {
5
+
6
+ // Constant identifier: "ERR_NOT_FOUND"
7
+ // Qualified name: "::framework::FrameworkException::ERR_NOT_FOUND"
8
+ const long ERR_NOT_FOUND = 1;
9
+
10
+ // Exception field identifier: "code"
11
+ long code;
12
+ };
13
+ };
@@ -0,0 +1,6 @@
1
+ module foo {
2
+ interface bar {};
3
+ interface baz {};
4
+
5
+ bar implements baz;
6
+ };
@@ -0,0 +1,4 @@
1
+ module gui {
2
+ typedef DOMString string;
3
+
4
+ };
@@ -0,0 +1,4 @@
1
+ [PutForwards=name]
2
+ module gui {
3
+
4
+ };
@@ -0,0 +1,5 @@
1
+ [NamedConstructor=Image(in DOMString src)]
2
+ module gui {
3
+ typedef DOMString string;
4
+
5
+ };
@@ -0,0 +1,5 @@
1
+ [OverrideBuiltins]
2
+ module gui {
3
+ typedef DOMString string;
4
+
5
+ };
@@ -0,0 +1,4 @@
1
+ [Prefix=org::example]
2
+ module gui {
3
+
4
+ };
@@ -0,0 +1,4 @@
1
+ [Constructor(in float x, in float y)]
2
+ module gui {
3
+
4
+ };
@@ -0,0 +1,4 @@
1
+ module foo {
2
+ interface bar {};
3
+ interface baz {};
4
+ };
@@ -0,0 +1,19 @@
1
+ [Constructor(in DOMString url, in optional DOMString protocol)]
2
+ interface WebSocket {
3
+ readonly attribute DOMString URL;
4
+
5
+ // ready state
6
+ const unsigned short CONNECTING = 0;
7
+ const unsigned short OPEN = 1;
8
+ const unsigned short CLOSED = 2;
9
+ readonly attribute unsigned short readyState;
10
+ readonly attribute unsigned long bufferedAmount;
11
+
12
+ // networking
13
+ attribute Function onopen;
14
+ attribute Function onmessage;
15
+ attribute Function onclose;
16
+ boolean send(in DOMString data);
17
+ void close();
18
+ };
19
+ WebSocket implements EventTarget;
@@ -0,0 +1,92 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe WebIDL::Generator do
4
+
5
+ it "generates an empty module" do
6
+ expected = %Q{module Gui\n # do nothing\nend\n}
7
+ actual = generate(fixture('empty_module.idl'))
8
+
9
+ actual.should == expected
10
+ end
11
+
12
+ it "generates an empty interface" do
13
+ expected = %Q{module System\n # do nothing\nend}
14
+ actual = generate(fixture('empty_interface.idl'))
15
+
16
+ actual.should == expected
17
+ end
18
+
19
+ it "generates nested modules/interfaces" do
20
+ expected = <<-RUBY
21
+ module Foo
22
+ module Bar
23
+ # do nothing
24
+ end
25
+ module Baz
26
+ # do nothing
27
+ end
28
+ end
29
+ RUBY
30
+
31
+ actual = generate(fixture("nested.idl"))
32
+ actual.should == expected
33
+ end
34
+
35
+ it "generates a module with an exception" do
36
+ expected = <<-RUBY
37
+ module Framework
38
+ class FrameworkException < StandardError
39
+ ERR_NOT_FOUND = 1
40
+ attr_accessor(:code)
41
+ end
42
+ end
43
+ RUBY
44
+
45
+ actual = generate(fixture('module_with_exception.idl'))
46
+ actual.should == expected
47
+ end
48
+
49
+ it "generates an interface with attributes" do
50
+ expected = <<-RUBY
51
+ module Foo
52
+ attr_accessor(:const)
53
+ attr_accessor(:value)
54
+ end
55
+ RUBY
56
+
57
+ actual = generate(fixture('interface_with_attribute.idl'))
58
+ actual.should == expected.strip
59
+ end
60
+
61
+ it "generates an interface with a member operation" do
62
+ expected = <<-RUBY
63
+ module System
64
+ def create_object(interface)
65
+ raise(NotImplementedError)
66
+ end
67
+ end
68
+ RUBY
69
+
70
+ actual = generate(fixture("interface_with_members.idl"))
71
+ actual.should == expected.strip
72
+ end
73
+
74
+ it "generates an implements statement" do
75
+ expected = <<-RUBY
76
+ module Foo
77
+ module Bar
78
+ # do nothing
79
+ end
80
+ module Baz
81
+ # do nothing
82
+ end
83
+ module Foo::Bar
84
+ include(Foo::Baz)
85
+ end
86
+ end
87
+ RUBY
88
+
89
+ actual = generate(fixture("module_with_implements_statement.idl"))
90
+ actual.should == expected
91
+ end
92
+ end
@@ -0,0 +1,64 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe WebIDL::Parser::IDLParser do
4
+
5
+ #
6
+ # modules
7
+ #
8
+
9
+ it "parses an empty module" do
10
+ parse(fixture("empty_module.idl")).should_not be_nil
11
+ end
12
+
13
+ it "parses a module with a typedef" do
14
+ parse(fixture("module_with_typedef.idl")).should_not be_nil
15
+ end
16
+
17
+ it "parses modules with extended attributes" do
18
+ parse(fixture("module_with_xattr_ident.idl")).should_not be_nil
19
+ parse(fixture("module_with_xattr_named_args.idl")).should_not be_nil
20
+ parse(fixture("module_with_xattr_no_arg.idl")).should_not be_nil
21
+ parse(fixture("module_with_xattr_scoped.idl")).should_not be_nil
22
+ parse(fixture("module_with_xattr_two_args.idl")).should_not be_nil
23
+ end
24
+
25
+ #
26
+ # interfaces
27
+ #
28
+
29
+ it "parses an empty interface" do
30
+ parse(fixture("empty_interface.idl")).should_not be_nil
31
+ end
32
+
33
+ it "parses a module with several interfaces" do
34
+ result = parse fixture("framework.idl")
35
+ result.should_not be_nil
36
+ end
37
+
38
+ it "parses an interface with an attribute" do
39
+ parse(fixture("interface_with_attribute.idl")).should_not be_nil
40
+ end
41
+
42
+
43
+ #
44
+ # various
45
+ #
46
+
47
+ it "parses a known type followed by other characters" do
48
+ str = <<-IDL
49
+ interface Foo { readonly attribute DOMStringMap bar; };
50
+ IDL
51
+
52
+ parse(str).should_not be_nil
53
+ end
54
+
55
+ it "parses the WebSocket interface idl" do
56
+ parse(fixture("websocket.idl")).should_not be_nil
57
+ end
58
+
59
+ it "parses the HTML5 DOM interface idl" do
60
+ parse(fixture("html5.idl")).build
61
+ parse(fixture("html5.idl")).should_not be_nil
62
+ end
63
+
64
+ end
@@ -0,0 +1,45 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require "rubygems"
5
+ require 'webidl'
6
+ require 'spec'
7
+ require 'spec/autorun'
8
+ require "pp"
9
+
10
+ require "ruby-debug"
11
+
12
+ Debugger.start
13
+ Debugger.settings[:autoeval] = true
14
+ Debugger.settings[:autolist] = 1
15
+
16
+ module ParseHelper
17
+ def parse(input)
18
+ result = @parser.parse(input)
19
+
20
+ unless result
21
+ raise @parser.failure_reason
22
+ end
23
+
24
+ result
25
+ end
26
+
27
+ def generate(str)
28
+ generator.generate(str)
29
+ end
30
+
31
+ def generator
32
+ @generator ||= WebIDL::Generator.new
33
+ end
34
+
35
+ def fixture(name)
36
+ File.read("#{File.dirname(__FILE__)}/fixtures/#{name}")
37
+ end
38
+ end
39
+
40
+ Spec::Runner.configure do |c|
41
+ c.include(ParseHelper)
42
+ c.before(:each) do
43
+ @parser = WebIDL::Parser::IDLParser.new
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webidl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jari Bakken
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-08 00:00:00 +01:00
13
+ default_executable: webidl2ruby
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: treetop
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: ruby2ruby
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ description: Built on Treetop, this gem will parse an interface declaration in WebIDL and generate ruby code
46
+ email: jari.bakken@gmail.com
47
+ executables:
48
+ - webidl2ruby
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.rdoc
54
+ files:
55
+ - .autotest
56
+ - .document
57
+ - .gitignore
58
+ - LICENSE
59
+ - README.rdoc
60
+ - Rakefile
61
+ - VERSION
62
+ - bin/webidl2ruby
63
+ - examples/html5.rb
64
+ - lib/webidl.rb
65
+ - lib/webidl/ast/argument.rb
66
+ - lib/webidl/ast/attribute.rb
67
+ - lib/webidl/ast/const.rb
68
+ - lib/webidl/ast/exception.rb
69
+ - lib/webidl/ast/extended_attribute.rb
70
+ - lib/webidl/ast/field.rb
71
+ - lib/webidl/ast/implements_statement.rb
72
+ - lib/webidl/ast/interface.rb
73
+ - lib/webidl/ast/module.rb
74
+ - lib/webidl/ast/node.rb
75
+ - lib/webidl/ast/operation.rb
76
+ - lib/webidl/ast/scoped_name.rb
77
+ - lib/webidl/ast/type.rb
78
+ - lib/webidl/ast/typedef.rb
79
+ - lib/webidl/extensions/string.rb
80
+ - lib/webidl/extensions/syntax_node.rb
81
+ - lib/webidl/generator.rb
82
+ - lib/webidl/generator/ruby_sexp_visitor.rb
83
+ - lib/webidl/parse_tree/absolute_scoped_name.rb
84
+ - lib/webidl/parse_tree/argument.rb
85
+ - lib/webidl/parse_tree/argument_list.rb
86
+ - lib/webidl/parse_tree/attribute.rb
87
+ - lib/webidl/parse_tree/const.rb
88
+ - lib/webidl/parse_tree/definitions.rb
89
+ - lib/webidl/parse_tree/exception.rb
90
+ - lib/webidl/parse_tree/exception_field.rb
91
+ - lib/webidl/parse_tree/extended_attributes.rb
92
+ - lib/webidl/parse_tree/implements_statement.rb
93
+ - lib/webidl/parse_tree/interface.rb
94
+ - lib/webidl/parse_tree/interface_inheritance.rb
95
+ - lib/webidl/parse_tree/interface_members.rb
96
+ - lib/webidl/parse_tree/module.rb
97
+ - lib/webidl/parse_tree/nullable_type.rb
98
+ - lib/webidl/parse_tree/operation.rb
99
+ - lib/webidl/parse_tree/relative_scoped_name.rb
100
+ - lib/webidl/parse_tree/scoped_name_list.rb
101
+ - lib/webidl/parse_tree/specials.rb
102
+ - lib/webidl/parse_tree/stringifier_attribute_or_operation.rb
103
+ - lib/webidl/parse_tree/typedef.rb
104
+ - lib/webidl/parser/debug_helper.rb
105
+ - lib/webidl/parser/idl.treetop
106
+ - spec/ast_spec.rb
107
+ - spec/fixtures/empty_interface.idl
108
+ - spec/fixtures/empty_module.idl
109
+ - spec/fixtures/framework.idl
110
+ - spec/fixtures/html5.idl
111
+ - spec/fixtures/interface_with_attribute.idl
112
+ - spec/fixtures/interface_with_inheritance.idl
113
+ - spec/fixtures/interface_with_members.idl
114
+ - spec/fixtures/interface_with_stringifiers.idl
115
+ - spec/fixtures/module_with_exception.idl
116
+ - spec/fixtures/module_with_implements_statement.idl
117
+ - spec/fixtures/module_with_typedef.idl
118
+ - spec/fixtures/module_with_xattr_ident.idl
119
+ - spec/fixtures/module_with_xattr_named_args.idl
120
+ - spec/fixtures/module_with_xattr_no_arg.idl
121
+ - spec/fixtures/module_with_xattr_scoped.idl
122
+ - spec/fixtures/module_with_xattr_two_args.idl
123
+ - spec/fixtures/nested.idl
124
+ - spec/fixtures/websocket.idl
125
+ - spec/generator_spec.rb
126
+ - spec/parser_spec.rb
127
+ - spec/spec_helper.rb
128
+ has_rdoc: true
129
+ homepage: http://github.com/jarib/webidl
130
+ licenses: []
131
+
132
+ post_install_message:
133
+ rdoc_options:
134
+ - --charset=UTF-8
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: "0"
142
+ version:
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: "0"
148
+ version:
149
+ requirements: []
150
+
151
+ rubyforge_project:
152
+ rubygems_version: 1.3.5
153
+ signing_key:
154
+ specification_version: 3
155
+ summary: WebIDL parser/generator for ruby
156
+ test_files:
157
+ - spec/ast_spec.rb
158
+ - spec/generator_spec.rb
159
+ - spec/parser_spec.rb
160
+ - spec/spec_helper.rb
161
+ - examples/html5.rb