pbxproj
Version:
parse & stringify xcode pbxproj format
99 lines (75 loc) • 1.88 kB
JavaScript
'use strict';
/*
* Module dependencies
*/
var _ = require('lodash');
var util = require('util');
var ParserStage = require('../stage');
/*
* Stage for inline and block comments
*/
var CommentStage = module.exports = function () {
ParserStage.apply(this, arguments);
_.bindAll(this);
this.firstRun = true;
};
util.inherits(CommentStage, ParserStage);
/*
* Check if next 2 characters are the begining of a comment
*/
CommentStage.isComment = function (data, cursor) {
var str = data.substr(cursor, 2);
return str === '//' || str === '/*';
};
/*
* Override parsing run cycle
*/
CommentStage.prototype.run = function () {
if (this.firstRun) this.expect(/\//, this.beginComment);
this.firstRun = false;
ParserStage.prototype.run.apply(this, arguments);
};
/*
* Event callback : begin comment after one '/'
*/
CommentStage.prototype.beginComment = function () {
this.expect(/\//, this.feedInline);
this.expect(/\*/, this.feedBlock);
this.run();
};
/*
* Event callback : feed inline comment
*/
CommentStage.prototype.feedInline = function () {
this.expect(/\n/, this.closeInline);
this.expect(/[^\n]{1}/, this.feedInline);
this.run();
};
/*
* Event callback : found end of line -> close inline
*/
CommentStage.prototype.closeInline = function () {
this.back();
};
/*
* Event callback : feed block comment
*/
CommentStage.prototype.feedBlock = function () {
this.expect(/[^\*]{1}/, this.feedBlock);
this.expect(/\*/, this.beginCloseBlock);
this.run();
};
/*
* Event callback : found '*' and expect '/' or more comments
*/
CommentStage.prototype.beginCloseBlock = function () {
this.expect(/[^\/]{1}/, this.feedBlock);
this.expect(/\//, this.endCloseBlock);
this.run();
};
/*
* Event callback : found '*' + '/' -> close block
*/
CommentStage.prototype.endCloseBlock = function () {
this.back();
};