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
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]
impl Token
pub fn ident(name: &str) -> Token
[src]
pub fn ident(name: &str) -> Token
Create and instance of Token::Ident from a &str
pub fn keyword(name: &str) -> Token
[src]
pub fn keyword(name: &str) -> Token
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]
pub fn numeric(number: &str) -> Token
Create and instance of Token::Numeric from a &str
pub fn punct(s: &str) -> Token
[src]
pub fn punct(s: &str) -> Token
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]
pub fn double_quoted_string(s: &str) -> Token
Create and instance of Token::String from a &str wrapped in double quotes
pub fn single_quoted_string(s: &str) -> Token
[src]
pub fn single_quoted_string(s: &str) -> Token
Create an instance of Token::String from a &str wrapped in single quotes
pub fn regex(body: &str, flags: Option<String>) -> Token
[src]
pub fn regex(body: &str, flags: Option<String>) -> Token
Create an instance of Token::RegEx from a &str and an Option
pub fn no_sub_template(s: &str) -> Token
[src]
pub fn no_sub_template(s: &str) -> Token
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]
pub fn template_head(s: &str) -> Token
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]
pub fn template_middle(s: &str) -> Token
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]
pub fn template_tail(s: &str) -> Token
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]
pub fn comment(comment: &str, multi: bool) -> Token
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]
impl Token
pub fn is_boolean(&self) -> bool
[src]
pub fn is_boolean(&self) -> bool
pub fn is_boolean_true(&self) -> bool
[src]
pub fn is_boolean_true(&self) -> bool
pub fn is_boolean_false(&self) -> bool
[src]
pub fn is_boolean_false(&self) -> bool
pub fn is_eof(&self) -> bool
[src]
pub fn is_eof(&self) -> bool
pub fn is_ident(&self) -> bool
[src]
pub fn is_ident(&self) -> bool
pub fn is_keyword(&self) -> bool
[src]
pub fn is_keyword(&self) -> bool
pub fn is_strict_reserved(&self) -> bool
[src]
pub fn is_strict_reserved(&self) -> bool
pub fn is_restricted(&self) -> bool
[src]
pub fn is_restricted(&self) -> bool
pub fn is_null(&self) -> bool
[src]
pub fn is_null(&self) -> bool
pub fn is_numeric(&self) -> bool
[src]
pub fn is_numeric(&self) -> bool
pub fn is_hex_literal(&self) -> bool
[src]
pub fn is_hex_literal(&self) -> bool
pub fn is_bin_literal(&self) -> bool
[src]
pub fn is_bin_literal(&self) -> bool
pub fn is_oct_literal(&self) -> bool
[src]
pub fn is_oct_literal(&self) -> bool
pub fn is_punct(&self) -> bool
[src]
pub fn is_punct(&self) -> bool
pub fn is_string(&self) -> bool
[src]
pub fn is_string(&self) -> bool
pub fn is_double_quoted_string(&self) -> bool
[src]
pub fn is_double_quoted_string(&self) -> bool
pub fn is_single_quoted_string(&self) -> bool
[src]
pub fn is_single_quoted_string(&self) -> bool
pub fn is_regex(&self) -> bool
[src]
pub fn is_regex(&self) -> bool
pub fn is_template(&self) -> bool
[src]
pub fn is_template(&self) -> bool
pub fn is_template_no_sub(&self) -> bool
[src]
pub fn is_template_no_sub(&self) -> bool
pub fn is_template_head(&self) -> bool
[src]
pub fn is_template_head(&self) -> bool
pub fn is_template_middle(&self) -> bool
[src]
pub fn is_template_middle(&self) -> bool
pub fn is_template_tail(&self) -> bool
[src]
pub fn is_template_tail(&self) -> bool
pub fn is_literal(&self) -> bool
[src]
pub fn is_literal(&self) -> bool
pub fn is_comment(&self) -> bool
[src]
pub fn is_comment(&self) -> bool
pub fn is_multi_line_comment(&self) -> bool
[src]
pub fn is_multi_line_comment(&self) -> bool
pub fn is_single_line_comment(&self) -> bool
[src]
pub fn is_single_line_comment(&self) -> bool
impl Token
[src]
impl Token
pub fn matches_boolean(&self, b: BooleanLiteral) -> bool
[src]
pub fn matches_boolean(&self, b: BooleanLiteral) -> bool
pub fn matches_boolean_str(&self, b: &str) -> bool
[src]
pub fn matches_boolean_str(&self, b: &str) -> bool
pub fn matches_ident_str(&self, name: &str) -> bool
[src]
pub fn matches_ident_str(&self, name: &str) -> bool
pub fn matches_keyword(&self, keyword: Keyword) -> bool
[src]
pub fn matches_keyword(&self, keyword: Keyword) -> bool
pub fn matches_keyword_str(&self, name: &str) -> bool
[src]
pub fn matches_keyword_str(&self, name: &str) -> bool
pub fn matches_numeric(&self, number: Number) -> bool
[src]
pub fn matches_numeric(&self, number: Number) -> bool
pub fn matches_numeric_str(&self, number: &str) -> bool
[src]
pub fn matches_numeric_str(&self, number: &str) -> bool
pub fn matches_punct(&self, p: Punct) -> bool
[src]
pub fn matches_punct(&self, p: Punct) -> bool
pub fn matches_punct_str(&self, s: &str) -> bool
[src]
pub fn matches_punct_str(&self, s: &str) -> bool
pub fn matches_regex(&self, regex: RegEx) -> bool
[src]
pub fn matches_regex(&self, regex: RegEx) -> bool
pub fn matches_regex_str(&self, regex: &str) -> bool
[src]
pub fn matches_regex_str(&self, regex: &str) -> bool
pub fn matches_comment(&self, comment: Comment) -> bool
[src]
pub fn matches_comment(&self, comment: Comment) -> bool
pub fn matches_comment_str(&self, comment: &str) -> bool
[src]
pub fn matches_comment_str(&self, comment: &str) -> bool
pub fn matches_string_content(&self, content: &str) -> bool
[src]
pub fn matches_string_content(&self, content: &str) -> bool
Trait Implementations
impl Debug for Token
[src]
impl Debug for Token
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl PartialEq for Token
[src]
impl PartialEq for Token
fn eq(&self, other: &Token) -> bool
[src]
fn eq(&self, other: &Token) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Token) -> bool
[src]
fn ne(&self, other: &Token) -> bool
This method tests for !=
.
impl Clone for Token
[src]
impl Clone for Token
fn clone(&self) -> Token
[src]
fn clone(&self) -> Token
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl ToString for Token
[src]
impl ToString for Token