ea7676477ccc7fc6c5fa96d1ff8c8ce417672738
[platform/framework/web/crosswalk-tizen.git] /
1 /**
2  * @fileoverview Contains token information.
3  * @author Nicholas C. Zakas
4  * @copyright 2014 Nicholas C. Zakas. All rights reserved.
5  * @copyright 2013 Thaddee Tyl <thaddee.tyl@gmail.com>
6  * @copyright 2011-2013 Ariya Hidayat <ariya.hidayat@gmail.com>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  *   notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  *   notice, this list of conditions and the following disclaimer in the
15  *   documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 "use strict";
30
31 //------------------------------------------------------------------------------
32 // Requirements
33 //------------------------------------------------------------------------------
34
35 // None!
36
37 //------------------------------------------------------------------------------
38 // Private
39 //------------------------------------------------------------------------------
40
41 var Token = {
42     BooleanLiteral: 1,
43     EOF: 2,
44     Identifier: 3,
45     Keyword: 4,
46     NullLiteral: 5,
47     NumericLiteral: 6,
48     Punctuator: 7,
49     StringLiteral: 8,
50     RegularExpression: 9,
51     Template: 10,
52     JSXIdentifier: 11,
53     JSXText: 12
54 };
55
56 var TokenName = {};
57 TokenName[Token.BooleanLiteral] = "Boolean";
58 TokenName[Token.EOF] = "<end>";
59 TokenName[Token.Identifier] = "Identifier";
60 TokenName[Token.Keyword] = "Keyword";
61 TokenName[Token.NullLiteral] = "Null";
62 TokenName[Token.NumericLiteral] = "Numeric";
63 TokenName[Token.Punctuator] = "Punctuator";
64 TokenName[Token.StringLiteral] = "String";
65 TokenName[Token.RegularExpression] = "RegularExpression";
66 TokenName[Token.Template] = "Template";
67 TokenName[Token.JSXIdentifier] = "JSXIdentifier";
68 TokenName[Token.JSXText] = "JSXText";
69
70 // A function following one of those tokens is an expression.
71 var FnExprTokens = ["(", "{", "[", "in", "typeof", "instanceof", "new",
72                 "return", "case", "delete", "throw", "void",
73                 // assignment operators
74                 "=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", ">>>=",
75                 "&=", "|=", "^=", ",",
76                 // binary/unary operators
77                 "+", "-", "*", "/", "%", "++", "--", "<<", ">>", ">>>", "&",
78                 "|", "^", "!", "~", "&&", "||", "?", ":", "===", "==", ">=",
79                 "<=", "<", ">", "!=", "!=="];
80
81
82 //------------------------------------------------------------------------------
83 // Public
84 //------------------------------------------------------------------------------
85
86 module.exports = {
87     Token: Token,
88     TokenName: TokenName,
89     FnExprTokens: FnExprTokens
90 };