Parses the provided API file for JSDoc comments.
@function
@param {string} file - File to be parsed
@returns {{jsdoc: array, yaml: array}} JSDoc comments and Yaml files
@requires doctrine
964721
function parseApiFile(file) {
  const jsDocRegex = /\/\*\*([\s\S]*?)\*\//gm;
  const fileContent = fs.readFileSync(file, { encoding: 'utf8' });
  const ext = path.extname(file);
  const yaml = [];
  const jsDocComments = [];

  if (ext === '.yaml' || ext === '.yml') {
    yaml.push(jsYaml.safeLoad(fileContent));
  } else {
    const regexResults = fileContent.match(jsDocRegex);
    if (regexResults) {
      for (let i = 0; i < regexResults.length; i += 1) {
        const jsDocComment = doctrine.parse(regexResults[i], { unwrap: true });
        jsDocComments.push(jsDocComment);
      }
    }
  }

  return {
    yaml,
    jsdoc: jsDocComments,
  };
}
460315
function parseModule(fileInfo) {

    var moduleName = file2modulename(fileInfo.relativePath);
    var sourceFile = new SourceFile(moduleName, fileInfo.content);
    var comments = [];
    var moduleTree;
    var parser = new Parser(sourceFile);

    // Configure the parser
    parser.handleComment = function(range) {
      comments.push({ range: range });
    };
    traceurOptions.setFromObject(service.traceurOptions);

    try {
      // Parse the file as a module, attaching the comments
      moduleTree = parser.parseModule();
      attachComments(moduleTree, comments);
    } catch(ex) {
      // HACK: sometime traceur crashes for various reasons including
      // Not Yet Implemented (NYI)!
      log.error(ex.stack);
      moduleTree = {};
    }
    log.debug(moduleName);
    moduleTree.moduleName = moduleName;

    // We return the module AST but also a collection of all the comments
    // since it can be helpful to iterate through them without having to
    // traverse the AST again
    return {
      moduleTree: moduleTree,
      comments: comments
    };
  }
558541
protected function parse($file)
    {
        $data = json_decode(file_get_contents($file), true) ?: Yaml::parse(file_get_contents($file));

        return $data;
    }
1151685
function parseFile (filePath, fileContent) {
  let config = null
  const extension = path.extname(filePath)

  if (extension === '.yml' || extension === '.yaml') {
    config = yaml.safeLoad(replaceEnvironmentVariables(fileContent))
  } else if (extension === '.js') {
    config = require(path.resolve(filePath)) // eslint-disable-line
  } else if (extension === '.json') {
    config = JSON.parse(replaceEnvironmentVariables(fileContent))
  } else {
    throw new Error(`${extension} is not supported as configuration file`)
  }

  return config
}
1076968
function(file) {
        var self = this;

        return new Promise(function(resolve) {
            fs.readFileAsync(file, 'utf-8')
                .then(function(content) {
                    return self._parseFile(file, content);
                })
                .then(function(ast) {
                    return self._getConfig(file, ast);
                })
                .then(function(config) {
                    self._modules = self._modules.concat(config);

                    resolve(config);
                });
        });
    }
1319305
function(file, opts) {
	if (util.isObject(file) || util.isArray(file)) {
		return file;
	}

	var options = util.extend({
		asText: false, // true, false, 'pretty'
		javascript: false, // true, false
		scope: '', // directory to look for initial file
		variables: {
			// contains a key->value object with variables to @extends
		}
	}, opts);

	file = util.template(file, options.variables);

	/*****************************************************************************
	*  Initialize
	*****************************************************************************/

	var file_path;

	// If the file path is absolute use it
	// If not then prepend the current scope of the previous file.
	if (path.resolve(file) === path.normalize(file)) {
		file_path = path.normalize(file);
	}
	else {
		file_path = path.normalize(
			options.scope ? options.scope + '/' + file : file
		);
	}
	var class_json = parseFile(file_path, options);

	// Stores JSON objects of files that have to be merged together:
	// ["a", "b"]
	var file_list = util.isArray(class_json[indicators.EXTENDS]) ?
		class_json[indicators.EXTENDS] :
		class_json[indicators.EXTENDS] != null ?
			[ class_json[indicators.EXTENDS] ] :
			[];

	// Delete @extends from base_json to avoid infinitive recursion
	delete class_json[indicators.EXTENDS];

	// Push class_json to the path list:
	file_list.push(class_json);
	/*****************************************************************************
	*  Merge file by file
	*****************************************************************************/

	// default config for each file required:
	// set asText = false so we get an object returned
	// set scope = file's directory so there can be relative references
	var json_config = util.defaults({
		asText: false,
		scope: path.dirname(file_path),

		// _as is a hack so that we know its we are calling the function recursive
		_as: ANTI_SANITIZER
	}, options);

	// super_json is our output, start by containing first file in array
	var super_json = fromFile(file_list.shift(), json_config);

	// TODO: Figure out when to sanitize super_json hopefully we don't have to
	//   santize all returns. I'm not sure about this, and I'm not sure if we
	//   can even sanitize super_json when we return it.
	//   Is super_json used by anyone recursively?

	while (file_list.length) {
		var json = fromFile(file_list.shift(), json_config);

		merge(super_json, json);
	}

	// If this file is called from the outside eg json_merger.from...
	//   File('file_which_doesnt_extends_another_file.json')
	//   we need to sanitize the file and remove all indicators
	if (options._as != ANTI_SANITIZER) {
		super_json = util.sanitizeValue(super_json);
	}

	/*****************************************************************************
	*  Return super_json
	*****************************************************************************/
	if (options.asText) {
		return stringify(super_json, options);
	}
	else {
		return super_json;
	}
}
471581
function parse_javascript(file, options, callback) { 
  fs.readFile(file, 'utf8', function (err, source) {
    if (err) {
      callback(err);
      return;
    }
    process_jsd(source, file, options, callback);
  });
}
224297
public function parse(string $file): array
    {
        if (false === file_exists($file)) {
            throw InvalidArgumentExceptionFactory::createForFileCouldNotBeFound($file);
        }

        try {
            $data = defined('Symfony\\Component\\Yaml\\Yaml::PARSE_CONSTANT')
                ? $this->yamlParser->parse(file_get_contents($file), Yaml::PARSE_CONSTANT)
                : $this->yamlParser->parse(file_get_contents($file));

            // $data is null only if the YAML file was empty; otherwise an exception is thrown
            return (null === $data) ? [] : $data;
        } catch (\Exception $exception) {
            if ($exception instanceof SymfonyParseException) {
                throw ParseExceptionFactory::createForInvalidYaml($file, 0, $exception);
            }

            throw ParseExceptionFactory::createForUnparsableFile($file, 0, $exception);
        }
    }
210844
function parse( $file ) {

		// ------------------------------------------------------------------------------------------------------------
		// Setup & sanity check
		// ------------------------------------------------------------------------------------------------------------

		$authors = [];
		$posts = [];
		$categories = [];
		$tags = [];
		$terms = [];

		libxml_use_internal_errors( true );

		$old_value = libxml_disable_entity_loader( true );
		$dom = new \DOMDocument;
		$dom->recover = true; // Try to parse non-well formed documents
		$success = $dom->loadXML( \Pressbooks\Utility\get_contents( $file ) );
		foreach ( $dom->childNodes as $child ) {
			if ( XML_DOCUMENT_TYPE_NODE === $child->nodeType ) {
				// Invalid XML: Detected use of disallowed DOCTYPE
				$success = false;
				break;
			}
		}
		libxml_disable_entity_loader( $old_value );

		// @codingStandardsIgnoreStart
		if ( ! $success || isset( $dom->doctype ) ) {
			throw new \Exception( print_r( libxml_get_errors(), true ) );
		}

		$xml = @simplexml_import_dom( $dom );
		unset( $dom );

		// halt if loading produces an error
		if ( ! $xml ) {
			throw new \Exception( print_r( libxml_get_errors(), true ) );
		}
		// @codingStandardsIgnoreEnd

		$wxr_version = $xml->xpath( '/rss/channel/wp:wxr_version' );
		if ( ! $wxr_version ) {
			throw new \Exception( __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'pressbooks' ) );
		}

		$wxr_version = (string) trim( $wxr_version[0] );
		// confirm that we are dealing with the correct file format
		if ( ! preg_match( '/^\d+\.\d+$/', $wxr_version ) ) {
			throw new \Exception( __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'pressbooks' ) );
		}

		// ------------------------------------------------------------------------------------------------------------
		// Ladies and gentlemen, start your parsing
		// ------------------------------------------------------------------------------------------------------------

		$base_url = $xml->xpath( '/rss/channel/wp:base_site_url' );
		$base_url = (string) trim( $base_url[0] );

		$namespaces = $xml->getDocNamespaces();
		if ( ! isset( $namespaces['wp'] ) ) {
			$namespaces['wp'] = 'http://wordpress.org/export/1.1/';
		}
		if ( ! isset( $namespaces['excerpt'] ) ) {
			$namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/';
		}

		// grab authors
		foreach ( $xml->xpath( '/rss/channel/wp:author' ) as $author_arr ) {
			$a = $author_arr->children( $namespaces['wp'] );
			$login = (string) $a->author_login;
			$authors[ $login ] = [
				'author_id' => (int) $a->author_id,
				'author_login' => $login,
				'author_email' => (string) $a->author_email,
				'author_display_name' => (string) $a->author_display_name,
				'author_first_name' => (string) $a->author_first_name,
				'author_last_name' => (string) $a->author_last_name,
			];
		}

		// grab cats, tags and terms
		foreach ( $xml->xpath( '/rss/channel/wp:category' ) as $term_arr ) {
			$t = $term_arr->children( $namespaces['wp'] );
			$category = [
				'term_id' => (int) $t->term_id,
				'category_nicename' => (string) $t->category_nicename,
				'category_parent' => (string) $t->category_parent,
				'cat_name' => (string) $t->cat_name,
				'category_description' => (string) $t->category_description,
			];

			foreach ( $t->termmeta as $meta ) {
				$category['termmeta'][] = [
					'key' => (string) $meta->meta_key,
					'value' => (string) $meta->meta_value,
				];
			}

			$categories[] = $category;
		}

		foreach ( $xml->xpath( '/rss/channel/wp:tag' ) as $term_arr ) {
			$t = $term_arr->children( $namespaces['wp'] );
			$tag = [
				'term_id' => (int) $t->term_id,
				'tag_slug' => (string) $t->tag_slug,
				'tag_name' => (string) $t->tag_name,
				'tag_description' => (string) $t->tag_description,
			];

			foreach ( $t->termmeta as $meta ) {
				$tag['termmeta'][] = [
					'key' => (string) $meta->meta_key,
					'value' => (string) $meta->meta_value,
				];
			}

			$tags[] = $tag;
		}

		foreach ( $xml->xpath( '/rss/channel/wp:term' ) as $term_arr ) {
			$t = $term_arr->children( $namespaces['wp'] );
			$term = [
				'term_id' => (int) $t->term_id,
				'term_taxonomy' => (string) $t->term_taxonomy,
				'slug' => (string) $t->term_slug,
				'term_parent' => (string) $t->term_parent,
				'term_name' => (string) $t->term_name,
				'term_description' => (string) $t->term_description,
			];

			foreach ( $t->termmeta as $meta ) {
				$term['termmeta'][] = [
					'key' => (string) $meta->meta_key,
					'value' => (string) $meta->meta_value,
				];
			}

			$terms[] = $term;
		}

		// grab posts
		foreach ( $xml->channel->item as $item ) {
			$post = [
				'post_title' => (string) $item->title,
				'guid' => (string) $item->guid,
			];

			$dc = $item->children( 'http://purl.org/dc/elements/1.1/' );
			$post['post_author'] = (string) $dc->creator;

			$content = $item->children( 'http://purl.org/rss/1.0/modules/content/' );
			$excerpt = $item->children( $namespaces['excerpt'] );
			$post['post_content'] = (string) $content->encoded;
			$post['post_excerpt'] = (string) $excerpt->encoded;

			$wp = $item->children( $namespaces['wp'] );
			$post['post_id'] = (int) $wp->post_id;
			$post['post_date'] = (string) $wp->post_date;
			$post['post_date_gmt'] = (string) $wp->post_date_gmt;
			$post['comment_status'] = (string) $wp->comment_status;
			$post['ping_status'] = (string) $wp->ping_status;
			$post['post_name'] = (string) $wp->post_name;
			$post['status'] = (string) $wp->status;
			$post['post_parent'] = (int) $wp->post_parent;
			$post['menu_order'] = (int) $wp->menu_order;
			$post['post_type'] = (string) $wp->post_type;
			$post['post_password'] = (string) $wp->post_password;
			$post['is_sticky'] = (int) $wp->is_sticky;

			if ( isset( $wp->attachment_url ) ) {
				$post['attachment_url'] = (string) $wp->attachment_url;
			}

			foreach ( $item->category as $c ) {
				$att = $c->attributes();
				if ( isset( $att['nicename'] ) ) {
					$post['terms'][] = [
						'name' => (string) $c,
						'slug' => (string) $att['nicename'],
						'domain' => (string) $att['domain'],
					];
				}
			}

			foreach ( $wp->postmeta as $meta ) {
				$post['postmeta'][] = [
					'key' => (string) $meta->meta_key,
					'value' => (string) $meta->meta_value,
				];
			}

			foreach ( $wp->comment as $comment ) {
				$meta = [];
				if ( isset( $comment->commentmeta ) ) {
					foreach ( $comment->commentmeta as $m ) {
						$meta[] = [
							'key' => (string) $m->meta_key,
							'value' => (string) $m->meta_value,
						];
					}
				}

				$post['comments'][] = [
					'comment_id' => (int) $comment->comment_id,
					'comment_author' => (string) $comment->comment_author,
					'comment_author_email' => (string) $comment->comment_author_email,
					'comment_author_IP' => (string) $comment->comment_author_IP,
					'comment_author_url' => (string) $comment->comment_author_url,
					'comment_date' => (string) $comment->comment_date,
					'comment_date_gmt' => (string) $comment->comment_date_gmt,
					'comment_content' => (string) $comment->comment_content,
					'comment_approved' => (string) $comment->comment_approved,
					'comment_type' => (string) $comment->comment_type,
					'comment_parent' => (string) $comment->comment_parent,
					'comment_user_id' => (int) $comment->comment_user_id,
					'commentmeta' => $meta,
				];
			}

			$posts[] = $post;
		}

		return [
			'authors' => $authors,
			'posts' => $posts,
			'categories' => $categories,
			'tags' => $tags,
			'terms' => $terms,
			'base_url' => $base_url,
			'version' => $wxr_version,
		];
	}
894701
public static function parseYamlFile($file): array
    {
        if (file_exists($file)) {
            $data = file_get_contents($file);
            if (!empty($data)) {
                $data = static::replaceEnvVariables($data);
                return Yaml::parse($data);
            }
        }

        return [];
    }
377672
def parse_from_file
      parsed_opts = YAML.load_file(config_path)
      parsed_opts.delete_if{|k| k.to_s == 'config_path'}
      parsed_opts.each_pair{|k,v| self[k] = v}
      true
    rescue Errno::ENOENT
      false
    end
164993
def parsed_options_from_yaml(file)
      options_to_merge = {}

      if File.exist?(file)
        # Load YAML content
        content = YAML.load(File.read(file))

        # Symbolize keys
        options_to_merge = content.reduce({}) do |memo, (key, value)|
          memo.merge! key.to_sym => value
        end
      end

      options_to_merge
    end
1134242
def read_file(file)
      json = JSON.parse(File.read(file))
      json.key?('definitions') ? json['definitions'] : {}
    end
1332695
protected function parseFromFile(string $file) : array
    {
        if (function_exists('yaml_parse_file')) {
            try {
                set_error_handler(function ($code, $message) {
                    throw new \RuntimeException(
                        $message,
                        $code
                    );
                });

                $array = yaml_parse_file($file);
                restore_error_handler();
                if (!is_array($array)) {
                    throw new \RuntimeException(
                        sprintf(
                            'Configuration file in : %s does not return array',
                            $file
                        )
                    );
                }
                return $array;
            } catch (\Throwable $e) {
                restore_error_handler();
                throw  $e;
            }
        }

        $array =  SymfonyYAML::parse(file_get_contents($file));
        if (!is_array($array)) {
            throw new \RuntimeException(
                sprintf(
                    'Configuration file in : %s does not return array',
                    $file
                )
            );
        }

        return $array;
    }
1245532
function load(file, loadDescription) {
            try {
                var data = fs.readFileSync(file, 'utf8');
            
                var regex = /(\/\*\*([^*]|[\r\n]|(\*+([^*\/]|[\r\n])))*\*+\/)/g;
                
                var commentRaw;
                var comments = [];
                var commentParsed;
                var description;
                
                if (loadDescription) {
                    commentRaw = regex.exec(data);
                    commentParsed = doctrine.parse(commentRaw[0], { unwrap: true });
                    description = commentParsed.description;
                } else {
                    description = '';
                }

                while ((commentRaw = regex.exec(data)) !== null) {
                    commentParsed = doctrine.parse(commentRaw[0], { unwrap: true });

                    commentParsed.getMethod = function() {
                        for (var tag of this.tags)
                        {
                            if (tag.title === 'function') {
                                return tag.name;
                            }
                        }
                    };
                    commentParsed.getSummary = function() {
                        for (var tag of this.tags)
                        {
                            if (tag.title === 'summary') {
                                return tag.description.replace(/(\r\n|\n)/gm,'');
                            }
                        }
                    };
                    commentParsed.getDescription = function() {
                        for (var tag of this.tags)
                        {
                            if (tag.title === 'description') {
                                return tag.description.replace(/(?<!  )(\r\n|\n)/gm,''); 
                            }
                        }
                    };
                    // TODO: add support for multiple examples
                    commentParsed.getExample = function() {
                        for (var tag of this.tags)
                        {
                            if (tag.title === 'example') {
                                var example = {
                                    description: tag.description,
                                    caption: tag.caption
                                }
                                return example;
                            }
                        }
                    };
                    commentParsed.getReturn = function() {
                        for (var tag of this.tags)
                        {
                            if (tag.title === 'return') {
                                var type = doctrine.type.stringify(tag.type, {compact:true});
                                type = type.replace(/<|>/ig, function(m){
                                    return '&' + (m == '>' ? 'g' : 'l') + 't;';
                                });

                                return { 
                                    description: tag.description.replace(/(\r\n|\n)/gm,''), 
                                    type: type
                                };
                            }
                        }
                    };
                    commentParsed.getParams = function() {
                        var params = [];
                        for (var tag of this.tags)
                        {
                            if (tag.title === 'param') {
                                var optional;
                                if (tag.type.type === 'OptionalType' || tag.type.type === 'RestType') {
                                    optional = true;
                                } else {
                                    optional = false;
                                }

                                var type = doctrine.type.stringify(tag.type, {compact:true});
                                type = type.replace(/<|>/ig, function(m){
                                    return '&' + (m == '>' ? 'g' : 'l') + 't;';
                                });
                                
                                params.push({ 
                                    description: tag.description.replace(/(\r\n|\n)/gm,''), 
                                    name: tag.name, 
                                    type: type,
                                    optional: optional
                                });
                            }
                        }
                        return params;
                    };
                    commentParsed.getFor = function() {
                        for (var tag of this.tags)
                        {
                            if (tag.title === 'for') {
                                var fors = tag.description.replace(/(\r\n|\n)/gm,'').split(',').map(function(item) {
                                    return item.trim();
                                });
                                return fors;
                            }
                        }
                    };
                    commentParsed.getDeprecated = function() {
                        for (var tag of this.tags)
                        {
                            if (tag.title === 'deprecated') {
                                return 'This command is deprecated and will be removed in the future. ' + tag.description;
                            }
                        }
                    };


                    comments.push(commentParsed);
                }
                return { description: description.replace(/(?<!  )(\r\n|\n)/gm, ''), methods: comments };
            } catch (exc) {       
                grunt.log.error("Unable to load/parse " + file, exc);
            }
        }
126885
public static DesignDocument fromFile(File file) throws FileNotFoundException {
        assertNotEmpty(file, "Design js file");
        DesignDocument designDocument;
        Gson gson = new Gson();
        InputStreamReader reader = null;
        try {
            reader = new InputStreamReader(new FileInputStream(file),"UTF-8");
            //Deserialize JS file contents into DesignDocument object
            designDocument = gson.fromJson(reader, DesignDocument.class);
            return designDocument;
        } catch (UnsupportedEncodingException e) {
            //UTF-8 should be supported on all JVMs
            throw new RuntimeException(e);
        } finally {
            IOUtils.closeQuietly(reader);
        }
    }
1118398
function jsCompile(content, file)
{
  // make it as a child of this module
  // Would be nice to actually make it transparent
  // and pretend it to be child of the caller module
  // but there is no obvious way, yet
  var jsMod = new Module(file, module);

  // override parents to exclude configly from the chain
  // it's like this js file is included directly
  // from the file that included `configly`
  while (jsMod.parent
    && typeof jsMod.parent.id === 'string'
    && jsMod.parent.id.match(/\/node_modules\/configly\//)
    && jsMod.parent.parent) {
    /* istanbul ignore next */
    jsMod.parent = jsMod.parent.parent;
  }

  // generate node_modules paths for the file
  jsMod.paths = Module._nodeModulePaths(path.dirname(file));

  // execute the module
  jsMod._compile(content, file);
  // return just exported object
  return jsMod.exports;
}