[][src]Enum ress::Token

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

Boolean(BooleanLiteral)

true of false

EoF

The end of the file

Ident(Ident)

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

Keyword(Keyword)

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

Null

A null literal value

Numeric(Number)

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

Punct(Punct)

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

String(StringLit)

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

RegEx(RegEx)

A regular expression literal.

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

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"));
Comment(Comment)

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]

pub fn ident(name: &str) -> Token
[src]

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

pub fn keyword(name: &str) -> Token
[src]

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

panics if the argument isn't a valid js keyword

pub fn numeric(number: &str) -> Token
[src]

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

pub fn punct(s: &str) -> Token
[src]

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

panics if the augment isn't valid js punctuation

pub fn double_quoted_string(s: &str) -> Token
[src]

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

pub fn single_quoted_string(s: &str) -> Token
[src]

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

pub fn regex(body: &str, flags: Option<String>) -> Token
[src]

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

pub fn no_sub_template(s: &str) -> Token
[src]

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

var noSub = `template string with no subs`;

pub fn template_head(s: &str) -> Token
[src]

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

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

pub fn template_middle(s: &str) -> Token
[src]

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

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

pub fn template_tail(s: &str) -> Token
[src]

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

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

pub fn comment(comment: &str, multi: bool) -> Token
[src]

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 note, this will not generate HTML-style comments

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]

pub fn is_boolean(&self) -> bool
[src]

pub fn is_boolean_true(&self) -> bool
[src]

pub fn is_boolean_false(&self) -> bool
[src]

pub fn is_eof(&self) -> bool
[src]

pub fn is_ident(&self) -> bool
[src]

pub fn is_keyword(&self) -> bool
[src]

pub fn is_strict_reserved(&self) -> bool
[src]

pub fn is_restricted(&self) -> bool
[src]

pub fn is_null(&self) -> bool
[src]

pub fn is_numeric(&self) -> bool
[src]

pub fn is_hex_literal(&self) -> bool
[src]

pub fn is_bin_literal(&self) -> bool
[src]

pub fn is_oct_literal(&self) -> bool
[src]

pub fn is_punct(&self) -> bool
[src]

pub fn is_string(&self) -> bool
[src]

pub fn is_double_quoted_string(&self) -> bool
[src]

pub fn is_single_quoted_string(&self) -> bool
[src]

pub fn is_regex(&self) -> bool
[src]

pub fn is_template(&self) -> bool
[src]

pub fn is_template_no_sub(&self) -> bool
[src]

pub fn is_template_head(&self) -> bool
[src]

pub fn is_template_middle(&self) -> bool
[src]

pub fn is_template_tail(&self) -> bool
[src]

pub fn is_literal(&self) -> bool
[src]

pub fn is_comment(&self) -> bool
[src]

pub fn is_multi_line_comment(&self) -> bool
[src]

pub fn is_single_line_comment(&self) -> bool
[src]

impl Token
[src]

pub fn matches_boolean(&self, b: BooleanLiteral) -> bool
[src]

pub fn matches_boolean_str(&self, b: &str) -> bool
[src]

pub fn matches_ident_str(&self, name: &str) -> bool
[src]

pub fn matches_keyword(&self, keyword: Keyword) -> bool
[src]

pub fn matches_keyword_str(&self, name: &str) -> bool
[src]

pub fn matches_numeric(&self, number: Number) -> bool
[src]

pub fn matches_numeric_str(&self, number: &str) -> bool
[src]

pub fn matches_punct(&self, p: Punct) -> bool
[src]

pub fn matches_punct_str(&self, s: &str) -> bool
[src]

pub fn matches_regex(&self, regex: RegEx) -> bool
[src]

pub fn matches_regex_str(&self, regex: &str) -> bool
[src]

pub fn matches_comment(&self, comment: Comment) -> bool
[src]

pub fn matches_comment_str(&self, comment: &str) -> bool
[src]

pub fn matches_string_content(&self, content: &str) -> bool
[src]

Trait Implementations

impl ToString for Token
[src]

impl Clone for Token
[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl PartialEq<Token> for Token
[src]

impl Debug for Token
[src]

Auto Trait Implementations

impl Send for Token

impl Sync for Token

Blanket Implementations

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]