pub struct Builder { /* private fields */ }
Expand description
This is used to create a Parser
using
the builder method
use ressa::Builder;
use ressa::node::*;
fn main() {
let js = "for (var i = 0; i < 100; i++) {
console.log('loop', i);
}";
let p = Builder::new()
.module(false)
.js(js)
.build()
.unwrap();
for part in p {
let expectation = ProgramPart::Statement(
Statement::For(
ForStatement {
init: Some(
LoopInit::Variable(
vec![VariableDecl::with_value("i", Expression::number("0"))]
)
),
test: Some(
Expression::binary(Expression::ident("i"), BinaryOperator::LessThan, Expression::number("100"))
),
update: Some(
Expression::Update(
UpdateExpression {
operator: UpdateOperator::Increment,
argument: Box::new(Expression::ident("i")),
prefix: false,
}
)
),
body:
Box::new(Statement::Block(
vec![ProgramPart::Statement(
Statement::Expr(
Expression::call(Expression::member(Expression::ident("console"), Expression::ident("log"), false),
vec![
Expression::string("'loop'"),
Expression::ident("i"),
])
)
)]
)
)
}
)
);
assert_eq!(part.unwrap(), expectation);
}
}
Implementations
sourceimpl Builder
impl Builder
pub fn new() -> Self
sourcepub fn set_tolerant(&mut self, value: bool)
pub fn set_tolerant(&mut self, value: bool)
Enable or disable error tolerance
default: false
sourcepub fn tolerant(&mut self, value: bool) -> &mut Self
pub fn tolerant(&mut self, value: bool) -> &mut Self
Enable or disable error tolerance with a builder
pattern
default: false
sourcepub fn set_module(&mut self, value: bool)
pub fn set_module(&mut self, value: bool)
Set the parsing context to module or script
default: false
(script)
sourcepub fn module(&mut self, value: bool) -> &mut Self
pub fn module(&mut self, value: bool) -> &mut Self
Set the parsing context to module or script
with a builder pattern
default: false
(script)
sourcepub fn set_js(&mut self, js: impl Into<String>)
pub fn set_js(&mut self, js: impl Into<String>)
Set the js text that this parser would operate on
sourcepub fn js(&mut self, js: impl Into<String>) -> &mut Self
pub fn js(&mut self, js: impl Into<String>) -> &mut Self
Set the js text that this parser would operate on with a builder pattern
sourcepub fn build(&self) -> Result<Parser<DefaultCommentHandler>, Error>
pub fn build(&self) -> Result<Parser<DefaultCommentHandler>, Error>
Complete the builder pattern returning
Result<Parser, Error>
sourcepub fn with_comment_handler<CH>(
&self,
comment_handler: CH
) -> Result<Parser<CH>, Error>where
CH: CommentHandler + Sized,
pub fn with_comment_handler<CH>(
&self,
comment_handler: CH
) -> Result<Parser<CH>, Error>where
CH: CommentHandler + Sized,
An alternate to the build
method. This will allow
users to define their own comment handler
Auto Trait Implementations
impl RefUnwindSafe for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl UnwindSafe for Builder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more