Performs the actual replacing of tokens with translations.
@param {File} file
@param {Object} options
@returns {File[]}
429010
function replace(file, options) {
  var contents = file.contents;
  var copied = 0;

  var processed = translate(options, contents, copied, file.path);

  var files = [];
  for (var lang in processed) {
    var params = {};
    params.ext = path.extname(file.path).substr(1);
    params.name = path.basename(file.path, path.extname(file.path));
    params.path = file.path.substring(file.base.length, file.path.lastIndexOf(path.sep));
    params.lang = lang;

    var filePath = options.filename;
    for (var param in params) {
      filePath = filePath.replace('${' + param + '}', params[param]);
    }
    filePath = path.join(file.base,filePath);

    var newFile = new gutil.File({
      base: file.base,
      cwd: file.cwd,
      path: filePath,
      contents: new Buffer(processed[lang], 'utf8')
    });
    files.push(newFile);
  }

	return files;
}
70881
function (file) {
    if (file.substr(file.length - 1) === '/') {
        file = file + 'index.html';
    }
    if (fss.exists(file + '.html')) {
        return file + '.html';
    } else if (fss.exists(file.replace(/\.html$/, ''))) {
        return file.replace(/\.html$/, '');
    } else if (fss.filename(file).indexOf('.') === -1 && fss.exists(file + '/index.html')) {
        return file + '/index.html';
    } else {
        return file;
    }
}
533436
function tokenize(source, options){
  var result = [];
  var tagStack = [];
  var lastTag = { children: result };
  var parseTag = false;
  var token;
  var state = TEXT;
  var pos = 0;
  var textStateEndPos = 0;
  var textEndPos;
  var bufferPos;
  var startPos;
  var m;

  /** @cut */ var attrMap;  // map to detect attribute duplicates
  /** @cut */ result.source_ = source;
  /** @cut */ result.warns = [];

  // skip starting whitespaces
  if (!options || options.trim !== false)
  {
    pos = textStateEndPos = source.match(/^\s*/)[0].length;
    source = source.trimRight();  // TODO: replace for basis.string.trimRight
  }

  while (pos < source.length || state != TEXT)
  {
    state.lastIndex = pos;
    startPos = pos;

    m = state.exec(source);

    if (!m || m.index !== pos)
    {
      // treat broken comment reference as comment content
      if (state == REFERENCE && token && token.type == TYPE_COMMENT)
      {
        state = COMMENT;
        continue;
      }

      if (parseTag)
        lastTag = tagStack.pop();

      if (token)
        lastTag.children.pop();

      if (token = lastTag.children.pop())
      {
        if (token.type == TYPE_TEXT && !token.refs)
          textStateEndPos -= token.value.length;
        else
          lastTag.children.push(token);
      }

      parseTag = false;
      state = TEXT;
      continue;
    }

    pos = state.lastIndex;

    //stat[state] = (stat[state] || 0) + 1;
    switch (state)
    {
      case TEXT:

        textEndPos = startPos + m[1].length;

        if (textStateEndPos != textEndPos)
        {
          var sourceText = textStateEndPos == startPos
            ? m[1]
            : source.substring(textStateEndPos, textEndPos);

          sourceText = sourceText.replace(/\s*(\r\n?|\n\r?)\s*/g, '');

          if (sourceText)
            lastTag.children.push({
              type: TYPE_TEXT,
              value: sourceText,
              range: {
                start_: textStateEndPos,
                end_: textEndPos
              }
            });
        }

        textStateEndPos = textEndPos;

        if (m[3])
        {
          lastTag.children.push({
            type: TYPE_TEXT,
            refs: ['l10n:' + m[3]],
            value: '{l10n:' + m[3] + '}',
            range: {
              start_: textEndPos,
              end_: pos
            }
          });
        }
        else if (m[2] == '{')
        {
          bufferPos = pos - 1;
          lastTag.children.push(token = {
            type: TYPE_TEXT,
            range: {
              start_: textEndPos,
              end_: textEndPos
            }
          });
          state = REFERENCE;
        }
        else if (m[4])
        {
          if (m[4] == '/')
          {
            token = null;
            state = CLOSE_TAG;
          }
          else //if (m[3] == '!--')
          {
            lastTag.children.push(token = {
              type: TYPE_COMMENT,
              range: {
                start_: textEndPos,
                end_: textEndPos
              }
            });

            if (m[5])
            {
              bufferPos = pos - m[5].length;
              state = REFERENCE;
            }
            else
            {
              bufferPos = pos;
              state = COMMENT;
            }
          }
        }
        else if (m[2]) // m[2] == '<' open tag
        {
          parseTag = true;
          tagStack.push(lastTag);

          lastTag.children.push(token = {
            type: TYPE_ELEMENT,
            attrs: [],
            children: [],
            range: {
              start_: textEndPos,
              end_: textEndPos
            }
          });
          lastTag = token;

          state = TAG_NAME;

          // create attribute map
          /** @cut */ attrMap = {};
        }

        break;

      case CLOSE_TAG:
        if (m[1] !== (lastTag.prefix ? lastTag.prefix + ':' : '') + lastTag.name)
        {
          lastTag.children.push({
            type: TYPE_TEXT,
            value: '</' + m[0],
            range: {
              start_: startPos - 2,
              end_: startPos + m[0].length
            }
          });
          /** @cut */ result.warns.push(['Wrong close tag: ' + source.substr(startPos - 2, m[0].length + 2), lastTag.children[lastTag.children.length - 1]]);
        }
        else
        {
          lastTag.range.end_ = startPos + m[0].length;
          lastTag = tagStack.pop();
        }

        state = TEXT;
        break;

      case TAG_NAME:
      case ATTRIBUTE_NAME_OR_END:
        if (m[2] == ':')
        {
          if (token.prefix)      // prefix was before, break tag parse
            state = BREAK_TAG_PARSE;
          else
            token.prefix = m[1];

          break;
        }

        if (m[1])
        {
          // store name (it may be null when check for attribute and end)
          token.name = m[1];
          token.range.end_ = startPos + m[1].length;

          // store attribute
          if (token.type == TYPE_ATTRIBUTE)
          {
            // detect attribute duplicates
            /** @cut */ var fullName = (token.prefix ? token.prefix + ':' : '') + token.name;
            /** @cut */ if (Object.prototype.hasOwnProperty.call(attrMap, fullName))
            /** @cut */   result.warns.push(['Duplicate attribute: ' + fullName, token]);
            /** @cut */ attrMap[fullName] = true;

            lastTag.attrs.push(token);
          }
        }

        if (m[2] == '{')
        {
          if (token.type == TYPE_ELEMENT)
            state = REFERENCE;
          else
            state = BREAK_TAG_PARSE;

          break;
        }

        if (m[3]) // end tag declaration
        {
          parseTag = false;
          lastTag.range.end_ = pos;

          if (m[3] == '/>' ||
              (!lastTag.prefix && SINGLETON_TAG.test(lastTag.name)))
          {
            /** @cut */ if (m[3] != '/>')
            /** @cut */   result.warns.push(['Tag <' + lastTag.name + '> doesn\'t closed explicit (use `/>` as tag ending)', lastTag]);

            lastTag = tagStack.pop();
          }
          else
          {
            // otherwise m[3] == '>'
            if (lastTag.prefix == 'b' && lastTag.name in TAG_IGNORE_CONTENT)
            {
              state = TAG_IGNORE_CONTENT[lastTag.name];
              break;
            }
          }

          state = TEXT;
          break;
        }

        if (m[2] == '=') // ATTRIBUTE_NAME_OR_END only
        {
          state = ATTRIBUTE_VALUE;
          break;
        }

        // m[2] == '\s+' next attr, state doesn't change
        token = {
          type: TYPE_ATTRIBUTE,
          range: {
            start_: pos,
            end_: pos
          }
        };
        state = ATTRIBUTE_NAME_OR_END;
        break;

      case COMMENT:
        token.value = source.substring(bufferPos, pos - 3);
        token.range.end_ = pos;
        state = TEXT;
        break;

      case REFERENCE:
        // add reference to token list name
        if (token.refs)
          token.refs.push(m[1]);
        else
          token.refs = [m[1]];

        // go next
        if (m[2] != '|') // m[2] == '}\s*'
        {
          if (token.type == TYPE_TEXT)
          {
            pos -= m[2].length - 1;
            token.value = source.substring(bufferPos, pos);
            token.range.end_ = pos;
            state = TEXT;
          }
          else if (token.type == TYPE_COMMENT)
          {
            state = COMMENT;
          }
          else if (token.type == TYPE_ATTRIBUTE && source[pos] == '=')
          {
            pos++;
            state = ATTRIBUTE_VALUE;
          }
          else // ATTRIBUTE || ELEMENT
          {
            token = {
              type: TYPE_ATTRIBUTE,
              range: {
                start_: pos,
                end_: pos
              }
            };
            state = ATTRIBUTE_NAME_OR_END;
          }
        }

        // continue to collect references
        break;

      case ATTRIBUTE_VALUE:
        token.value = m[1].replace(QUOTE_UNESCAPE, '"');
        token.range.end_ = pos;
        token.valueRange = {
          start_: startPos + 1,
          end_: startPos + 1 + m[1].length
        };

        token = {
          type: TYPE_ATTRIBUTE,
          range: {
            start_: pos,
            end_: pos
          }
        };
        state = ATTRIBUTE_NAME_OR_END;

        break;

      case TAG_IGNORE_CONTENT.text:
      case TAG_IGNORE_CONTENT.style:
        lastTag.children.push({
          type: TYPE_TEXT,
          value: m[1],
          range: {
            start_: startPos,
            end_: startPos + m[1].length
          }
        });

        lastTag = tagStack.pop();

        state = TEXT;
        break;

      default:
        throw SYNTAX_ERROR; // Must never to be here; bug in parser otherwise
    }

    if (state == TEXT)
      textStateEndPos = pos;
  }

  if (textStateEndPos != pos)
    lastTag.children.push({
      type: TYPE_TEXT,
      value: source.substring(textStateEndPos, pos),
      range: {
        start_: textStateEndPos,
        end_: pos
      }
    });

  // process attributes binding, join text tokens, normalize ranges and add location info
  postProcessing(result, options || {}, source);

  /** @cut */ if (lastTag.name)
  /** @cut */   result.warns.push(['No close tag for <' + (lastTag.prefix ? lastTag.prefix + ':' : '') + lastTag.name + '>', lastTag]);
  /** @cut */
  /** @cut */ if (!result.warns.length)
  /** @cut */   result.warns = false;

  result.templateTokens = true;

  return result;
}
1338034
function(file, mode, options) {
		mode = mode || "replace";
		const args = options ? [file, mode].concat(util.formatOptions(options)) : [file, mode];
		this.socket.command("loadfile", args);
	}
467664
function fixLinks(file) {
  return fs.readFile(file, 'utf8').then(data => {
    const flattenedLinks = data
      .replace(/\.\.\//g, '')
      .replace(/(modules|interfaces|classes)\//g, '');
    let caseFixedLinks = flattenedLinks;
    for (const lower in lowerToUpperLookup) {
      const re = new RegExp(lower, 'g');
      caseFixedLinks = caseFixedLinks.replace(re, lowerToUpperLookup[lower]);
    }
    return fs.writeFile(file, caseFixedLinks);
  });
}
109483
function translate(id, filename, buffer, options, next) {
	var ext = (filename.match(extexp) || [])[1] || '',
		encoding = options.encoding || exports.defaults.encoding,
		trans = options.translate, js, nowrap;

	// make a list of what not to wrap
	nowrap = options.nowrap || exports.defaults.nowrap;
	nowrap = [ 'define', 'define.min', 'define.shim' ].concat(nowrap);
	// should this code get wrapped with a define?
	nowrap = nowrap.some(function(no) {
		return no.test ? no.test(id) : (no === id);
	});

	// convert commonjs to amd
	function wrap(err, js) {
		if (err) { return next(err); }

		var deps = exports.dependencies(id, js), params = [], undef = '';

		// make sure require, exports, and module are properly passed into the factory
		if (/\brequire\b/.test(js)) { params.push('require'); }
		if (/\bexports\b/.test(js)) { params.push('exports'); }
		if (/\bmodule\b/.test(js)) { params.push('module'); }

		// make sure code follows the `exports` path instead of `define` path once wrapped
		if (/\bdefine\.amd\b/.test(js)) { undef = 'var define;'; }

		if (deps.length) {
			deps = ',' + JSON.stringify(params.concat(deps));
		} else if (params.length) {
			params = [ 'require', 'exports', 'module' ];
		}

		js = 'define(' + JSON.stringify(id) + deps + ',function(' + params + ')' +
				'{' + js + '\n' + undef + '}' + // rely on hoisting for define
			');\n';
		next(null, js);
	}

	// find the translate function
	trans = trans && (trans[filename] || trans[id] || trans[ext]);
	if (trans) { // user configured translation
		return trans(
			{ id:id, filename:filename, buffer:buffer },
			options, (nowrap ? next : wrap)
		);
	}

	js = buffer.toString(encoding);

	// handle javascript files
	if ('js' === ext) {
		return (nowrap ? next : wrap)(null, js);
	}

	// handle non-javascript files
	if ('json' !== ext) { js = JSON.stringify(js); } // export file as json string
	if (nowrap) { return next(null, 'return ' + js); }
	return next(null, 'define(' + JSON.stringify(id) + ',' + js + ');\n');
}
675154
function parse_javascript(file /*, options*/) {
  let source = fs.readFileSync(file, 'utf8');

  let nodes, list = {};

  try {
    nodes = parser.parse(source);
  } catch (err) {
    throw new Error(`${err} [${file}:${err.line},${err.column}]`);
  }

  // do pre-distribute early work
  _.each(nodes, node /*, id*/ => {
    let clone;

    // assign hierarchy helpers
    node.aliases  = [];
    node.children = [];

    // set source fiel of the node
    node.file = file;

    if (node.type === 'class') {
      node.subclasses = [];
    }

    // collect sections
    if (node.type === 'section') {
      list[node.id] = node;
      return;
    }

    // elements with undefined section get '' section,
    // and will be resolved later, when we'll have full
    // element list
    list[(node.section || '') + '.' + node.id] = node;

    // bound methods produce two methods with the same description but different signatures
    // E.g. Element.foo(@element, a, b) becomes
    // Element.foo(element, a, b) and Element#foo(a, b)
    if (node.type === 'method' && node.bound) {
      clone = _.clone(node);
      clone.id = node.id.replace(/(.+)\.(.+)$/, '$1#$2');

      // link to methods
      node.bound = clone.id;
      clone.bound = node.id;

      // insert bound method clone
      list[(node.section || '') + '.' + clone.id] = clone;
    }
  });

  // TODO: section.related_to should mark related element as belonging to the section
  //_.each(list, function (node, id) {
  //  var ref_id = '.' + node.related_to, ref;
  //  if ('section' === node.type && node.related_to && list[ref_id]) {
  //    ref = list[ref_id];
  //    ref.id = node.id + '.' + node.related_to;
  //    delete list[ref_id];
  //    list[ref.id] = ref;
  //  }
  //});

  return list;
}
1074730
function(file, options, callback) {
        fs.readFile(file, options, function(err, data) {
            if (err) {
                return callback(err);
            }
            module.exports.parse(data.toString(), function(parseErr, lines) {
                if (parseErr) {
                    return callback(parseErr);
                }
                callback(undefined, lines);
            });
        });
    }
989352
function(source) {
			// transform tokens
			var tokens = this.lex(source), pos = 0, token;
			for (var i = 0, il = tokens.length; i < il; i++) {
				token = tokens[i];
				token.start = pos;
				token.end = (pos += token.value.length);
			}
			return tokens;
		}
1073956
function(file, options, callback) {
        var lines;
        fs.readFile(file, options, function(err, data) {
            if (err) {
                //err
                return callback(err);
            }
            if (/\r\n/.test(data.toString())) {
                lines = data.toString().split('\r\n');
            } else {
                lines = data.toString().split('\n');
            }
            if (module.exports.verify(lines[0])) {
                callback(undefined, lines);
            } else {
                callback("INVALID_SCC_FORMAT");
            }
        });
    }
283634
function (file) {
      var result = getRawData(file), type = JSZip.utils.getTypeOf(result);
      if (type === "string") {
         if (!file.options.binary) {
            // unicode text !
            // unicode string => binary string is a painful process, check if we can avoid it.
            if (JSZip.support.uint8array && typeof TextEncoder === "function") {
               return TextEncoder("utf-8").encode(result);
            }
            if (JSZip.support.nodebuffer) {
               return new Buffer(result, "utf-8");
            }
         }
         return file.asBinary();
      }
      return result;
   }
832999
function Parser(tokens, options) {
  options = options || {};
  if (!Array.isArray(tokens)) {
    throw new Error('Expected tokens to be an Array but got "' + (typeof tokens) + '"');
  }
  if (typeof options !== 'object') {
    throw new Error('Expected "options" to be an object but got "' + (typeof options) + '"');
  }
  this.tokens = new TokenStream(tokens);
  this.filename = options.filename;
  this.src = options.src;
  this.inMixin = 0;
  this.plugins = options.plugins || [];
}
1147598
function token() {
    if (re.lastIndex >= text.length) return EOF; // special case: end of file
    if (eol) { eol = false; return EOL; } // special case: end of line

    // special case: quotes
    var j = re.lastIndex;
    if (text.charCodeAt(j) === 34) {
      var i = j;
      while (i++ < text.length) {
        if (text.charCodeAt(i) === 34) {
          if (text.charCodeAt(i + 1) !== 34) break;
          i++;
        }
      }
      re.lastIndex = i + 2;
      var c = text.charCodeAt(i + 1);
      if (c === 13) {
        eol = true;
        if (text.charCodeAt(i + 2) === 10) re.lastIndex++;
      } else if (c === 10) {
        eol = true;
      }
      return text.substring(j + 1, i).replace(/""/g, "\"");
    }

    // common case
    var m = re.exec(text);
    if (m) {
      eol = m[0].charCodeAt(0) !== 44;
      return text.substring(j, m.index);
    }
    re.lastIndex = text.length;
    return text.substring(j);
  }
1220433
function normalize(file, fn) {
  var orig = utils.extend({}, file);

  // support paths
  if (typeof fn === 'string') {
    file.type = 'path';
    file.path = fn;
    file.origPath = fn;
    file = resolve(file, file.options);

  // support functions
  } else if (typeof fn === 'function') {
    file.type = 'function';
    file.path = file.name;
    file.fn = fn;

  // support instances
  } else if (utils.isAppArg(file.app)) {
    file.type = 'app';
    file.path = file.name;
    file.app = fn;

  } else {
    throw new TypeError('expected env to be a string or function');
  }

  if (file === null) {
    var name = typeof fn === 'string' ? fn : orig.key;
    throw new Error('cannot resolve: ' + util.inspect(name));
  }
  return file;
}
1311352
protected function typeHint(File $file, array $tokens, $functionIndex) {
		$parenthesisCloseTagIndex = $tokens[$functionIndex]['parenthesis_closer'];
		$scopeOpenTagIndex = $tokens[$functionIndex]['scope_opener'];

		$typehintIndex = $file->findNext(T_STRING, $parenthesisCloseTagIndex + 1, $scopeOpenTagIndex);
		if ($typehintIndex === false) {
			return 'mixed';
		}

		$returnType = $tokens[$typehintIndex]['content'];

		$nullableIndex = $file->findNext(T_NULLABLE, $parenthesisCloseTagIndex + 1, $typehintIndex);

		if ($nullableIndex) {
			$returnType .= '|null';
		}

		return $returnType;
	}
48570
function script(source, options) {
  var tokens

  /* Make sure the require to the main module
   * is showed as if it was a require from
   * `./node_modules`.
   *
   * For example, when the example file
   * (`test/example.js`) requires the main file (as
   * listed in `test/package.json`, `main: "module.js"`)
   * as `./module`, it is replaced with `test`. */
  source = source.replace(EXPRESSION_REQUIRE, replace)

  /* Transform comments into markdown: */
  tokens = []

  source.split('\n').forEach(each)

  return tokens

  function replace($0, $1, $2, $3) {
    var filepath = resolveFrom.silent(
      path.dirname(options.example),
      unquote($2)
    )
    var quote

    if (options.main === filepath && options.name) {
      /* Honour quote style. */
      quote = $2.charAt(0)

      return $1 + quote + options.name + quote + $3
    }

    return $0
  }

  function each(line) {
    var match = line.match(EXPRESSION_COMMENT)

    tokens.push({
      type: match ? 'markdown' : 'javascript',
      value: match ? match[4] : line
    })
  }
}
562753
function (files, callback) {
		//loop on all files and write them
		async.each(files, function (fileObj, mCb) {
			var data = swagger.cloneObj(fileObj.data);
			
			//if tokens, replace all occurences with corresponding values
			if (fileObj.tokens) {
				for (var i in fileObj.tokens) {
					var regexp = new RegExp("%" + i + "%", "g");
					data = data.replace(regexp, fileObj.tokens[i]);
				}
			}
			if (fileObj.purify) {
				data = data.replace(/\\"/g, '"').replace(/["]+/g, '"').replace(/"__dirname/g, '__dirname');
				data = data.replace(/("group": "__empty__")/g, '"group": ""');
				data = data.replace(/("prefix": "(\s?|\s+),)/g, '"prefix": "",');
				data = data.replace(/("l": "__empty__")/g, '"l": ""');
				//"__dirname + \"/lib/mw/_get.js\""
				//"__dirname + "/lib/mw/_get.js""
				//"__dirname + "/lib/mw/_get.js"
				//__dirname + "/lib/mw/_get.js"
			}
			console.log("creating file:", fileObj.file);
			fs.writeFile(fileObj.file, data, "utf8", mCb);
		}, function (error) {
			if (error) {
				return callback({"code": 854, "msg": error.message});
			}
			return callback(null, true);
		});
	}