本文整理匯總了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
}
}