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


TypeScript pegjs.buildParser函數代碼示例

本文整理匯總了TypeScript中pegjs.buildParser函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript buildParser函數的具體用法?TypeScript buildParser怎麽用?TypeScript buildParser使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了buildParser函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: catch

documents.onDidChangeContent((change) => {
    let diagnostics: Diagnostic[] = [];
    
    try {
        let result = pegjs.buildParser(change.document.getText());
    } catch(error)
    {
        let err : pegjs.PegjsError = error;
        diagnostics.push({
            severity: DiagnosticSeverity.Error,
            range: pegjsLoc_to_vscodeRange(err.location),
            message: error.name + ": " + error.message
        });
    }
    
    // Send the computed diagnostics to VS Code.
    connection.sendDiagnostics({ uri: change.document.uri, diagnostics });
});
開發者ID:ebugusey,項目名稱:code-pegjs-language,代碼行數:18,代碼來源:server.ts

示例2: catch

import * as pegjs from 'pegjs';
{
    let input: string;
    let result = pegjs.PEG.parse(input);
    console.log(result);
}

{
    let pegparser: pegjs.Parser = pegjs.buildParser("start = ('a' / 'b')+");

    try {
        let result: string = pegparser.parse("abba");
    } catch (error) {
        if (error instanceof pegparser.SyntaxError) {
            
        }
    }
}

{
    let parser = pegjs.buildParser("A = 'test'", {
        cache: true,
        allowedStartRules: ["A"],
        optimize: "speed",
        plugins: []
    })
}

try {
    let parserOrSource: pegjs.Parser | string = pegjs.buildParser("A = 'test'", {output: "source"});
} catch (error) {
開發者ID:rchaser53,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:pegjs-tests.ts

示例3: pJoin

    start
      = Expression

    Expression
        = Join
        / Terminal

    Join
        = left:Terminal right:Expression { return pJoin(left, right) }

    Terminal
        = Param
        / Num

    Param "param"
        = char:[a-zA-Z] { return pParam(char) }

    Num "num"
        = digits:\[0-9]*\.\[0-9]+ { return pNum(digits) }
        / digits:\[0-9]+ { return pNum(digits) }



`

export const parse = buildParser(grammar).parse

export const parse2 = buildParser(grammar2).parse

console.log('parse2', parse2('abc'))
開發者ID:argonauthills,項目名稱:mr-graph,代碼行數:30,代碼來源:parser.ts

示例4: require

ďťżimport path = require('path');
import fs = require('fs');
var peg = require('pegjs');


// Create a global variable that the code inside the PEG grammar can access.
global.pegopts = 'options';


// Create a parser for typescript model definitions (using pegjs).
var grammar = fs.readFileSync(path.join(__dirname, './ts.peg'), 'utf8');
var parser = peg.buildParser(grammar);


/** Generate a schema corresponding to the declarations in the given typescript file. */
export function parse(source: string) {
    var ast = parser.parse(source);
    return ast;
}
開發者ID:yortus,項目名稱:typeinfo,代碼行數:19,代碼來源:index.ts


注:本文中的pegjs.buildParser函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。