UNPKG

parsing

Version:
54 lines (49 loc) 1.54 kB
/* * 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 */ 'use strict'; var expect = require('chai').expect, Parser = require('../../../src/Parser'); describe('Parser special Beginning-Of-File <BOF> rule', function () { it('should support capturing bounds for every AST node with a single rule', function () { var grammarSpec = { ignore: 'whitespace', rules: { 'my_rule': { components: [ {name: 'my_capture', what: ['<BOF>', /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: 0, line: 1, column: 1 }, end: { offset: 8, line: 2, column: 6 } } }); }); });