9fa0bf90 by David LaPalomento

Integrate peg-based parser into qunit tests

Add the peg parser generation step to the gruntfile. Include the generated parser in the test harness page. Update many of the m3u8 tests to work with the new parser. There are a number of tests still failing. I believe this is because parts of the grammar are not sufficiently flexible to handle some optional parameters. For instance, #EXT-X-BYTE-RANGE is being glommed incorrectly into the #EXTINF definition and that's throwing off parsing. This commit is a progress checkpoint; things are definitely not working correctly.
1 parent 3f975913
'use strict';
var peg = require('pegjs');
module.exports = function(grunt) {
// Project configuration.
......@@ -12,7 +14,7 @@ module.exports = function(grunt) {
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
// Task configuration.
clean: {
files: ['dist']
files: ['build', 'dist']
},
concat: {
options: {
......@@ -95,8 +97,19 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('peg', 'generate the manifest parser', function() {
var parser = peg.buildParser(grunt.file.read('src/m3u8/m3u8.pegjs'));
grunt.file.write('build/m3u8-parser.js',
'window.videojs.hls.M3U8Parser = ' + parser.toSource());
});
// Default task.
grunt.registerTask('default',
['jshint', 'qunit', 'clean', 'concat', 'uglify']);
['peg',
'jshint',
'qunit',
'clean',
'concat',
'uglify']);
};
......
......@@ -15,6 +15,7 @@
"grunt-contrib-jshint": "~0.6.0",
"grunt-contrib-qunit": "~0.2.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-nodeunit": "~0.1.2",
"grunt-contrib-uglify": "~0.2.0",
"grunt-contrib-watch": "~0.4.0",
"grunt-contrib-clean": "~0.4.0",
......
......@@ -269,13 +269,13 @@ number "number"
/ parts:(int) _ { return parts; }
resolution
= width:int "x" height:int { return {resolution: {width: width, height: height}}; }
= width:int "x" height:int { return {width: width, height: height}; }
int
= first:digit19 rest:digits { return parseInt(first + rest.join(''), 10); }
/ digit:digit { return parseInt(digit, 10); }
/ neg:"-" first:digit19 rest:digits { return parseInt(neg + first + rest.join(''), 10); }
/ neg:"-" digit { return parseInt(neg + digit, 10); }
/ neg:"-" digit:digit { return parseInt(neg + digit, 10); }
hexint
= "0x" hexDigits:hexDigit+ { return '0x' + hexDigits.join(''); }
......
(function (window) {
var
M3U8Parser = window.videojs.hls.M3U8Parser;
var parser = window.videojs.hls.M3U8Parser;
window.videojs.hls.ManifestController = function() {
var self = this;
......@@ -22,12 +22,8 @@
window.vjs.get(manifestUrl, self.onManifestLoadComplete, self.onManifestLoadError);
};
self.parseManifest = function(dataAsString) {
self.parser = new M3U8Parser();
self.parser.directory = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/.exec(self.url).slice(1)[1];
self.data = self.parser.parse(dataAsString);
return self.data;
self.parseManifest = function(manifest) {
return parser.parse(manifest);
};
self.onManifestLoadComplete = function(response) {
......
......@@ -44,7 +44,7 @@ window.playlistData = '#EXTM3U\n'+
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:468684@7108092\n' +
'hls_450k_video.ts' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:444996@7576776\n' +
'hls_450k_video.ts\n' +
......
......@@ -46,7 +46,7 @@ window.playlist_byte_range = '#EXTM3U\n'+
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:468684@7108092\n' +
'hls_450k_video.ts' +
'hls_450k_video.ts\n' +
'#EXTINF:10,\n' +
'#EXT-X-BYTERANGE:444996@7576776\n' +
'hls_450k_video.ts\n' +
......
var fs = require('fs');
var path = require('path');
var manifest = fs.readFileSync(__dirname + '/fixtures/prog_index.m3u8').toString();
var parser = require('../src/m3u8/m3u8-generated.js');
var parsed = parser.parse(manifest);
console.log(parsed);
......@@ -24,7 +24,7 @@
<!-- M3U8 -->
<script src="../src/m3u8/m3u8.js"></script>
<script src="../src/m3u8/m3u8-tag-types.js"></script>
<script src="../src/m3u8/m3u8-parser.js"></script>
<script src="../build/m3u8-parser.js"></script>
<script src="../src/manifest-controller.js"></script>
<!-- M3U8 TEST DATA -->
<script src="manifest/playlistM3U8data.js"></script>
......@@ -43,6 +43,7 @@
<script src="../src/bin-utils.js"></script>
<!-- Test cases -->
<script src="video-js-hls_test.js"></script>
<script src="exp-golomb_test.js"></script>
<script src="flv-tag_test.js"></script>
......