本文整理汇总了TypeScript中nearley.Parser类的典型用法代码示例。如果您正苦于以下问题:TypeScript Parser类的具体用法?TypeScript Parser怎么用?TypeScript Parser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Parser类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: catch
const processInput = _.debounce(() => {
if(!grammar) return;
try {
const parser = new nearley.Parser(grammar.ParserRules, grammar.ParserStart);
parser.feed(input.val());
output.text(JSON.stringify(parser.results[0]) || '');
console.log(parser.results);
} catch (e) {
output.text(`Error at character ${e.offset}`);
}
}, 1000);
开发者ID:shnud94,项目名称:livelang,代码行数:11,代码来源:test.ts
示例2: catch
export const parse = (grammar: nearley.Grammar, input: string) : Result<any> => {
const parser = new Nearley.Parser(grammar.ParserRules, grammar.ParserStart);
try {
parser.feed(input);
} catch (e) {
return {error: e.stack};
}
return {result: parser.results.last()};
};
开发者ID:shnud94,项目名称:livelang,代码行数:11,代码来源:nearley.ts
示例3: Parser
import { Parser, Grammar, Rule, Lexer } from 'nearley';
declare const parserRules: Rule[];
declare const parserStart: string;
declare const lexer: Lexer;
declare const grammar: Grammar;
let parser = new Parser(parserRules, parserStart, { lexer, keepHistory: false });
parser = new Parser(grammar);
try {
parser.feed("<123>");
if (parser.results) {
console.log(parser.results[0]);
}
} catch (error) {
console.log(error);
}
开发者ID:Crevil,项目名称:DefinitelyTyped,代码行数:18,代码来源:nearley-tests.ts
示例4: Grammar
rule.postprocess; // $ExpectType Postprocessor | undefined
rule.toString(); // $ExpectType string
rule.toString(1);
Grammar.fromCompiled(compiledRules); // $ExpectType Grammar
const grammar = new Grammar([rule]);
grammar.rules; // $ExpectType Rule[]
grammar.start; // $ExpectType string
grammar.byName; // $ExpectType { [ruleName: string]: Rule[]; }
grammar.lexer; // $ExpectType Lexer | undefined
Parser.fail; // $ExpectType {}
const parser = new Parser(grammar);
new Parser(grammar, {lexer});
new Parser(grammar, {keepHistory: false});
parser.grammar; // $ExpectType Grammar
parser.options; // $ExpectType ParserOptions
parser.lexer; // $ExpectType Lexer
parser.lexerState; // $ExpectType LexerState | undefined
parser.current; // $ExpectType number
parser.results; // $ExpectType any[]
parser.feed(''); // $ExpectType Parser
parser.finish(); // $ExpectType any[]
const state = parser.save();
state; // $ExpectType { [key: string]: any; lexerState: LexerState; }
parser.restore(state);
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:31,代码来源:nearley-tests.ts
示例5:
export const parse = (text: string, grammar: CompiledRules): Parser => {
const noExtraSpaces = text.replace(/[\s]+/gi, ' ').trim();
const parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar));
parser.feed(noExtraSpaces);
return parser;
};
开发者ID:theseyi,项目名称:WhereHows,代码行数:6,代码来源:parser.ts
注:本文中的nearley.Parser类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论