當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript jison.Parser類代碼示例

本文整理匯總了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;未經允許,請勿轉載。