pub enum Literal {
Null,
Boolean(bool),
Integer(i64),
Real(f64),
String(Vec<u8>),
}
Expand description
A literal represents a fixed value, aka an atom.
Variants§
Null
A null value.
§Examples
use tagua_parser::Result;
use tagua_parser::ast::Literal;
use tagua_parser::rules::literals::literal;
assert_eq!(literal(b"null"), Result::Done(&b""[..], Literal::Null));
Boolean(bool)
A boolean, either true
or false
.
§Examples
use tagua_parser::Result;
use tagua_parser::ast::Literal;
use tagua_parser::rules::literals::literal;
assert_eq!(literal(b"true"), Result::Done(&b""[..], Literal::Boolean(true)));
assert_eq!(literal(b"false"), Result::Done(&b""[..], Literal::Boolean(false)));
Integer(i64)
An integer, for instance a binary, octal, decimal or hexadecimal number.
§Examples
use tagua_parser::Result;
use tagua_parser::ast::Literal;
use tagua_parser::rules::literals::literal;
let output = Result::Done(&b""[..], Literal::Integer(42i64));
assert_eq!(literal(b"0b101010"), output);
assert_eq!(literal(b"052"), output);
assert_eq!(literal(b"42"), output);
assert_eq!(literal(b"0x2a"), output);
Real(f64)
A real, for instance an exponential number.
§Examples
use tagua_parser::Result;
use tagua_parser::ast::Literal;
use tagua_parser::rules::literals::literal;
let output = Result::Done(&b""[..], Literal::Real(4.2f64));
assert_eq!(literal(b"4.2"), output);
assert_eq!(literal(b".42e1"), output);
assert_eq!(literal(b"420e-2"), output);
String(Vec<u8>)
A string.
§Examples
use tagua_parser::Result;
use tagua_parser::ast::Literal;
use tagua_parser::rules::literals::literal;
assert_eq!(
literal(b"'foo\\'bar'"),
Result::Done(&b""[..], Literal::String(b"foo'bar".to_vec()))
);
Trait Implementations§
impl StructuralPartialEq for Literal
Auto Trait Implementations§
impl Freeze for Literal
impl RefUnwindSafe for Literal
impl Send for Literal
impl Sync for Literal
impl Unpin for Literal
impl UnwindSafe for Literal
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more