forked from olcxjas-softworks/LarpixClient
Add capacitorjs runtime
This commit is contained in:
parent
d0ece489ee
commit
f90c0e6c40
8362 changed files with 1502407 additions and 1 deletions
87
node_modules/chevrotain/src/parse/cst/cst.ts
generated
vendored
Normal file
87
node_modules/chevrotain/src/parse/cst/cst.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
import { CstNode, CstNodeLocation, IToken } from "../../../api"
|
||||
|
||||
/**
|
||||
* This nodeLocation tracking is not efficient and should only be used
|
||||
* when error recovery is enabled or the Token Vector contains virtual Tokens
|
||||
* (e.g, Python Indent/Outdent)
|
||||
* As it executes the calculation for every single terminal/nonTerminal
|
||||
* and does not rely on the fact the token vector is **sorted**
|
||||
*/
|
||||
export function setNodeLocationOnlyOffset(
|
||||
currNodeLocation: CstNodeLocation,
|
||||
newLocationInfo: IToken
|
||||
): void {
|
||||
// First (valid) update for this cst node
|
||||
if (isNaN(currNodeLocation.startOffset) === true) {
|
||||
// assumption1: Token location information is either NaN or a valid number
|
||||
// assumption2: Token location information is fully valid if it exist
|
||||
// (both start/end offsets exist and are numbers).
|
||||
currNodeLocation.startOffset = newLocationInfo.startOffset
|
||||
currNodeLocation.endOffset = newLocationInfo.endOffset
|
||||
}
|
||||
// Once the startOffset has been updated with a valid number it should never receive
|
||||
// any farther updates as the Token vector is sorted.
|
||||
// We still have to check this this condition for every new possible location info
|
||||
// because with error recovery enabled we may encounter invalid tokens (NaN location props)
|
||||
else if (currNodeLocation.endOffset < newLocationInfo.endOffset === true) {
|
||||
currNodeLocation.endOffset = newLocationInfo.endOffset
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This nodeLocation tracking is not efficient and should only be used
|
||||
* when error recovery is enabled or the Token Vector contains virtual Tokens
|
||||
* (e.g, Python Indent/Outdent)
|
||||
* As it executes the calculation for every single terminal/nonTerminal
|
||||
* and does not rely on the fact the token vector is **sorted**
|
||||
*/
|
||||
export function setNodeLocationFull(
|
||||
currNodeLocation: CstNodeLocation,
|
||||
newLocationInfo: CstNodeLocation
|
||||
): void {
|
||||
// First (valid) update for this cst node
|
||||
if (isNaN(currNodeLocation.startOffset) === true) {
|
||||
// assumption1: Token location information is either NaN or a valid number
|
||||
// assumption2: Token location information is fully valid if it exist
|
||||
// (all start/end props exist and are numbers).
|
||||
currNodeLocation.startOffset = newLocationInfo.startOffset
|
||||
currNodeLocation.startColumn = newLocationInfo.startColumn
|
||||
currNodeLocation.startLine = newLocationInfo.startLine
|
||||
currNodeLocation.endOffset = newLocationInfo.endOffset
|
||||
currNodeLocation.endColumn = newLocationInfo.endColumn
|
||||
currNodeLocation.endLine = newLocationInfo.endLine
|
||||
}
|
||||
// Once the start props has been updated with a valid number it should never receive
|
||||
// any farther updates as the Token vector is sorted.
|
||||
// We still have to check this this condition for every new possible location info
|
||||
// because with error recovery enabled we may encounter invalid tokens (NaN location props)
|
||||
else if (currNodeLocation.endOffset < newLocationInfo.endOffset === true) {
|
||||
currNodeLocation.endOffset = newLocationInfo.endOffset
|
||||
currNodeLocation.endColumn = newLocationInfo.endColumn
|
||||
currNodeLocation.endLine = newLocationInfo.endLine
|
||||
}
|
||||
}
|
||||
|
||||
export function addTerminalToCst(
|
||||
node: CstNode,
|
||||
token: IToken,
|
||||
tokenTypeName: string
|
||||
): void {
|
||||
if (node.children[tokenTypeName] === undefined) {
|
||||
node.children[tokenTypeName] = [token]
|
||||
} else {
|
||||
node.children[tokenTypeName].push(token)
|
||||
}
|
||||
}
|
||||
|
||||
export function addNoneTerminalToCst(
|
||||
node: CstNode,
|
||||
ruleName: string,
|
||||
ruleResult: any
|
||||
): void {
|
||||
if (node.children[ruleName] === undefined) {
|
||||
node.children[ruleName] = [ruleResult]
|
||||
} else {
|
||||
node.children[ruleName].push(ruleResult)
|
||||
}
|
||||
}
|
||||
178
node_modules/chevrotain/src/parse/cst/cst_visitor.ts
generated
vendored
Normal file
178
node_modules/chevrotain/src/parse/cst/cst_visitor.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
import {
|
||||
compact,
|
||||
contains,
|
||||
forEach,
|
||||
isArray,
|
||||
isEmpty,
|
||||
isFunction,
|
||||
isUndefined,
|
||||
keys,
|
||||
map
|
||||
} from "../../utils/utils"
|
||||
import { defineNameProp, functionName } from "../../lang/lang_extensions"
|
||||
import { ICstVisitor } from "../../../api"
|
||||
|
||||
export function defaultVisit<IN, OUT>(ctx: any, param: IN): OUT {
|
||||
let childrenNames = keys(ctx)
|
||||
let childrenNamesLength = childrenNames.length
|
||||
for (let i = 0; i < childrenNamesLength; i++) {
|
||||
let currChildName = childrenNames[i]
|
||||
let currChildArray = ctx[currChildName]
|
||||
let currChildArrayLength = currChildArray.length
|
||||
for (let j = 0; j < currChildArrayLength; j++) {
|
||||
let currChild: any = currChildArray[j]
|
||||
// distinction between Tokens Children and CstNode children
|
||||
if (currChild.tokenTypeIdx === undefined) {
|
||||
this[currChild.name](currChild.children, param)
|
||||
}
|
||||
}
|
||||
}
|
||||
// defaultVisit does not support generic out param
|
||||
return undefined
|
||||
}
|
||||
|
||||
export function createBaseSemanticVisitorConstructor(
|
||||
grammarName: string,
|
||||
ruleNames: string[]
|
||||
): {
|
||||
new (...args: any[]): ICstVisitor<any, any>
|
||||
} {
|
||||
let derivedConstructor: any = function () {}
|
||||
|
||||
// can be overwritten according to:
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/
|
||||
// name?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FFunction%2Fname
|
||||
defineNameProp(derivedConstructor, grammarName + "BaseSemantics")
|
||||
|
||||
let semanticProto = {
|
||||
visit: function (cstNode, param) {
|
||||
// enables writing more concise visitor methods when CstNode has only a single child
|
||||
if (isArray(cstNode)) {
|
||||
// A CST Node's children dictionary can never have empty arrays as values
|
||||
// If a key is defined there will be at least one element in the corresponding value array.
|
||||
cstNode = cstNode[0]
|
||||
}
|
||||
|
||||
// enables passing optional CstNodes concisely.
|
||||
if (isUndefined(cstNode)) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return this[cstNode.name](cstNode.children, param)
|
||||
},
|
||||
|
||||
validateVisitor: function () {
|
||||
let semanticDefinitionErrors = validateVisitor(this, ruleNames)
|
||||
if (!isEmpty(semanticDefinitionErrors)) {
|
||||
let errorMessages = map(
|
||||
semanticDefinitionErrors,
|
||||
(currDefError) => currDefError.msg
|
||||
)
|
||||
throw Error(
|
||||
`Errors Detected in CST Visitor <${functionName(
|
||||
this.constructor
|
||||
)}>:\n\t` + `${errorMessages.join("\n\n").replace(/\n/g, "\n\t")}`
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
derivedConstructor.prototype = semanticProto
|
||||
derivedConstructor.prototype.constructor = derivedConstructor
|
||||
|
||||
derivedConstructor._RULE_NAMES = ruleNames
|
||||
|
||||
return derivedConstructor
|
||||
}
|
||||
|
||||
export function createBaseVisitorConstructorWithDefaults(
|
||||
grammarName: string,
|
||||
ruleNames: string[],
|
||||
baseConstructor: Function
|
||||
): {
|
||||
new (...args: any[]): ICstVisitor<any, any>
|
||||
} {
|
||||
let derivedConstructor: any = function () {}
|
||||
|
||||
// can be overwritten according to:
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/
|
||||
// name?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FFunction%2Fname
|
||||
defineNameProp(derivedConstructor, grammarName + "BaseSemanticsWithDefaults")
|
||||
|
||||
let withDefaultsProto = Object.create(baseConstructor.prototype)
|
||||
forEach(ruleNames, (ruleName) => {
|
||||
withDefaultsProto[ruleName] = defaultVisit
|
||||
})
|
||||
|
||||
derivedConstructor.prototype = withDefaultsProto
|
||||
derivedConstructor.prototype.constructor = derivedConstructor
|
||||
|
||||
return derivedConstructor
|
||||
}
|
||||
|
||||
export enum CstVisitorDefinitionError {
|
||||
REDUNDANT_METHOD,
|
||||
MISSING_METHOD
|
||||
}
|
||||
|
||||
export interface IVisitorDefinitionError {
|
||||
msg: string
|
||||
type: CstVisitorDefinitionError
|
||||
methodName: string
|
||||
}
|
||||
|
||||
export function validateVisitor(
|
||||
visitorInstance: Function,
|
||||
ruleNames: string[]
|
||||
): IVisitorDefinitionError[] {
|
||||
let missingErrors = validateMissingCstMethods(visitorInstance, ruleNames)
|
||||
let redundantErrors = validateRedundantMethods(visitorInstance, ruleNames)
|
||||
|
||||
return missingErrors.concat(redundantErrors)
|
||||
}
|
||||
|
||||
export function validateMissingCstMethods(
|
||||
visitorInstance: Function,
|
||||
ruleNames: string[]
|
||||
): IVisitorDefinitionError[] {
|
||||
let errors: IVisitorDefinitionError[] = map(ruleNames, (currRuleName) => {
|
||||
if (!isFunction(visitorInstance[currRuleName])) {
|
||||
return {
|
||||
msg: `Missing visitor method: <${currRuleName}> on ${functionName(
|
||||
<any>visitorInstance.constructor
|
||||
)} CST Visitor.`,
|
||||
type: CstVisitorDefinitionError.MISSING_METHOD,
|
||||
methodName: currRuleName
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return compact<IVisitorDefinitionError>(errors)
|
||||
}
|
||||
|
||||
const VALID_PROP_NAMES = ["constructor", "visit", "validateVisitor"]
|
||||
export function validateRedundantMethods(
|
||||
visitorInstance: Function,
|
||||
ruleNames: string[]
|
||||
): IVisitorDefinitionError[] {
|
||||
let errors = []
|
||||
|
||||
for (let prop in visitorInstance) {
|
||||
if (
|
||||
isFunction(visitorInstance[prop]) &&
|
||||
!contains(VALID_PROP_NAMES, prop) &&
|
||||
!contains(ruleNames, prop)
|
||||
) {
|
||||
errors.push({
|
||||
msg:
|
||||
`Redundant visitor method: <${prop}> on ${functionName(
|
||||
<any>visitorInstance.constructor
|
||||
)} CST Visitor\n` +
|
||||
`There is no Grammar Rule corresponding to this method's name.\n`,
|
||||
type: CstVisitorDefinitionError.REDUNDANT_METHOD,
|
||||
methodName: prop
|
||||
})
|
||||
}
|
||||
}
|
||||
return errors
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue