Skip to content

Commit

Permalink
fix promise bug. add 'required' keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
mastahyeti authored and jarib committed Aug 10, 2016
1 parent 5829184 commit 222d68e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/webidl/parser/idl.treetop
Expand Up @@ -74,8 +74,12 @@ module WebIDL
(eal:ExtendedAttributeList ws member:DictionaryMember ws members:DictionaryMembers <ParseTree::DictionaryMembers>)?
end

rule Required
"required"
end

rule DictionaryMember
type:Type ws name:identifier ws default:Default ws ";" <ParseTree::DictionaryMember>
required:Required? ws type:Type ws name:identifier ws default:Default ws ";" <ParseTree::DictionaryMember>
end

rule Default
Expand Down Expand Up @@ -442,7 +446,7 @@ module WebIDL
end

rule PromiseType
"Promise" "<" return_type:ReturnType ">" {
"Promise" ws "<" ws return_type:ReturnType ws ">" {
def build(parent)
Ast::PromiseType.new(return_type.text_value)
end
Expand Down
47 changes: 47 additions & 0 deletions spec/parser_spec.rb
Expand Up @@ -2,6 +2,53 @@

describe WebIDL::Parser::IDLParser do

#
# dictionaries
#

it "parses an empty dictionary" do
str = <<-IDL
dictionary Foo {};
IDL
parse(str).should_not be_nil
end

it "parses dictionary members" do
str = <<-IDL
dictionary Foo { DOMString foo; };
IDL
parse(str).should_not be_nil
end

it "parses required dictionary members" do
str = <<-IDL
dictionary Foo { required DOMString foo; };
IDL
parse(str).should_not be_nil
end

#
# promises
#

it "parses empty promises" do
str = <<-IDL
interface Asdf {
Promise <DOMString> doSomething ();
};
IDL
parse(str).should_not be_nil
end

it "parses promises with ws around return type" do
str = <<-IDL
interface Asdf {
Promise < DOMString > doSomething ();
};
IDL
parse(str).should_not be_nil
end

#
# interfaces
#
Expand Down

0 comments on commit 222d68e

Please sign in to comment.