[−][src]Crate ressa
RESSA (Rusty ECMAScript Syntax Analyzer) A library for parsing js files
The main interface for this library would be
the Parser
iterator. A parser is constructed
either via the ::new()
function or a Builder
.
As part of the constructor, you have to provide
the js you want to parse as an &str
.
Once constructed the parser will return a
ProgramPart
for each iteration.
A very simple example might look like this
use ressa::Parser; use resast::prelude::*; fn main() { let js = "function helloWorld() { alert('Hello world'); }"; let p = Parser::new(&js).unwrap(); let f = ProgramPart::decl( Decl::Func( Func { id: Some(Ident::from("helloWorld")), params: vec![], body: FuncBody( vec![ ProgramPart::Stmt( Stmt::Expr( Expr::Call( CallExpr { callee: Box::new( Expr::ident_from("alert") ), arguments: vec![ Expr::Lit( Lit::single_string_from("Hello world") ) ], } ) ) ) ] ), generator: false, is_async: false, } ) ); for part in p { assert_eq!(part.unwrap(), f); } }
checkout the examples
folders for slightly larger
examples.
Structs
Builder | This is used to create a |
Line | The start/end index of a line |
Parser | This is the primary interface that you would interact with.
There are two main ways to use it, the first is to utilize
the |
Span | The start and end of a token as the byte index in the original text |
Enums
Error |
Traits
CommentHandler | A comment handler will allow you to specify behavior about what to do with comments officially comments are supposed to operate the same as whitespace so the default behavior would be to throw away any comments found |