本文整理汇总了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;
}
}
开发者ID:Kalmac,项目名称:duniter,代码行数:28,代码来源:txunlock.ts
示例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);
}
}
开发者ID:joeferner,项目名称:node-rpncalc,代码行数:27,代码来源:ExpressionParser.ts
示例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;
}
开发者ID:Togusa09,项目名称:vscode-tmlanguage,代码行数:11,代码来源:jsonTmLanguageAnalyser.ts
示例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
}
}
开发者ID:duniter,项目名称:duniter,代码行数:18,代码来源:txunlock.ts
示例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
}
}
开发者ID:duniter,项目名称:duniter,代码行数:62,代码来源:txunlock.ts
注:本文中的jison.Parser类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论