webidl-parser

Crates.iowebidl-parser
lib.rswebidl-parser
version0.2.0
sourcesrc
created_at2017-06-19 11:02:33.189756
updated_at2017-06-21 00:29:49.205591
descriptionA WebIDL parser
homepagehttps://github.com/sgodwincs/webidl-parser
repositoryhttps://github.com/sgodwincs/webidl-parser
max_upload_size
id19496
size101,782
Scott Godwin (sgodwincs)

documentation

README

webidl-parser

LICENSE Build Status Crates.io Version

A lexer and parser for WebIDL in Rust.

Documentation.

Example

Lexing

use webidl_parser::*;

let lexer = Lexer::new("/* Example taken from emscripten site */\n\
                        enum EnumClass_EnumWithinClass {\n\
                            \"EnumClass::e_val\"\n\
                        };");
assert_eq!(lexer.collect::<Vec<_>>(),
           vec![Ok((41, Token::Enum, 45)),
                Ok((46, Token::Identifier("EnumClass_EnumWithinClass".to_string()), 71)),
                Ok((72, Token::LeftBrace, 73)),
                Ok((74, Token::StringLiteral("EnumClass::e_val".to_string()), 92)),
                Ok((93, Token::RightBrace, 94)),
                Ok((94, Token::Semicolon, 95))]);

Parsing

use webidl_parser::*;
use webidl_parser::ast::*;

let result = Parser::parse_string("[Attribute] interface Node { };");

assert_eq!(result,
           Ok(vec![Definition {
                definition_type: DefinitionType::Interface(Interface {
                    members: vec![],
                    name: "Node".to_string(),
                    type_:
                        InterfaceType::NonPartial(None),
                }),
                extended_attributes: vec![
                    Box::new(ExtendedAttribute::Other {
                        other: Other::Identifier("Attribute".to_string()),
                        rest: None,
                    })],
           }]));
Commit count: 95

cargo fmt