本文整理汇总了TypeScript中jison.Parser类的典型用法代码示例。如果您正苦于以下问题:TypeScript Parser类的具体用法?TypeScript Parser怎么用?TypeScript Parser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Parser类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: unlock
export function unlock(conditionsStr:string, executions:any, metadata:any) {
let parser = new Parser(grammar);
parser.yy = {
i: 0,
sig: function (pubkey:string) {
let sigParam = executions[this.i++];
return (sigParam && pubkey === sigParam.pubkey && sigParam.sigOK) || false;
},
xHx: function(hash:string) {
let xhxParam = executions[this.i++];
return hashf(xhxParam) === hash;
},
cltv: function(deadline:string) {
return metadata.currentTime && metadata.currentTime >= parseInt(deadline);
},
csv: function(amountToWait:string) {
return metadata.elapsedTime && metadata.elapsedTime >= parseInt(amountToWait);
}
};
try {
return parser.parse(conditionsStr);
} catch(e) {
return false;
}
}
示例2: execute
public async execute(expr: string, rpnCalculator: RpnCalculator): Promise<StackItem[]> {
try {
const parser = new Parser(this.grammer);
parser.yy = {
binary: (a: Part, b: Part, op: string) => {
return {type: PartType.BINARY, a, b, op};
},
unary: (a: Part, op: string) => {
return {type: PartType.UNARY, a, op};
},
value: (value: string) => {
return {type: PartType.VALUE, value};
},
functionCall: (functionName: string, args: Part[]) => {
return {type: PartType.FUNCTION_CALL, functionName, args};
}
};
const calc = rpnCalculator.cloneWithoutStackItems();
const tree: Part[] = parser.parse(expr);
return ExpressionParser.executeTreeArray(tree, calc)
.then(() => {
return calc.pop(calc.size());
});
} catch (e) {
return Promise.reject(e);
}
}
示例3: getAnalysis
public getAnalysis(document : vscode.TextDocument){
let docToCheck = document.getText();
var t = new JisonTest();
var grammar = t.grammar;
var parser = new Parser(grammar);
this._docContent = parser.parse(docToCheck);
// Would having a type on the document content be useful?
//return docContent;
}
示例4: checkGrammar
export function checkGrammar(conditionsStr:string): boolean|null {
let parser = new Parser(grammar);
parser.yy = {
i: 0,
sig: () => true,
xHx: () => true,
cltv: () => true,
csv: () => true
}
try {
return parser.parse(conditionsStr)
} catch(e) {
return null
}
}
示例5: unlock
export function unlock(conditionsStr:string, unlockParams:string[], sigResult:TxSignatureResult, metadata?:UnlockMetadata): boolean|null {
const params = evalParams(unlockParams, conditionsStr, sigResult)
let parser = new Parser(grammar)
let nbFunctions = 0
parser.yy = {
i: 0,
sig: function (pubkey:string) {
// Counting functions
nbFunctions++
// Make the test
let success = false
let i = 0
while (!success && i < params.length) {
const p = params[i]
success = p.successful && p.funcName === 'SIG' && p.parameter === pubkey
i++
}
return success
},
xHx: function(hash:string) {
// Counting functions
nbFunctions++
// Make the test
let success = false
let i = 0
while (!success && i < params.length) {
const p = params[i]
success = p.successful && p.funcName === 'XHX' && hashf(p.parameter) === hash
i++
}
return success
},
cltv: function(deadline:string) {
// Counting functions
nbFunctions++
// Make the test
return metadata && metadata.currentTime && metadata.currentTime >= parseInt(deadline)
},
csv: function(amountToWait:string) {
// Counting functions
nbFunctions++
// Make the test
return metadata && metadata.elapsedTime && metadata.elapsedTime >= parseInt(amountToWait)
}
}
try {
const areAllValidParameters = params.reduce((success, p) => success && !!(p.successful), true)
if (!areAllValidParameters) {
throw "All parameters must be successful"
}
const unlocked = parser.parse(conditionsStr)
if (unlockParams.length > nbFunctions) {
throw "There must be at most as much params as function calls"
}
return unlocked
} catch(e) {
return null
}
}