Enum tagua_parser::ast::Literal [] [src]

pub enum Literal {
    Null,
    Boolean(bool),
    Integer(i64),
    Real(f64),
    String(Vec<u8>),
}

A literal represents a fixed value, aka an atom.

Variants

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));

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)));

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);

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);

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 Debug for Literal
[src]

Formats the value using the given formatter.

impl PartialEq for Literal
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.