amazon-dax-client-sdkv3
Version:
Amazon DAX Client for JavaScript
1 lines • 1.35 MB
Source Map (JSON)
{"version":3,"sources":["../src/DaxClientError.ts","../src/DaxErrorCode.ts","../src/Util.ts","../src/Cache.ts","../node_modules/antlr4/Utils.js","../node_modules/antlr4/Token.js","../node_modules/antlr4/atn/ATNState.js","../node_modules/antlr4/atn/SemanticContext.js","../node_modules/antlr4/atn/ATNConfig.js","../node_modules/antlr4/IntervalSet.js","../node_modules/antlr4/atn/Transition.js","../node_modules/antlr4/tree/Tree.js","../node_modules/antlr4/ParserRuleContext.js","../node_modules/antlr4/tree/Trees.js","../node_modules/antlr4/RuleContext.js","../node_modules/antlr4/PredictionContext.js","../node_modules/antlr4/LL1Analyzer.js","../node_modules/antlr4/atn/ATN.js","../node_modules/antlr4/atn/ATNType.js","../node_modules/antlr4/atn/ATNDeserializationOptions.js","../node_modules/antlr4/atn/LexerAction.js","../node_modules/antlr4/atn/ATNDeserializer.js","../node_modules/antlr4/error/ErrorListener.js","../node_modules/antlr4/Recognizer.js","../node_modules/antlr4/CommonTokenFactory.js","../node_modules/antlr4/error/Errors.js","../node_modules/antlr4/Lexer.js","../node_modules/antlr4/atn/ATNConfigSet.js","../node_modules/antlr4/dfa/DFAState.js","../node_modules/antlr4/atn/ATNSimulator.js","../node_modules/antlr4/atn/LexerActionExecutor.js","../node_modules/antlr4/atn/LexerATNSimulator.js","../node_modules/antlr4/atn/PredictionMode.js","../node_modules/antlr4/atn/ParserATNSimulator.js","../node_modules/antlr4/atn/index.js","../node_modules/antlr4/polyfills/codepointat.js","../node_modules/antlr4/dfa/DFASerializer.js","../node_modules/antlr4/dfa/DFA.js","../node_modules/antlr4/dfa/index.js","../node_modules/antlr4/polyfills/fromcodepoint.js","../node_modules/antlr4/tree/index.js","../node_modules/antlr4/error/DiagnosticErrorListener.js","../node_modules/antlr4/error/ErrorStrategy.js","../node_modules/antlr4/error/index.js","../node_modules/antlr4/InputStream.js","../node_modules/antlr4/CharStreams.js","../node_modules/antlr4/FileStream.js","../node_modules/antlr4/BufferedTokenStream.js","../node_modules/antlr4/CommonTokenStream.js","../node_modules/antlr4/Parser.js","../node_modules/antlr4/index.js","../src/DynamoDbGrammarListener.ts","../src/Constants.ts","../src/AmazonDaxClient.ts","../src/SessionVersion.ts","../src/Backend.ts","../src/Router.ts","../src/DaxHealthAgent.ts","../src/Source.ts","../src/CborEncoder.ts","../src/ByteStreamBuffer.ts","../src/CborTypes.ts","../src/BigDecimal.ts","../src/Tube.ts","../src/SigV4Gen.ts","../src/ControllablePromise.ts","../src/Cluster.ts","../src/SimpleCache.ts","../src/RefreshingCache.ts","../src/BaseOperations.ts","../src/Encoders.ts","../src/AttributeValueEncoder.ts","../src/LexDecimal.ts","../src/DaxCborTypes.ts","../src/CborSExprGenerator.ts","../src/AbstractTwoStageExpressionParser.ts","../src/DynamoDbGrammarLexer.ts","../src/DynamoDbGrammarParser.ts","../src/ProjectionExpressionParser.ts","../src/ConditionExpressionParser.ts","../src/UpdateExpressionParser.ts","../src/DynamoDbExpressionParser.ts","../src/ExpressionErrorListener.ts","../src/DocumentPath.ts","../src/DaxServiceError.ts","../src/RequestValidator.ts","../src/Stubs.ts","../src/Assembler.ts","../src/CborDecoder.ts","../src/CborSkipper.ts","../src/DaxCborDecoder.ts","../src/ItemBuilder.ts","../src/CustomAssemblers.ts","../src/DynamoDBV1Converter.ts","../src/Operations.ts","../src/DaxClient.ts"],"sourcesContent":["/*\n * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"). You may not\n * use this file except in compliance with the License. A copy of the License\n * is located at\n *\n * http://aws.amazon.com/apache2.0/\n *\n * or in the \"license\" file accompanying this file. This file is distributed on\n * an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\n'use strict';\n\n/*\n * Used for any errors detected in the client side\n*/\nexport class DaxClientError extends Error {\n time: number;\n code: any;\n retryable: any;\n requestId: any;\n statusCode: any;\n _tubeInvalid: boolean;\n waitForRecoveryBeforeRetrying: boolean;\n constructor(message: any, code?: any, retryable?: any, requestId?: any, statusCode?: any) {\n super(message);\n this.time = Date.now();\n this.code = code;\n this.retryable = retryable === undefined ? true : retryable;\n this.requestId = requestId === undefined ? null : requestId;\n this.statusCode = statusCode === undefined ? -1 : statusCode;\n this._tubeInvalid = false;\n this.waitForRecoveryBeforeRetrying = false;\n\n this.message = DaxClientError._formatMessage(code, message);\n }\n\n static _formatMessage(code: any, message: any) {\n return !code || message.startsWith(code) ? message : code + ': ' + message;\n }\n}\n","/*\n * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"). You may not\n * use this file except in compliance with the License. A copy of the License\n * is located at\n *\n * http://aws.amazon.com/apache2.0/\n *\n * or in the \"license\" file accompanying this file. This file is distributed on\n * an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\n'use strict';\n\nexport const DaxErrorCode = {\n Decoder: 'DecoderException',\n Encoder: 'EncoderException',\n Unrecognized: 'UnrecognizedClientException',\n Authentication: 'MissingAuthenticationTokenException',\n MalformedResult: 'MalformedResultException',\n EndOfStream: 'EndOfStreamException',\n IllegalArgument: 'IllegalArgumentException',\n Validation: 'ValidationException',\n NoRoute: 'NoRouteException',\n ResourceNotFound: 'ResourceNotFoundException',\n ResourceInUse: 'ResourceInUseException',\n ProvisionedThroughputExceeded: 'ProvisionedThroughputExceededException',\n ConditionalCheckFailed: 'ConditionalCheckFailedException',\n InternalServerError: 'InternalServerErrorException',\n ItemCollectionSizeLimitExceeded: 'ItemCollectionSizeLimitExceededException',\n LimitExceeded: 'LimitExceededException',\n RequestLimitExceeded: 'RequestLimitExceeded',\n Throttling: 'ThrottlingException',\n Connection: 'ConnectionException',\n};\n","/*\n * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"). You may not\n * use this file except in compliance with the License. A copy of the License\n * is located at\n *\n * http://aws.amazon.com/apache2.0/\n *\n * or in the \"license\" file accompanying this file. This file is distributed on\n * an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\n'use strict';\nconst ALPHABET = '0123456789abcdef';\nimport { Buffer } from 'buffer';\nimport { DaxClientError } from './DaxClientError'\nimport { DaxErrorCode } from './DaxErrorCode'\n\nexport const ENCRYPTED_SCHEME = 'daxs';\nexport const UNENCRYPTED_SCHEME = 'dax';\nconst SCHEMES_TO_PORTS = { [UNENCRYPTED_SCHEME]: 8111, [ENCRYPTED_SCHEME]: 9111 };\n\nexport class Util {\n static convertBase(str, baseIn, baseOut) {\n if (str[0] === '-') {\n str = str.slice(1);\n }\n let j;\n let arr = [0];\n let arrL;\n let i = 0;\n let len = str.length;\n\n for (; i < len;) {\n for (arrL = arr.length; arrL--; arr[arrL] *= baseIn) {\n\n }\n arr[j = 0] += ALPHABET.indexOf(str[i++]);\n\n for (; j < arr.length; j++) {\n if (arr[j] > baseOut - 1) {\n if (arr[j + 1] == null) {\n arr[j + 1] = 0;\n }\n arr[j + 1] += arr[j] / baseOut | 0;\n arr[j] %= baseOut;\n }\n }\n }\n\n let outstr = '';\n for (i = arr.length - 1; i >= 0; --i) {\n outstr += ALPHABET[arr[i]];\n }\n if (baseOut === 16) { // to hex then has to have certain length\n switch (true) {\n case outstr.length <= 2:\n outstr = '0'.repeat(2 - outstr.length) + outstr;\n break;\n case outstr.length <= 4:\n outstr = '0'.repeat(4 - outstr.length) + outstr;\n break;\n case outstr.length <= 8:\n outstr = '0'.repeat(8 - outstr.length) + outstr;\n break;\n case outstr.length <= 16:\n outstr = '0'.repeat(16 - outstr.length) + outstr;\n break;\n default:\n outstr = ((outstr.length % 2) ? '0' : '') + outstr;\n }\n }\n return outstr;\n }\n\n static parseHostPorts(hostports) {\n if (hostports == null || hostports == '') {\n throw new DaxClientError('Provide a Cluster Discovery Endpoint to connect.');\n }\n\n // Handle the case of a single string\n if (typeof hostports === 'string') {\n return [Util.parseHostPort(hostports)];\n }\n\n let addrs: { host: any, scheme: any, port: number }[] = [];\n for (let hostport of hostports) {\n addrs.push(Util.parseHostPort(hostport));\n }\n\n const schemesInAddrs = addrs.map((addr) => addr.scheme);\n const daxScheme = schemesInAddrs[0];\n const areAllSchemesTheSame = schemesInAddrs.every((scheme) => scheme == daxScheme);\n if (!areAllSchemesTheSame) {\n throw new DaxClientError('Inconsistency between the schemes of provided endpoints.', DaxErrorCode.IllegalArgument, false);\n }\n\n if (daxScheme == ENCRYPTED_SCHEME && addrs != null && addrs.length >= 2) {\n throw new DaxClientError('Only one encrypted endpoint URL is allowed.');\n }\n\n return addrs;\n }\n\n static parseHostPort(hostport: any) {\n let url;\n\n if (hostport.indexOf('://') == -1) { // url has no scheme\n if (hostport.indexOf(':') == -1) { // url has no port\n throw new DaxClientError('Invalid hostport: ' + hostport, DaxErrorCode.IllegalArgument, false);\n }\n // This scheme assumption exists to support legacy <host>:<port> endpoints.\n hostport = `${UNENCRYPTED_SCHEME}://${hostport}`;\n }\n\n try {\n url = new URL(hostport);\n } catch (error) {\n throw new DaxClientError('Invalid hostport: ' + hostport, DaxErrorCode.IllegalArgument, false);\n }\n\n const host = url.hostname;\n let port = url.port;\n const scheme = url.protocol.replace(':', ''); // changes `daxs:` to `daxs`\n\n if (!Object.keys(SCHEMES_TO_PORTS).includes(scheme)) {\n throw new DaxClientError('URL scheme must be one of: ' + Object.keys(SCHEMES_TO_PORTS), DaxErrorCode.IllegalArgument, false);\n }\n\n if (port == '' || port == null) {\n port = SCHEMES_TO_PORTS[scheme];\n }\n\n return { host: host, port: parseInt(port), scheme: scheme };\n }\n\n static objEqual(a, b) {\n // Create arrays of property names\n if (!a || !b) {\n return a === b;\n }\n\n if (typeof (a) === typeof (b)) {\n // handle primitive types using native equality\n switch (typeof (a)) {\n case 'string':\n case 'number':\n case 'boolean':\n return a === b;\n }\n }\n\n let aProps = Object.getOwnPropertyNames(a);\n let bProps = Object.getOwnPropertyNames(b);\n\n // If number of properties is different,\n // objects are not equivalent\n if (aProps.length != bProps.length) {\n return false;\n }\n\n for (let i = 0; i < aProps.length; i++) {\n let propName = aProps[i];\n\n // If values of same property are not equal,\n // objects are not equivalent\n if (typeof a[propName] === 'object') {\n if (!Util.objEqual(a[propName], b[propName])) {\n return false;\n }\n } else if (a[propName] !== b[propName]) {\n return false;\n }\n }\n\n // If we made it this far, objects\n // are considered equivalent\n return true;\n }\n\n // compare two Lists\n static arrayEquals(lista, listb) {\n if (lista.length !== listb.length) {\n return false;\n }\n let usedIndex = new Set();\n for (let i = 0; i < lista.length; ++i) {\n let equal = false;\n for (let j = 0; j < listb.length; ++j) {\n if (!usedIndex.has(j) && Util.objEqual(lista[i], listb[j])) {\n equal = true;\n usedIndex.add(j);\n break;\n }\n }\n if (!equal) {\n return false;\n }\n }\n return true;\n }\n\n // compare two sorted Lists\n static sortedArrayEquals(lista, listb) {\n if (lista.length !== listb.length) {\n return false;\n }\n\n for (let i = 0; i < lista.length; ++i) {\n if (!Util.objEqual(lista[i], listb[i])) {\n return false;\n }\n }\n\n return true;\n }\n\n static objArrayEquals(a, b) {\n // Create arrays of property names\n if (!a || !b) {\n return a === b;\n }\n\n if (typeof (a) === typeof (b)) {\n // handle primitive types using native equality\n switch (typeof (a)) {\n case 'string':\n case 'number':\n case 'boolean':\n return a === b;\n }\n }\n\n let aProps = Object.getOwnPropertyNames(a);\n let bProps = Object.getOwnPropertyNames(b);\n\n // If number of properties is different,\n // objects are not equivalent\n if (aProps.length != bProps.length) {\n return false;\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n return Util.arrayEquals(a, b);\n }\n\n for (let i = 0; i < aProps.length; i++) {\n let propName = aProps[i];\n\n // If values of same property are not equal,\n // objects are not equivalent\n if (typeof a[propName] === 'object') {\n if (!Util.objArrayEquals(a[propName], b[propName])) {\n return false;\n }\n } else if (a[propName] !== b[propName]) {\n return false;\n }\n }\n\n // If we made it this far, objects\n // are considered equivalent\n return true;\n }\n\n static deepCopy(obj) {\n if (obj === undefined || obj === null || typeof (obj) !== 'object') {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((e) => Util.deepCopy(e));\n }\n\n if (Buffer.isBuffer(obj)) {\n return Buffer.from(obj);\n }\n\n let clone = {};\n for (let prop in obj) {\n if (obj.hasOwnProperty(prop)) {\n clone[prop] = Util.deepCopy(obj[prop]);\n }\n }\n\n return clone;\n }\n\n static serviceEndpointFrom(nodeId, hostname, address, port, role, zone, leaderSessionId) {\n return { nodeId: nodeId, hostname: hostname, address: address, port: port, role: role, zone: zone, leaderSessionId: leaderSessionId };\n }\n\n static deanonymizeAttributeValues(item, attrNames) {\n let attrValues = item._anonymousAttributeValues;\n\n // For projected attr lists (PutItem UPDATED_NEW/UPDATED_OLD) _anonymousAttributeValues is a sparse array\n // (i.e. if only 1 attribute is present the array would [, \"value\", ] or similar).\n // So we want to iterate over the present indices only\n // A rare case where for...in on an array is exactly what is needed\n attrValues.forEach((attrValue, index) => {\n item[attrNames[index]] = attrValue;\n });\n\n delete item._anonymousAttributeValues;\n delete item._attrListId;\n return item;\n }\n\n static extractKey(item, tableKeys) {\n let keys = {};\n for (let keyDef of tableKeys) {\n let keyName = keyDef.AttributeName;\n keys[keyName] = item[keyName];\n }\n return keys;\n }\n}\n","/*\n * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"). You may not\n * use this file except in compliance with the License. A copy of the License\n * is located at\n *\n * http://aws.amazon.com/apache2.0/\n *\n * or in the \"license\" file accompanying this file. This file is distributed on\n * an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n * express or implied. See the License for the specific language governing\n * permissions and limitations under the License.\n */\n'use strict';\n\nimport { Util } from './Util';\n\nexport class CacheFactory {\n static create(CacheType, size) {\n if (!CacheType) {\n throw new Error('not support Cache type');\n }\n return new CacheType();\n }\n}\n\nexport class Cache {\n _size: any;\n _cache: {};\n // plain object cache\n constructor(size) {\n this._size = size;\n this._cache = {};\n }\n\n get(key) {\n return this._cache[key];\n }\n\n put(key, val) {\n let old = this._cache[key];\n this._cache[key] = val;\n return old;\n }\n\n remove(key) {\n delete this._cache[key];\n }\n}\n\nexport class StringListCache {\n _size: any;\n _cache: {};\n // internal storage structure { _hash: [ [key, value], ...] }\n // when insert an string-list key into JS object, it will automatically\n // convert into string seperated by comma e.g. ['1', '2'] => '1,2'\n // to solve the conflicts we have to store its real value\n // For performance, arrays are compared as if they are sorted\n constructor(size) {\n this._size = size;\n this._cache = {};\n }\n\n _hash(key) {\n return key.toString();\n }\n\n get(key) {\n let keyValuePairs = this._cache[this._hash(key)];\n if (!keyValuePairs) {\n return null;\n }\n // compare real key\n for (let keyValuePair of keyValuePairs) {\n let storedKey = keyValuePair[0];\n if (Util.sortedArrayEquals(key, storedKey)) {\n // if we agree on sort first then check cache, we can use in order compare, which will save a lot\n return keyValuePair[1];\n }\n }\n // pairs is empty array\n return null;\n }\n\n put(key, val) {\n let old = this.get(key);\n let hashedKey = this._hash(key);\n if (!this._cache[hashedKey]) {\n this._cache[hashedKey] = [];\n }\n let keyValuePairs = this._cache[hashedKey];\n if (old !== null && old !== undefined) {\n for (let pair of keyValuePairs) {\n if (Util.sortedArrayEquals(pair[0], key)) {\n pair[1] = val;\n return old;\n }\n }\n }\n keyValuePairs.push([key, val]);\n return old;\n }\n\n remove(key) {\n let hashKey = this._hash(key);\n let keyValuePairs = this._cache[hashKey];\n if (keyValuePairs) {\n for (let i = 0; i < keyValuePairs.length; ++i) {\n let pair = keyValuePairs[i];\n if (Util.sortedArrayEquals(pair[0], key)) {\n // delete this entry\n this._cache[hashKey].splice(i, 1);\n return;\n }\n }\n }\n }\n}\n\nexport const CacheType = {\n Cache: Cache,\n StringListCache: StringListCache,\n};","/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.\n * Use of this file is governed by the BSD 3-clause license that\n * can be found in the LICENSE.txt file in the project root.\n */\n\nfunction arrayToString(a) {\n return \"[\" + a.join(\", \") + \"]\";\n}\n\nString.prototype.seed = String.prototype.seed || Math.round(Math.random() * Math.pow(2, 32));\n\nString.prototype.hashCode = function () {\n var remainder, bytes, h1, h1b, c1, c1b, c2, c2b, k1, i,\n key = this.toString();\n\n remainder = key.length & 3; // key.length % 4\n bytes = key.length - remainder;\n h1 = String.prototype.seed;\n c1 = 0xcc9e2d51;\n c2 = 0x1b873593;\n i = 0;\n\n while (i < bytes) {\n k1 =\n ((key.charCodeAt(i) & 0xff)) |\n ((key.charCodeAt(++i) & 0xff) << 8) |\n ((key.charCodeAt(++i) & 0xff) << 16) |\n ((key.charCodeAt(++i) & 0xff) << 24);\n ++i;\n\n k1 = ((((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16))) & 0xffffffff;\n k1 = (k1 << 15) | (k1 >>> 17);\n k1 = ((((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16))) & 0xffffffff;\n\n h1 ^= k1;\n h1 = (h1 << 13) | (h1 >>> 19);\n h1b = ((((h1 & 0xffff) * 5) + ((((h1 >>> 16) * 5) & 0xffff) << 16))) & 0xffffffff;\n h1 = (((h1b & 0xffff) + 0x6b64) + ((((h1b >>> 16) + 0xe654) & 0xffff) << 16));\n }\n\n k1 = 0;\n\n switch (remainder) {\n case 3:\n k1 ^= (key.charCodeAt(i + 2) & 0xff) << 16;\n case 2:\n k1 ^= (key.charCodeAt(i + 1) & 0xff) << 8;\n case 1:\n k1 ^= (key.charCodeAt(i) & 0xff);\n\n k1 = (((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16)) & 0xffffffff;\n k1 = (k1 << 15) | (k1 >>> 17);\n k1 = (((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16)) & 0xffffffff;\n h1 ^= k1;\n }\n\n h1 ^= key.length;\n\n h1 ^= h1 >>> 16;\n h1 = (((h1 & 0xffff) * 0x85ebca6b) + ((((h1 >>> 16) * 0x85ebca6b) & 0xffff) << 16)) & 0xffffffff;\n h1 ^= h1 >>> 13;\n h1 = ((((h1 & 0xffff) * 0xc2b2ae35) + ((((h1 >>> 16) * 0xc2b2ae35) & 0xffff) << 16))) & 0xffffffff;\n h1 ^= h1 >>> 16;\n\n return h1 >>> 0;\n};\n\nfunction standardEqualsFunction(a, b) {\n return a.equals(b);\n}\n\nfunction standardHashCodeFunction(a) {\n return a.hashCode();\n}\n\nfunction Set(hashFunction, equalsFunction) {\n this.data = {};\n this.hashFunction = hashFunction || standardHashCodeFunction;\n this.equalsFunction = equalsFunction || standardEqualsFunction;\n return this;\n}\n\nObject.defineProperty(Set.prototype, \"length\", {\n get: function () {\n var l = 0;\n for (var key in this.data) {\n if (key.indexOf(\"hash_\") === 0) {\n l = l + this.data[key].length;\n }\n }\n return l;\n }\n});\n\nSet.prototype.add = function (value) {\n var hash = this.hashFunction(value);\n var key = \"hash_\" + hash;\n if (key in this.data) {\n var values = this.data[key];\n for (var i = 0; i < values.length; i++) {\n if (this.equalsFunction(value, values[i])) {\n return values[i];\n }\n }\n values.push(value);\n return value;\n } else {\n this.data[key] = [value];\n return value;\n }\n};\n\nSet.prototype.contains = function (value) {\n return this.get(value) != null;\n};\n\nSet.prototype.get = function (value) {\n var hash = this.hashFunction(value);\n var key = \"hash_\" + hash;\n if (key in this.data) {\n var values = this.data[key];\n for (var i = 0; i < values.length; i++) {\n if (this.equalsFunction(value, values[i])) {\n return values[i];\n }\n }\n }\n return null;\n};\n\nSet.prototype.values = function () {\n var l = [];\n for (var key in this.data) {\n if (key.indexOf(\"hash_\") === 0) {\n l = l.concat(this.data[key]);\n }\n }\n return l;\n};\n\nSet.prototype.toString = function () {\n return arrayToString(this.values());\n};\n\nfunction BitSet() {\n this.data = [];\n return this;\n}\n\nBitSet.prototype.add = function (value) {\n this.data[value] = true;\n};\n\nBitSet.prototype.or = function (set) {\n var bits = this;\n Object.keys(set.data).map(function (alt) {\n bits.add(alt);\n });\n};\n\nBitSet.prototype.remove = function (value) {\n delete this.data[value];\n};\n\nBitSet.prototype.contains = function (value) {\n return this.data[value] === true;\n};\n\nBitSet.prototype.values = function () {\n return Object.keys(this.data);\n};\n\nBitSet.prototype.minValue = function () {\n return Math.min.apply(null, this.values());\n};\n\nBitSet.prototype.hashCode = function () {\n var hash = new Hash();\n hash.update(this.values());\n return hash.finish();\n};\n\nBitSet.prototype.equals = function (other) {\n if (!(other instanceof BitSet)) {\n return false;\n }\n return this.hashCode() === other.hashCode();\n};\n\nObject.defineProperty(BitSet.prototype, \"length\", {\n get: function () {\n return this.values().length;\n }\n});\n\nBitSet.prototype.toString = function () {\n return \"{\" + this.values().join(\", \") + \"}\";\n};\n\nfunction Map(hashFunction, equalsFunction) {\n this.data = {};\n this.hashFunction = hashFunction || standardHashCodeFunction;\n this.equalsFunction = equalsFunction || standardEqualsFunction;\n return this;\n}\n\nObject.defineProperty(Map.prototype, \"length\", {\n get: function () {\n var l = 0;\n for (var hashKey in this.data) {\n if (hashKey.indexOf(\"hash_\") === 0) {\n l = l + this.data[hashKey].length;\n }\n }\n return l;\n }\n});\n\nMap.prototype.put = function (key, value) {\n var hashKey = \"hash_\" + this.hashFunction(key);\n if (hashKey in this.data) {\n var entries = this.data[hashKey];\n for (var i = 0; i < entries.length; i++) {\n var entry = entries[i];\n if (this.equalsFunction(key, entry.key)) {\n var oldValue = entry.value;\n entry.value = value;\n return oldValue;\n }\n }\n entries.push({key:key, value:value});\n return value;\n } else {\n this.data[hashKey] = [{key:key, value:value}];\n return value;\n }\n};\n\nMap.prototype.containsKey = function (key) {\n var hashKey = \"hash_\" + this.hashFunction(key);\n if(hashKey in this.data) {\n var entries = this.data[hashKey];\n for (var i = 0; i < entries.length; i++) {\n var entry = entries[i];\n if (this.equalsFunction(key, entry.key))\n return true;\n }\n }\n return false;\n};\n\nMap.prototype.get = function (key) {\n var hashKey = \"hash_\" + this.hashFunction(key);\n if(hashKey in this.data) {\n var entries = this.data[hashKey];\n for (var i = 0; i < entries.length; i++) {\n var entry = entries[i];\n if (this.equalsFunction(key, entry.key))\n return entry.value;\n }\n }\n return null;\n};\n\nMap.prototype.entries = function () {\n var l = [];\n for (var key in this.data) {\n if (key.indexOf(\"hash_\") === 0) {\n l = l.concat(this.data[key]);\n }\n }\n return l;\n};\n\n\nMap.prototype.getKeys = function () {\n return this.entries().map(function(e) {\n return e.key;\n });\n};\n\n\nMap.prototype.getValues = function () {\n return this.entries().map(function(e) {\n return e.value;\n });\n};\n\n\nMap.prototype.toString = function () {\n var ss = this.entries().map(function(entry) {\n return '{' + entry.key + ':' + entry.value + '}';\n });\n return '[' + ss.join(\", \") + ']';\n};\n\n\nfunction AltDict() {\n this.data = {};\n return this;\n}\n\n\nAltDict.prototype.get = function (key) {\n key = \"k-\" + key;\n if (key in this.data) {\n return this.data[key];\n } else {\n return null;\n }\n};\n\nAltDict.prototype.put = function (key, value) {\n key = \"k-\" + key;\n this.data[key] = value;\n};\n\nAltDict.prototype.values = function () {\n var data = this.data;\n var keys = Object.keys(this.data);\n return keys.map(function (key) {\n return data[key];\n });\n};\n\nfunction DoubleDict(defaultMapCtor) {\n this.defaultMapCtor = defaultMapCtor || Map;\n this.cacheMap = new this.defaultMapCtor();\n return this;\n}\n\nfunction Hash() {\n this.count = 0;\n this.hash = 0;\n return this;\n}\n\nHash.prototype.update = function () {\n for(var i=0;i<arguments.length;i++) {\n var value = arguments[i];\n if (value == null)\n continue;\n if(Array.isArray(value))\n this.update.apply(this, value);\n else {\n var k = 0;\n switch (typeof(value)) {\n case 'undefined':\n case 'function':\n continue;\n case 'number':\n case 'boolean':\n k = value;\n break;\n case 'string':\n k = value.hashCode();\n break;\n default:\n if(value.updateHashCode)\n value.updateHashCode(this);\n else\n console.log(\"No updateHashCode for \" + value.toString())\n continue;\n }\n k = k * 0xCC9E2D51;\n k = (k << 15) | (k >>> (32 - 15));\n k = k * 0x1B873593;\n this.count = this.count + 1;\n var hash = this.hash ^ k;\n hash = (hash << 13) | (hash >>> (32 - 13));\n hash = hash * 5 + 0xE6546B64;\n this.hash = hash;\n }\n }\n};\n\nHash.prototype.finish = function () {\n var hash = this.hash ^ (this.count * 4);\n hash = hash ^ (hash >>> 16);\n hash = hash * 0x85EBCA6B;\n hash = hash ^ (hash >>> 13);\n hash = hash * 0xC2B2AE35;\n hash = hash ^ (hash >>> 16);\n return hash;\n};\n\nfunction hashStuff() {\n var hash = new Hash();\n hash.update.apply(hash, arguments);\n return hash.finish();\n}\n\nDoubleDict.prototype.get = function (a, b) {\n var d = this.cacheMap.get(a) || null;\n return d === null ? null : (d.get(b) || null);\n};\n\nDoubleDict.prototype.set = function (a, b, o) {\n var d = this.cacheMap.get(a) || null;\n if (d === null) {\n d = new this.defaultMapCtor();\n this.cacheMap.put(a, d);\n }\n d.put(b, o);\n};\n\n\nfunction escapeWhitespace(s, escapeSpaces) {\n s = s.replace(/\\t/g, \"\\\\t\")\n .replace(/\\n/g, \"\\\\n\")\n .replace(/\\r/g, \"\\\\r\");\n if (escapeSpaces) {\n s = s.replace(/ /g, \"\\u00B7\");\n }\n return s;\n}\n\nfunction titleCase(str) {\n return str.replace(/\\w\\S*/g, function (txt) {\n return txt.charAt(0).toUpperCase() + txt.substr(1);\n });\n};\n\nfunction equalArrays(a, b)\n{\n if (!Array.isArray(a) || !Array.isArray(b))\n return false;\n if (a == b)\n return true;\n if (a.length != b.length)\n return false;\n for (var i = 0; i < a.length; i++) {\n if (a[i] == b[i])\n continue;\n if (!a[i].equals(b[i]))\n return false;\n }\n return true;\n};\n\nexports.Hash = Hash;\nexports.Set = Set;\nexports.Map = Map;\nexports.BitSet = BitSet;\nexports.AltDict = AltDict;\nexports.DoubleDict = DoubleDict;\nexports.hashStuff = hashStuff;\nexports.escapeWhitespace = escapeWhitespace;\nexports.arrayToString = arrayToString;\nexports.titleCase = titleCase;\nexports.equalArrays = equalArrays;\n","/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.\n * Use of this file is governed by the BSD 3-clause license that\n * can be found in the LICENSE.txt file in the project root.\n */\n//\n\n// A token has properties: text, type, line, character position in the line\n// (so we can ignore tabs), token channel, index, and source from which\n// we obtained this token.\n\nfunction Token() {\n\tthis.source = null;\n\tthis.type = null; // token type of the token\n\tthis.channel = null; // The parser ignores everything not on DEFAULT_CHANNEL\n\tthis.start = null; // optional; return -1 if not implemented.\n\tthis.stop = null; // optional; return -1 if not implemented.\n\tthis.tokenIndex = null; // from 0..n-1 of the token object in the input stream\n\tthis.line = null; // line=1..n of the 1st character\n\tthis.column = null; // beginning of the line at which it occurs, 0..n-1\n\tthis._text = null; // text of the token.\n\treturn this;\n}\n\nToken.INVALID_TYPE = 0;\n\n// During lookahead operations, this \"token\" signifies we hit rule end ATN state\n// and did not follow it despite needing to.\nToken.EPSILON = -2;\n\nToken.MIN_USER_TOKEN_TYPE = 1;\n\nToken.EOF = -1;\n\n// All tokens go to the parser (unless skip() is called in that rule)\n// on a particular \"channel\". The parser tunes to a particular channel\n// so that whitespace etc... can go to the parser on a \"hidden\" channel.\n\nToken.DEFAULT_CHANNEL = 0;\n\n// Anything on different channel than DEFAULT_CHANNEL is not parsed\n// by parser.\n\nToken.HIDDEN_CHANNEL = 1;\n\n// Explicitly set the text for this token. If {code text} is not\n// {@code null}, then {@link //getText} will return this value rather than\n// extracting the text from the input.\n//\n// @param text The explicit text of the token, or {@code null} if the text\n// should be obtained from the input along with the start and stop indexes\n// of the token.\n\nObject.defineProperty(Token.prototype, \"text\", {\n\tget : function() {\n\t\treturn this._text;\n\t},\n\tset : function(text) {\n\t\tthis._text = text;\n\t}\n});\n\nToken.prototype.getTokenSource = function() {\n\treturn this.source[0];\n};\n\nToken.prototype.getInputStream = function() {\n\treturn this.source[1];\n};\n\nfunction CommonToken(source, type, channel, start, stop) {\n\tToken.call(this);\n\tthis.source = source !== undefined ? source : CommonToken.EMPTY_SOURCE;\n\tthis.type = type !== undefined ? type : null;\n\tthis.channel = channel !== undefined ? channel : Token.DEFAULT_CHANNEL;\n\tthis.start = start !== undefined ? start : -1;\n\tthis.stop = stop !== undefined ? stop : -1;\n\tthis.tokenIndex = -1;\n\tif (this.source[0] !== null) {\n\t\tthis.line = source[0].line;\n\t\tthis.column = source[0].column;\n\t} else {\n\t\tthis.column = -1;\n\t}\n\treturn this;\n}\n\nCommonToken.prototype = Object.create(Token.prototype);\nCommonToken.prototype.constructor = CommonToken;\n\n// An empty {@link Pair} which is used as the default value of\n// {@link //source} for tokens that do not have a source.\nCommonToken.EMPTY_SOURCE = [ null, null ];\n\n// Constructs a new {@link CommonToken} as a copy of another {@link Token}.\n//\n// <p>\n// If {@code oldToken} is also a {@link CommonToken} instance, the newly\n// constructed token will share a reference to the {@link //text} field and\n// the {@link Pair} stored in {@link //source}. Otherwise, {@link //text} will\n// be assigned the result of calling {@link //getText}, and {@link //source}\n// will be constructed from the result of {@link Token//getTokenSource} and\n// {@link Token//getInputStream}.</p>\n//\n// @param oldToken The token to copy.\n//\nCommonToken.prototype.clone = function() {\n\tvar t = new CommonToken(this.source, this.type, this.channel, this.start,\n\t\t\tthis.stop);\n\tt.tokenIndex = this.tokenIndex;\n\tt.line = this.line;\n\tt.column = this.column;\n\tt.text = this.text;\n\treturn t;\n};\n\nObject.defineProperty(CommonToken.prototype, \"text\", {\n\tget : function() {\n\t\tif (this._text !== null) {\n\t\t\treturn this._text;\n\t\t}\n\t\tvar input = this.getInputStream();\n\t\tif (input === null) {\n\t\t\treturn null;\n\t\t}\n\t\tvar n = input.size;\n\t\tif (this.start < n && this.stop < n) {\n\t\t\treturn input.getText(this.start, this.stop);\n\t\t} else {\n\t\t\treturn \"<EOF>\";\n\t\t}\n\t},\n\tset : function(text) {\n\t\tthis._text = text;\n\t}\n});\n\nCommonToken.prototype.toString = function() {\n\tvar txt = this.text;\n\tif (txt !== null) {\n\t\ttxt = txt.replace(/\\n/g, \"\\\\n\").replace(/\\r/g, \"\\\\r\").replace(/\\t/g, \"\\\\t\");\n\t} else {\n\t\ttxt = \"<no text>\";\n\t}\n\treturn \"[@\" + this.tokenIndex + \",\" + this.start + \":\" + this.stop + \"='\" +\n\t\t\ttxt + \"',<\" + this.type + \">\" +\n\t\t\t(this.channel > 0 ? \",channel=\" + this.channel : \"\") + \",\" +\n\t\t\tthis.line + \":\" + this.column + \"]\";\n};\n\nexports.Token = Token;\nexports.CommonToken = CommonToken;\n","//\n/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.\n * Use of this file is governed by the BSD 3-clause license that\n * can be found in the LICENSE.txt file in the project root.\n */\n//\n\n// The following images show the relation of states and\n// {@link ATNState//transitions} for various grammar constructs.\n//\n// <ul>\n//\n// <li>Solid edges marked with an &//0949; indicate a required\n// {@link EpsilonTransition}.</li>\n//\n// <li>Dashed edges indicate locations where any transition derived from\n// {@link Transition} might appear.</li>\n//\n// <li>Dashed nodes are place holders for either a sequence of linked\n// {@link BasicState} states or the inclusion of a block representing a nested\n// construct in one of the forms below.</li>\n//\n// <li>Nodes showing multiple outgoing alternatives with a {@code ...} support\n// any number of alternatives (one or more). Nodes without the {@code ...} only\n// support the exact number of alternatives shown in the diagram.</li>\n//\n// </ul>\n//\n// <h2>Basic Blocks</h2>\n//\n// <h3>Rule</h3>\n//\n// <embed src=\"images/Rule.svg\" type=\"image/svg+xml\"/>\n//\n// <h3>Block of 1 or more alternatives</h3>\n//\n// <embed src=\"images/Block.svg\" type=\"image/svg+xml\"/>\n//\n// <h2>Greedy Loops</h2>\n//\n// <h3>Greedy Closure: {@code (...)*}</h3>\n//\n// <embed src=\"images/ClosureGreedy.svg\" type=\"image/svg+xml\"/>\n//\n// <h3>Greedy Positive Closure: {@code (...)+}</h3>\n//\n// <embed src=\"images/PositiveClosureGreedy.svg\" type=\"image/svg+xml\"/>\n//\n// <h3>Greedy Optional: {@code (...)?}</h3>\n//\n// <embed src=\"images/OptionalGreedy.svg\" type=\"image/svg+xml\"/>\n//\n// <h2>Non-Greedy Loops</h2>\n//\n// <h3>Non-Greedy Closure: {@code (...)*?}</h3>\n//\n// <embed src=\"images/ClosureNonGreedy.svg\" type=\"image/svg+xml\"/>\n//\n// <h3>Non-Greedy Positive Closure: {@code (...)+?}</h3>\n//\n// <embed src=\"images/PositiveClosureNonGreedy.svg\" type=\"image/svg+xml\"/>\n//\n// <h3>Non-Greedy Optional: {@code (...)??}</h3>\n//\n// <embed src=\"images/OptionalNonGreedy.svg\" type=\"image/svg+xml\"/>\n//\n\nvar INITIAL_NUM_TRANSITIONS = 4;\n\nfunction ATNState() {\n // Which ATN are we in?\n this.atn = null;\n this.stateNumber = ATNState.INVALID_STATE_NUMBER;\n this.stateType = null;\n this.ruleIndex = 0; // at runtime, we don't have Rule objects\n this.epsilonOnlyTransitions = false;\n // Track the transitions emanating from this ATN state.\n this.transitions = [];\n // Used to cache lookahead during parsing, not used during construction\n this.nextTokenWithinRule = null;\n return this;\n}\n\n// constants for serialization\nATNState.INVALID_TYPE = 0;\nATNState.BASIC = 1;\nATNState.RULE_START = 2;\nATNState.BLOCK_START = 3;\nATNState.PLUS_BLOCK_START = 4;\nATNState.STAR_BLOCK_START = 5;\nATNState.TOKEN_START = 6;\nATNState.RULE_STOP = 7;\nATNState.BLOCK_END = 8;\nATNState.STAR_LOOP_BACK = 9;\nATNState.STAR_LOOP_ENTRY = 10;\nATNState.PLUS_LOOP_BACK = 11;\nATNState.LOOP_END = 12;\n\nATNState.serializationNames = [\n \"INVALID\",\n \"BASIC\",\n \"RULE_START\",\n \"BLOCK_START\",\n \"PLUS_BLOCK_START\",\n \"STAR_BLOCK_START\",\n \"TOKEN_START\",\n \"RULE_STOP\",\n \"BLOCK_END\",\n \"STAR_LOOP_BACK\",\n \"STAR_LOOP_ENTRY\",\n \"PLUS_LOOP_BACK\",\n \"LOOP_END\" ];\n\nATNState.INVALID_STATE_NUMBER = -1;\n\nATNState.prototype.toString = function() {\n\treturn this.stateNumber;\n};\n\nATNState.prototype.equals = function(other) {\n if (other instanceof ATNState) {\n return this.stateNumber===other.stateNumber;\n } else {\n return false;\n }\n};\n\nATNState.prototype.isNonGreedyExitState = function() {\n return false;\n};\n\n\nATNState.prototype.addTransition = function(trans, index) {\n\tif(index===undefined) {\n\t\tindex = -1;\n\t}\n if (this.transitions.length===0) {\n this.epsilonOnlyTransitions = trans.isEpsilon;\n } else if(this.epsilonOnlyTransitions !== trans.isEpsilon) {\n this.epsilonOnlyTransitions = false;\n }\n if (index===-1) {\n this.transitions.push(trans);\n } else {\n this.transitions.splice(index, 1, trans);\n }\n};\n\nfunction BasicState() {\n\tATNState.call(this);\n this.stateType = ATNState.BASIC;\n return this;\n}\n\nBasicState.prototype = Object.create(ATNState.prototype);\nBasicState.prototype.constructor = BasicState;\n\n\nfunction DecisionState() {\n\tATNState.call(this);\n this.decision = -1;\n this.nonGreedy = false;\n return this;\n}\n\nDecisionState.prototype = Object.create(ATNState.prototype);\nDecisionState.prototype.constructor = DecisionState;\n\n\n// The start of a regular {@code (...)} block.\nfunction BlockStartState() {\n\tDecisionState.call(this);\n\tthis.endState = null;\n\treturn this;\n}\n\nBlockStartState.prototype = Object.create(DecisionState.prototype);\nBlockStartState.prototype.constructor = BlockStartState;\n\n\nfunction BasicBlockStartState() {\n\tBlockStartState.call(this);\n\tthis.stateType = ATNState.BLOCK_START;\n\treturn this;\n}\n\nBasicBlockStartState.prototype = Object.create(BlockStartState.prototype);\nBasicBlockStartState.prototype.constructor = BasicBlockStartState;\n\n\n// Terminal node of a simple {@code (a|b|c)} block.\nfunction BlockEndState() {\n\tATNState.call(this);\n\tthis.stateType = ATNState.BLOCK_END;\n this.startState = null;\n return this;\n}\n\nBlockEndState.prototype = Object.create(ATNState.prototype);\nBlockEndState.prototype.constructor = BlockEndState;\n\n\n// The last node in the ATN for a rule, unless that rule is the start symbol.\n// In that case, there is one transition to EOF. Later, we might encode\n// references to all calls to this rule to compute FOLLOW sets for\n// error handling.\n//\nfunction RuleStopState() {\n\tATNState.call(this);\n this.stateType = ATNState.RULE_STOP;\n return this;\n}\n\nRuleStopState.prototype = Object.create(ATNState.prototype);\nRuleStopState.prototype.constructor = RuleStopState;\n\nfunction RuleStartState() {\n\tATNState.call(this);\n\tthis.stateType = ATNState.RULE_START;\n\tthis.stopState = null;\n\tthis.isPrecedenceRule = false;\n\treturn this;\n}\n\nRuleStartState.prototype = Object.create(ATNState.prototype);\nRuleStartState.prototype.constructor = RuleStartState;\n\n// Decision state for {@code A+} and {@code (A|B)+}. It has two transitions:\n// one to the loop back to start of the block and one to exit.\n//\nfunction PlusLoopbackState() {\n\tDecisionState.call(this);\n\tthis.stateType = ATNState.PLUS_LOOP_BACK;\n\treturn this;\n}\n\nPlusLoopbackState.prototype = Object.create(DecisionState.prototype);\nPlusLoopbackState.prototype.constructor = PlusLoopbackState;\n\n\n// Start of {@code (A|B|...)+} loop. Technically a decision state, but\n// we don't use for code generation; somebody might need it, so I'm defining\n// it for completeness. In reality, the {@link PlusLoopbackState} node is the\n// real decision-making note for {@code A+}.\n//\nfunction PlusBlockStartState() {\n\tBlockStartState.call(this);\n\tthis.stateType = ATNState.PLUS_BLOCK_START;\n this.loopBackState = null;\n return this;\n}\n\nPlusBlockStartState.prototype = Object.create(BlockStartState.prototype);\nPlusBlockStartState.prototype.constructor = PlusBlockStartState;\n\n// The block that begins a closure loop.\nfunction StarBlockStartState() {\n\tBlockStartState.call(this);\n\tthis.stateType = ATNState.STAR_BLOCK_START;\n\treturn this;\n}\n\nStarBlockStartState.prototype = Object.create(BlockStartState.prototype);\nStarBlockStartState.prototype.constructor = StarBlockStartState;\n\n\nfunction StarLoopbackState() {\n\tATNState.call(this);\n\tthis.stateType = ATNState.STAR_LOOP_BACK;\n\treturn this;\n}\n\nStarLoopbackState.prototype = Object.create(ATNState.prototype);\nStarLoopbackState.prototype.constructor = StarLoopbackState;\n\n\nfunction StarLoopEntryState() {\n\tDecisionState.call(this);\n\tthis.stateType = ATNState.STAR_LOOP_ENTRY;\n this.loopBackState = null;\n // Indicates whether this state can benefit from a precedence DFA during SLL decision making.\n this.isPrecedenceDecision = null;\n return this;\n}\n\nStarLoopEntryState.prototype = Object.create(DecisionState.prototype);\nStarLoopEntryState.prototype.constructor = StarLoopEntryState;\n\n\n// Mark the end of a * or + loop.\nfunction LoopEndState() {\n\tATNState.call(this);\n\tthis.stateType = ATNState.LOOP_END;\n\tthis.loopBackState = null;\n\treturn this;\n}\n\nLoopEndState.prototype = Object.create(ATNState.prototype);\nLoopEndState.prototype.constructor = LoopEndState;\n\n\n// The Tokens rule start state linking to each lexer rule start state */\nfunction TokensStartState() {\n\tDecisionState.call(this);\n\tthis.stateType = ATNState.TOKEN_START;\n\treturn this;\n}\n\nTokensStartState.prototype = Object.create(DecisionState.prototype);\nTokensStartState.prototype.constructor = TokensStartState;\n\nexports.ATNState = ATNState;\nexports.BasicState = BasicState;\nexports.DecisionState = DecisionState;\nexports.BlockStartState = BlockStartState;\nexports.BlockEndState = BlockEndState;\nexports.LoopEndState = LoopEndState;\nexports.RuleStartState = RuleStartState;\nexports.RuleStopState = RuleStopState;\nexports.TokensStartState = TokensStartState;\nexports.PlusLoopbackState = PlusLoopbackState;\nexports.StarLoopbackState = StarLoopbackState;\nexports.StarLoopEntryState = StarLoopEntryState;\nexports.PlusBlockStartState = PlusBlockStartState;\nexports.StarBlockStartState = StarBlockStartState;\nexports.BasicBlockStartState = BasicBlockStartState;\n","//\n/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.\n * Use of this file is governed by the BSD 3-clause license that\n * can be found in the LICENSE.txt file in the project root.\n */\n//\n\n// A tree structure used to record the semantic context in which\n// an ATN configuration is valid. It's either a single predicate,\n// a conjunction {@code p1&&p2}, or a sum of products {@code p1||p2}.\n//\n// <p>I have scoped the {@link AND}, {@link OR}, and {@link Predicate} subclasses of\n// {@link SemanticContext} within the scope of this outer class.</p>\n//\n\nvar Set = require('./../Utils').Set;\nvar Hash = require('./../Utils').Hash;\n\nfunction SemanticContext() {\n\treturn this;\n}\n\nSemanticContext.prototype.hashCode = function() {\n var hash = new Hash();\n this.updateHashCode(hash);\n return hash.finish();\n};\n\n// For context independent predicates, we evaluate them without a local\n// context (i.e., null context). That way, we can evaluate them without\n// having to create proper rule-specific context during prediction (as\n// opposed to the parser, which creates them naturally). In a practical\n// sense, this avoids a cast exception from RuleContext to myruleContext.\n//\n// <p>For context dependent predicates, we must pass in a local context so that\n// references such as $arg evaluate properly as _localctx.arg. We only\n// capture context dependent predicates in the context in which we begin\n// prediction, so we passed in the outer context here in case of context\n// dependent predicate evaluation.</p>\n//\nSemanticContext.prototype.evaluate = function(parser, outerContext) {\n};\n\n//\n// Evaluate the precedence predicates for the context and reduce the result.\n//\n// @param parser The parser instance.\n// @param outerContext The current parser context object.\n// @return The simplified semantic context after precedence predicates are\n// evaluated, which will be one of the following values.\n// <ul>\n// <li>{@link //NONE}: if the predicate simplifies to {@code true} after\n// precedence predicates are evaluated.</li>\n// <li>{@code null}: if the predicate simplifies to {@code false} after\n// precedence predicates are evaluated.</li>\n// <li>{@code this}: if the semantic context is not changed as a result of\n// precedence predicate evaluation.</li>\n// <li>A non-{@code null} {@link SemanticContext}: the new simplified\n// semantic context after precedence predicates are evaluated.</li>\n// </ul>\n//\nSemanticContext.prototype.evalPrecedence = function(parser, outerContext) {\n\treturn this;\n};\n\nSemanticContext.andContext = function(a, b) {\n\tif (a === null || a === SemanticContext.NONE) {\n\t\treturn b;\n\t}\n\tif (b === null || b === SemanticContext.NONE) {\n\t\treturn a;\n\t}\n\tvar result = new AND(a, b);\n\tif (result.opnds.length === 1) {\n\t\treturn result.opnds[0];\n\t} else {\n\t\treturn result;\n\t}\n};\n\nSemanticContext.orContext = function(a, b) {\n\tif (a === null) {\n\t\treturn b;\n\t}\n\tif (b === null) {\n\t\treturn a;\n\t}\n\tif (a === SemanticContext.NONE || b === SemanticContext.NONE) {\n\t\treturn SemanticContext.NONE;\n\t}\n\tvar result = new OR(a, b);\n\tif (result.opnds.length === 1) {\n\t\treturn result.opnds[0];\n\t} else {\n\t\treturn result;\n\t}\n};\n\nfunction Predicate(ruleIndex, predIndex, isCtxDependent) {\n\tSemanticContext.call(this);\n\tthis.ruleIndex = ruleIndex === undefined ? -1 : ruleIndex;\n\tthis.predIndex = predIndex === undefined ? -1 : predIndex;\n\tthis.isCtxDependent = isCtxDependent === undefined ? false : isCtxDependent; // e.g., $i ref in pred\n\treturn this;\n}\n\nPredicate.prototype = Object.create(SemanticContext.prototype);\nPredicate.prototype.constructor = Predicate;\n\n//The default {@link SemanticContext}, which is semantically equivalent to\n//a predicate of the form {@code {true}?}.\n//\nSemanticContext.NONE = new Predicate();\n\n\nPredicate.prototype.evaluate = function(parser, outerContext) {\n\tvar localctx = this.isCtxDependent ? outerContext : null;\n\treturn parser.sempred(localctx, this.ruleIndex, this.predIndex);\n};\n\nPredicate.prototype.updateHashCode = function(hash) {\n\thash.update(this.ruleIndex, this.predIndex, this.isCtxDependent);\n};\n\nPredicate.prototype.equals = function(other) {\n\tif (this === other) {\n\t\tret