DefinitelyTyped/pegjs/pegjs-tests.ts
Kanchalai Tanglertsampan 1200f753d6 Merge branch 'master' into types-2.0
# Conflicts:
#	.gitignore
#	ajv/ajv.d.ts
#	angular-material/angular-material.d.ts
#	angular-protractor/angular-protractor.d.ts
#	angularjs/angular-tests.ts
#	angularjs/angular.d.ts
#	aws-sdk/aws-sdk.d.ts
#	electron-devtools-installer/electron-devtools-installer-tests.ts
#	electron-json-storage/electron-json-storage-tests.ts
#	electron-notifications/electron-notifications.d.ts
#	electron-notify/electron-notify.d.ts
#	electron-window-state/electron-window-state.d.ts
#	electron/electron-prebuilt.d.ts
#	enzyme/enzyme.d.ts
#	eventemitter3/eventemitter3-tests.ts
#	eventemitter3/eventemitter3.d.ts
#	graphql/graphql.d.ts
#	highcharts/highcharts.d.ts
#	immutable/immutable.d.ts
#	inquirer/inquirer.d.ts
#	jasmine/jasmine.d.ts
#	joi/joi.d.ts
#	jquery.dataTables/jquery.dataTables-tests.ts
#	jquery.dataTables/jquery.dataTables.d.ts
#	kafka-node/kafka-node.d.ts
#	kefir/kefir.d.ts
#	kendo-ui/kendo-ui.d.ts
#	koa/koa.d.ts
#	leaflet/leaflet.d.ts
#	lodash/lodash.d.ts
#	mapbox-gl/mapbox-gl.d.ts
#	material-ui/material-ui.d.ts
#	menubar/menubar.d.ts
#	mongodb/mongodb.d.ts
#	needle/needle-tests.ts
#	needle/needle.d.ts
#	noble/noble.d.ts
#	node/node.d.ts
#	pegjs/pegjs.d.ts
#	pixi.js/pixi.js.d.ts
#	polymer/polymer.d.ts
#	quill/quill-tests.ts
#	quill/quill.d.ts
#	react-bootstrap/react-bootstrap.d.ts
#	react-fa/react-fa-tests.tsx
#	react-fa/react-fa.d.ts
#	react-native/react-native.d.ts
#	react-select/react-select.d.ts
#	react/react.d.ts
#	threejs/three-vrcontrols.d.ts
#	threejs/three-vreffect.d.ts
#	toastr/toastr.d.ts
#	validator/validator.d.ts
#	webpack/webpack.d.ts
#	winston/winston.d.ts
2016-11-09 17:20:41 -08:00

47 lines
1.1 KiB
TypeScript

import * as pegjs from 'pegjs';
{
let input: string;
let result = pegjs.PEG.parse(input);
console.log(result);
}
{
let pegparser: pegjs.Parser = pegjs.generate("start = ('a' / 'b')+");
try {
let result: string = pegparser.parse("abba");
} catch (error) {
if (error instanceof pegparser.SyntaxError) {
}
}
}
{
let parser = pegjs.generate("A = 'test'", {
cache: true,
allowedStartRules: ["A"],
optimize: "speed",
plugins: []
})
}
try {
let source: string = pegjs.generate("A = 'test'", {output: "source"});
} catch (error) {
if (error instanceof pegjs.GrammarError) {
let e: pegjs.GrammarError = error;
} else if (error instanceof pegjs.parser.SyntaxError) {
let e: pegjs.parser.SyntaxError = error;
}
let e: pegjs.PegjsError = error;
console.log(e.expected[0].description);
console.log(e.expected[0].type);
console.log(e.expected[0].value);
console.log(e.location.end.column);
console.log(e.location.end.offset);
console.log(e.location.end.line);
console.log(e.message);
console.log(e.name);
}