Array unification switch
[hiphop-php.git] / hphp / hack / src / parser / api / direct_decl_parser.rs
blobe0a6bcc8e890b78731adfd5013082032c532f80e
1 // Copyright (c) Facebook, Inc. and its affiliates.
2 //
3 // This source code is licensed under the MIT license found in the
4 // LICENSE file in the "hack" directory of this source tree.
6 use std::collections::BTreeMap;
8 use bumpalo::Bump;
10 use direct_decl_smart_constructors::{DirectDeclSmartConstructors, Node};
11 use mode_parser::parse_mode;
12 use oxidized_by_ref::file_info::Mode;
13 use parser::parser::Parser;
14 use parser_core_types::{
15     parser_env::ParserEnv, source_text::SourceText, syntax_error::SyntaxError,
17 use stack_limit::StackLimit;
19 pub fn parse_script<'a>(
20     source: &SourceText<'a>,
21     env: ParserEnv,
22     auto_namespace_map: &'a BTreeMap<String, String>,
23     arena: &'a Bump,
24     stack_limit: Option<&'a StackLimit>,
25 ) -> (
26     Node<'a>,
27     Vec<SyntaxError>,
28     DirectDeclSmartConstructors<'a>,
29     Option<Mode>,
30 ) {
31     let (_, mode_opt) = parse_mode(source);
32     let mode = mode_opt.unwrap_or(Mode::Mpartial);
33     let sc = DirectDeclSmartConstructors::new(
34         &source,
35         mode,
36         env.disable_xhp_element_mangling,
37         env.array_unification,
38         auto_namespace_map,
39         arena,
40     );
41     let mut parser = Parser::new(&source, env, sc);
42     let root = parser.parse_script(stack_limit);
43     let errors = parser.errors();
44     let sc_state = parser.into_sc_state();
45     (root, errors, sc_state, mode_opt)