1 // Copyright (c) Facebook, Inc. and its affiliates.
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;
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>,
22 auto_namespace_map: &'a BTreeMap<String, String>,
24 stack_limit: Option<&'a StackLimit>,
28 DirectDeclSmartConstructors<'a>,
31 let (_, mode_opt) = parse_mode(source);
32 let mode = mode_opt.unwrap_or(Mode::Mpartial);
33 let sc = DirectDeclSmartConstructors::new(
36 env.disable_xhp_element_mangling,
37 env.array_unification,
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)