|
|
@ -4,71 +4,73 @@ use std::fmt::{Display, Formatter}; |
|
|
|
use std::str::FromStr; |
|
|
|
use std::str::FromStr; |
|
|
|
use syntax::ast::keyword::Keyword::*; |
|
|
|
use syntax::ast::keyword::Keyword::*; |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, PartialEq)] |
|
|
|
#[derive(Clone, PartialEq, Debug)] |
|
|
|
/// A Javascript Keyword
|
|
|
|
/// A Javascript Keyword
|
|
|
|
pub enum Keyword { |
|
|
|
pub enum Keyword { |
|
|
|
/// The `break` keyword
|
|
|
|
/// The `break` keyword
|
|
|
|
KBreak, |
|
|
|
Break, |
|
|
|
/// The `case` keyword
|
|
|
|
/// The `case` keyword
|
|
|
|
KCase, |
|
|
|
Case, |
|
|
|
/// The `catch` keyword
|
|
|
|
/// The `catch` keyword
|
|
|
|
KCatch, |
|
|
|
Catch, |
|
|
|
/// The `class` keyword, which is reserved for future use
|
|
|
|
/// The `class` keyword, which is reserved for future use
|
|
|
|
KClass, |
|
|
|
Class, |
|
|
|
/// The `continue` keyword
|
|
|
|
/// The `continue` keyword
|
|
|
|
KContinue, |
|
|
|
Continue, |
|
|
|
/// The `debugger` keyword
|
|
|
|
/// The `debugger` keyword
|
|
|
|
KDebugger, |
|
|
|
Debugger, |
|
|
|
/// The `default` keyword
|
|
|
|
/// The `default` keyword
|
|
|
|
KDefault, |
|
|
|
Default, |
|
|
|
/// The `delete` keyword
|
|
|
|
/// The `delete` keyword
|
|
|
|
KDelete, |
|
|
|
Delete, |
|
|
|
/// The `do` keyword
|
|
|
|
/// The `do` keyword
|
|
|
|
KDo, |
|
|
|
Do, |
|
|
|
/// The `else` keyword
|
|
|
|
/// The `else` keyword
|
|
|
|
KElse, |
|
|
|
Else, |
|
|
|
/// The `enum` keyword
|
|
|
|
/// The `enum` keyword
|
|
|
|
KEnum, |
|
|
|
Enum, |
|
|
|
/// The `extends` keyword
|
|
|
|
/// The `extends` keyword
|
|
|
|
KExtends, |
|
|
|
Extends, |
|
|
|
/// The `finally` keyword
|
|
|
|
/// The `finally` keyword
|
|
|
|
KFinally, |
|
|
|
Finally, |
|
|
|
/// The `for` keyword
|
|
|
|
/// The `for` keyword
|
|
|
|
KFor, |
|
|
|
For, |
|
|
|
/// The `function` keyword
|
|
|
|
/// The `function` keyword
|
|
|
|
KFunction, |
|
|
|
Function, |
|
|
|
/// The `if` keyword
|
|
|
|
/// The `if` keyword
|
|
|
|
KIf, |
|
|
|
If, |
|
|
|
/// The `in` keyword
|
|
|
|
/// The `in` keyword
|
|
|
|
KIn, |
|
|
|
In, |
|
|
|
/// The `instanceof` keyword
|
|
|
|
/// The `instanceof` keyword
|
|
|
|
KInstanceOf, |
|
|
|
InstanceOf, |
|
|
|
/// The `import` keyword
|
|
|
|
/// The `import` keyword
|
|
|
|
KImport, |
|
|
|
Import, |
|
|
|
|
|
|
|
/// The `let` keyword
|
|
|
|
|
|
|
|
Let, |
|
|
|
/// The `new` keyword
|
|
|
|
/// The `new` keyword
|
|
|
|
KNew, |
|
|
|
New, |
|
|
|
/// The `return` keyword
|
|
|
|
/// The `return` keyword
|
|
|
|
KReturn, |
|
|
|
Return, |
|
|
|
/// The `super` keyword
|
|
|
|
/// The `super` keyword
|
|
|
|
KSuper, |
|
|
|
Super, |
|
|
|
/// The `switch` keyword
|
|
|
|
/// The `switch` keyword
|
|
|
|
KSwitch, |
|
|
|
Switch, |
|
|
|
/// The `this` keyword
|
|
|
|
/// The `this` keyword
|
|
|
|
KThis, |
|
|
|
This, |
|
|
|
/// The `throw` keyword
|
|
|
|
/// The `throw` keyword
|
|
|
|
KThrow, |
|
|
|
Throw, |
|
|
|
/// The `try` keyword
|
|
|
|
/// The `try` keyword
|
|
|
|
KTry, |
|
|
|
Try, |
|
|
|
/// The `typeof` keyword
|
|
|
|
/// The `typeof` keyword
|
|
|
|
KTypeOf, |
|
|
|
TypeOf, |
|
|
|
/// The `var` keyword
|
|
|
|
/// The `var` keyword
|
|
|
|
KVar, |
|
|
|
Var, |
|
|
|
/// The `void` keyword
|
|
|
|
/// The `void` keyword
|
|
|
|
KVoid, |
|
|
|
Void, |
|
|
|
/// The `while` keyword
|
|
|
|
/// The `while` keyword
|
|
|
|
KWhile, |
|
|
|
While, |
|
|
|
/// The `with` keyword
|
|
|
|
/// The `with` keyword
|
|
|
|
KWith, |
|
|
|
With, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)] |
|
|
|
#[derive(Debug, Clone)] |
|
|
@ -94,37 +96,38 @@ impl FromStr for Keyword { |
|
|
|
type Err = KeywordError; |
|
|
|
type Err = KeywordError; |
|
|
|
fn from_str(s: &str) -> Result<Keyword, Self::Err> { |
|
|
|
fn from_str(s: &str) -> Result<Keyword, Self::Err> { |
|
|
|
match s { |
|
|
|
match s { |
|
|
|
"break" => Ok(KBreak), |
|
|
|
"break" => Ok(Break), |
|
|
|
"case" => Ok(KCase), |
|
|
|
"case" => Ok(Case), |
|
|
|
"catch" => Ok(KCatch), |
|
|
|
"catch" => Ok(Catch), |
|
|
|
"class" => Ok(KClass), |
|
|
|
"class" => Ok(Class), |
|
|
|
"continue" => Ok(KContinue), |
|
|
|
"continue" => Ok(Continue), |
|
|
|
"debugger" => Ok(KDebugger), |
|
|
|
"debugger" => Ok(Debugger), |
|
|
|
"default" => Ok(KDefault), |
|
|
|
"default" => Ok(Default), |
|
|
|
"delete" => Ok(KDelete), |
|
|
|
"delete" => Ok(Delete), |
|
|
|
"do" => Ok(KDo), |
|
|
|
"do" => Ok(Do), |
|
|
|
"else" => Ok(KElse), |
|
|
|
"else" => Ok(Else), |
|
|
|
"enum" => Ok(KEnum), |
|
|
|
"enum" => Ok(Enum), |
|
|
|
"extends" => Ok(KExtends), |
|
|
|
"extends" => Ok(Extends), |
|
|
|
"finally" => Ok(KFinally), |
|
|
|
"finally" => Ok(Finally), |
|
|
|
"for" => Ok(KFor), |
|
|
|
"for" => Ok(For), |
|
|
|
"function" => Ok(KFunction), |
|
|
|
"function" => Ok(Function), |
|
|
|
"if" => Ok(KIf), |
|
|
|
"if" => Ok(If), |
|
|
|
"in" => Ok(KIn), |
|
|
|
"in" => Ok(In), |
|
|
|
"instanceof" => Ok(KInstanceOf), |
|
|
|
"instanceof" => Ok(InstanceOf), |
|
|
|
"import" => Ok(KImport), |
|
|
|
"import" => Ok(Import), |
|
|
|
"new" => Ok(KNew), |
|
|
|
"let" => Ok(Let), |
|
|
|
"return" => Ok(KReturn), |
|
|
|
"new" => Ok(New), |
|
|
|
"super" => Ok(KSuper), |
|
|
|
"return" => Ok(Return), |
|
|
|
"switch" => Ok(KSwitch), |
|
|
|
"super" => Ok(Super), |
|
|
|
"this" => Ok(KThis), |
|
|
|
"switch" => Ok(Switch), |
|
|
|
"throw" => Ok(KThrow), |
|
|
|
"this" => Ok(This), |
|
|
|
"try" => Ok(KTry), |
|
|
|
"throw" => Ok(Throw), |
|
|
|
"typeof" => Ok(KTypeOf), |
|
|
|
"try" => Ok(Try), |
|
|
|
"var" => Ok(KVar), |
|
|
|
"typeof" => Ok(TypeOf), |
|
|
|
"void" => Ok(KVoid), |
|
|
|
"var" => Ok(Var), |
|
|
|
"while" => Ok(KWhile), |
|
|
|
"void" => Ok(Void), |
|
|
|
"with" => Ok(KWith), |
|
|
|
"while" => Ok(While), |
|
|
|
|
|
|
|
"with" => Ok(With), |
|
|
|
_ => Err(KeywordError), |
|
|
|
_ => Err(KeywordError), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -135,37 +138,38 @@ impl Display for Keyword { |
|
|
|
f, |
|
|
|
f, |
|
|
|
"{}", |
|
|
|
"{}", |
|
|
|
match *self { |
|
|
|
match *self { |
|
|
|
KBreak => "break", |
|
|
|
Break => "break", |
|
|
|
KCase => "case", |
|
|
|
Case => "case", |
|
|
|
KCatch => "catch", |
|
|
|
Catch => "catch", |
|
|
|
KClass => "class", |
|
|
|
Class => "class", |
|
|
|
KContinue => "continue", |
|
|
|
Continue => "continue", |
|
|
|
KDebugger => "debugger", |
|
|
|
Debugger => "debugger", |
|
|
|
KDefault => "default", |
|
|
|
Default => "default", |
|
|
|
KDelete => "delete", |
|
|
|
Delete => "delete", |
|
|
|
KDo => "do", |
|
|
|
Do => "do", |
|
|
|
KElse => "else", |
|
|
|
Else => "else", |
|
|
|
KEnum => "enum", |
|
|
|
Enum => "enum", |
|
|
|
KExtends => "extends", |
|
|
|
Extends => "extends", |
|
|
|
KFinally => "finally", |
|
|
|
Finally => "finally", |
|
|
|
KFor => "for", |
|
|
|
For => "for", |
|
|
|
KFunction => "function", |
|
|
|
Function => "function", |
|
|
|
KIf => "if", |
|
|
|
If => "if", |
|
|
|
KIn => "in", |
|
|
|
In => "in", |
|
|
|
KInstanceOf => "instanceof", |
|
|
|
InstanceOf => "instanceof", |
|
|
|
KImport => "import", |
|
|
|
Import => "import", |
|
|
|
KNew => "new", |
|
|
|
Let => "let", |
|
|
|
KReturn => "return", |
|
|
|
New => "new", |
|
|
|
KSuper => "super", |
|
|
|
Return => "return", |
|
|
|
KSwitch => "switch", |
|
|
|
Super => "super", |
|
|
|
KThis => "this", |
|
|
|
Switch => "switch", |
|
|
|
KThrow => "throw", |
|
|
|
This => "this", |
|
|
|
KTry => "try", |
|
|
|
Throw => "throw", |
|
|
|
KTypeOf => "typeof", |
|
|
|
Try => "try", |
|
|
|
KVar => "var", |
|
|
|
TypeOf => "typeof", |
|
|
|
KVoid => "void", |
|
|
|
Var => "var", |
|
|
|
KWhile => "while", |
|
|
|
Void => "void", |
|
|
|
KWith => "with", |
|
|
|
While => "while", |
|
|
|
|
|
|
|
With => "with", |
|
|
|
} |
|
|
|
} |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|