~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/pagespeed/kernel/js/js_keywords.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2011 Google Inc. All Rights Reserved.
2
 
//
3
 
// Licensed under the Apache License, Version 2.0 (the "License");
4
 
// you may not use this file except in compliance with the License.
5
 
// You may obtain a copy of the License at
6
 
//
7
 
//      http://www.apache.org/licenses/LICENSE-2.0
8
 
//
9
 
// Unless required by applicable law or agreed to in writing, software
10
 
// distributed under the License is distributed on an "AS IS" BASIS,
11
 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 
// See the License for the specific language governing permissions and
13
 
// limitations under the License.
14
 
//
15
 
// Author: jmarantz@google.com
16
 
//
17
 
// This is based on third_party/libpagespeed/src/pagespeed/js/js_minify.cc by
18
 
// mdsteele@google.com
19
 
 
20
 
#ifndef PAGESPEED_KERNEL_JS_JS_KEYWORDS_H_
21
 
#define PAGESPEED_KERNEL_JS_JS_KEYWORDS_H_
22
 
 
23
 
#include "pagespeed/kernel/base/string_util.h"
24
 
 
25
 
namespace net_instaweb {
26
 
  class JsLexer;
27
 
}
28
 
 
29
 
namespace pagespeed {
30
 
 
31
 
class JsKeywords {
32
 
 public:
33
 
  enum Type {
34
 
    // literals
35
 
    kNull,
36
 
    kTrue,
37
 
    kFalse,
38
 
 
39
 
    // keywords
40
 
    kBreak,
41
 
    kCase,
42
 
    kCatch,
43
 
    kConst,
44
 
    kDefault,
45
 
    kFinally,
46
 
    kFor,
47
 
    kInstanceof,
48
 
    kNew,
49
 
    kVar,
50
 
    kContinue,
51
 
    kFunction,
52
 
    kReturn,
53
 
    kVoid,
54
 
    kDelete,
55
 
    kIf,
56
 
    kThis,
57
 
    kDo,
58
 
    kWhile,
59
 
    kElse,
60
 
    kIn,
61
 
    kSwitch,
62
 
    kThrow,
63
 
    kTry,
64
 
    kTypeof,
65
 
    kWith,
66
 
    kDebugger,
67
 
 
68
 
    // reserved for future use
69
 
    kClass,
70
 
    kEnum,
71
 
    kExport,
72
 
    kExtends,
73
 
    kImport,
74
 
    kSuper,
75
 
 
76
 
    // reserved for future use in strict code
77
 
    kImplements,
78
 
    kInterface,
79
 
    kLet,
80
 
    kPackage,
81
 
    kPrivate,
82
 
    kProtected,
83
 
    kPublic,
84
 
    kStatic,
85
 
    kYield,
86
 
 
87
 
    // Sentinel value for gperf.
88
 
    kNotAKeyword,
89
 
 
90
 
    // Other types of lexical tokens; returned by lexer, but not gperf.
91
 
    kComment,        // A block or line comment (not including the linebreak).
92
 
    kWhitespace,     // Whitespace not containing any linebreaks.
93
 
    kLineSeparator,  // Whitespace with linebreaks, but no semicolon insertion.
94
 
    kSemiInsert,     // Whitespace that triggers semicolon insertion.
95
 
    kRegex,          // A regex literal, such as /foo/i or /a+b*/
96
 
    kStringLiteral,  // A string literal, such as 'foo' or "bar"
97
 
    kNumber,         // A numeric literal, such as 3.5 or 017 or .2e+10
98
 
    kOperator,       // An operator or symbol, such as && or <<= or (
99
 
    kIdentifier,     // An identifier (variable name, label, etc).
100
 
    kEndOfInput,     // End of input was reached without errors.
101
 
    kError           // A syntax error occurred.
102
 
  };
103
 
 
104
 
  static bool IsAKeyword(Type type) { return type < kNotAKeyword; }
105
 
 
106
 
  // Returns true if name is a javascript keyword that can precede a regular
107
 
  // expression. Keywords such as 'return' and 'throw' can precede a regex '/'
108
 
  // but keywords such as 'while' cannot.
109
 
  static bool CanKeywordPrecedeRegEx(const StringPiece& name);
110
 
 
111
 
  enum Flag {
112
 
    kNone,
113
 
    kIsValue,
114
 
    kIsReservedNonStrict,
115
 
    kIsReservedStrict,
116
 
    kCanPrecedeRegEx  // keywords that can be placed directly before a regex
117
 
  };
118
 
 
119
 
  // Finds a Keyword based on a keyword string.  If not found, returns
120
 
  // kNotAKeyword.  Otherwise, this always returns a Type for which
121
 
  // IsAKeyword is true.
122
 
  static Type Lookup(const StringPiece& name, Flag* flag);
123
 
 
124
 
  // Limited iterator (not an STL iterator).  Example usage:
125
 
  //    for (JsKeywords::Iterator iter; !iter.AtEnd(); iter.Next()) {
126
 
  //      use(iter.keyword(), iter.name());
127
 
  //    }
128
 
  class Iterator {
129
 
   public:
130
 
    Iterator() : index_(-1) { Next(); }
131
 
    bool AtEnd() const;
132
 
    void Next();
133
 
    Type keyword() const;
134
 
    const char* name() const;
135
 
 
136
 
   private:
137
 
    int index_;
138
 
 
139
 
    // Implicit copy and assign ok.  The members can be safely copied by bits.
140
 
  };
141
 
 
142
 
 private:
143
 
  // TODO(jkarlin): Get rid of the net_instaweb namespace once JsLexer is
144
 
  // moved into kernel/js.
145
 
  friend class net_instaweb::JsLexer;
146
 
 
147
 
  // Returns the number of keywords recognized by the Lookup function.  This is
148
 
  // used by the Lexer to size the keyword-sring array prior to iterating over
149
 
  // the keywords to populate it.
150
 
  static int num_keywords();
151
 
};
152
 
 
153
 
}  // namespace pagespeed
154
 
 
155
 
#endif  // PAGESPEED_KERNEL_JS_JS_KEYWORDS_H_