Enum ress::Token[][src]

pub enum Token {
    Boolean(BooleanLiteral),
    EoF,
    Ident(Ident),
    Keyword(Keyword),
    Null,
    Numeric(Number),
    Punct(Punct),
    String(StringLit),
    RegEx(RegEx),
    Template(Template),
    Comment(Comment),
}

The representation of a single JS token

Variants

true of false

The end of the file

An identifier this will be either a variable name or a function/method name

A word that has been reserved to not be used as an identifier

A null literal value

A number, this includes integers (1), decimals (0.1), hex (0x8f), binary (0b010011010), and octal (0o273)

A punctuation mark, this includes all mathematical operators logical operators and general syntax punctuation

A string literal, either double or single quoted, the associated value will be the unquoted string

A regular expression literal.

let regex = /[a-zA-Z]+/g;

The string parts of a template string

let js = "`Things and stuff times ${10} equals ${100000000}... i think`";
let mut s = Scanner::new(js);
assert_eq!(s.next().unwrap().token,
            Token::template_head("Things and stuff times "));
assert_eq!(s.next().unwrap().token,
            Token::numeric("10"));
assert_eq!(s.next().unwrap().token,
            Token::template_middle(" equals "));
assert_eq!(s.next().unwrap().token,
            Token::numeric("100000000"));
assert_eq!(s.next().unwrap().token,
            Token::template_tail("... i think"));

A comment, the associated value will contain the raw comment This will capture both inline comments // I am an inline comment and multi-line comments

/*multi lines
* comments
*/

Methods

impl Token
[src]

Create and instance of Token::Ident from a &str

Create and instance of Token::Keyword from a &str

panics if the argument isn't a valid js keyword

Create and instance of Token::Numeric from a &str

Create and instance of Token::Punct from a &str

panics if the augment isn't valid js punctuation

Create and instance of Token::String from a &str wrapped in double quotes

Create an instance of Token::String from a &str wrapped in single quotes

Create an instance of Token::RegEx from a &str and an Option

Creates an instance of Token::Template with a template string that has no substitutions

var noSub = `template string with no subs`;

Creates an instance of Token::Template for a template head

let t = `head ${true} middle ${false} tail ${false}`;

Creates an instance of a Token::Template for a template middle

let t = `head ${false} middle ${true} tail ${false}`;

Creates an instance of a Token::Template for a template tail

let t = `head ${false} middle ${false} tail ${true}`;

Creates an instance of a Token::Comment for a comment string and a flag if this comment should be treated as a multi line comment

let single_js = "//I am a comment";
let multi_js = "/*I am a multi-line comment*/";
let mut s = Scanner::new(single_js);
let single_scanner = s.next().expect("unable to parse single line comment");
let single = Token::comment("I am a comment", false);
assert_eq!(single, single_scanner.token);
s = Scanner::new(multi_js);
let multi_scanner = s.next().expect("Unable to parse multi-line comment");
let multi = Token::comment("I am a multi-line comment", true);
assert_eq!(multi, multi_scanner.token);

impl Token
[src]

impl Token
[src]

Trait Implementations

impl Debug for Token
[src]

Formats the value using the given formatter. Read more

impl PartialEq for Token
[src]

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

This method tests for !=.

impl Clone for Token
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl ToString for Token
[src]

Converts the given value to a String. Read more

Auto Trait Implementations

impl Send for Token

impl Sync for Token