UNPKG

pbxproj

Version:

parse & stringify xcode pbxproj format

130 lines (101 loc) 2.54 kB
'use strict'; /* * Module dependencies */ var _ = require('lodash'); var util = require('util'); var CommentStage = require('./comment'); var ParserStage = require('../stage'); /* * Stage for arrays type : * * ( * foo; * bar; * 42; * ); */ var ArrayStage = module.exports = function () { ParserStage.apply(this, arguments); _.bindAll(this); this.firstRun = true; }; util.inherits(ArrayStage, ParserStage); /* * Override parsing run cycle */ ArrayStage.prototype.run = function () { var commentStage; if (this.firstRun) this.expect(/\(/, this.open); if (CommentStage.isComment(this.data, this.cursor)) { commentStage = new CommentStage(null, this.data, this.cursor, this.line); commentStage.run(); this.cursor = commentStage.cursor; } this.firstRun = false; ParserStage.prototype.run.apply(this, arguments); }; /* * Event callback : open object */ ArrayStage.prototype.open = function () { this.expect(/\)/, this.beginClose); this.expect(/\{/, this.openObject); this.expect(/[^\;\s]{1}/, this.openValue); this.run(); }; /* * Event callback : open object if '{' is found */ ArrayStage.prototype.openObject = function () { var ObjectStage = require('./object'); var objCtx = {}; var objectStage = new ObjectStage(objCtx, this.data, this.cursor - 1, this.line); objectStage.run(); this.cursor = objectStage.cursor; this.ctx.push(objCtx); this.expect(/\)/, this.beginClose); this.expect(/\{/, this.openObject); this.expect(/[^\;\s]{1}/, this.openValue); this.run(); }; /* * Event callback : begin close with '}' */ ArrayStage.prototype.beginClose = function () { this.expect(/\;/, this.endClose); this.run(); }; /* * Event callback : end close with ';' */ ArrayStage.prototype.endClose = function () { this.back(); }; /* * Event callback : starts to read tag value */ ArrayStage.prototype.openValue = function (car) { this.value = car; this.expect(/[^\;\s]{1}/, this.feedValue); this.run(); }; /* * Event callback : feed current tag value */ ArrayStage.prototype.feedValue = function (car) { this.value += car; this.expect(/[^\;\s]{1}/, this.feedValue); this.expect(/\;/, this.closeValue); this.run(); }; /* * Event callback : end feeding current tag value, wait end or new tag */ ArrayStage.prototype.closeValue = function (car) { this.ctx.push(this.value); this.expect(/\)/, this.beginClose); this.expect(/\{/, this.openObject); this.expect(/[^\;\s]{1}/, this.openValue); this.run(); };