parsing
Version:
JSON grammar-based parser
53 lines (48 loc) • 1.55 kB
JavaScript
/*
* Parsing - JSON grammar-based parser
* Copyright (c) Dan Phillimore (asmblah)
* http://asmblah.github.com/parsing/
*
* Released under the MIT license
* https://github.com/asmblah/parsing/raw/master/MIT-LICENSE.txt
*/
;
var expect = require('chai').expect,
Parser = require('../../../src/Parser');
describe('Parser "allOf" qualifier', function () {
it('should support capturing bounds for every AST node with a single rule', function () {
var grammarSpec = {
ignore: 'whitespace',
rules: {
'my_rule': {
// Implicit "allOf" qualifier by using an array of rule components
components: [{name: 'my_capture', what: /my\s+\w+/}]
},
'whitespace': /\s+/,
},
start: 'my_rule',
bounds: 'my_bounds'
},
options = {
captureAllBounds: true
},
parser = new Parser(grammarSpec, null, options),
code = ' my\n text ';
expect(parser.parse(code)).to.deep.equal({
name: 'my_rule',
my_capture: 'my\n text',
my_bounds: {
start: {
offset: 2,
line: 1,
column: 3
},
end: {
offset: 10,
line: 2,
column: 6
}
}
});
});
});