language
stringlengths
0
24
filename
stringlengths
9
214
code
stringlengths
99
9.93M
OCaml
hhvm/hphp/hack/src/parser/limited_width_pretty_printing_library.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) (* implementation of pretty printing library based on Philip Wadler's paper * titled "A Prettier Printer", and the strict ocaml implementation based on * Christian Lindig's paper "Strictly Pretty" *) open Pretty_printing_library_sig module type LineSpec = sig val line_width : int end (* comparator using line width as constraint *) module WidthConstrainedDocComparator (C : LineSpec) : DocCompare = struct type t = doc type mode = | Flat | Vert let strlen = String.length let line_width = C.line_width (* implementation as specified in the Prettier Printer paper *) (* width is the constraint, and k is the number of chars already occupied *) let rec format width k = function | [] -> LNil | (_i, _m, Nil) :: tl -> format width k tl | (i, m, Cons (x, y)) :: tl -> format width k ((i, m, x) :: (i, m, y) :: tl) | (i, m, Nest (j, x)) :: tl -> format width k ((i + j, m, x) :: tl) | (_i, _m, Text s) :: tl -> LText (s, format width (k + strlen s) tl) | (_i, Flat, Break s) :: tl -> LText (s, format width (k + strlen s) tl) | (i, Vert, Break _s) :: tl -> LLine (i, format width i tl) | (i, _m, MustBreak) :: tl -> LLine (i, format width i tl) (* "lazy evaluation". We expand group only at here. * Note also that only one of if and else will be executed *) | (i, _m, Group x) :: tl -> if fits (width - k) ((i, Flat, x) :: tl) && not (must_break x) then format width k ((i, Flat, x) :: tl) else format width k ((i, Vert, x) :: tl) (* recursively check that the subgroup fits in the given width * "Fit" is checked by seeing that the document being expanded * horizontally can stay in one line within the width limit, unitil * a known newline is seen *) and fits w = function | _ when w < 0 -> false | [] -> true | (_i, _m, Nil) :: tl -> fits w tl | (i, m, Cons (x, y)) :: tl -> fits w ((i, m, x) :: (i, m, y) :: tl) | (i, m, Nest (j, x)) :: tl -> fits w ((i + j, m, x) :: tl) | (_i, _m, Text s) :: tl -> fits (w - strlen s) tl | (_i, Flat, Break s) :: tl -> fits (w - strlen s) tl | (_i, Vert, Break _) :: _tl -> true | (_i, _m, MustBreak) :: _tl -> true (* See flatten in Wadler's paper. Entire document is flattened *) | (i, _m, Group x) :: tl -> fits w ((i, Flat, x) :: tl) (* returns true if the doc expands to contain a Mustbreak. If it does, then * we know that all breaks in this part of the doc have to be newlines *) and must_break x = let rec aux_must_break = function | [] -> false | Nil :: tl -> aux_must_break tl | Cons (x, y) :: tl -> aux_must_break (x :: y :: tl) | Nest (_j, x) :: tl -> aux_must_break (x :: tl) | Text _ :: tl -> aux_must_break tl | Break _ :: tl -> aux_must_break tl | MustBreak :: _tl -> true | Group x :: tl -> aux_must_break (x :: tl) in aux_must_break [x] let best k doc = format line_width k [(0, Flat, Group doc)] end
Rust
hhvm/hphp/hack/src/parser/minimal_trivia.rs
// Copyright (c) 2019, Facebook, Inc. // All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use ocamlrep::FromOcamlRep; use ocamlrep::ToOcamlRep; use crate::lexable_trivia::LexableTrivia; use crate::lexable_trivia::LexableTrivium; use crate::trivia_factory::SimpleTriviaFactory; use crate::trivia_kind::TriviaKind; #[derive(Debug, Clone, FromOcamlRep, ToOcamlRep, PartialEq)] pub struct MinimalTrivium { pub kind: TriviaKind, pub width: usize, } pub type MinimalTrivia = Vec<MinimalTrivium>; impl LexableTrivia for MinimalTrivia { type Trivium = MinimalTrivium; fn is_empty(&self) -> bool { self.is_empty() } fn has_kind(&self, kind: TriviaKind) -> bool { self.iter().any(|t| t.kind == kind) } fn push(&mut self, trivium: Self::Trivium) { self.push(trivium) } fn extend(&mut self, other: Self) { for trivium in other { self.push(trivium) } } } impl LexableTrivium for MinimalTrivium { fn kind(&self) -> TriviaKind { self.kind } fn width(&self) -> usize { self.width } fn make_whitespace(_offset: usize, width: usize) -> Self { Self { kind: TriviaKind::WhiteSpace, width, } } fn make_eol(_offset: usize, width: usize) -> Self { Self { kind: TriviaKind::EndOfLine, width, } } fn make_single_line_comment(_offset: usize, width: usize) -> Self { Self { kind: TriviaKind::SingleLineComment, width, } } fn make_fallthrough(_offset: usize, width: usize) -> Self { Self { kind: TriviaKind::FallThrough, width, } } fn make_fix_me(_offset: usize, width: usize) -> Self { Self { kind: TriviaKind::FixMe, width, } } fn make_ignore_error(_offset: usize, width: usize) -> Self { Self { kind: TriviaKind::IgnoreError, width, } } fn make_extra_token_error(_offset: usize, width: usize) -> Self { Self { kind: TriviaKind::ExtraTokenError, width, } } fn make_delimited_comment(_offset: usize, width: usize) -> Self { Self { kind: TriviaKind::DelimitedComment, width, } } } impl SimpleTriviaFactory for MinimalTrivia { fn make() -> Self { vec![] } }
Rust
hhvm/hphp/hack/src/parser/mode_parser.rs
// Copyright (c) 2019, Facebook, Inc. // All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use bumpalo::Bump; use parser_core_types::parser_env::ParserEnv; use parser_core_types::source_text::SourceText; use parser_core_types::syntax_by_ref::syntax::Syntax; use parser_core_types::syntax_by_ref::syntax_variant_generated::SyntaxVariant; use parser_core_types::syntax_by_ref::syntax_variant_generated::{self as syntax}; use parser_core_types::syntax_tree::FileMode; pub enum Language { Hack, PHP, } // Returns Language::PHP if text is a PHP file (has .php extension and starts // with anything other than <?hh). Correctly recognizing PHP files is important // for open-source projects, which may need Hack and PHP files to coexist in the // same directory. pub fn parse_mode(text: &SourceText<'_>) -> (Language, Option<FileMode>) { let bump = Bump::new(); if let Some(header) = positioned_by_ref_parser::parse_header_only(ParserEnv::default(), &bump, text) { match header.children { SyntaxVariant::MarkupSection(section_children) => { match section_children { syntax::MarkupSectionChildren { suffix: Syntax { children: SyntaxVariant::MarkupSuffix(suffix_children), .. }, .. } => { let syntax::MarkupSuffixChildren { name, .. } = *suffix_children; match &name.children { // <?, <?php or <?anything_else except <?hh SyntaxVariant::Missing => (Language::PHP, None), // <?hh _ => { if text.file_path().has_extension("hhi") { (Language::Hack, Some(FileMode::Hhi)) } else { (Language::Hack, Some(FileMode::Strict)) } } } } _ => { // unreachable (parser either returns a value that matches // the above expressions, or None) (Language::Hack, Some(FileMode::Strict)) } } } // unreachable (parser either returns a value that matches // the above expression, or None) _ => (Language::Hack, Some(FileMode::Strict)), } } else { (Language::Hack, Some(FileMode::Strict)) } }
Rust
hhvm/hphp/hack/src/parser/modules_check.rs
// Copyright (c) 2022, Meta, Inc. // All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use oxidized::aast; use oxidized::pos::Pos; use parser_core_types::syntax_error; use parser_core_types::syntax_error::Error as ErrorMsg; use parser_core_types::syntax_error::SyntaxError; struct Checker { errors: Vec<SyntaxError>, } impl Checker { fn new() -> Self { Self { errors: vec![] } } fn add_error(&mut self, pos: &Pos, msg: ErrorMsg) { let (start_offset, end_offset) = pos.info_raw(); self.errors .push(SyntaxError::make(start_offset, end_offset, msg, vec![])); } } /* Module membership declarations must be before any real declaration in the file You can have use namespace or file attributes in any order before it, but actual declarations must follow the module membership decl. This check also prevents having two module declarations in the file. */ fn check_module_declaration_first(checker: &mut Checker, program: &aast::Program<(), ()>) { let mut past_first_def = false; let mut past_module_membership = false; for def in program { match def { aast::Def::Stmt(_) /* Stmt is only used for Markup */ | aast::Def::FileAttributes(_) => {} aast::Def::SetModule(m) => { if past_first_def { let oxidized::ast::Id(pos, name) = &**m; checker.add_error(pos, syntax_error::module_first_in_file(name)); } past_first_def = true; past_module_membership = true } // We do not allow module declarations within a module aast::Def::Module(m) => { if past_module_membership { checker.add_error(&m.name.0, syntax_error::module_declaration_in_module); } past_first_def = true; } aast::Def::Fun(_) | aast::Def::Class(_) | aast::Def::Typedef(_) | aast::Def::Namespace(_) | aast::Def::SetNamespaceEnv(_) | aast::Def::NamespaceUse(_) | aast::Def::Constant(_) => past_first_def = true, } } } pub fn check_program(program: &aast::Program<(), ()>) -> Vec<SyntaxError> { let mut checker = Checker::new(); check_module_declaration_first(&mut checker, program); checker.errors }
OCaml
hhvm/hphp/hack/src/parser/namespaces.ml
(* * Copyright (c) 2015, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) open Hh_prelude open Namespace_env module SN = Naming_special_names type elaborate_kind = | ElaborateFun | ElaborateClass | ElaborateConst let elaborate_into_ns ns_name id = match ns_name with | None -> "\\" ^ id | Some ns -> "\\" ^ ns ^ "\\" ^ id let elaborate_into_current_ns nsenv id = elaborate_into_ns nsenv.ns_name id (* If the given id is an xhp id, for example :foo:bar * we will pull it apart into foo and bar, then reassemble * into \foo\bar. This gives us the fully qualified name * in a way that the rest of elaborate_id_impl expects. *) let elaborate_xhp_namespace id = let is_xhp s = String.(s <> "" && contains s ':') in if is_xhp id then Str.global_replace (Str.regexp ":") "\\\\" id else id (* Resolves an identifier in a given namespace environment. For example, if we * are in the namespace "N\O", the identifier "P\Q" is resolved to "\N\O\P\Q". * * All identifiers are fully-qualified by this function; the internal * representation of identifiers inside the typechecker after naming is a fully * qualified identifier. * * It's extremely important that this function is idempotent. We actually * normalize identifiers in two phases. Right after parsing, we need to have * the class hierarchy normalized so that we can recompute dependencies for * incremental mode properly. Other identifiers are normalized during naming. * However, we don't do any bookkeeping to determine which we've normalized or * not, just relying on the idempotence of this function to make sure everything * works out. (Fully qualifying identifiers is of course idempotent, but there * used to be other schemes here.) *) let elaborate_raw_id nsenv kind id = (* in case we've found an xhp id let's do some preparation to get it into the \namespace\xhp format *) let id = match kind with | ElaborateClass when nsenv.ns_disable_xhp_element_mangling -> elaborate_xhp_namespace id | _ -> id in if (not (String.equal id "")) && Char.equal id.[0] '\\' then id else let fqid = Utils.add_ns id in match kind with | ElaborateConst when SN.PseudoConsts.is_pseudo_const fqid -> fqid | ElaborateFun when SN.PseudoFunctions.is_pseudo_function fqid -> fqid | ElaborateClass when SN.Typehints.is_reserved_global_name id -> fqid | ElaborateClass when SN.Typehints.is_reserved_hh_name id -> if nsenv.ns_is_codegen then elaborate_into_ns (Some "HH") id else fqid | _ -> let (prefix, has_bslash) = match String.index id '\\' with | Some i -> (String.sub id ~pos:0 ~len:i, true) | None -> (id, false) in if has_bslash && String.equal prefix "namespace" then elaborate_into_current_ns nsenv (String_utils.lstrip id "namespace\\") else let uses = match kind with | _ when has_bslash -> nsenv.ns_ns_uses | ElaborateClass -> nsenv.ns_class_uses | ElaborateFun -> nsenv.ns_fun_uses | ElaborateConst -> nsenv.ns_const_uses in (match SMap.find_opt prefix uses with | Some use -> Utils.add_ns (use ^ String_utils.lstrip id prefix) | None -> elaborate_into_current_ns nsenv id) let elaborate_id nsenv kind (p, id) = (p, elaborate_raw_id nsenv kind id)
OCaml Interface
hhvm/hphp/hack/src/parser/namespaces.mli
(* * Copyright (c) 2015, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) type elaborate_kind = | ElaborateFun | ElaborateClass | ElaborateConst val elaborate_id : Namespace_env.env -> elaborate_kind -> Ast_defs.id -> Ast_defs.id
Rust
hhvm/hphp/hack/src/parser/namespaces.rs
// Copyright (c) Facebook, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use std::borrow::Cow; use naming_special_names_rust as sn; use oxidized::ast::*; use oxidized::namespace_env; trait NamespaceEnv { fn disable_xhp_element_mangling(&self) -> bool; fn is_codegen(&self) -> bool; fn name(&self) -> Option<&str>; fn get_imported_name( &self, kind: ElaborateKind, name: &str, has_backslash: bool, ) -> Option<&str>; } impl NamespaceEnv for namespace_env::Env { fn disable_xhp_element_mangling(&self) -> bool { self.disable_xhp_element_mangling } fn is_codegen(&self) -> bool { self.is_codegen } fn name(&self) -> Option<&str> { match &self.name { None => None, Some(name) => Some(name.as_ref()), } } fn get_imported_name( &self, kind: ElaborateKind, prefix: &str, has_bslash: bool, ) -> Option<&str> { let uses = { if has_bslash { &self.ns_uses } else { match kind { ElaborateKind::Class => &self.class_uses, ElaborateKind::Fun => &self.fun_uses, ElaborateKind::Const => &self.const_uses, } } }; match uses.get(prefix) { None => None, Some(used) => Some(used.as_ref()), } } } impl NamespaceEnv for oxidized_by_ref::namespace_env::Env<'_> { fn disable_xhp_element_mangling(&self) -> bool { self.disable_xhp_element_mangling } fn is_codegen(&self) -> bool { self.is_codegen } fn name(&self) -> Option<&str> { self.name } fn get_imported_name( &self, kind: ElaborateKind, prefix: &str, has_bslash: bool, ) -> Option<&str> { let uses = { if has_bslash { self.ns_uses } else { match kind { ElaborateKind::Class => self.class_uses, ElaborateKind::Fun => self.fun_uses, ElaborateKind::Const => self.const_uses, } } }; uses.get(&prefix).copied() } } #[derive(Clone, Debug, Copy, Eq, PartialEq)] pub enum ElaborateKind { Fun, Class, Const, } fn elaborate_into_ns(ns_name: Option<&str>, id: &str) -> String { match ns_name { None => { let mut s = String::with_capacity(1 + id.len()); s.push('\\'); s.push_str(id); s } Some(ns) => { let mut s = String::with_capacity(2 + ns.len() + id.len()); s.push('\\'); s.push_str(ns); s.push('\\'); s.push_str(id); s } } } fn elaborate_into_current_ns(nsenv: &impl NamespaceEnv, id: &str) -> String { elaborate_into_ns(nsenv.name(), id) } pub fn elaborate_xhp_namespace(id: &str) -> Option<String> { let is_xhp = !id.is_empty() && id.contains(':'); if is_xhp { Some(id.replace(':', "\\")) } else { None } } /// Resolves an identifier in a given namespace environment. For example, if we /// are in the namespace "N\O", the identifier "P\Q" is resolved to "\N\O\P\Q". /// /// All identifiers are fully-qualified by this function; the internal /// representation of identifiers inside the typechecker after naming is a fully /// qualified identifier. /// /// It's extremely important that this function is idempotent. We actually /// normalize identifiers in two phases. Right after parsing, we need to have /// the class hierarchy normalized so that we can recompute dependencies for /// incremental mode properly. Other identifiers are normalized during naming. /// However, we don't do any bookkeeping to determine which we've normalized or /// not, just relying on the idempotence of this function to make sure everything /// works out. (Fully qualifying identifiers is of course idempotent, but there /// used to be other schemes here.) fn elaborate_raw_id<'a>( nsenv: &impl NamespaceEnv, kind: ElaborateKind, id: &'a str, elaborate_xhp_namespaces_for_facts: bool, ) -> Option<String> { let id = if kind == ElaborateKind::Class && nsenv.disable_xhp_element_mangling() { let qualified = elaborate_xhp_namespace(id); match qualified { None => Cow::Borrowed(id), Some(s) if id.starts_with(':') && elaborate_xhp_namespaces_for_facts => { // allow :foo:bar to be elaborated into // \currentnamespace\foo\bar rather than \foo\bar Cow::Owned(s.get(1..).unwrap().to_string()) } Some(s) => Cow::Owned(s), } } else { Cow::Borrowed(id) }; // It is already qualified if id.starts_with('\\') { return match id { Cow::Borrowed(..) => None, Cow::Owned(s) => Some(s), }; } let id = id.as_ref(); // Return early if it's a special/pseudo name let fqid = core_utils_rust::add_ns(id).into_owned(); match kind { ElaborateKind::Const => { if sn::pseudo_consts::is_pseudo_const(&fqid) { return Some(fqid); } } ElaborateKind::Fun if sn::pseudo_functions::is_pseudo_function(&fqid) => { return Some(fqid); } ElaborateKind::Class if sn::typehints::is_reserved_global_name(id) => { return Some(fqid); } ElaborateKind::Class if sn::typehints::is_reserved_hh_name(id) && nsenv.is_codegen() => { return Some(elaborate_into_ns(Some("HH"), id)); } ElaborateKind::Class if sn::typehints::is_reserved_hh_name(id) => { return Some(fqid); } _ => {} } let (prefix, has_bslash) = match id.find('\\') { Some(i) => (&id[..i], true), None => (id, false), }; if has_bslash && prefix == "namespace" { return Some(elaborate_into_current_ns( nsenv, id.trim_start_matches("namespace\\"), )); } match nsenv.get_imported_name(kind, prefix, has_bslash) { Some(used) => { let without_prefix = id.trim_start_matches(prefix); let mut s = String::with_capacity(used.len() + without_prefix.len()); s.push_str(used); s.push_str(without_prefix); Some(core_utils_rust::add_ns(&s).into_owned()) } None => Some(elaborate_into_current_ns(nsenv, id)), } } pub fn elaborate_id(nsenv: &namespace_env::Env, kind: ElaborateKind, id: &mut Id) { if let Some(s) = elaborate_raw_id(nsenv, kind, &id.1, false) { id.1 = s; } } pub fn elaborate_raw_id_in<'a>( arena: &'a bumpalo::Bump, nsenv: &oxidized_by_ref::namespace_env::Env<'a>, kind: ElaborateKind, id: &'a str, elaborate_xhp_namespaces_for_facts: bool, ) -> &'a str { match elaborate_raw_id(nsenv, kind, id, elaborate_xhp_namespaces_for_facts) { Some(s) => arena.alloc_str(&s), None => id, } } pub fn elaborate_into_current_ns_in<'a>( arena: &'a bumpalo::Bump, nsenv: &oxidized_by_ref::namespace_env::Env<'a>, id: &str, ) -> &'a str { arena.alloc_str(&elaborate_into_current_ns(nsenv, id)) } /// First pass of flattening namespaces, run super early in the pipeline, right /// after parsing. /// /// Fully-qualifies the things we need for Parsing_service.AddDeps -- the classes /// we extend, traits we use, interfaces we implement; along with classes we /// define. So that we can also use them to figure out fallback behavior, we also /// fully-qualify functions that we define, even though AddDeps doesn't need /// them this early. /// /// Note that, since AddDeps doesn't need it, we don't recursively traverse /// through Happly in hints -- we rely on the idempotence of elaborate_id to /// allow us to fix those up during a second pass during naming. pub mod toplevel_elaborator { use std::sync::Arc; use oxidized::ast::*; use oxidized::namespace_env; fn elaborate_xhp_namespace(id: &mut String) { if let Some(s) = super::elaborate_xhp_namespace(id.as_str()) { *id = s } } fn elaborate_into_current_ns(nsenv: &namespace_env::Env, id: &mut String) { *id = super::elaborate_into_current_ns(nsenv, id.as_str()); } /// Elaborate a defined identifier in a given namespace environment. For example, /// a class might be defined inside a namespace. fn elaborate_defined_id(nsenv: &namespace_env::Env, sid: &mut Sid) { if nsenv.disable_xhp_element_mangling && !sid.1.is_empty() && sid.1.contains(':') { elaborate_xhp_namespace(&mut sid.1); if sid.1.as_bytes()[0] != b'\\' { elaborate_into_current_ns(nsenv, &mut sid.1); } } else { elaborate_into_current_ns(nsenv, &mut sid.1); } } fn on_hint(nsenv: &namespace_env::Env, hint: &mut Hint) { if let Hint_::Happly(id, _) = hint.1.as_mut() { super::elaborate_id(nsenv, super::ElaborateKind::Class, id); } } fn on_def(nsenv: &mut Arc<namespace_env::Env>, acc: &mut Vec<Def>, def: Def) { use oxidized::ast::Def as D; match def { // The default namespace in php is the global namespace specified by // the empty string. In the case of an empty string, we model it as // the global namespace. // // We remove namespace and use nodes and replace them with // SetNamespaceEnv nodes that contain the namespace environment D::Namespace(ns) => { let (Id(_, nsname), defs) = *ns; let nsname: Option<String> = if nsname.is_empty() { None } else { match &nsenv.as_ref().name { None => Some(nsname), Some(p) => Some(p.to_string() + "\\" + &nsname[..]), } }; let mut new_nsenv = nsenv.as_ref().clone(); new_nsenv.name = nsname; let new_nsenv = Arc::new(new_nsenv); acc.push(Def::mk_set_namespace_env(Arc::clone(&new_nsenv))); on_program_(new_nsenv, defs, acc); } D::NamespaceUse(nsu) => { let mut new_nsenv = nsenv.as_ref().clone(); for (kind, Id(_, id1), Id(_, id2)) in nsu.into_iter() { match kind { NsKind::NSNamespace => new_nsenv.ns_uses.insert(id2, id1), NsKind::NSClass => new_nsenv.class_uses.insert(id2, id1), NsKind::NSClassAndNamespace => { new_nsenv.ns_uses.insert(id2.clone(), id1.clone()); new_nsenv.class_uses.insert(id2, id1) } NsKind::NSFun => new_nsenv.fun_uses.insert(id2, id1), NsKind::NSConst => new_nsenv.const_uses.insert(id2, id1), }; } let new_nsenv = Arc::new(new_nsenv); *nsenv = Arc::clone(&new_nsenv); acc.push(Def::mk_set_namespace_env(new_nsenv)); } D::Class(mut x) => { let c = x.as_mut(); elaborate_defined_id(nsenv, &mut c.name); c.extends.iter_mut().for_each(|ref mut x| on_hint(nsenv, x)); c.reqs .iter_mut() .for_each(|ref mut x| on_hint(nsenv, &mut x.0)); c.implements .iter_mut() .for_each(|ref mut x| on_hint(nsenv, x)); c.uses.iter_mut().for_each(|ref mut x| on_hint(nsenv, x)); c.xhp_attr_uses .iter_mut() .for_each(|ref mut x| on_hint(nsenv, x)); c.namespace = Arc::clone(nsenv); acc.push(Def::Class(x)); } D::Fun(mut x) => { let f = x.as_mut(); elaborate_defined_id(nsenv, &mut f.name); f.namespace = Arc::clone(nsenv); acc.push(Def::Fun(x)); } D::Typedef(mut x) => { let t = x.as_mut(); elaborate_defined_id(nsenv, &mut t.name); t.namespace = Arc::clone(nsenv); acc.push(Def::Typedef(x)); } D::Constant(mut x) => { let c = x.as_mut(); elaborate_defined_id(nsenv, &mut c.name); c.namespace = Arc::clone(nsenv); acc.push(Def::Constant(x)); } D::FileAttributes(mut f) => { f.as_mut().namespace = Arc::clone(nsenv); acc.push(Def::FileAttributes(f)); } x => acc.push(x), } } fn attach_file_level_info(p: &mut [Def]) { let file_attrs: Vec<FileAttribute> = p .iter() .filter_map(|x| x.as_file_attributes()) .cloned() .collect(); let module_name: Option<Id> = p.iter().find_map(|x| x.as_set_module()).cloned(); p.iter_mut().for_each(|x| match x { Def::Class(c) => { c.file_attributes = file_attrs.clone(); c.module = module_name.clone() } Def::Fun(f) => { f.file_attributes = file_attrs.clone(); f.module = module_name.clone() } Def::Typedef(t) => { t.file_attributes = file_attrs.clone(); t.module = module_name.clone() } Def::Module(m) => { m.file_attributes = file_attrs.clone(); } Def::Stmt(_) | Def::Constant(_) | Def::Namespace(_) | Def::NamespaceUse(_) | Def::SetNamespaceEnv(_) | Def::FileAttributes(_) | Def::SetModule(_) => {} }); } fn on_program_(mut nsenv: Arc<namespace_env::Env>, p: Vec<Def>, acc: &mut Vec<Def>) { let mut new_acc = vec![]; for def in p.into_iter() { on_def(&mut nsenv, &mut new_acc, def) } attach_file_level_info(&mut new_acc); acc.append(&mut new_acc); } fn on_program(nsenv: Arc<namespace_env::Env>, p: Program) -> Program { let mut acc = vec![]; on_program_(nsenv, p.0, &mut acc); Program(acc) } /// This function processes only top-level declarations and does not dive /// into inline classes/functions - those are disallowed in Hack and doing it will /// incur a perf hit that everybody will have to pay. For codegen purposed /// namespaces are propagated to inline declarations /// during closure conversion process pub fn elaborate_toplevel_defs(ns: Arc<namespace_env::Env>, defs: Program) -> Program { on_program(ns, defs) } }
Rust
hhvm/hphp/hack/src/parser/operator.rs
// Copyright (c) 2019, Facebook, Inc. // All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. mod operator_generated; use ocamlrep::FromOcamlRep; use ocamlrep::ToOcamlRep; use parser_core_types::parser_env::ParserEnv; use parser_core_types::token_kind::TokenKind; pub use crate::operator_generated::*; #[derive(PartialEq, FromOcamlRep, ToOcamlRep)] pub enum Assoc { LeftAssociative, RightAssociative, NotAssociative, } use self::Operator::*; impl Operator { // NOTE: ParserEnv is not used in operator::precedence(). The function rust_precedence_helper (defined in rust_parser_ffi.rs) // assumes that ParserEnv is not used. If operator::precedence() starts using ParserEnv, the helper and the callsites in OCaml // must be updated. pub fn precedence(&self, _: &ParserEnv) -> usize { // TODO: eval // TODO: Comma // TODO: elseif // TODO: else // TODO: endif // TODO: variable operator $ match self { IncludeOperator | IncludeOnceOperator | RequireOperator | RequireOnceOperator => 1, PrintOperator => 5, AssignmentOperator | AdditionAssignmentOperator | SubtractionAssignmentOperator | MultiplicationAssignmentOperator | DivisionAssignmentOperator | ExponentiationAssignmentOperator | RemainderAssignmentOperator | ConcatenationAssignmentOperator | AndAssignmentOperator | OrAssignmentOperator | ExclusiveOrAssignmentOperator | LeftShiftAssignmentOperator | RightShiftAssignmentOperator | CoalesceAssignmentOperator => 6, PipeOperator => 7, ConditionalQuestionOperator | ConditionalColonOperator | DegenerateConditionalOperator => 8, CoalesceOperator => 9, LogicalOrOperator => 10, LogicalAndOperator => 11, OrOperator => 12, ExclusiveOrOperator => 13, AndOperator => 14, EqualOperator | StrictEqualOperator | NotEqualOperator | StrictNotEqualOperator => 15, SpaceshipOperator | LessThanOperator | LessThanOrEqualOperator | GreaterThanOperator | GreaterThanOrEqualOperator => 16, LeftShiftOperator | RightShiftOperator => 17, AdditionOperator | SubtractionOperator | ConcatenationOperator => 18, MultiplicationOperator | DivisionOperator | RemainderOperator => 19, LogicalNotOperator | NotOperator | UnaryPlusOperator | UnaryMinusOperator => 20, InstanceofOperator | IsOperator | AsOperator | NullableAsOperator | UpcastOperator => { 21 } CastOperator | ErrorControlOperator | PrefixIncrementOperator | PrefixDecrementOperator | ExponentOperator => 22, PostfixIncrementOperator | PostfixDecrementOperator | AwaitOperator | ReadonlyOperator => 23, CloneOperator => 24, // value 25 is reserved for assignment that appear in expressions EnumClassLabelOperator | FunctionCallOperator => 26, NewOperator => 27, MemberSelectionOperator | NullSafeMemberSelectionOperator => 28, IndexingOperator => 29, ScopeResolutionOperator => 30, DollarOperator => 31, PackageOperator => 32, } } pub fn precedence_for_assignment_in_expressions() -> usize { 25 } // NOTE: ParserEnv is not used in operator::associativity(). The function rust_associativity_helper (defined in rust_parser_ffi.rs) // assumes that ParserEnv is not used. If operator::associativity() starts using ParserEnv, the function and the callsites in OCaml // must be updated. pub fn associativity(&self, _: &ParserEnv) -> Assoc { match self { | EqualOperator | StrictEqualOperator | NotEqualOperator | StrictNotEqualOperator | LessThanOperator | LessThanOrEqualOperator | GreaterThanOperator | GreaterThanOrEqualOperator | InstanceofOperator | NewOperator | CloneOperator | SpaceshipOperator => Assoc::NotAssociative, | DegenerateConditionalOperator | PipeOperator | ConditionalQuestionOperator | ConditionalColonOperator | LogicalOrOperator | ExclusiveOrOperator | LogicalAndOperator | OrOperator | AndOperator | LeftShiftOperator | RightShiftOperator | AdditionOperator | SubtractionOperator | ConcatenationOperator | MultiplicationOperator | DivisionOperator | RemainderOperator | MemberSelectionOperator | NullSafeMemberSelectionOperator | ScopeResolutionOperator | EnumClassLabelOperator | FunctionCallOperator | IndexingOperator | IncludeOperator | IncludeOnceOperator | RequireOperator | RequireOnceOperator | IsOperator | AsOperator | NullableAsOperator | UpcastOperator // eval // Comma // elseif // else // endif => Assoc::LeftAssociative, | CoalesceOperator | CoalesceAssignmentOperator | LogicalNotOperator | NotOperator | CastOperator | DollarOperator | UnaryPlusOperator | UnaryMinusOperator // TODO: Correct? | ErrorControlOperator // TODO: Correct? | PostfixIncrementOperator | PostfixDecrementOperator | PrefixIncrementOperator | PrefixDecrementOperator | ExponentOperator | AssignmentOperator | AdditionAssignmentOperator | SubtractionAssignmentOperator | MultiplicationAssignmentOperator | DivisionAssignmentOperator | ExponentiationAssignmentOperator | ConcatenationAssignmentOperator | RemainderAssignmentOperator | AndAssignmentOperator | OrAssignmentOperator | ExclusiveOrAssignmentOperator | LeftShiftAssignmentOperator | RightShiftAssignmentOperator | PrintOperator | AwaitOperator | ReadonlyOperator | PackageOperator => Assoc::RightAssociative, } } pub fn prefix_unary_from_token(token: TokenKind) -> Operator { match token { TokenKind::Await => AwaitOperator, TokenKind::Exclamation => LogicalNotOperator, TokenKind::Tilde => NotOperator, TokenKind::PlusPlus => PrefixIncrementOperator, TokenKind::MinusMinus => PrefixDecrementOperator, TokenKind::Dollar => DollarOperator, TokenKind::Plus => UnaryPlusOperator, TokenKind::Minus => UnaryMinusOperator, TokenKind::At => ErrorControlOperator, TokenKind::New => NewOperator, TokenKind::Clone => CloneOperator, TokenKind::Include => IncludeOperator, TokenKind::Include_once => IncludeOnceOperator, TokenKind::Require => RequireOperator, TokenKind::Require_once => RequireOnceOperator, TokenKind::Print => PrintOperator, TokenKind::Readonly => ReadonlyOperator, TokenKind::Package => PackageOperator, _ => panic!("not a unary operator"), } } // Is this a token that can appear after an expression? pub fn is_trailing_operator_token(token: TokenKind) -> bool { match token { TokenKind::PlusPlus | TokenKind::MinusMinus | TokenKind::LeftParen | TokenKind::LeftBracket | TokenKind::LeftBrace | TokenKind::Plus | TokenKind::Minus | TokenKind::Ampersand | TokenKind::BarGreaterThan | TokenKind::Question | TokenKind::QuestionQuestion | TokenKind::QuestionQuestionEqual | TokenKind::QuestionColon | TokenKind::BarBar | TokenKind::Carat | TokenKind::AmpersandAmpersand | TokenKind::Bar | TokenKind::EqualEqual | TokenKind::EqualEqualEqual | TokenKind::ExclamationEqual | TokenKind::ExclamationEqualEqual | TokenKind::LessThanEqualGreaterThan | TokenKind::LessThan | TokenKind::LessThanEqual | TokenKind::GreaterThan | TokenKind::GreaterThanEqual | TokenKind::LessThanLessThan | TokenKind::GreaterThanGreaterThan | TokenKind::Dot | TokenKind::Star | TokenKind::Slash | TokenKind::Percent | TokenKind::Instanceof | TokenKind::Is | TokenKind::As | TokenKind::QuestionAs | TokenKind::Upcast | TokenKind::StarStar | TokenKind::Equal | TokenKind::PlusEqual | TokenKind::MinusEqual | TokenKind::StarEqual | TokenKind::SlashEqual | TokenKind::StarStarEqual | TokenKind::DotEqual | TokenKind::PercentEqual | TokenKind::AmpersandEqual | TokenKind::BarEqual | TokenKind::CaratEqual | TokenKind::LessThanLessThanEqual | TokenKind::GreaterThanGreaterThanEqual | TokenKind::MinusGreaterThan | TokenKind::QuestionMinusGreaterThan | TokenKind::ColonColon | TokenKind::Hash => true, _ => false, } } pub fn trailing_from_token(token: TokenKind) -> Operator { match token { TokenKind::BarGreaterThan => PipeOperator, TokenKind::Question => ConditionalQuestionOperator, TokenKind::Colon => ConditionalColonOperator, TokenKind::QuestionQuestion => CoalesceOperator, TokenKind::QuestionQuestionEqual => CoalesceAssignmentOperator, TokenKind::QuestionColon => DegenerateConditionalOperator, TokenKind::BarBar => LogicalOrOperator, TokenKind::Carat => ExclusiveOrOperator, TokenKind::AmpersandAmpersand => LogicalAndOperator, TokenKind::Bar => OrOperator, TokenKind::Ampersand => AndOperator, TokenKind::EqualEqual => EqualOperator, TokenKind::EqualEqualEqual => StrictEqualOperator, TokenKind::ExclamationEqual => NotEqualOperator, TokenKind::ExclamationEqualEqual => StrictNotEqualOperator, TokenKind::LessThan => LessThanOperator, TokenKind::LessThanEqualGreaterThan => SpaceshipOperator, TokenKind::LessThanEqual => LessThanOrEqualOperator, TokenKind::GreaterThan => GreaterThanOperator, TokenKind::GreaterThanEqual => GreaterThanOrEqualOperator, TokenKind::LessThanLessThan => LeftShiftOperator, TokenKind::GreaterThanGreaterThan => RightShiftOperator, TokenKind::Plus => AdditionOperator, TokenKind::Minus => SubtractionOperator, TokenKind::Dot => ConcatenationOperator, TokenKind::Star => MultiplicationOperator, TokenKind::Slash => DivisionOperator, TokenKind::Percent => RemainderOperator, TokenKind::Instanceof => InstanceofOperator, TokenKind::Is => IsOperator, TokenKind::As => AsOperator, TokenKind::QuestionAs => NullableAsOperator, TokenKind::Upcast => UpcastOperator, TokenKind::StarStar => ExponentOperator, TokenKind::Equal => AssignmentOperator, TokenKind::PlusEqual => AdditionAssignmentOperator, TokenKind::MinusEqual => SubtractionAssignmentOperator, TokenKind::StarEqual => MultiplicationAssignmentOperator, TokenKind::SlashEqual => DivisionAssignmentOperator, TokenKind::StarStarEqual => ExponentiationAssignmentOperator, TokenKind::DotEqual => ConcatenationAssignmentOperator, TokenKind::PercentEqual => RemainderAssignmentOperator, TokenKind::AmpersandEqual => AndAssignmentOperator, TokenKind::BarEqual => OrAssignmentOperator, TokenKind::CaratEqual => ExclusiveOrAssignmentOperator, TokenKind::LessThanLessThanEqual => LeftShiftAssignmentOperator, TokenKind::GreaterThanGreaterThanEqual => RightShiftAssignmentOperator, TokenKind::MinusGreaterThan => MemberSelectionOperator, TokenKind::QuestionMinusGreaterThan => NullSafeMemberSelectionOperator, TokenKind::ColonColon => ScopeResolutionOperator, TokenKind::PlusPlus => PostfixIncrementOperator, TokenKind::MinusMinus => PostfixDecrementOperator, TokenKind::LeftParen => FunctionCallOperator, TokenKind::LeftBracket => IndexingOperator, TokenKind::LeftBrace => IndexingOperator, TokenKind::Hash => EnumClassLabelOperator, _ => panic!("not a trailing operator"), } } pub fn is_binary_operator_token(token: TokenKind) -> bool { match token { TokenKind::Plus | TokenKind::Minus | TokenKind::Ampersand | TokenKind::BarGreaterThan | TokenKind::QuestionQuestion | TokenKind::QuestionQuestionEqual | TokenKind::QuestionColon | TokenKind::BarBar | TokenKind::Carat | TokenKind::AmpersandAmpersand | TokenKind::Bar | TokenKind::EqualEqual | TokenKind::EqualEqualEqual | TokenKind::ExclamationEqual | TokenKind::ExclamationEqualEqual | TokenKind::LessThanEqualGreaterThan | TokenKind::LessThan | TokenKind::LessThanEqual | TokenKind::GreaterThan | TokenKind::GreaterThanEqual | TokenKind::LessThanLessThan | TokenKind::GreaterThanGreaterThan | TokenKind::Dot | TokenKind::Star | TokenKind::Slash | TokenKind::Percent | TokenKind::StarStar | TokenKind::Equal | TokenKind::PlusEqual | TokenKind::MinusEqual | TokenKind::StarEqual | TokenKind::SlashEqual | TokenKind::DotEqual | TokenKind::PercentEqual | TokenKind::AmpersandEqual | TokenKind::BarEqual | TokenKind::CaratEqual | TokenKind::LessThanLessThanEqual | TokenKind::GreaterThanGreaterThanEqual | TokenKind::MinusGreaterThan | TokenKind::QuestionMinusGreaterThan => true, _ => false, } } pub fn is_assignment(&self) -> bool { match self { AssignmentOperator | AdditionAssignmentOperator | SubtractionAssignmentOperator | MultiplicationAssignmentOperator | DivisionAssignmentOperator | ExponentiationAssignmentOperator | ConcatenationAssignmentOperator | RemainderAssignmentOperator | AndAssignmentOperator | OrAssignmentOperator | ExclusiveOrAssignmentOperator | LeftShiftAssignmentOperator | RightShiftAssignmentOperator | CoalesceAssignmentOperator => true, _ => false, } } pub fn is_comparison(&self) -> bool { match self { EqualOperator | StrictEqualOperator | NotEqualOperator | StrictNotEqualOperator | LessThanOperator | LessThanOrEqualOperator | GreaterThanOperator | GreaterThanOrEqualOperator | SpaceshipOperator => true, _ => false, } } }
Rust
hhvm/hphp/hack/src/parser/operator_generated.rs
/** * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. An additional * directory. * ** * * THIS FILE IS @generated; DO NOT EDIT IT * To regenerate this file, run * * buck run //hphp/hack/src:generate_full_fidelity * ** * */ use ocamlrep::{FromOcamlRep, ToOcamlRep}; #[derive(FromOcamlRep, ToOcamlRep)] pub enum Operator { DollarOperator, ScopeResolutionOperator, IndexingOperator, NullSafeMemberSelectionOperator, MemberSelectionOperator, NewOperator, FunctionCallOperator, CloneOperator, PostfixIncrementOperator, PostfixDecrementOperator, PrefixIncrementOperator, PrefixDecrementOperator, ExponentOperator, ErrorControlOperator, CastOperator, NullableAsOperator, IsOperator, InstanceofOperator, AsOperator, UpcastOperator, UnaryPlusOperator, UnaryMinusOperator, NotOperator, LogicalNotOperator, RemainderOperator, MultiplicationOperator, DivisionOperator, SubtractionOperator, ConcatenationOperator, AdditionOperator, RightShiftOperator, LeftShiftOperator, SpaceshipOperator, LessThanOrEqualOperator, LessThanOperator, GreaterThanOrEqualOperator, GreaterThanOperator, StrictNotEqualOperator, StrictEqualOperator, NotEqualOperator, EqualOperator, AndOperator, ExclusiveOrOperator, OrOperator, LogicalAndOperator, LogicalOrOperator, CoalesceOperator, DegenerateConditionalOperator, ConditionalQuestionOperator, ConditionalColonOperator, PipeOperator, SubtractionAssignmentOperator, RightShiftAssignmentOperator, RemainderAssignmentOperator, OrAssignmentOperator, MultiplicationAssignmentOperator, LeftShiftAssignmentOperator, ExponentiationAssignmentOperator, ExclusiveOrAssignmentOperator, DivisionAssignmentOperator, ConcatenationAssignmentOperator, CoalesceAssignmentOperator, AssignmentOperator, AndAssignmentOperator, AdditionAssignmentOperator, PrintOperator, RequireOperator, RequireOnceOperator, IncludeOperator, IncludeOnceOperator, AwaitOperator, ReadonlyOperator, EnumClassLabelOperator, PackageOperator, }
Rust
hhvm/hphp/hack/src/parser/pair_smart_constructors.rs
// Copyright (c) Facebook, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. #![allow(unused_variables)] use parser_core_types::lexable_token::LexableToken; use parser_core_types::lexable_trivia::LexableTrivia; use parser_core_types::lexable_trivia::LexableTrivium; use parser_core_types::token_factory::TokenFactory; use parser_core_types::token_factory::Trivia; use parser_core_types::token_kind::TokenKind; use parser_core_types::trivia_factory::TriviaFactory; use parser_core_types::trivia_kind::TriviaKind; use smart_constructors::NodeType; mod pair_smart_constructors_generated; pub use pair_smart_constructors_generated::PairSmartConstructors; pub struct Node<N0, N1>(pub N0, pub N1) where N0: NodeType, N1: NodeType; impl<N0, N1> NodeType for Node<N0, N1> where N0: NodeType, N1: NodeType, { type Output = Node<N0, N1>; fn extract(self) -> Self::Output { self } fn is_abstract(&self) -> bool { let result = self.0.is_abstract(); debug_assert_eq!(result, self.1.is_abstract()); result } fn is_name(&self) -> bool { let result = self.0.is_name(); debug_assert_eq!(result, self.1.is_name()); result } fn is_qualified_name(&self) -> bool { let result = self.0.is_qualified_name(); debug_assert_eq!(result, self.1.is_qualified_name()); result } fn is_prefix_unary_expression(&self) -> bool { let result = self.0.is_prefix_unary_expression(); debug_assert_eq!(result, self.1.is_prefix_unary_expression()); result } fn is_scope_resolution_expression(&self) -> bool { let result = self.0.is_scope_resolution_expression(); debug_assert_eq!(result, self.1.is_scope_resolution_expression()); result } fn is_missing(&self) -> bool { let result = self.0.is_missing(); debug_assert_eq!(result, self.1.is_missing()); result } fn is_variable_expression(&self) -> bool { let result = self.0.is_variable_expression(); debug_assert_eq!(result, self.1.is_variable_expression()); result } fn is_subscript_expression(&self) -> bool { let result = self.0.is_subscript_expression(); debug_assert_eq!(result, self.1.is_subscript_expression()); result } fn is_member_selection_expression(&self) -> bool { let result = self.0.is_member_selection_expression(); debug_assert_eq!(result, self.1.is_member_selection_expression()); result } fn is_object_creation_expression(&self) -> bool { let result = self.0.is_object_creation_expression(); debug_assert_eq!(result, self.1.is_object_creation_expression()); result } fn is_safe_member_selection_expression(&self) -> bool { let result = self.0.is_safe_member_selection_expression(); debug_assert_eq!(result, self.1.is_safe_member_selection_expression()); result } fn is_function_call_expression(&self) -> bool { let result = self.0.is_function_call_expression(); debug_assert_eq!(result, self.1.is_function_call_expression()); result } fn is_list_expression(&self) -> bool { let result = self.0.is_list_expression(); debug_assert_eq!(result, self.1.is_list_expression()); result } } #[derive(Clone, Debug)] pub struct PairTokenFactory<TF0, TF1>( TF0, TF1, PairTriviaFactory<TF0::TriviaFactory, TF1::TriviaFactory>, ) where TF0: TokenFactory, TF1: TokenFactory; impl<TF0, TF1> PairTokenFactory<TF0, TF1> where TF0: TokenFactory, TF1: TokenFactory, { fn new(mut tf0: TF0, mut tf1: TF1) -> Self { let tvf0 = tf0.trivia_factory_mut().clone(); let tvf1 = tf1.trivia_factory_mut().clone(); let tvf = PairTriviaFactory(tvf0, tvf1); Self(tf0, tf1, tvf) } } impl<TF0, TF1> TokenFactory for PairTokenFactory<TF0, TF1> where TF0: TokenFactory, TF1: TokenFactory, { type Token = PairToken<TF0::Token, TF1::Token>; type TriviaFactory = PairTriviaFactory<TF0::TriviaFactory, TF1::TriviaFactory>; fn make( &mut self, kind: TokenKind, offset: usize, width: usize, leading: Trivia<Self>, trailing: Trivia<Self>, ) -> Self::Token { let t0 = self.0.make(kind, offset, width, leading.0, trailing.0); let t1 = self.1.make(kind, offset, width, leading.1, trailing.1); PairToken(t0, t1) } fn with_leading(&mut self, token: Self::Token, leading: Trivia<Self>) -> Self::Token { let t0 = self.0.with_leading(token.0, leading.0); let t1 = self.1.with_leading(token.1, leading.1); PairToken(t0, t1) } fn with_trailing(&mut self, token: Self::Token, trailing: Trivia<Self>) -> Self::Token { let t0 = self.0.with_trailing(token.0, trailing.0); let t1 = self.1.with_trailing(token.1, trailing.1); PairToken(t0, t1) } fn with_kind(&mut self, token: Self::Token, kind: TokenKind) -> Self::Token { let t0 = self.0.with_kind(token.0, kind); let t1 = self.1.with_kind(token.1, kind); PairToken(t0, t1) } fn trivia_factory_mut(&mut self) -> &mut Self::TriviaFactory { &mut self.2 } } #[derive(Clone, Debug)] pub struct PairTriviaFactory<T0, T1>(T0, T1) where T0: TriviaFactory, T1: TriviaFactory; impl<T0, T1> TriviaFactory for PairTriviaFactory<T0, T1> where T0: TriviaFactory, T1: TriviaFactory, { type Trivia = PairTrivia<T0::Trivia, T1::Trivia>; fn make(&mut self) -> Self::Trivia { PairTrivia(self.0.make(), self.1.make()) } } #[derive(Clone, Debug)] pub struct PairToken<T0, T1>(T0, T1) where T0: LexableToken, T1: LexableToken; impl<T0, T1> LexableToken for PairToken<T0, T1> where T0: LexableToken, T1: LexableToken, { type Trivia = PairTrivia<T0::Trivia, T1::Trivia>; fn kind(&self) -> TokenKind { let result = self.0.kind(); debug_assert_eq!(result, self.1.kind()); result } fn leading_start_offset(&self) -> Option<usize> { match (self.0.leading_start_offset(), self.1.leading_start_offset()) { (Some(offset0), Some(offset1)) => { debug_assert_eq!(offset0, offset1); Some(offset0) } (None, None) => None, // TODO: Is it right to return Some in these cases? (Some(offset), None) | (None, Some(offset)) => Some(offset), } } fn width(&self) -> usize { let result = self.0.width(); debug_assert_eq!(result, self.1.width()); result } fn leading_width(&self) -> usize { let result = self.0.leading_width(); debug_assert_eq!(result, self.1.leading_width()); result } fn trailing_width(&self) -> usize { let result = self.0.trailing_width(); debug_assert_eq!(result, self.1.trailing_width()); result } fn full_width(&self) -> usize { let result = self.0.full_width(); debug_assert_eq!(result, self.1.full_width()); result } fn clone_leading(&self) -> Self::Trivia { PairTrivia(self.0.clone_leading(), self.1.clone_leading()) } fn clone_trailing(&self) -> Self::Trivia { PairTrivia(self.0.clone_trailing(), self.1.clone_trailing()) } fn leading_is_empty(&self) -> bool { let result = self.0.leading_is_empty(); debug_assert_eq!(result, self.1.leading_is_empty()); result } fn trailing_is_empty(&self) -> bool { let result = self.0.trailing_is_empty(); debug_assert_eq!(result, self.1.trailing_is_empty()); result } fn has_leading_trivia_kind(&self, kind: TriviaKind) -> bool { let result = self.0.has_leading_trivia_kind(kind); debug_assert_eq!(result, self.1.has_leading_trivia_kind(kind)); result } fn has_trailing_trivia_kind(&self, kind: TriviaKind) -> bool { let result = self.0.has_trailing_trivia_kind(kind); debug_assert_eq!(result, self.1.has_trailing_trivia_kind(kind)); result } fn into_trivia_and_width(self) -> (Self::Trivia, usize, Self::Trivia) { let (leading0, width0, trailing0) = self.0.into_trivia_and_width(); let (leading1, width1, trailing1) = self.1.into_trivia_and_width(); let leading = PairTrivia(leading0, leading1); let trailing = PairTrivia(trailing0, trailing1); debug_assert_eq!(width0, width1); (leading, width0, trailing) } } #[derive(Clone, Debug)] pub struct PairTrivia<T0, T1>(T0, T1) where T0: LexableTrivia, T1: LexableTrivia; impl<T0, T1> LexableTrivia for PairTrivia<T0, T1> where T0: LexableTrivia, T1: LexableTrivia, { type Trivium = PairTrivium<T0::Trivium, T1::Trivium>; fn is_empty(&self) -> bool { let result = self.0.is_empty(); debug_assert_eq!(result, self.1.is_empty()); result } fn has_kind(&self, kind: TriviaKind) -> bool { let result = self.0.has_kind(kind); debug_assert_eq!(result, self.1.has_kind(kind)); result } fn push(&mut self, trivium: Self::Trivium) { self.0.push(trivium.0); self.1.push(trivium.1); } fn extend(&mut self, other: Self) { self.0.extend(other.0); self.1.extend(other.1); } #[inline] fn make_whitespace(offset: usize, width: usize) -> Self::Trivium { PairTrivium( T0::make_whitespace(offset, width), T1::make_whitespace(offset, width), ) } #[inline] fn make_eol(offset: usize, width: usize) -> Self::Trivium { PairTrivium(T0::make_eol(offset, width), T1::make_eol(offset, width)) } #[inline] fn make_single_line_comment(offset: usize, width: usize) -> Self::Trivium { PairTrivium( T0::make_single_line_comment(offset, width), T1::make_single_line_comment(offset, width), ) } #[inline] fn make_fallthrough(offset: usize, width: usize) -> Self::Trivium { PairTrivium( T0::make_fallthrough(offset, width), T1::make_fallthrough(offset, width), ) } #[inline] fn make_fix_me(offset: usize, width: usize) -> Self::Trivium { PairTrivium( T0::make_fix_me(offset, width), T1::make_fix_me(offset, width), ) } #[inline] fn make_ignore_error(offset: usize, width: usize) -> Self::Trivium { PairTrivium( T0::make_ignore_error(offset, width), T1::make_ignore_error(offset, width), ) } #[inline] fn make_extra_token_error(offset: usize, width: usize) -> Self::Trivium { PairTrivium( T0::make_extra_token_error(offset, width), T1::make_extra_token_error(offset, width), ) } #[inline] fn make_delimited_comment(offset: usize, width: usize) -> Self::Trivium { PairTrivium( T0::make_delimited_comment(offset, width), T1::make_delimited_comment(offset, width), ) } } #[derive(Clone, Debug)] pub struct PairTrivium<T0, T1>(T0, T1) where T0: LexableTrivium, T1: LexableTrivium; impl<T0, T1> LexableTrivium for PairTrivium<T0, T1> where T0: LexableTrivium, T1: LexableTrivium, { fn make_whitespace(offset: usize, width: usize) -> Self { Self( T0::make_whitespace(offset, width), T1::make_whitespace(offset, width), ) } fn make_eol(offset: usize, width: usize) -> Self { Self(T0::make_eol(offset, width), T1::make_eol(offset, width)) } fn make_single_line_comment(offset: usize, width: usize) -> Self { Self( T0::make_single_line_comment(offset, width), T1::make_single_line_comment(offset, width), ) } fn make_fallthrough(offset: usize, width: usize) -> Self { Self( T0::make_fallthrough(offset, width), T1::make_fallthrough(offset, width), ) } fn make_fix_me(offset: usize, width: usize) -> Self { Self( T0::make_fix_me(offset, width), T1::make_fix_me(offset, width), ) } fn make_ignore_error(offset: usize, width: usize) -> Self { Self( T0::make_ignore_error(offset, width), T1::make_ignore_error(offset, width), ) } fn make_extra_token_error(offset: usize, width: usize) -> Self { Self( T0::make_extra_token_error(offset, width), T1::make_extra_token_error(offset, width), ) } fn make_delimited_comment(offset: usize, width: usize) -> Self { Self( T0::make_delimited_comment(offset, width), T1::make_delimited_comment(offset, width), ) } fn kind(&self) -> TriviaKind { let result = self.0.kind(); debug_assert_eq!(result, self.1.kind()); result } fn width(&self) -> usize { let result = self.0.width(); debug_assert_eq!(result, self.1.width()); result } } impl<T0, T1> PartialEq for PairTrivium<T0, T1> where T0: LexableTrivium, T1: LexableTrivium, { fn eq(&self, other: &Self) -> bool { let result = self.0 == other.0; debug_assert_eq!(result, self.1 == other.1); result } }
Rust
hhvm/hphp/hack/src/parser/pair_smart_constructors_generated.rs
/** * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. An additional * directory. * ** * * THIS FILE IS @generated; DO NOT EDIT IT * To regenerate this file, run * * buck run //hphp/hack/src:generate_full_fidelity * ** * */ use parser_core_types::token_factory::TokenFactory; use smart_constructors::{NodeType, SmartConstructors}; use crate::{PairTokenFactory, Node}; #[derive(Clone)] pub struct PairSmartConstructors<SC0, SC1>(pub SC0, pub SC1, PairTokenFactory<SC0::Factory, SC1::Factory>) where SC0: SmartConstructors, SC0::Output: NodeType, SC1: SmartConstructors, SC1::Output: NodeType; impl<SC0, SC1> PairSmartConstructors<SC0, SC1> where SC0: SmartConstructors, SC0::Output: NodeType, SC1: SmartConstructors, SC1::Output: NodeType, { pub fn new(mut sc0: SC0, mut sc1: SC1) -> Self { let tf0 = sc0.token_factory_mut().clone(); let tf1 = sc1.token_factory_mut().clone(); let tf = PairTokenFactory::new(tf0, tf1); Self(sc0, sc1, tf) } } impl<SC0, SC1> SmartConstructors for PairSmartConstructors<SC0, SC1> where SC0: SmartConstructors, SC0::Output: NodeType, SC1: SmartConstructors, SC1::Output: NodeType, { type State = Self; type Factory = PairTokenFactory<SC0::Factory, SC1::Factory>; type Output = Node<SC0::Output, SC1::Output>; fn state_mut(&mut self) -> &mut Self { self } fn into_state(self) -> Self { self } fn token_factory_mut(&mut self) -> &mut Self::Factory { &mut self.2 } fn make_missing(&mut self, offset: usize) -> Self::Output { Node(self.0.make_missing(offset), self.1.make_missing(offset)) } fn make_token(&mut self, token: <Self::Factory as TokenFactory>::Token) -> Self::Output { Node(self.0.make_token(token.0), self.1.make_token(token.1)) } fn make_list(&mut self, items: Vec<Self::Output>, offset: usize) -> Self::Output { let (items0, items1) = items.into_iter().map(|n| (n.0, n.1)).unzip(); Node(self.0.make_list(items0, offset), self.1.make_list(items1, offset)) } fn make_end_of_file(&mut self, token: Self::Output) -> Self::Output { Node(self.0.make_end_of_file(token.0), self.1.make_end_of_file(token.1)) } fn make_script(&mut self, declarations: Self::Output) -> Self::Output { Node(self.0.make_script(declarations.0), self.1.make_script(declarations.1)) } fn make_qualified_name(&mut self, parts: Self::Output) -> Self::Output { Node(self.0.make_qualified_name(parts.0), self.1.make_qualified_name(parts.1)) } fn make_module_name(&mut self, parts: Self::Output) -> Self::Output { Node(self.0.make_module_name(parts.0), self.1.make_module_name(parts.1)) } fn make_simple_type_specifier(&mut self, specifier: Self::Output) -> Self::Output { Node(self.0.make_simple_type_specifier(specifier.0), self.1.make_simple_type_specifier(specifier.1)) } fn make_literal_expression(&mut self, expression: Self::Output) -> Self::Output { Node(self.0.make_literal_expression(expression.0), self.1.make_literal_expression(expression.1)) } fn make_prefixed_string_expression(&mut self, name: Self::Output, str: Self::Output) -> Self::Output { Node(self.0.make_prefixed_string_expression(name.0, str.0), self.1.make_prefixed_string_expression(name.1, str.1)) } fn make_prefixed_code_expression(&mut self, prefix: Self::Output, left_backtick: Self::Output, body: Self::Output, right_backtick: Self::Output) -> Self::Output { Node(self.0.make_prefixed_code_expression(prefix.0, left_backtick.0, body.0, right_backtick.0), self.1.make_prefixed_code_expression(prefix.1, left_backtick.1, body.1, right_backtick.1)) } fn make_variable_expression(&mut self, expression: Self::Output) -> Self::Output { Node(self.0.make_variable_expression(expression.0), self.1.make_variable_expression(expression.1)) } fn make_pipe_variable_expression(&mut self, expression: Self::Output) -> Self::Output { Node(self.0.make_pipe_variable_expression(expression.0), self.1.make_pipe_variable_expression(expression.1)) } fn make_file_attribute_specification(&mut self, left_double_angle: Self::Output, keyword: Self::Output, colon: Self::Output, attributes: Self::Output, right_double_angle: Self::Output) -> Self::Output { Node(self.0.make_file_attribute_specification(left_double_angle.0, keyword.0, colon.0, attributes.0, right_double_angle.0), self.1.make_file_attribute_specification(left_double_angle.1, keyword.1, colon.1, attributes.1, right_double_angle.1)) } fn make_enum_declaration(&mut self, attribute_spec: Self::Output, modifiers: Self::Output, keyword: Self::Output, name: Self::Output, colon: Self::Output, base: Self::Output, type_: Self::Output, left_brace: Self::Output, use_clauses: Self::Output, enumerators: Self::Output, right_brace: Self::Output) -> Self::Output { Node(self.0.make_enum_declaration(attribute_spec.0, modifiers.0, keyword.0, name.0, colon.0, base.0, type_.0, left_brace.0, use_clauses.0, enumerators.0, right_brace.0), self.1.make_enum_declaration(attribute_spec.1, modifiers.1, keyword.1, name.1, colon.1, base.1, type_.1, left_brace.1, use_clauses.1, enumerators.1, right_brace.1)) } fn make_enum_use(&mut self, keyword: Self::Output, names: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_enum_use(keyword.0, names.0, semicolon.0), self.1.make_enum_use(keyword.1, names.1, semicolon.1)) } fn make_enumerator(&mut self, name: Self::Output, equal: Self::Output, value: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_enumerator(name.0, equal.0, value.0, semicolon.0), self.1.make_enumerator(name.1, equal.1, value.1, semicolon.1)) } fn make_enum_class_declaration(&mut self, attribute_spec: Self::Output, modifiers: Self::Output, enum_keyword: Self::Output, class_keyword: Self::Output, name: Self::Output, colon: Self::Output, base: Self::Output, extends: Self::Output, extends_list: Self::Output, left_brace: Self::Output, elements: Self::Output, right_brace: Self::Output) -> Self::Output { Node(self.0.make_enum_class_declaration(attribute_spec.0, modifiers.0, enum_keyword.0, class_keyword.0, name.0, colon.0, base.0, extends.0, extends_list.0, left_brace.0, elements.0, right_brace.0), self.1.make_enum_class_declaration(attribute_spec.1, modifiers.1, enum_keyword.1, class_keyword.1, name.1, colon.1, base.1, extends.1, extends_list.1, left_brace.1, elements.1, right_brace.1)) } fn make_enum_class_enumerator(&mut self, modifiers: Self::Output, type_: Self::Output, name: Self::Output, initializer: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_enum_class_enumerator(modifiers.0, type_.0, name.0, initializer.0, semicolon.0), self.1.make_enum_class_enumerator(modifiers.1, type_.1, name.1, initializer.1, semicolon.1)) } fn make_alias_declaration(&mut self, attribute_spec: Self::Output, modifiers: Self::Output, module_kw_opt: Self::Output, keyword: Self::Output, name: Self::Output, generic_parameter: Self::Output, constraint: Self::Output, equal: Self::Output, type_: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_alias_declaration(attribute_spec.0, modifiers.0, module_kw_opt.0, keyword.0, name.0, generic_parameter.0, constraint.0, equal.0, type_.0, semicolon.0), self.1.make_alias_declaration(attribute_spec.1, modifiers.1, module_kw_opt.1, keyword.1, name.1, generic_parameter.1, constraint.1, equal.1, type_.1, semicolon.1)) } fn make_context_alias_declaration(&mut self, attribute_spec: Self::Output, keyword: Self::Output, name: Self::Output, generic_parameter: Self::Output, as_constraint: Self::Output, equal: Self::Output, context: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_context_alias_declaration(attribute_spec.0, keyword.0, name.0, generic_parameter.0, as_constraint.0, equal.0, context.0, semicolon.0), self.1.make_context_alias_declaration(attribute_spec.1, keyword.1, name.1, generic_parameter.1, as_constraint.1, equal.1, context.1, semicolon.1)) } fn make_case_type_declaration(&mut self, attribute_spec: Self::Output, modifiers: Self::Output, case_keyword: Self::Output, type_keyword: Self::Output, name: Self::Output, generic_parameter: Self::Output, as_: Self::Output, bounds: Self::Output, equal: Self::Output, variants: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_case_type_declaration(attribute_spec.0, modifiers.0, case_keyword.0, type_keyword.0, name.0, generic_parameter.0, as_.0, bounds.0, equal.0, variants.0, semicolon.0), self.1.make_case_type_declaration(attribute_spec.1, modifiers.1, case_keyword.1, type_keyword.1, name.1, generic_parameter.1, as_.1, bounds.1, equal.1, variants.1, semicolon.1)) } fn make_case_type_variant(&mut self, bar: Self::Output, type_: Self::Output) -> Self::Output { Node(self.0.make_case_type_variant(bar.0, type_.0), self.1.make_case_type_variant(bar.1, type_.1)) } fn make_property_declaration(&mut self, attribute_spec: Self::Output, modifiers: Self::Output, type_: Self::Output, declarators: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_property_declaration(attribute_spec.0, modifiers.0, type_.0, declarators.0, semicolon.0), self.1.make_property_declaration(attribute_spec.1, modifiers.1, type_.1, declarators.1, semicolon.1)) } fn make_property_declarator(&mut self, name: Self::Output, initializer: Self::Output) -> Self::Output { Node(self.0.make_property_declarator(name.0, initializer.0), self.1.make_property_declarator(name.1, initializer.1)) } fn make_namespace_declaration(&mut self, header: Self::Output, body: Self::Output) -> Self::Output { Node(self.0.make_namespace_declaration(header.0, body.0), self.1.make_namespace_declaration(header.1, body.1)) } fn make_namespace_declaration_header(&mut self, keyword: Self::Output, name: Self::Output) -> Self::Output { Node(self.0.make_namespace_declaration_header(keyword.0, name.0), self.1.make_namespace_declaration_header(keyword.1, name.1)) } fn make_namespace_body(&mut self, left_brace: Self::Output, declarations: Self::Output, right_brace: Self::Output) -> Self::Output { Node(self.0.make_namespace_body(left_brace.0, declarations.0, right_brace.0), self.1.make_namespace_body(left_brace.1, declarations.1, right_brace.1)) } fn make_namespace_empty_body(&mut self, semicolon: Self::Output) -> Self::Output { Node(self.0.make_namespace_empty_body(semicolon.0), self.1.make_namespace_empty_body(semicolon.1)) } fn make_namespace_use_declaration(&mut self, keyword: Self::Output, kind: Self::Output, clauses: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_namespace_use_declaration(keyword.0, kind.0, clauses.0, semicolon.0), self.1.make_namespace_use_declaration(keyword.1, kind.1, clauses.1, semicolon.1)) } fn make_namespace_group_use_declaration(&mut self, keyword: Self::Output, kind: Self::Output, prefix: Self::Output, left_brace: Self::Output, clauses: Self::Output, right_brace: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_namespace_group_use_declaration(keyword.0, kind.0, prefix.0, left_brace.0, clauses.0, right_brace.0, semicolon.0), self.1.make_namespace_group_use_declaration(keyword.1, kind.1, prefix.1, left_brace.1, clauses.1, right_brace.1, semicolon.1)) } fn make_namespace_use_clause(&mut self, clause_kind: Self::Output, name: Self::Output, as_: Self::Output, alias: Self::Output) -> Self::Output { Node(self.0.make_namespace_use_clause(clause_kind.0, name.0, as_.0, alias.0), self.1.make_namespace_use_clause(clause_kind.1, name.1, as_.1, alias.1)) } fn make_function_declaration(&mut self, attribute_spec: Self::Output, declaration_header: Self::Output, body: Self::Output) -> Self::Output { Node(self.0.make_function_declaration(attribute_spec.0, declaration_header.0, body.0), self.1.make_function_declaration(attribute_spec.1, declaration_header.1, body.1)) } fn make_function_declaration_header(&mut self, modifiers: Self::Output, keyword: Self::Output, name: Self::Output, type_parameter_list: Self::Output, left_paren: Self::Output, parameter_list: Self::Output, right_paren: Self::Output, contexts: Self::Output, colon: Self::Output, readonly_return: Self::Output, type_: Self::Output, where_clause: Self::Output) -> Self::Output { Node(self.0.make_function_declaration_header(modifiers.0, keyword.0, name.0, type_parameter_list.0, left_paren.0, parameter_list.0, right_paren.0, contexts.0, colon.0, readonly_return.0, type_.0, where_clause.0), self.1.make_function_declaration_header(modifiers.1, keyword.1, name.1, type_parameter_list.1, left_paren.1, parameter_list.1, right_paren.1, contexts.1, colon.1, readonly_return.1, type_.1, where_clause.1)) } fn make_contexts(&mut self, left_bracket: Self::Output, types: Self::Output, right_bracket: Self::Output) -> Self::Output { Node(self.0.make_contexts(left_bracket.0, types.0, right_bracket.0), self.1.make_contexts(left_bracket.1, types.1, right_bracket.1)) } fn make_where_clause(&mut self, keyword: Self::Output, constraints: Self::Output) -> Self::Output { Node(self.0.make_where_clause(keyword.0, constraints.0), self.1.make_where_clause(keyword.1, constraints.1)) } fn make_where_constraint(&mut self, left_type: Self::Output, operator: Self::Output, right_type: Self::Output) -> Self::Output { Node(self.0.make_where_constraint(left_type.0, operator.0, right_type.0), self.1.make_where_constraint(left_type.1, operator.1, right_type.1)) } fn make_methodish_declaration(&mut self, attribute: Self::Output, function_decl_header: Self::Output, function_body: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_methodish_declaration(attribute.0, function_decl_header.0, function_body.0, semicolon.0), self.1.make_methodish_declaration(attribute.1, function_decl_header.1, function_body.1, semicolon.1)) } fn make_methodish_trait_resolution(&mut self, attribute: Self::Output, function_decl_header: Self::Output, equal: Self::Output, name: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_methodish_trait_resolution(attribute.0, function_decl_header.0, equal.0, name.0, semicolon.0), self.1.make_methodish_trait_resolution(attribute.1, function_decl_header.1, equal.1, name.1, semicolon.1)) } fn make_classish_declaration(&mut self, attribute: Self::Output, modifiers: Self::Output, xhp: Self::Output, keyword: Self::Output, name: Self::Output, type_parameters: Self::Output, extends_keyword: Self::Output, extends_list: Self::Output, implements_keyword: Self::Output, implements_list: Self::Output, where_clause: Self::Output, body: Self::Output) -> Self::Output { Node(self.0.make_classish_declaration(attribute.0, modifiers.0, xhp.0, keyword.0, name.0, type_parameters.0, extends_keyword.0, extends_list.0, implements_keyword.0, implements_list.0, where_clause.0, body.0), self.1.make_classish_declaration(attribute.1, modifiers.1, xhp.1, keyword.1, name.1, type_parameters.1, extends_keyword.1, extends_list.1, implements_keyword.1, implements_list.1, where_clause.1, body.1)) } fn make_classish_body(&mut self, left_brace: Self::Output, elements: Self::Output, right_brace: Self::Output) -> Self::Output { Node(self.0.make_classish_body(left_brace.0, elements.0, right_brace.0), self.1.make_classish_body(left_brace.1, elements.1, right_brace.1)) } fn make_trait_use(&mut self, keyword: Self::Output, names: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_trait_use(keyword.0, names.0, semicolon.0), self.1.make_trait_use(keyword.1, names.1, semicolon.1)) } fn make_require_clause(&mut self, keyword: Self::Output, kind: Self::Output, name: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_require_clause(keyword.0, kind.0, name.0, semicolon.0), self.1.make_require_clause(keyword.1, kind.1, name.1, semicolon.1)) } fn make_const_declaration(&mut self, attribute_spec: Self::Output, modifiers: Self::Output, keyword: Self::Output, type_specifier: Self::Output, declarators: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_const_declaration(attribute_spec.0, modifiers.0, keyword.0, type_specifier.0, declarators.0, semicolon.0), self.1.make_const_declaration(attribute_spec.1, modifiers.1, keyword.1, type_specifier.1, declarators.1, semicolon.1)) } fn make_constant_declarator(&mut self, name: Self::Output, initializer: Self::Output) -> Self::Output { Node(self.0.make_constant_declarator(name.0, initializer.0), self.1.make_constant_declarator(name.1, initializer.1)) } fn make_type_const_declaration(&mut self, attribute_spec: Self::Output, modifiers: Self::Output, keyword: Self::Output, type_keyword: Self::Output, name: Self::Output, type_parameters: Self::Output, type_constraints: Self::Output, equal: Self::Output, type_specifier: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_type_const_declaration(attribute_spec.0, modifiers.0, keyword.0, type_keyword.0, name.0, type_parameters.0, type_constraints.0, equal.0, type_specifier.0, semicolon.0), self.1.make_type_const_declaration(attribute_spec.1, modifiers.1, keyword.1, type_keyword.1, name.1, type_parameters.1, type_constraints.1, equal.1, type_specifier.1, semicolon.1)) } fn make_context_const_declaration(&mut self, modifiers: Self::Output, const_keyword: Self::Output, ctx_keyword: Self::Output, name: Self::Output, type_parameters: Self::Output, constraint: Self::Output, equal: Self::Output, ctx_list: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_context_const_declaration(modifiers.0, const_keyword.0, ctx_keyword.0, name.0, type_parameters.0, constraint.0, equal.0, ctx_list.0, semicolon.0), self.1.make_context_const_declaration(modifiers.1, const_keyword.1, ctx_keyword.1, name.1, type_parameters.1, constraint.1, equal.1, ctx_list.1, semicolon.1)) } fn make_decorated_expression(&mut self, decorator: Self::Output, expression: Self::Output) -> Self::Output { Node(self.0.make_decorated_expression(decorator.0, expression.0), self.1.make_decorated_expression(decorator.1, expression.1)) } fn make_parameter_declaration(&mut self, attribute: Self::Output, visibility: Self::Output, call_convention: Self::Output, readonly: Self::Output, type_: Self::Output, name: Self::Output, default_value: Self::Output) -> Self::Output { Node(self.0.make_parameter_declaration(attribute.0, visibility.0, call_convention.0, readonly.0, type_.0, name.0, default_value.0), self.1.make_parameter_declaration(attribute.1, visibility.1, call_convention.1, readonly.1, type_.1, name.1, default_value.1)) } fn make_variadic_parameter(&mut self, call_convention: Self::Output, type_: Self::Output, ellipsis: Self::Output) -> Self::Output { Node(self.0.make_variadic_parameter(call_convention.0, type_.0, ellipsis.0), self.1.make_variadic_parameter(call_convention.1, type_.1, ellipsis.1)) } fn make_old_attribute_specification(&mut self, left_double_angle: Self::Output, attributes: Self::Output, right_double_angle: Self::Output) -> Self::Output { Node(self.0.make_old_attribute_specification(left_double_angle.0, attributes.0, right_double_angle.0), self.1.make_old_attribute_specification(left_double_angle.1, attributes.1, right_double_angle.1)) } fn make_attribute_specification(&mut self, attributes: Self::Output) -> Self::Output { Node(self.0.make_attribute_specification(attributes.0), self.1.make_attribute_specification(attributes.1)) } fn make_attribute(&mut self, at: Self::Output, attribute_name: Self::Output) -> Self::Output { Node(self.0.make_attribute(at.0, attribute_name.0), self.1.make_attribute(at.1, attribute_name.1)) } fn make_inclusion_expression(&mut self, require: Self::Output, filename: Self::Output) -> Self::Output { Node(self.0.make_inclusion_expression(require.0, filename.0), self.1.make_inclusion_expression(require.1, filename.1)) } fn make_inclusion_directive(&mut self, expression: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_inclusion_directive(expression.0, semicolon.0), self.1.make_inclusion_directive(expression.1, semicolon.1)) } fn make_compound_statement(&mut self, left_brace: Self::Output, statements: Self::Output, right_brace: Self::Output) -> Self::Output { Node(self.0.make_compound_statement(left_brace.0, statements.0, right_brace.0), self.1.make_compound_statement(left_brace.1, statements.1, right_brace.1)) } fn make_expression_statement(&mut self, expression: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_expression_statement(expression.0, semicolon.0), self.1.make_expression_statement(expression.1, semicolon.1)) } fn make_markup_section(&mut self, hashbang: Self::Output, suffix: Self::Output) -> Self::Output { Node(self.0.make_markup_section(hashbang.0, suffix.0), self.1.make_markup_section(hashbang.1, suffix.1)) } fn make_markup_suffix(&mut self, less_than_question: Self::Output, name: Self::Output) -> Self::Output { Node(self.0.make_markup_suffix(less_than_question.0, name.0), self.1.make_markup_suffix(less_than_question.1, name.1)) } fn make_unset_statement(&mut self, keyword: Self::Output, left_paren: Self::Output, variables: Self::Output, right_paren: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_unset_statement(keyword.0, left_paren.0, variables.0, right_paren.0, semicolon.0), self.1.make_unset_statement(keyword.1, left_paren.1, variables.1, right_paren.1, semicolon.1)) } fn make_declare_local_statement(&mut self, keyword: Self::Output, variable: Self::Output, colon: Self::Output, type_: Self::Output, initializer: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_declare_local_statement(keyword.0, variable.0, colon.0, type_.0, initializer.0, semicolon.0), self.1.make_declare_local_statement(keyword.1, variable.1, colon.1, type_.1, initializer.1, semicolon.1)) } fn make_using_statement_block_scoped(&mut self, await_keyword: Self::Output, using_keyword: Self::Output, left_paren: Self::Output, expressions: Self::Output, right_paren: Self::Output, body: Self::Output) -> Self::Output { Node(self.0.make_using_statement_block_scoped(await_keyword.0, using_keyword.0, left_paren.0, expressions.0, right_paren.0, body.0), self.1.make_using_statement_block_scoped(await_keyword.1, using_keyword.1, left_paren.1, expressions.1, right_paren.1, body.1)) } fn make_using_statement_function_scoped(&mut self, await_keyword: Self::Output, using_keyword: Self::Output, expression: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_using_statement_function_scoped(await_keyword.0, using_keyword.0, expression.0, semicolon.0), self.1.make_using_statement_function_scoped(await_keyword.1, using_keyword.1, expression.1, semicolon.1)) } fn make_while_statement(&mut self, keyword: Self::Output, left_paren: Self::Output, condition: Self::Output, right_paren: Self::Output, body: Self::Output) -> Self::Output { Node(self.0.make_while_statement(keyword.0, left_paren.0, condition.0, right_paren.0, body.0), self.1.make_while_statement(keyword.1, left_paren.1, condition.1, right_paren.1, body.1)) } fn make_if_statement(&mut self, keyword: Self::Output, left_paren: Self::Output, condition: Self::Output, right_paren: Self::Output, statement: Self::Output, else_clause: Self::Output) -> Self::Output { Node(self.0.make_if_statement(keyword.0, left_paren.0, condition.0, right_paren.0, statement.0, else_clause.0), self.1.make_if_statement(keyword.1, left_paren.1, condition.1, right_paren.1, statement.1, else_clause.1)) } fn make_else_clause(&mut self, keyword: Self::Output, statement: Self::Output) -> Self::Output { Node(self.0.make_else_clause(keyword.0, statement.0), self.1.make_else_clause(keyword.1, statement.1)) } fn make_try_statement(&mut self, keyword: Self::Output, compound_statement: Self::Output, catch_clauses: Self::Output, finally_clause: Self::Output) -> Self::Output { Node(self.0.make_try_statement(keyword.0, compound_statement.0, catch_clauses.0, finally_clause.0), self.1.make_try_statement(keyword.1, compound_statement.1, catch_clauses.1, finally_clause.1)) } fn make_catch_clause(&mut self, keyword: Self::Output, left_paren: Self::Output, type_: Self::Output, variable: Self::Output, right_paren: Self::Output, body: Self::Output) -> Self::Output { Node(self.0.make_catch_clause(keyword.0, left_paren.0, type_.0, variable.0, right_paren.0, body.0), self.1.make_catch_clause(keyword.1, left_paren.1, type_.1, variable.1, right_paren.1, body.1)) } fn make_finally_clause(&mut self, keyword: Self::Output, body: Self::Output) -> Self::Output { Node(self.0.make_finally_clause(keyword.0, body.0), self.1.make_finally_clause(keyword.1, body.1)) } fn make_do_statement(&mut self, keyword: Self::Output, body: Self::Output, while_keyword: Self::Output, left_paren: Self::Output, condition: Self::Output, right_paren: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_do_statement(keyword.0, body.0, while_keyword.0, left_paren.0, condition.0, right_paren.0, semicolon.0), self.1.make_do_statement(keyword.1, body.1, while_keyword.1, left_paren.1, condition.1, right_paren.1, semicolon.1)) } fn make_for_statement(&mut self, keyword: Self::Output, left_paren: Self::Output, initializer: Self::Output, first_semicolon: Self::Output, control: Self::Output, second_semicolon: Self::Output, end_of_loop: Self::Output, right_paren: Self::Output, body: Self::Output) -> Self::Output { Node(self.0.make_for_statement(keyword.0, left_paren.0, initializer.0, first_semicolon.0, control.0, second_semicolon.0, end_of_loop.0, right_paren.0, body.0), self.1.make_for_statement(keyword.1, left_paren.1, initializer.1, first_semicolon.1, control.1, second_semicolon.1, end_of_loop.1, right_paren.1, body.1)) } fn make_foreach_statement(&mut self, keyword: Self::Output, left_paren: Self::Output, collection: Self::Output, await_keyword: Self::Output, as_: Self::Output, key: Self::Output, arrow: Self::Output, value: Self::Output, right_paren: Self::Output, body: Self::Output) -> Self::Output { Node(self.0.make_foreach_statement(keyword.0, left_paren.0, collection.0, await_keyword.0, as_.0, key.0, arrow.0, value.0, right_paren.0, body.0), self.1.make_foreach_statement(keyword.1, left_paren.1, collection.1, await_keyword.1, as_.1, key.1, arrow.1, value.1, right_paren.1, body.1)) } fn make_switch_statement(&mut self, keyword: Self::Output, left_paren: Self::Output, expression: Self::Output, right_paren: Self::Output, left_brace: Self::Output, sections: Self::Output, right_brace: Self::Output) -> Self::Output { Node(self.0.make_switch_statement(keyword.0, left_paren.0, expression.0, right_paren.0, left_brace.0, sections.0, right_brace.0), self.1.make_switch_statement(keyword.1, left_paren.1, expression.1, right_paren.1, left_brace.1, sections.1, right_brace.1)) } fn make_switch_section(&mut self, labels: Self::Output, statements: Self::Output, fallthrough: Self::Output) -> Self::Output { Node(self.0.make_switch_section(labels.0, statements.0, fallthrough.0), self.1.make_switch_section(labels.1, statements.1, fallthrough.1)) } fn make_switch_fallthrough(&mut self, keyword: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_switch_fallthrough(keyword.0, semicolon.0), self.1.make_switch_fallthrough(keyword.1, semicolon.1)) } fn make_case_label(&mut self, keyword: Self::Output, expression: Self::Output, colon: Self::Output) -> Self::Output { Node(self.0.make_case_label(keyword.0, expression.0, colon.0), self.1.make_case_label(keyword.1, expression.1, colon.1)) } fn make_default_label(&mut self, keyword: Self::Output, colon: Self::Output) -> Self::Output { Node(self.0.make_default_label(keyword.0, colon.0), self.1.make_default_label(keyword.1, colon.1)) } fn make_match_statement(&mut self, keyword: Self::Output, left_paren: Self::Output, expression: Self::Output, right_paren: Self::Output, left_brace: Self::Output, arms: Self::Output, right_brace: Self::Output) -> Self::Output { Node(self.0.make_match_statement(keyword.0, left_paren.0, expression.0, right_paren.0, left_brace.0, arms.0, right_brace.0), self.1.make_match_statement(keyword.1, left_paren.1, expression.1, right_paren.1, left_brace.1, arms.1, right_brace.1)) } fn make_match_statement_arm(&mut self, pattern: Self::Output, arrow: Self::Output, body: Self::Output) -> Self::Output { Node(self.0.make_match_statement_arm(pattern.0, arrow.0, body.0), self.1.make_match_statement_arm(pattern.1, arrow.1, body.1)) } fn make_return_statement(&mut self, keyword: Self::Output, expression: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_return_statement(keyword.0, expression.0, semicolon.0), self.1.make_return_statement(keyword.1, expression.1, semicolon.1)) } fn make_yield_break_statement(&mut self, keyword: Self::Output, break_: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_yield_break_statement(keyword.0, break_.0, semicolon.0), self.1.make_yield_break_statement(keyword.1, break_.1, semicolon.1)) } fn make_throw_statement(&mut self, keyword: Self::Output, expression: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_throw_statement(keyword.0, expression.0, semicolon.0), self.1.make_throw_statement(keyword.1, expression.1, semicolon.1)) } fn make_break_statement(&mut self, keyword: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_break_statement(keyword.0, semicolon.0), self.1.make_break_statement(keyword.1, semicolon.1)) } fn make_continue_statement(&mut self, keyword: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_continue_statement(keyword.0, semicolon.0), self.1.make_continue_statement(keyword.1, semicolon.1)) } fn make_echo_statement(&mut self, keyword: Self::Output, expressions: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_echo_statement(keyword.0, expressions.0, semicolon.0), self.1.make_echo_statement(keyword.1, expressions.1, semicolon.1)) } fn make_concurrent_statement(&mut self, keyword: Self::Output, statement: Self::Output) -> Self::Output { Node(self.0.make_concurrent_statement(keyword.0, statement.0), self.1.make_concurrent_statement(keyword.1, statement.1)) } fn make_simple_initializer(&mut self, equal: Self::Output, value: Self::Output) -> Self::Output { Node(self.0.make_simple_initializer(equal.0, value.0), self.1.make_simple_initializer(equal.1, value.1)) } fn make_anonymous_class(&mut self, class_keyword: Self::Output, left_paren: Self::Output, argument_list: Self::Output, right_paren: Self::Output, extends_keyword: Self::Output, extends_list: Self::Output, implements_keyword: Self::Output, implements_list: Self::Output, body: Self::Output) -> Self::Output { Node(self.0.make_anonymous_class(class_keyword.0, left_paren.0, argument_list.0, right_paren.0, extends_keyword.0, extends_list.0, implements_keyword.0, implements_list.0, body.0), self.1.make_anonymous_class(class_keyword.1, left_paren.1, argument_list.1, right_paren.1, extends_keyword.1, extends_list.1, implements_keyword.1, implements_list.1, body.1)) } fn make_anonymous_function(&mut self, attribute_spec: Self::Output, async_keyword: Self::Output, function_keyword: Self::Output, left_paren: Self::Output, parameters: Self::Output, right_paren: Self::Output, ctx_list: Self::Output, colon: Self::Output, readonly_return: Self::Output, type_: Self::Output, use_: Self::Output, body: Self::Output) -> Self::Output { Node(self.0.make_anonymous_function(attribute_spec.0, async_keyword.0, function_keyword.0, left_paren.0, parameters.0, right_paren.0, ctx_list.0, colon.0, readonly_return.0, type_.0, use_.0, body.0), self.1.make_anonymous_function(attribute_spec.1, async_keyword.1, function_keyword.1, left_paren.1, parameters.1, right_paren.1, ctx_list.1, colon.1, readonly_return.1, type_.1, use_.1, body.1)) } fn make_anonymous_function_use_clause(&mut self, keyword: Self::Output, left_paren: Self::Output, variables: Self::Output, right_paren: Self::Output) -> Self::Output { Node(self.0.make_anonymous_function_use_clause(keyword.0, left_paren.0, variables.0, right_paren.0), self.1.make_anonymous_function_use_clause(keyword.1, left_paren.1, variables.1, right_paren.1)) } fn make_variable_pattern(&mut self, variable: Self::Output) -> Self::Output { Node(self.0.make_variable_pattern(variable.0), self.1.make_variable_pattern(variable.1)) } fn make_constructor_pattern(&mut self, constructor: Self::Output, left_paren: Self::Output, members: Self::Output, right_paren: Self::Output) -> Self::Output { Node(self.0.make_constructor_pattern(constructor.0, left_paren.0, members.0, right_paren.0), self.1.make_constructor_pattern(constructor.1, left_paren.1, members.1, right_paren.1)) } fn make_refinement_pattern(&mut self, variable: Self::Output, colon: Self::Output, specifier: Self::Output) -> Self::Output { Node(self.0.make_refinement_pattern(variable.0, colon.0, specifier.0), self.1.make_refinement_pattern(variable.1, colon.1, specifier.1)) } fn make_lambda_expression(&mut self, attribute_spec: Self::Output, async_: Self::Output, signature: Self::Output, arrow: Self::Output, body: Self::Output) -> Self::Output { Node(self.0.make_lambda_expression(attribute_spec.0, async_.0, signature.0, arrow.0, body.0), self.1.make_lambda_expression(attribute_spec.1, async_.1, signature.1, arrow.1, body.1)) } fn make_lambda_signature(&mut self, left_paren: Self::Output, parameters: Self::Output, right_paren: Self::Output, contexts: Self::Output, colon: Self::Output, readonly_return: Self::Output, type_: Self::Output) -> Self::Output { Node(self.0.make_lambda_signature(left_paren.0, parameters.0, right_paren.0, contexts.0, colon.0, readonly_return.0, type_.0), self.1.make_lambda_signature(left_paren.1, parameters.1, right_paren.1, contexts.1, colon.1, readonly_return.1, type_.1)) } fn make_cast_expression(&mut self, left_paren: Self::Output, type_: Self::Output, right_paren: Self::Output, operand: Self::Output) -> Self::Output { Node(self.0.make_cast_expression(left_paren.0, type_.0, right_paren.0, operand.0), self.1.make_cast_expression(left_paren.1, type_.1, right_paren.1, operand.1)) } fn make_scope_resolution_expression(&mut self, qualifier: Self::Output, operator: Self::Output, name: Self::Output) -> Self::Output { Node(self.0.make_scope_resolution_expression(qualifier.0, operator.0, name.0), self.1.make_scope_resolution_expression(qualifier.1, operator.1, name.1)) } fn make_member_selection_expression(&mut self, object: Self::Output, operator: Self::Output, name: Self::Output) -> Self::Output { Node(self.0.make_member_selection_expression(object.0, operator.0, name.0), self.1.make_member_selection_expression(object.1, operator.1, name.1)) } fn make_safe_member_selection_expression(&mut self, object: Self::Output, operator: Self::Output, name: Self::Output) -> Self::Output { Node(self.0.make_safe_member_selection_expression(object.0, operator.0, name.0), self.1.make_safe_member_selection_expression(object.1, operator.1, name.1)) } fn make_embedded_member_selection_expression(&mut self, object: Self::Output, operator: Self::Output, name: Self::Output) -> Self::Output { Node(self.0.make_embedded_member_selection_expression(object.0, operator.0, name.0), self.1.make_embedded_member_selection_expression(object.1, operator.1, name.1)) } fn make_yield_expression(&mut self, keyword: Self::Output, operand: Self::Output) -> Self::Output { Node(self.0.make_yield_expression(keyword.0, operand.0), self.1.make_yield_expression(keyword.1, operand.1)) } fn make_prefix_unary_expression(&mut self, operator: Self::Output, operand: Self::Output) -> Self::Output { Node(self.0.make_prefix_unary_expression(operator.0, operand.0), self.1.make_prefix_unary_expression(operator.1, operand.1)) } fn make_postfix_unary_expression(&mut self, operand: Self::Output, operator: Self::Output) -> Self::Output { Node(self.0.make_postfix_unary_expression(operand.0, operator.0), self.1.make_postfix_unary_expression(operand.1, operator.1)) } fn make_binary_expression(&mut self, left_operand: Self::Output, operator: Self::Output, right_operand: Self::Output) -> Self::Output { Node(self.0.make_binary_expression(left_operand.0, operator.0, right_operand.0), self.1.make_binary_expression(left_operand.1, operator.1, right_operand.1)) } fn make_is_expression(&mut self, left_operand: Self::Output, operator: Self::Output, right_operand: Self::Output) -> Self::Output { Node(self.0.make_is_expression(left_operand.0, operator.0, right_operand.0), self.1.make_is_expression(left_operand.1, operator.1, right_operand.1)) } fn make_as_expression(&mut self, left_operand: Self::Output, operator: Self::Output, right_operand: Self::Output) -> Self::Output { Node(self.0.make_as_expression(left_operand.0, operator.0, right_operand.0), self.1.make_as_expression(left_operand.1, operator.1, right_operand.1)) } fn make_nullable_as_expression(&mut self, left_operand: Self::Output, operator: Self::Output, right_operand: Self::Output) -> Self::Output { Node(self.0.make_nullable_as_expression(left_operand.0, operator.0, right_operand.0), self.1.make_nullable_as_expression(left_operand.1, operator.1, right_operand.1)) } fn make_upcast_expression(&mut self, left_operand: Self::Output, operator: Self::Output, right_operand: Self::Output) -> Self::Output { Node(self.0.make_upcast_expression(left_operand.0, operator.0, right_operand.0), self.1.make_upcast_expression(left_operand.1, operator.1, right_operand.1)) } fn make_conditional_expression(&mut self, test: Self::Output, question: Self::Output, consequence: Self::Output, colon: Self::Output, alternative: Self::Output) -> Self::Output { Node(self.0.make_conditional_expression(test.0, question.0, consequence.0, colon.0, alternative.0), self.1.make_conditional_expression(test.1, question.1, consequence.1, colon.1, alternative.1)) } fn make_eval_expression(&mut self, keyword: Self::Output, left_paren: Self::Output, argument: Self::Output, right_paren: Self::Output) -> Self::Output { Node(self.0.make_eval_expression(keyword.0, left_paren.0, argument.0, right_paren.0), self.1.make_eval_expression(keyword.1, left_paren.1, argument.1, right_paren.1)) } fn make_isset_expression(&mut self, keyword: Self::Output, left_paren: Self::Output, argument_list: Self::Output, right_paren: Self::Output) -> Self::Output { Node(self.0.make_isset_expression(keyword.0, left_paren.0, argument_list.0, right_paren.0), self.1.make_isset_expression(keyword.1, left_paren.1, argument_list.1, right_paren.1)) } fn make_function_call_expression(&mut self, receiver: Self::Output, type_args: Self::Output, left_paren: Self::Output, argument_list: Self::Output, right_paren: Self::Output) -> Self::Output { Node(self.0.make_function_call_expression(receiver.0, type_args.0, left_paren.0, argument_list.0, right_paren.0), self.1.make_function_call_expression(receiver.1, type_args.1, left_paren.1, argument_list.1, right_paren.1)) } fn make_function_pointer_expression(&mut self, receiver: Self::Output, type_args: Self::Output) -> Self::Output { Node(self.0.make_function_pointer_expression(receiver.0, type_args.0), self.1.make_function_pointer_expression(receiver.1, type_args.1)) } fn make_parenthesized_expression(&mut self, left_paren: Self::Output, expression: Self::Output, right_paren: Self::Output) -> Self::Output { Node(self.0.make_parenthesized_expression(left_paren.0, expression.0, right_paren.0), self.1.make_parenthesized_expression(left_paren.1, expression.1, right_paren.1)) } fn make_braced_expression(&mut self, left_brace: Self::Output, expression: Self::Output, right_brace: Self::Output) -> Self::Output { Node(self.0.make_braced_expression(left_brace.0, expression.0, right_brace.0), self.1.make_braced_expression(left_brace.1, expression.1, right_brace.1)) } fn make_et_splice_expression(&mut self, dollar: Self::Output, left_brace: Self::Output, expression: Self::Output, right_brace: Self::Output) -> Self::Output { Node(self.0.make_et_splice_expression(dollar.0, left_brace.0, expression.0, right_brace.0), self.1.make_et_splice_expression(dollar.1, left_brace.1, expression.1, right_brace.1)) } fn make_embedded_braced_expression(&mut self, left_brace: Self::Output, expression: Self::Output, right_brace: Self::Output) -> Self::Output { Node(self.0.make_embedded_braced_expression(left_brace.0, expression.0, right_brace.0), self.1.make_embedded_braced_expression(left_brace.1, expression.1, right_brace.1)) } fn make_list_expression(&mut self, keyword: Self::Output, left_paren: Self::Output, members: Self::Output, right_paren: Self::Output) -> Self::Output { Node(self.0.make_list_expression(keyword.0, left_paren.0, members.0, right_paren.0), self.1.make_list_expression(keyword.1, left_paren.1, members.1, right_paren.1)) } fn make_collection_literal_expression(&mut self, name: Self::Output, left_brace: Self::Output, initializers: Self::Output, right_brace: Self::Output) -> Self::Output { Node(self.0.make_collection_literal_expression(name.0, left_brace.0, initializers.0, right_brace.0), self.1.make_collection_literal_expression(name.1, left_brace.1, initializers.1, right_brace.1)) } fn make_object_creation_expression(&mut self, new_keyword: Self::Output, object: Self::Output) -> Self::Output { Node(self.0.make_object_creation_expression(new_keyword.0, object.0), self.1.make_object_creation_expression(new_keyword.1, object.1)) } fn make_constructor_call(&mut self, type_: Self::Output, left_paren: Self::Output, argument_list: Self::Output, right_paren: Self::Output) -> Self::Output { Node(self.0.make_constructor_call(type_.0, left_paren.0, argument_list.0, right_paren.0), self.1.make_constructor_call(type_.1, left_paren.1, argument_list.1, right_paren.1)) } fn make_darray_intrinsic_expression(&mut self, keyword: Self::Output, explicit_type: Self::Output, left_bracket: Self::Output, members: Self::Output, right_bracket: Self::Output) -> Self::Output { Node(self.0.make_darray_intrinsic_expression(keyword.0, explicit_type.0, left_bracket.0, members.0, right_bracket.0), self.1.make_darray_intrinsic_expression(keyword.1, explicit_type.1, left_bracket.1, members.1, right_bracket.1)) } fn make_dictionary_intrinsic_expression(&mut self, keyword: Self::Output, explicit_type: Self::Output, left_bracket: Self::Output, members: Self::Output, right_bracket: Self::Output) -> Self::Output { Node(self.0.make_dictionary_intrinsic_expression(keyword.0, explicit_type.0, left_bracket.0, members.0, right_bracket.0), self.1.make_dictionary_intrinsic_expression(keyword.1, explicit_type.1, left_bracket.1, members.1, right_bracket.1)) } fn make_keyset_intrinsic_expression(&mut self, keyword: Self::Output, explicit_type: Self::Output, left_bracket: Self::Output, members: Self::Output, right_bracket: Self::Output) -> Self::Output { Node(self.0.make_keyset_intrinsic_expression(keyword.0, explicit_type.0, left_bracket.0, members.0, right_bracket.0), self.1.make_keyset_intrinsic_expression(keyword.1, explicit_type.1, left_bracket.1, members.1, right_bracket.1)) } fn make_varray_intrinsic_expression(&mut self, keyword: Self::Output, explicit_type: Self::Output, left_bracket: Self::Output, members: Self::Output, right_bracket: Self::Output) -> Self::Output { Node(self.0.make_varray_intrinsic_expression(keyword.0, explicit_type.0, left_bracket.0, members.0, right_bracket.0), self.1.make_varray_intrinsic_expression(keyword.1, explicit_type.1, left_bracket.1, members.1, right_bracket.1)) } fn make_vector_intrinsic_expression(&mut self, keyword: Self::Output, explicit_type: Self::Output, left_bracket: Self::Output, members: Self::Output, right_bracket: Self::Output) -> Self::Output { Node(self.0.make_vector_intrinsic_expression(keyword.0, explicit_type.0, left_bracket.0, members.0, right_bracket.0), self.1.make_vector_intrinsic_expression(keyword.1, explicit_type.1, left_bracket.1, members.1, right_bracket.1)) } fn make_element_initializer(&mut self, key: Self::Output, arrow: Self::Output, value: Self::Output) -> Self::Output { Node(self.0.make_element_initializer(key.0, arrow.0, value.0), self.1.make_element_initializer(key.1, arrow.1, value.1)) } fn make_subscript_expression(&mut self, receiver: Self::Output, left_bracket: Self::Output, index: Self::Output, right_bracket: Self::Output) -> Self::Output { Node(self.0.make_subscript_expression(receiver.0, left_bracket.0, index.0, right_bracket.0), self.1.make_subscript_expression(receiver.1, left_bracket.1, index.1, right_bracket.1)) } fn make_embedded_subscript_expression(&mut self, receiver: Self::Output, left_bracket: Self::Output, index: Self::Output, right_bracket: Self::Output) -> Self::Output { Node(self.0.make_embedded_subscript_expression(receiver.0, left_bracket.0, index.0, right_bracket.0), self.1.make_embedded_subscript_expression(receiver.1, left_bracket.1, index.1, right_bracket.1)) } fn make_awaitable_creation_expression(&mut self, attribute_spec: Self::Output, async_: Self::Output, compound_statement: Self::Output) -> Self::Output { Node(self.0.make_awaitable_creation_expression(attribute_spec.0, async_.0, compound_statement.0), self.1.make_awaitable_creation_expression(attribute_spec.1, async_.1, compound_statement.1)) } fn make_xhp_children_declaration(&mut self, keyword: Self::Output, expression: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_xhp_children_declaration(keyword.0, expression.0, semicolon.0), self.1.make_xhp_children_declaration(keyword.1, expression.1, semicolon.1)) } fn make_xhp_children_parenthesized_list(&mut self, left_paren: Self::Output, xhp_children: Self::Output, right_paren: Self::Output) -> Self::Output { Node(self.0.make_xhp_children_parenthesized_list(left_paren.0, xhp_children.0, right_paren.0), self.1.make_xhp_children_parenthesized_list(left_paren.1, xhp_children.1, right_paren.1)) } fn make_xhp_category_declaration(&mut self, keyword: Self::Output, categories: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_xhp_category_declaration(keyword.0, categories.0, semicolon.0), self.1.make_xhp_category_declaration(keyword.1, categories.1, semicolon.1)) } fn make_xhp_enum_type(&mut self, like: Self::Output, keyword: Self::Output, left_brace: Self::Output, values: Self::Output, right_brace: Self::Output) -> Self::Output { Node(self.0.make_xhp_enum_type(like.0, keyword.0, left_brace.0, values.0, right_brace.0), self.1.make_xhp_enum_type(like.1, keyword.1, left_brace.1, values.1, right_brace.1)) } fn make_xhp_lateinit(&mut self, at: Self::Output, keyword: Self::Output) -> Self::Output { Node(self.0.make_xhp_lateinit(at.0, keyword.0), self.1.make_xhp_lateinit(at.1, keyword.1)) } fn make_xhp_required(&mut self, at: Self::Output, keyword: Self::Output) -> Self::Output { Node(self.0.make_xhp_required(at.0, keyword.0), self.1.make_xhp_required(at.1, keyword.1)) } fn make_xhp_class_attribute_declaration(&mut self, keyword: Self::Output, attributes: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_xhp_class_attribute_declaration(keyword.0, attributes.0, semicolon.0), self.1.make_xhp_class_attribute_declaration(keyword.1, attributes.1, semicolon.1)) } fn make_xhp_class_attribute(&mut self, type_: Self::Output, name: Self::Output, initializer: Self::Output, required: Self::Output) -> Self::Output { Node(self.0.make_xhp_class_attribute(type_.0, name.0, initializer.0, required.0), self.1.make_xhp_class_attribute(type_.1, name.1, initializer.1, required.1)) } fn make_xhp_simple_class_attribute(&mut self, type_: Self::Output) -> Self::Output { Node(self.0.make_xhp_simple_class_attribute(type_.0), self.1.make_xhp_simple_class_attribute(type_.1)) } fn make_xhp_simple_attribute(&mut self, name: Self::Output, equal: Self::Output, expression: Self::Output) -> Self::Output { Node(self.0.make_xhp_simple_attribute(name.0, equal.0, expression.0), self.1.make_xhp_simple_attribute(name.1, equal.1, expression.1)) } fn make_xhp_spread_attribute(&mut self, left_brace: Self::Output, spread_operator: Self::Output, expression: Self::Output, right_brace: Self::Output) -> Self::Output { Node(self.0.make_xhp_spread_attribute(left_brace.0, spread_operator.0, expression.0, right_brace.0), self.1.make_xhp_spread_attribute(left_brace.1, spread_operator.1, expression.1, right_brace.1)) } fn make_xhp_open(&mut self, left_angle: Self::Output, name: Self::Output, attributes: Self::Output, right_angle: Self::Output) -> Self::Output { Node(self.0.make_xhp_open(left_angle.0, name.0, attributes.0, right_angle.0), self.1.make_xhp_open(left_angle.1, name.1, attributes.1, right_angle.1)) } fn make_xhp_expression(&mut self, open: Self::Output, body: Self::Output, close: Self::Output) -> Self::Output { Node(self.0.make_xhp_expression(open.0, body.0, close.0), self.1.make_xhp_expression(open.1, body.1, close.1)) } fn make_xhp_close(&mut self, left_angle: Self::Output, name: Self::Output, right_angle: Self::Output) -> Self::Output { Node(self.0.make_xhp_close(left_angle.0, name.0, right_angle.0), self.1.make_xhp_close(left_angle.1, name.1, right_angle.1)) } fn make_type_constant(&mut self, left_type: Self::Output, separator: Self::Output, right_type: Self::Output) -> Self::Output { Node(self.0.make_type_constant(left_type.0, separator.0, right_type.0), self.1.make_type_constant(left_type.1, separator.1, right_type.1)) } fn make_vector_type_specifier(&mut self, keyword: Self::Output, left_angle: Self::Output, type_: Self::Output, trailing_comma: Self::Output, right_angle: Self::Output) -> Self::Output { Node(self.0.make_vector_type_specifier(keyword.0, left_angle.0, type_.0, trailing_comma.0, right_angle.0), self.1.make_vector_type_specifier(keyword.1, left_angle.1, type_.1, trailing_comma.1, right_angle.1)) } fn make_keyset_type_specifier(&mut self, keyword: Self::Output, left_angle: Self::Output, type_: Self::Output, trailing_comma: Self::Output, right_angle: Self::Output) -> Self::Output { Node(self.0.make_keyset_type_specifier(keyword.0, left_angle.0, type_.0, trailing_comma.0, right_angle.0), self.1.make_keyset_type_specifier(keyword.1, left_angle.1, type_.1, trailing_comma.1, right_angle.1)) } fn make_tuple_type_explicit_specifier(&mut self, keyword: Self::Output, left_angle: Self::Output, types: Self::Output, right_angle: Self::Output) -> Self::Output { Node(self.0.make_tuple_type_explicit_specifier(keyword.0, left_angle.0, types.0, right_angle.0), self.1.make_tuple_type_explicit_specifier(keyword.1, left_angle.1, types.1, right_angle.1)) } fn make_varray_type_specifier(&mut self, keyword: Self::Output, left_angle: Self::Output, type_: Self::Output, trailing_comma: Self::Output, right_angle: Self::Output) -> Self::Output { Node(self.0.make_varray_type_specifier(keyword.0, left_angle.0, type_.0, trailing_comma.0, right_angle.0), self.1.make_varray_type_specifier(keyword.1, left_angle.1, type_.1, trailing_comma.1, right_angle.1)) } fn make_function_ctx_type_specifier(&mut self, keyword: Self::Output, variable: Self::Output) -> Self::Output { Node(self.0.make_function_ctx_type_specifier(keyword.0, variable.0), self.1.make_function_ctx_type_specifier(keyword.1, variable.1)) } fn make_type_parameter(&mut self, attribute_spec: Self::Output, reified: Self::Output, variance: Self::Output, name: Self::Output, param_params: Self::Output, constraints: Self::Output) -> Self::Output { Node(self.0.make_type_parameter(attribute_spec.0, reified.0, variance.0, name.0, param_params.0, constraints.0), self.1.make_type_parameter(attribute_spec.1, reified.1, variance.1, name.1, param_params.1, constraints.1)) } fn make_type_constraint(&mut self, keyword: Self::Output, type_: Self::Output) -> Self::Output { Node(self.0.make_type_constraint(keyword.0, type_.0), self.1.make_type_constraint(keyword.1, type_.1)) } fn make_context_constraint(&mut self, keyword: Self::Output, ctx_list: Self::Output) -> Self::Output { Node(self.0.make_context_constraint(keyword.0, ctx_list.0), self.1.make_context_constraint(keyword.1, ctx_list.1)) } fn make_darray_type_specifier(&mut self, keyword: Self::Output, left_angle: Self::Output, key: Self::Output, comma: Self::Output, value: Self::Output, trailing_comma: Self::Output, right_angle: Self::Output) -> Self::Output { Node(self.0.make_darray_type_specifier(keyword.0, left_angle.0, key.0, comma.0, value.0, trailing_comma.0, right_angle.0), self.1.make_darray_type_specifier(keyword.1, left_angle.1, key.1, comma.1, value.1, trailing_comma.1, right_angle.1)) } fn make_dictionary_type_specifier(&mut self, keyword: Self::Output, left_angle: Self::Output, members: Self::Output, right_angle: Self::Output) -> Self::Output { Node(self.0.make_dictionary_type_specifier(keyword.0, left_angle.0, members.0, right_angle.0), self.1.make_dictionary_type_specifier(keyword.1, left_angle.1, members.1, right_angle.1)) } fn make_closure_type_specifier(&mut self, outer_left_paren: Self::Output, readonly_keyword: Self::Output, function_keyword: Self::Output, inner_left_paren: Self::Output, parameter_list: Self::Output, inner_right_paren: Self::Output, contexts: Self::Output, colon: Self::Output, readonly_return: Self::Output, return_type: Self::Output, outer_right_paren: Self::Output) -> Self::Output { Node(self.0.make_closure_type_specifier(outer_left_paren.0, readonly_keyword.0, function_keyword.0, inner_left_paren.0, parameter_list.0, inner_right_paren.0, contexts.0, colon.0, readonly_return.0, return_type.0, outer_right_paren.0), self.1.make_closure_type_specifier(outer_left_paren.1, readonly_keyword.1, function_keyword.1, inner_left_paren.1, parameter_list.1, inner_right_paren.1, contexts.1, colon.1, readonly_return.1, return_type.1, outer_right_paren.1)) } fn make_closure_parameter_type_specifier(&mut self, call_convention: Self::Output, readonly: Self::Output, type_: Self::Output) -> Self::Output { Node(self.0.make_closure_parameter_type_specifier(call_convention.0, readonly.0, type_.0), self.1.make_closure_parameter_type_specifier(call_convention.1, readonly.1, type_.1)) } fn make_type_refinement(&mut self, type_: Self::Output, keyword: Self::Output, left_brace: Self::Output, members: Self::Output, right_brace: Self::Output) -> Self::Output { Node(self.0.make_type_refinement(type_.0, keyword.0, left_brace.0, members.0, right_brace.0), self.1.make_type_refinement(type_.1, keyword.1, left_brace.1, members.1, right_brace.1)) } fn make_type_in_refinement(&mut self, keyword: Self::Output, name: Self::Output, type_parameters: Self::Output, constraints: Self::Output, equal: Self::Output, type_: Self::Output) -> Self::Output { Node(self.0.make_type_in_refinement(keyword.0, name.0, type_parameters.0, constraints.0, equal.0, type_.0), self.1.make_type_in_refinement(keyword.1, name.1, type_parameters.1, constraints.1, equal.1, type_.1)) } fn make_ctx_in_refinement(&mut self, keyword: Self::Output, name: Self::Output, type_parameters: Self::Output, constraints: Self::Output, equal: Self::Output, ctx_list: Self::Output) -> Self::Output { Node(self.0.make_ctx_in_refinement(keyword.0, name.0, type_parameters.0, constraints.0, equal.0, ctx_list.0), self.1.make_ctx_in_refinement(keyword.1, name.1, type_parameters.1, constraints.1, equal.1, ctx_list.1)) } fn make_classname_type_specifier(&mut self, keyword: Self::Output, left_angle: Self::Output, type_: Self::Output, trailing_comma: Self::Output, right_angle: Self::Output) -> Self::Output { Node(self.0.make_classname_type_specifier(keyword.0, left_angle.0, type_.0, trailing_comma.0, right_angle.0), self.1.make_classname_type_specifier(keyword.1, left_angle.1, type_.1, trailing_comma.1, right_angle.1)) } fn make_field_specifier(&mut self, question: Self::Output, name: Self::Output, arrow: Self::Output, type_: Self::Output) -> Self::Output { Node(self.0.make_field_specifier(question.0, name.0, arrow.0, type_.0), self.1.make_field_specifier(question.1, name.1, arrow.1, type_.1)) } fn make_field_initializer(&mut self, name: Self::Output, arrow: Self::Output, value: Self::Output) -> Self::Output { Node(self.0.make_field_initializer(name.0, arrow.0, value.0), self.1.make_field_initializer(name.1, arrow.1, value.1)) } fn make_shape_type_specifier(&mut self, keyword: Self::Output, left_paren: Self::Output, fields: Self::Output, ellipsis: Self::Output, right_paren: Self::Output) -> Self::Output { Node(self.0.make_shape_type_specifier(keyword.0, left_paren.0, fields.0, ellipsis.0, right_paren.0), self.1.make_shape_type_specifier(keyword.1, left_paren.1, fields.1, ellipsis.1, right_paren.1)) } fn make_shape_expression(&mut self, keyword: Self::Output, left_paren: Self::Output, fields: Self::Output, right_paren: Self::Output) -> Self::Output { Node(self.0.make_shape_expression(keyword.0, left_paren.0, fields.0, right_paren.0), self.1.make_shape_expression(keyword.1, left_paren.1, fields.1, right_paren.1)) } fn make_tuple_expression(&mut self, keyword: Self::Output, left_paren: Self::Output, items: Self::Output, right_paren: Self::Output) -> Self::Output { Node(self.0.make_tuple_expression(keyword.0, left_paren.0, items.0, right_paren.0), self.1.make_tuple_expression(keyword.1, left_paren.1, items.1, right_paren.1)) } fn make_generic_type_specifier(&mut self, class_type: Self::Output, argument_list: Self::Output) -> Self::Output { Node(self.0.make_generic_type_specifier(class_type.0, argument_list.0), self.1.make_generic_type_specifier(class_type.1, argument_list.1)) } fn make_nullable_type_specifier(&mut self, question: Self::Output, type_: Self::Output) -> Self::Output { Node(self.0.make_nullable_type_specifier(question.0, type_.0), self.1.make_nullable_type_specifier(question.1, type_.1)) } fn make_like_type_specifier(&mut self, tilde: Self::Output, type_: Self::Output) -> Self::Output { Node(self.0.make_like_type_specifier(tilde.0, type_.0), self.1.make_like_type_specifier(tilde.1, type_.1)) } fn make_soft_type_specifier(&mut self, at: Self::Output, type_: Self::Output) -> Self::Output { Node(self.0.make_soft_type_specifier(at.0, type_.0), self.1.make_soft_type_specifier(at.1, type_.1)) } fn make_attributized_specifier(&mut self, attribute_spec: Self::Output, type_: Self::Output) -> Self::Output { Node(self.0.make_attributized_specifier(attribute_spec.0, type_.0), self.1.make_attributized_specifier(attribute_spec.1, type_.1)) } fn make_reified_type_argument(&mut self, reified: Self::Output, type_: Self::Output) -> Self::Output { Node(self.0.make_reified_type_argument(reified.0, type_.0), self.1.make_reified_type_argument(reified.1, type_.1)) } fn make_type_arguments(&mut self, left_angle: Self::Output, types: Self::Output, right_angle: Self::Output) -> Self::Output { Node(self.0.make_type_arguments(left_angle.0, types.0, right_angle.0), self.1.make_type_arguments(left_angle.1, types.1, right_angle.1)) } fn make_type_parameters(&mut self, left_angle: Self::Output, parameters: Self::Output, right_angle: Self::Output) -> Self::Output { Node(self.0.make_type_parameters(left_angle.0, parameters.0, right_angle.0), self.1.make_type_parameters(left_angle.1, parameters.1, right_angle.1)) } fn make_tuple_type_specifier(&mut self, left_paren: Self::Output, types: Self::Output, right_paren: Self::Output) -> Self::Output { Node(self.0.make_tuple_type_specifier(left_paren.0, types.0, right_paren.0), self.1.make_tuple_type_specifier(left_paren.1, types.1, right_paren.1)) } fn make_union_type_specifier(&mut self, left_paren: Self::Output, types: Self::Output, right_paren: Self::Output) -> Self::Output { Node(self.0.make_union_type_specifier(left_paren.0, types.0, right_paren.0), self.1.make_union_type_specifier(left_paren.1, types.1, right_paren.1)) } fn make_intersection_type_specifier(&mut self, left_paren: Self::Output, types: Self::Output, right_paren: Self::Output) -> Self::Output { Node(self.0.make_intersection_type_specifier(left_paren.0, types.0, right_paren.0), self.1.make_intersection_type_specifier(left_paren.1, types.1, right_paren.1)) } fn make_error(&mut self, error: Self::Output) -> Self::Output { Node(self.0.make_error(error.0), self.1.make_error(error.1)) } fn make_list_item(&mut self, item: Self::Output, separator: Self::Output) -> Self::Output { Node(self.0.make_list_item(item.0, separator.0), self.1.make_list_item(item.1, separator.1)) } fn make_enum_class_label_expression(&mut self, qualifier: Self::Output, hash: Self::Output, expression: Self::Output) -> Self::Output { Node(self.0.make_enum_class_label_expression(qualifier.0, hash.0, expression.0), self.1.make_enum_class_label_expression(qualifier.1, hash.1, expression.1)) } fn make_module_declaration(&mut self, attribute_spec: Self::Output, new_keyword: Self::Output, module_keyword: Self::Output, name: Self::Output, left_brace: Self::Output, exports: Self::Output, imports: Self::Output, right_brace: Self::Output) -> Self::Output { Node(self.0.make_module_declaration(attribute_spec.0, new_keyword.0, module_keyword.0, name.0, left_brace.0, exports.0, imports.0, right_brace.0), self.1.make_module_declaration(attribute_spec.1, new_keyword.1, module_keyword.1, name.1, left_brace.1, exports.1, imports.1, right_brace.1)) } fn make_module_exports(&mut self, exports_keyword: Self::Output, left_brace: Self::Output, exports: Self::Output, right_brace: Self::Output) -> Self::Output { Node(self.0.make_module_exports(exports_keyword.0, left_brace.0, exports.0, right_brace.0), self.1.make_module_exports(exports_keyword.1, left_brace.1, exports.1, right_brace.1)) } fn make_module_imports(&mut self, imports_keyword: Self::Output, left_brace: Self::Output, imports: Self::Output, right_brace: Self::Output) -> Self::Output { Node(self.0.make_module_imports(imports_keyword.0, left_brace.0, imports.0, right_brace.0), self.1.make_module_imports(imports_keyword.1, left_brace.1, imports.1, right_brace.1)) } fn make_module_membership_declaration(&mut self, module_keyword: Self::Output, name: Self::Output, semicolon: Self::Output) -> Self::Output { Node(self.0.make_module_membership_declaration(module_keyword.0, name.0, semicolon.0), self.1.make_module_membership_declaration(module_keyword.1, name.1, semicolon.1)) } fn make_package_expression(&mut self, keyword: Self::Output, name: Self::Output) -> Self::Output { Node(self.0.make_package_expression(keyword.0, name.0), self.1.make_package_expression(keyword.1, name.1)) } }
Rust
hhvm/hphp/hack/src/parser/parser_core_types_lib.rs
// Copyright (c) Facebook, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. //! # parser_core_types: Data type definitions for the Hack parser //! //! This crate contains data definitions and commonly-used types //! used within and outside of the Hack parser. This library is separated //! from the parser proper for two reasons: //! //! 1. The Rust compiler is notoriously slow and splitting up "cold" or //! infrequently changed data type definitions from the parser code //! speeds up the build. //! 2. Separating the data definitions from the code makes it a little //! easier to reason about the structure of the parser. pub mod compact_token; pub mod compact_trivia; pub mod indexed_source_text; pub mod lexable_token; pub mod lexable_trivia; pub mod minimal_trivia; pub mod parser_env; pub mod positioned_syntax; pub mod positioned_token; pub mod positioned_trivia; pub mod source_text; pub mod syntax; pub mod syntax_by_ref; pub mod syntax_error; mod syntax_generated; pub mod syntax_kind; pub mod syntax_trait; pub mod syntax_tree; pub mod syntax_type; pub mod token_factory; pub mod token_kind; pub mod trivia_factory; pub mod trivia_kind; pub use syntax_tree::FileMode;
Rust
hhvm/hphp/hack/src/parser/parser_env.rs
// Copyright (c) 2019, Facebook, Inc. // All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. #[derive(Clone, Debug, Default)] pub struct ParserEnv { pub codegen: bool, pub hhvm_compat_mode: bool, pub php5_compat_mode: bool, pub allow_new_attribute_syntax: bool, pub enable_xhp_class_modifier: bool, pub disable_xhp_element_mangling: bool, pub disable_xhp_children_declarations: bool, pub interpret_soft_types_as_like_types: bool, }
OCaml
hhvm/hphp/hack/src/parser/parser_return.ml
(* * Copyright (c) 2015, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) type comments = (Pos.t * Prim_defs.comment) list type t = { file_mode: FileInfo.mode option; comments: comments; ast: Nast.program; content: string; }
OCaml Interface
hhvm/hphp/hack/src/parser/parser_return.mli
(* * Copyright (c) 2015, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) type comments = (Pos.t * Prim_defs.comment) list type t = { file_mode: FileInfo.mode option; comments: comments; ast: Nast.program; content: string; }
OCaml
hhvm/hphp/hack/src/parser/parsing_error.ml
(* * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) module Error_code = Error_codes.Parsing type t = | Fixme_format of Pos.t | Hh_ignore_comment of Pos.t | Parsing_error of { pos: Pos.t; msg: string; quickfixes: Pos.t Quickfix.t list; } | Xhp_parsing_error of { pos: Pos.t; msg: string; } | Package_config_error of { pos: Pos.t; msg: string; reasons: Pos_or_decl.t Message.t list; } let to_user_error = function | Fixme_format pos -> User_error.make Error_code.(to_enum FixmeFormat) (pos, "`HH_FIXME` wrong format, expected `/* HH_FIXME[ERROR_NUMBER] */`") [] | Hh_ignore_comment pos -> User_error.make Error_code.(to_enum HhIgnoreComment) ( pos, "`HH_IGNORE_ERROR` comments are disabled by configuration and will soon be treated like normal comments, so you cannot use them to suppress errors" ) [] | Parsing_error { pos; msg; quickfixes } -> User_error.make Error_code.(to_enum ParsingError) ~quickfixes (pos, msg) [] | Xhp_parsing_error { pos; msg } -> User_error.make Error_code.(to_enum XhpParsingError) (pos, msg) [] | Package_config_error { pos; msg; reasons } -> User_error.make Error_code.(to_enum PackageConfigError) (pos, msg) reasons
OCaml Interface
hhvm/hphp/hack/src/parser/parsing_error.mli
(* * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) module Error_code = Error_codes.Parsing type t = | Fixme_format of Pos.t | Hh_ignore_comment of Pos.t | Parsing_error of { pos: Pos.t; msg: string; quickfixes: Pos.t Quickfix.t list; } | Xhp_parsing_error of { pos: Pos.t; msg: string; } | Package_config_error of { pos: Pos.t; msg: string; reasons: Pos_or_decl.t Message.t list; } val to_user_error : t -> (Pos.t, Pos_or_decl.t) User_error.t
Rust
hhvm/hphp/hack/src/parser/positioned_by_ref_parser_ffi.rs
// Copyright (c) Facebook, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use ocamlrep::ptr::UnsafeOcamlPtr; use ocamlrep::FromOcamlRep; use oxidized::full_fidelity_parser_env::FullFidelityParserEnv; // We don't use the ocaml_ffi! macro here because we want precise // control over the Pool--when a parse fails, we want to free the old // pool and create a new one. #[no_mangle] pub extern "C" fn parse_positioned_by_ref(ocaml_source_text: usize, env: usize) -> usize { ocamlrep_ocamlpool::catch_unwind(|| { let ocaml_source_text = unsafe { UnsafeOcamlPtr::new(ocaml_source_text) }; let env = unsafe { FullFidelityParserEnv::from_ocaml(env).unwrap() }; rust_parser_ffi::parse(ocaml_source_text, env, |a, s, e| { positioned_by_ref_parser::parse_script(a, s, e) }) .as_usize() }) }
OCaml
hhvm/hphp/hack/src/parser/positioned_parser.ml
(* * Copyright (c) 2017, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) include Full_fidelity_parser.WithSyntax (Full_fidelity_positioned_syntax)
OCaml Interface
hhvm/hphp/hack/src/parser/positioned_parser.mli
(* * Copyright (c) 2017, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) type t [@@deriving sexp_of] val make : Full_fidelity_parser_env.t -> Full_fidelity_source_text.t -> t val errors : t -> Full_fidelity_syntax_error.t list val env : t -> Full_fidelity_parser_env.t val parse_script : t -> t * Full_fidelity_positioned_syntax.t * Rust_pointer.t option
Rust
hhvm/hphp/hack/src/parser/positioned_smart_constructors.rs
/** * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. An additional * directory. * ** * * THIS FILE IS @generated; DO NOT EDIT IT * To regenerate this file, run * * buck run //hphp/hack/src:generate_full_fidelity * ** * */ use parser_core_types::{ syntax::*, lexable_token::LexableToken, token_factory::TokenFactory, }; use smart_constructors::SmartConstructors; use syntax_smart_constructors::{SyntaxSmartConstructors, StateType}; #[derive(Clone)] pub struct PositionedSmartConstructors<S, TF, St: StateType<S>> { pub state: St, token_factory: TF, phantom_s: std::marker::PhantomData<S>, } impl<S, TF, St: StateType<S>> PositionedSmartConstructors<S, TF, St> { pub fn new(state: St, token_factory: TF) -> Self { Self { state, token_factory, phantom_s: std::marker::PhantomData } } } impl<S, TF, St> SyntaxSmartConstructors<S, TF, St> for PositionedSmartConstructors<S, TF, St> where TF: TokenFactory<Token = S::Token>, St: StateType<S>, S: SyntaxType<St> + Clone, S::Token: LexableToken, {} impl<S, TF, St> SmartConstructors for PositionedSmartConstructors<S, TF, St> where TF: TokenFactory<Token = S::Token>, S::Token: LexableToken, S: SyntaxType<St> + Clone, St: StateType<S>, { type Factory = TF; type State = St; type Output = S; fn state_mut(&mut self) -> &mut St { &mut self.state } fn into_state(self) -> St { self.state } fn token_factory_mut(&mut self) -> &mut Self::Factory { &mut self.token_factory } fn make_missing(&mut self, offset: usize) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_missing(self, offset) } fn make_token(&mut self, offset: <Self::Factory as TokenFactory>::Token) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_token(self, offset) } fn make_list(&mut self, lst: Vec<Self::Output>, offset: usize) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_list(self, lst, offset) } fn make_end_of_file(&mut self, arg0: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_end_of_file(self, arg0) } fn make_script(&mut self, arg0: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_script(self, arg0) } fn make_qualified_name(&mut self, arg0: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_qualified_name(self, arg0) } fn make_module_name(&mut self, arg0: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_module_name(self, arg0) } fn make_simple_type_specifier(&mut self, arg0: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_simple_type_specifier(self, arg0) } fn make_literal_expression(&mut self, arg0: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_literal_expression(self, arg0) } fn make_prefixed_string_expression(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_prefixed_string_expression(self, arg0, arg1) } fn make_prefixed_code_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_prefixed_code_expression(self, arg0, arg1, arg2, arg3) } fn make_variable_expression(&mut self, arg0: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_variable_expression(self, arg0) } fn make_pipe_variable_expression(&mut self, arg0: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_pipe_variable_expression(self, arg0) } fn make_file_attribute_specification(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_file_attribute_specification(self, arg0, arg1, arg2, arg3, arg4) } fn make_enum_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output, arg9: Self::Output, arg10: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_enum_declaration(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) } fn make_enum_use(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_enum_use(self, arg0, arg1, arg2) } fn make_enumerator(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_enumerator(self, arg0, arg1, arg2, arg3) } fn make_enum_class_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output, arg9: Self::Output, arg10: Self::Output, arg11: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_enum_class_declaration(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) } fn make_enum_class_enumerator(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_enum_class_enumerator(self, arg0, arg1, arg2, arg3, arg4) } fn make_alias_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output, arg9: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_alias_declaration(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) } fn make_context_alias_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_context_alias_declaration(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) } fn make_case_type_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output, arg9: Self::Output, arg10: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_case_type_declaration(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) } fn make_case_type_variant(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_case_type_variant(self, arg0, arg1) } fn make_property_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_property_declaration(self, arg0, arg1, arg2, arg3, arg4) } fn make_property_declarator(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_property_declarator(self, arg0, arg1) } fn make_namespace_declaration(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_namespace_declaration(self, arg0, arg1) } fn make_namespace_declaration_header(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_namespace_declaration_header(self, arg0, arg1) } fn make_namespace_body(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_namespace_body(self, arg0, arg1, arg2) } fn make_namespace_empty_body(&mut self, arg0: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_namespace_empty_body(self, arg0) } fn make_namespace_use_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_namespace_use_declaration(self, arg0, arg1, arg2, arg3) } fn make_namespace_group_use_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_namespace_group_use_declaration(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6) } fn make_namespace_use_clause(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_namespace_use_clause(self, arg0, arg1, arg2, arg3) } fn make_function_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_function_declaration(self, arg0, arg1, arg2) } fn make_function_declaration_header(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output, arg9: Self::Output, arg10: Self::Output, arg11: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_function_declaration_header(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) } fn make_contexts(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_contexts(self, arg0, arg1, arg2) } fn make_where_clause(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_where_clause(self, arg0, arg1) } fn make_where_constraint(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_where_constraint(self, arg0, arg1, arg2) } fn make_methodish_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_methodish_declaration(self, arg0, arg1, arg2, arg3) } fn make_methodish_trait_resolution(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_methodish_trait_resolution(self, arg0, arg1, arg2, arg3, arg4) } fn make_classish_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output, arg9: Self::Output, arg10: Self::Output, arg11: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_classish_declaration(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) } fn make_classish_body(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_classish_body(self, arg0, arg1, arg2) } fn make_trait_use(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_trait_use(self, arg0, arg1, arg2) } fn make_require_clause(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_require_clause(self, arg0, arg1, arg2, arg3) } fn make_const_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_const_declaration(self, arg0, arg1, arg2, arg3, arg4, arg5) } fn make_constant_declarator(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_constant_declarator(self, arg0, arg1) } fn make_type_const_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output, arg9: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_type_const_declaration(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) } fn make_context_const_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_context_const_declaration(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) } fn make_decorated_expression(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_decorated_expression(self, arg0, arg1) } fn make_parameter_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_parameter_declaration(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6) } fn make_variadic_parameter(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_variadic_parameter(self, arg0, arg1, arg2) } fn make_old_attribute_specification(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_old_attribute_specification(self, arg0, arg1, arg2) } fn make_attribute_specification(&mut self, arg0: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_attribute_specification(self, arg0) } fn make_attribute(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_attribute(self, arg0, arg1) } fn make_inclusion_expression(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_inclusion_expression(self, arg0, arg1) } fn make_inclusion_directive(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_inclusion_directive(self, arg0, arg1) } fn make_compound_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_compound_statement(self, arg0, arg1, arg2) } fn make_expression_statement(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_expression_statement(self, arg0, arg1) } fn make_markup_section(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_markup_section(self, arg0, arg1) } fn make_markup_suffix(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_markup_suffix(self, arg0, arg1) } fn make_unset_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_unset_statement(self, arg0, arg1, arg2, arg3, arg4) } fn make_declare_local_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_declare_local_statement(self, arg0, arg1, arg2, arg3, arg4, arg5) } fn make_using_statement_block_scoped(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_using_statement_block_scoped(self, arg0, arg1, arg2, arg3, arg4, arg5) } fn make_using_statement_function_scoped(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_using_statement_function_scoped(self, arg0, arg1, arg2, arg3) } fn make_while_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_while_statement(self, arg0, arg1, arg2, arg3, arg4) } fn make_if_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_if_statement(self, arg0, arg1, arg2, arg3, arg4, arg5) } fn make_else_clause(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_else_clause(self, arg0, arg1) } fn make_try_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_try_statement(self, arg0, arg1, arg2, arg3) } fn make_catch_clause(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_catch_clause(self, arg0, arg1, arg2, arg3, arg4, arg5) } fn make_finally_clause(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_finally_clause(self, arg0, arg1) } fn make_do_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_do_statement(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6) } fn make_for_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_for_statement(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) } fn make_foreach_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output, arg9: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_foreach_statement(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) } fn make_switch_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_switch_statement(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6) } fn make_switch_section(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_switch_section(self, arg0, arg1, arg2) } fn make_switch_fallthrough(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_switch_fallthrough(self, arg0, arg1) } fn make_case_label(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_case_label(self, arg0, arg1, arg2) } fn make_default_label(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_default_label(self, arg0, arg1) } fn make_match_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_match_statement(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6) } fn make_match_statement_arm(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_match_statement_arm(self, arg0, arg1, arg2) } fn make_return_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_return_statement(self, arg0, arg1, arg2) } fn make_yield_break_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_yield_break_statement(self, arg0, arg1, arg2) } fn make_throw_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_throw_statement(self, arg0, arg1, arg2) } fn make_break_statement(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_break_statement(self, arg0, arg1) } fn make_continue_statement(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_continue_statement(self, arg0, arg1) } fn make_echo_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_echo_statement(self, arg0, arg1, arg2) } fn make_concurrent_statement(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_concurrent_statement(self, arg0, arg1) } fn make_simple_initializer(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_simple_initializer(self, arg0, arg1) } fn make_anonymous_class(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_anonymous_class(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) } fn make_anonymous_function(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output, arg9: Self::Output, arg10: Self::Output, arg11: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_anonymous_function(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) } fn make_anonymous_function_use_clause(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_anonymous_function_use_clause(self, arg0, arg1, arg2, arg3) } fn make_variable_pattern(&mut self, arg0: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_variable_pattern(self, arg0) } fn make_constructor_pattern(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_constructor_pattern(self, arg0, arg1, arg2, arg3) } fn make_refinement_pattern(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_refinement_pattern(self, arg0, arg1, arg2) } fn make_lambda_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_lambda_expression(self, arg0, arg1, arg2, arg3, arg4) } fn make_lambda_signature(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_lambda_signature(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6) } fn make_cast_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_cast_expression(self, arg0, arg1, arg2, arg3) } fn make_scope_resolution_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_scope_resolution_expression(self, arg0, arg1, arg2) } fn make_member_selection_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_member_selection_expression(self, arg0, arg1, arg2) } fn make_safe_member_selection_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_safe_member_selection_expression(self, arg0, arg1, arg2) } fn make_embedded_member_selection_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_embedded_member_selection_expression(self, arg0, arg1, arg2) } fn make_yield_expression(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_yield_expression(self, arg0, arg1) } fn make_prefix_unary_expression(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_prefix_unary_expression(self, arg0, arg1) } fn make_postfix_unary_expression(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_postfix_unary_expression(self, arg0, arg1) } fn make_binary_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_binary_expression(self, arg0, arg1, arg2) } fn make_is_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_is_expression(self, arg0, arg1, arg2) } fn make_as_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_as_expression(self, arg0, arg1, arg2) } fn make_nullable_as_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_nullable_as_expression(self, arg0, arg1, arg2) } fn make_upcast_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_upcast_expression(self, arg0, arg1, arg2) } fn make_conditional_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_conditional_expression(self, arg0, arg1, arg2, arg3, arg4) } fn make_eval_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_eval_expression(self, arg0, arg1, arg2, arg3) } fn make_isset_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_isset_expression(self, arg0, arg1, arg2, arg3) } fn make_function_call_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_function_call_expression(self, arg0, arg1, arg2, arg3, arg4) } fn make_function_pointer_expression(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_function_pointer_expression(self, arg0, arg1) } fn make_parenthesized_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_parenthesized_expression(self, arg0, arg1, arg2) } fn make_braced_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_braced_expression(self, arg0, arg1, arg2) } fn make_et_splice_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_et_splice_expression(self, arg0, arg1, arg2, arg3) } fn make_embedded_braced_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_embedded_braced_expression(self, arg0, arg1, arg2) } fn make_list_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_list_expression(self, arg0, arg1, arg2, arg3) } fn make_collection_literal_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_collection_literal_expression(self, arg0, arg1, arg2, arg3) } fn make_object_creation_expression(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_object_creation_expression(self, arg0, arg1) } fn make_constructor_call(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_constructor_call(self, arg0, arg1, arg2, arg3) } fn make_darray_intrinsic_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_darray_intrinsic_expression(self, arg0, arg1, arg2, arg3, arg4) } fn make_dictionary_intrinsic_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_dictionary_intrinsic_expression(self, arg0, arg1, arg2, arg3, arg4) } fn make_keyset_intrinsic_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_keyset_intrinsic_expression(self, arg0, arg1, arg2, arg3, arg4) } fn make_varray_intrinsic_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_varray_intrinsic_expression(self, arg0, arg1, arg2, arg3, arg4) } fn make_vector_intrinsic_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_vector_intrinsic_expression(self, arg0, arg1, arg2, arg3, arg4) } fn make_element_initializer(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_element_initializer(self, arg0, arg1, arg2) } fn make_subscript_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_subscript_expression(self, arg0, arg1, arg2, arg3) } fn make_embedded_subscript_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_embedded_subscript_expression(self, arg0, arg1, arg2, arg3) } fn make_awaitable_creation_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_awaitable_creation_expression(self, arg0, arg1, arg2) } fn make_xhp_children_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_xhp_children_declaration(self, arg0, arg1, arg2) } fn make_xhp_children_parenthesized_list(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_xhp_children_parenthesized_list(self, arg0, arg1, arg2) } fn make_xhp_category_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_xhp_category_declaration(self, arg0, arg1, arg2) } fn make_xhp_enum_type(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_xhp_enum_type(self, arg0, arg1, arg2, arg3, arg4) } fn make_xhp_lateinit(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_xhp_lateinit(self, arg0, arg1) } fn make_xhp_required(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_xhp_required(self, arg0, arg1) } fn make_xhp_class_attribute_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_xhp_class_attribute_declaration(self, arg0, arg1, arg2) } fn make_xhp_class_attribute(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_xhp_class_attribute(self, arg0, arg1, arg2, arg3) } fn make_xhp_simple_class_attribute(&mut self, arg0: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_xhp_simple_class_attribute(self, arg0) } fn make_xhp_simple_attribute(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_xhp_simple_attribute(self, arg0, arg1, arg2) } fn make_xhp_spread_attribute(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_xhp_spread_attribute(self, arg0, arg1, arg2, arg3) } fn make_xhp_open(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_xhp_open(self, arg0, arg1, arg2, arg3) } fn make_xhp_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_xhp_expression(self, arg0, arg1, arg2) } fn make_xhp_close(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_xhp_close(self, arg0, arg1, arg2) } fn make_type_constant(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_type_constant(self, arg0, arg1, arg2) } fn make_vector_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_vector_type_specifier(self, arg0, arg1, arg2, arg3, arg4) } fn make_keyset_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_keyset_type_specifier(self, arg0, arg1, arg2, arg3, arg4) } fn make_tuple_type_explicit_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_tuple_type_explicit_specifier(self, arg0, arg1, arg2, arg3) } fn make_varray_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_varray_type_specifier(self, arg0, arg1, arg2, arg3, arg4) } fn make_function_ctx_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_function_ctx_type_specifier(self, arg0, arg1) } fn make_type_parameter(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_type_parameter(self, arg0, arg1, arg2, arg3, arg4, arg5) } fn make_type_constraint(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_type_constraint(self, arg0, arg1) } fn make_context_constraint(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_context_constraint(self, arg0, arg1) } fn make_darray_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_darray_type_specifier(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6) } fn make_dictionary_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_dictionary_type_specifier(self, arg0, arg1, arg2, arg3) } fn make_closure_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output, arg9: Self::Output, arg10: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_closure_type_specifier(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) } fn make_closure_parameter_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_closure_parameter_type_specifier(self, arg0, arg1, arg2) } fn make_type_refinement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_type_refinement(self, arg0, arg1, arg2, arg3, arg4) } fn make_type_in_refinement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_type_in_refinement(self, arg0, arg1, arg2, arg3, arg4, arg5) } fn make_ctx_in_refinement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_ctx_in_refinement(self, arg0, arg1, arg2, arg3, arg4, arg5) } fn make_classname_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_classname_type_specifier(self, arg0, arg1, arg2, arg3, arg4) } fn make_field_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_field_specifier(self, arg0, arg1, arg2, arg3) } fn make_field_initializer(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_field_initializer(self, arg0, arg1, arg2) } fn make_shape_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_shape_type_specifier(self, arg0, arg1, arg2, arg3, arg4) } fn make_shape_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_shape_expression(self, arg0, arg1, arg2, arg3) } fn make_tuple_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_tuple_expression(self, arg0, arg1, arg2, arg3) } fn make_generic_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_generic_type_specifier(self, arg0, arg1) } fn make_nullable_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_nullable_type_specifier(self, arg0, arg1) } fn make_like_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_like_type_specifier(self, arg0, arg1) } fn make_soft_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_soft_type_specifier(self, arg0, arg1) } fn make_attributized_specifier(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_attributized_specifier(self, arg0, arg1) } fn make_reified_type_argument(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_reified_type_argument(self, arg0, arg1) } fn make_type_arguments(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_type_arguments(self, arg0, arg1, arg2) } fn make_type_parameters(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_type_parameters(self, arg0, arg1, arg2) } fn make_tuple_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_tuple_type_specifier(self, arg0, arg1, arg2) } fn make_union_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_union_type_specifier(self, arg0, arg1, arg2) } fn make_intersection_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_intersection_type_specifier(self, arg0, arg1, arg2) } fn make_error(&mut self, arg0: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_error(self, arg0) } fn make_list_item(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_list_item(self, arg0, arg1) } fn make_enum_class_label_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_enum_class_label_expression(self, arg0, arg1, arg2) } fn make_module_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_module_declaration(self, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) } fn make_module_exports(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_module_exports(self, arg0, arg1, arg2, arg3) } fn make_module_imports(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_module_imports(self, arg0, arg1, arg2, arg3) } fn make_module_membership_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_module_membership_declaration(self, arg0, arg1, arg2) } fn make_package_expression(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output { <Self as SyntaxSmartConstructors<S, TF, St>>::make_package_expression(self, arg0, arg1) } }
Rust
hhvm/hphp/hack/src/parser/positioned_syntax.rs
// Copyright (c) 2019, Facebook, Inc. // All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use std::sync::Arc; use crate::lexable_token::LexableToken; use crate::positioned_token::PositionedToken; use crate::source_text::SourceText; use crate::syntax::*; use crate::syntax_kind::SyntaxKind; use crate::syntax_trait::SyntaxTrait; use crate::token_kind::TokenKind; #[derive(Debug, Clone)] pub struct Span { pub left: PositionedToken, pub right: PositionedToken, } #[derive(Debug, Clone)] pub enum PositionedValue { /// value for a token node is token itself TokenValue(PositionedToken), /// value for a range denoted by pair of tokens TokenSpan(Box<Span>), Missing { offset: usize, }, } impl PositionedValue { pub fn width(&self) -> usize { match self { PositionedValue::TokenValue(t) => t.width(), PositionedValue::TokenSpan(x) => (x.right.end_offset() - x.left.start_offset()) + 1, PositionedValue::Missing { .. } => 0, } } fn start_offset(&self) -> usize { use PositionedValue::*; match &self { TokenValue(t) => t .leading_start_offset() .expect("invariant violation for Positioned Syntax"), TokenSpan(x) => x .left .leading_start_offset() .expect("invariant violation for Positioned Syntax"), Missing { offset, .. } => *offset, } } fn leading_width(&self) -> usize { use PositionedValue::*; match self { TokenValue(t) => t.leading_width(), TokenSpan(x) => x.left.leading_width(), Missing { .. } => 0, } } fn trailing_width(&self) -> usize { use PositionedValue::*; match self { TokenValue(t) => t.trailing_width(), TokenSpan(x) => x.right.trailing_width(), Missing { .. } => 0, } } fn leading_token(&self) -> Option<&PositionedToken> { use PositionedValue::*; match self { TokenValue(l) => Some(l), TokenSpan(x) => Some(&x.left), _ => None, } } fn trailing_token(&self) -> Option<&PositionedToken> { use PositionedValue::*; match self { TokenValue(r) => Some(r), TokenSpan(x) => Some(&x.right), _ => None, } } fn value_from_outer_children(first: &Self, last: &Self) -> Self { use PositionedValue::*; match (first, last) { (TokenValue(_), TokenValue(_)) | (TokenSpan(_), TokenValue(_)) | (TokenValue(_), TokenSpan(_)) | (TokenSpan(_), TokenSpan(_)) => { let l = first.leading_token().unwrap(); let r = last.trailing_token().unwrap(); if Arc::ptr_eq(l, r) { TokenValue(Arc::clone(l)) } else { TokenSpan(Box::new(Span { left: Arc::clone(l), right: Arc::clone(r), })) } } // can have two missing nodes if first and last child nodes of // the node are missing - this means that entire node is missing. // NOTE: offset must match otherwise it will mean that there is a real node // in between that should be picked instead (Missing { offset: o1 }, Missing { offset: o2 }) if o1 == o2 => first.clone(), _ => panic!(), } } fn from_<'a>(child_values: impl Iterator<Item = &'a Self>) -> Self { use PositionedValue::*; let mut first = None; let mut first_non_zero = None; let mut last_non_zero = None; let mut last = None; for value in child_values { match (first.is_some(), first_non_zero.is_some(), value) { (false, false, TokenValue { .. }) | (false, false, TokenSpan { .. }) => { // first iteration and first node has some token representation - // record it as first, first_non_zero, last and last_non_zero first = Some(value); first_non_zero = Some(value); last_non_zero = Some(value); last = Some(value); } (false, false, Missing { .. }) => { // first iteration - first node is missing - // record it as first and last first = Some(value); first_non_zero = None; last_non_zero = None; last = Some(value); } (true, false, TokenValue { .. }) | (true, false, TokenSpan { .. }) => { // in progress, found first node that include tokens - // record it as first_non_zero, last and last_non_zero first_non_zero = Some(value); last_non_zero = Some(value); last = Some(value); } (true, true, TokenValue { .. }) | (true, true, TokenSpan { .. }) => { // in progress found some node that includes tokens - // record it as last_non_zero and last last_non_zero = Some(value); last = Some(value); } _ => { // in progress, stepped on missing node - // record it as last and move on last = Some(value); } } } match (first, first_non_zero, last_non_zero, last) { (_, Some(first_non_zero), Some(last_non_zero), _) => { Self::value_from_outer_children(first_non_zero, last_non_zero) } (Some(first), None, None, Some(last)) => Self::value_from_outer_children(first, last), _ => panic!("how did we get a node with no children in value_from_syntax?"), } } } impl SyntaxValueWithKind for PositionedValue { fn is_missing(&self) -> bool { if let PositionedValue::Missing { .. } = self { true } else { false } } fn token_kind(&self) -> Option<TokenKind> { match self { PositionedValue::TokenValue(pt) => Some(pt.kind()), _ => None, } } } impl SyntaxValueType<PositionedToken> for PositionedValue { fn from_values<'a>(child_values: impl Iterator<Item = &'a Self>) -> Self { Self::from_(child_values) } fn from_children<'a>( _: SyntaxKind, offset: usize, nodes: impl Iterator<Item = &'a Self>, ) -> Self { // We need to determine the offset, leading, middle and trailing widths of // the node to be constructed based on its children. If the children are // all of zero width -- including the case where there are no children at // all -- then we make a zero-width value at the given offset. // Otherwise, we can determine the associated value from the first and last // children that have width. let mut have_width = nodes.filter(|x| x.width() > 0).peekable(); match have_width.peek() { None => PositionedValue::Missing { offset }, Some(first) => Self::value_from_outer_children(first, have_width.last().unwrap()), } } fn from_token(token: PositionedToken) -> Self { if token.kind() == TokenKind::EndOfFile || token.full_width() == 0 { PositionedValue::Missing { offset: token.end_offset(), } } else { PositionedValue::TokenValue(token) } } } pub type PositionedSyntax = Syntax<PositionedToken, PositionedValue>; impl SyntaxTrait for PositionedSyntax { fn offset(&self) -> Option<usize> { Some(self.start_offset()) } fn width(&self) -> usize { self.value.width() } fn leading_width(&self) -> usize { self.value.leading_width() } fn trailing_width(&self) -> usize { self.value.trailing_width() } fn full_width(&self) -> usize { self.leading_width() + self.width() + self.trailing_width() } fn leading_start_offset(&self) -> usize { self.value.start_offset() } fn extract_text<'a>(&self, source_text: &'a SourceText<'_>) -> Option<&'a str> { Some(self.text(source_text)) } } impl PositionedSyntax { /// Invariant: every token in the tree must have a valid offset&width, /// leading trivia offset&width, and trailing trivia offset&width (meaning, /// they point to an empty or valid non-empty slice of `source_text`), with /// one exception: fixed-width tokens (tokens where `TokenKind::fixed_width` /// returns `Some`) need not point to a valid offset&width (but their /// leading and trailing trivia offset&width should be empty or valid slices /// of `source_text`), since their text will be that returned by /// `TokenKind::to_string`. Undefined (but valid) slices of `source_text` /// will be used for invalid offsets/widths. pub fn text_from_edited_tree(&self, source_text: &SourceText<'_>) -> std::io::Result<Vec<u8>> { let mut text = vec![]; self.write_text_from_edited_tree(source_text, &mut text)?; Ok(text) } /// Invariant: Same requirements as `text_from_edited_tree`. pub fn write_text_from_edited_tree( &self, source_text: &SourceText<'_>, w: &mut impl std::io::Write, ) -> std::io::Result<()> { self.try_iter_pre(|node| { if let Some(token) = node.get_token() { if token.kind().fixed_width().is_some() { w.write_all(token.leading_text(source_text))?; w.write_all(token.kind().to_string().as_bytes())?; w.write_all(token.trailing_text(source_text))?; } else { w.write_all(source_text.sub(token.offset(), token.full_width()))?; } } Ok(()) }) } }
OCaml
hhvm/hphp/hack/src/parser/positioned_syntax_sig.ml
(* * Copyright (c) 2018, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. An additional * directory. *) module SourceText = Full_fidelity_source_text module type PositionedSyntax_S = sig module Token : Lexable_positioned_token_sig.LexablePositionedToken_S include Syntax_sig.Syntax_S with module Token := Token val text : t -> string val full_text : t -> string val leading_text : t -> string val source_text : t -> SourceText.t val start_offset : t -> int val end_offset : t -> int val is_synthetic : t -> bool (* * Similar to position except that the end_offset does not include * the last character. (the end offset is one larger than given by position) *) val position_exclusive : Relative_path.t -> t -> Pos.t option end
Rust
hhvm/hphp/hack/src/parser/positioned_token.rs
// Copyright (c) 2019, Facebook, Inc. // All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use std::sync::Arc; use crate::lexable_token::LexablePositionedToken; use crate::lexable_token::LexableToken; use crate::lexable_trivia::LexableTrivia; use crate::positioned_trivia::PositionedTrivia; use crate::positioned_trivia::PositionedTrivium; use crate::source_text::SourceText; use crate::token_factory::SimpleTokenFactory; use crate::token_kind::TokenKind; use crate::trivia_factory::SimpleTriviaFactory; use crate::trivia_kind::TriviaKind; #[derive(Debug, Clone, PartialEq)] pub struct PositionedTokenImpl { pub kind: TokenKind, pub offset: usize, // Beginning of first trivia pub leading_width: usize, pub width: usize, // Width of actual token, not counting trivia pub trailing_width: usize, // TODO (kasper): implement LazyTrivia pub leading: PositionedTrivia, pub trailing: PositionedTrivia, } // Positioned tokens, when used as part of positioned syntax are shared - same leaf token can be // embedded in multiple internal nodes (node can store the leftmost and rightmost token of its // subtree to describe span covered by it - see PositionedSyntaxValue for details). // We don't want to have to clone and store multiple copies of the token, so we define it as ref // counted pointer to the actual shared struct pub type PositionedToken = Arc<PositionedTokenImpl>; pub fn new( kind: TokenKind, offset: usize, width: usize, leading: PositionedTrivia, trailing: PositionedTrivia, ) -> PositionedToken { let leading_width = leading.iter().map(|x| x.width).sum(); let trailing_width = trailing.iter().map(|x| x.width).sum(); Arc::new(PositionedTokenImpl { kind, offset, leading_width, width, trailing_width, leading, trailing, }) } impl SimpleTokenFactory for PositionedToken { fn make( kind: TokenKind, offset: usize, width: usize, leading: PositionedTrivia, trailing: PositionedTrivia, ) -> Self { new(kind, offset, width, leading, trailing) } // Tricky: the with_ functions that modify tokens can be very cheap (when ref count is 1), or // possibly expensive (when make_mut has to perform a clone of underlying token that is shared). // Fortunately, they are used only in lexer/parser BEFORE the tokens are embedded in syntax, so // before any sharing occurs fn with_leading(mut self, leading: PositionedTrivia) -> Self { let token = Arc::make_mut(&mut self); let token_start_offset = token.offset + token.leading_width; let leading_width = leading.iter().map(|x| x.width).sum(); token.offset = token_start_offset - leading_width; token.leading_width = leading_width; token.leading = leading; self } fn with_trailing(mut self, trailing: PositionedTrivia) -> Self { let token = Arc::make_mut(&mut self); let trailing_width = trailing.iter().map(|x| x.width).sum(); token.trailing_width = trailing_width; token.trailing = trailing; self } fn with_kind(mut self, kind: TokenKind) -> Self { let token = Arc::make_mut(&mut self); token.kind = kind; self } } impl LexableToken for PositionedToken { type Trivia = PositionedTrivia; fn kind(&self) -> TokenKind { self.kind } fn leading_start_offset(&self) -> Option<usize> { self.as_ref().leading_start_offset() } fn width(&self) -> usize { self.width } fn leading_width(&self) -> usize { self.leading_width } fn trailing_width(&self) -> usize { self.trailing_width } fn full_width(&self) -> usize { self.leading_width() + self.width() + self.trailing_width() } fn clone_leading(&self) -> PositionedTrivia { self.leading.clone() } fn clone_trailing(&self) -> PositionedTrivia { self.trailing.clone() } fn leading_is_empty(&self) -> bool { self.leading.is_empty() } fn trailing_is_empty(&self) -> bool { self.trailing.is_empty() } fn has_leading_trivia_kind(&self, kind: TriviaKind) -> bool { self.leading.has_kind(kind) } fn has_trailing_trivia_kind(&self, kind: TriviaKind) -> bool { self.trailing.has_kind(kind) } fn into_trivia_and_width(self) -> (Self::Trivia, usize, Self::Trivia) { match Arc::try_unwrap(self) { Ok(t) => (t.leading, t.width, t.trailing), Err(t_ptr) => (t_ptr.leading.clone(), t_ptr.width, t_ptr.trailing.clone()), } } } impl PositionedTokenImpl { pub fn offset(&self) -> usize { self.offset } pub fn start_offset(&self) -> usize { self.offset() + self.leading_width } pub fn end_offset(&self) -> usize { let w = self.width; let w = if w == 0 { 0 } else { w - 1 }; self.start_offset() + w } fn leading_start_offset(&self) -> Option<usize> { Some(self.offset) } pub fn leading_text<'a>(&self, source_text: &SourceText<'a>) -> &'a [u8] { source_text.sub(self.leading_start_offset().unwrap(), self.leading_width) } pub fn trailing_text<'a>(&self, source_text: &SourceText<'a>) -> &'a [u8] { source_text.sub(self.end_offset() + 1, self.trailing_width) } } impl LexablePositionedToken for PositionedToken { fn text<'b>(&self, source_text: &'b SourceText<'_>) -> &'b str { source_text.sub_as_str(self.start_offset(), self.width()) } fn text_raw<'b>(&self, source_text: &'b SourceText<'_>) -> &'b [u8] { source_text.sub(self.start_offset(), self.width()) } fn clone_value(&self) -> Self { let inner = self.as_ref().clone(); Arc::new(inner) } fn positioned_leading(&self) -> &[PositionedTrivium] { &self.leading } fn positioned_trailing(&self) -> &[PositionedTrivium] { &self.trailing } } impl SimpleTriviaFactory for PositionedTrivia { fn make() -> Self { Self::new() } }
Rust
hhvm/hphp/hack/src/parser/positioned_trivia.rs
// Copyright (c) 2019, Facebook, Inc. // All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use ocamlrep::ToOcamlRep; use crate::lexable_trivia::LexableTrivia; use crate::lexable_trivia::LexableTrivium; use crate::source_text::SourceText; use crate::trivia_kind::TriviaKind; #[derive(Debug, Clone, PartialEq, ToOcamlRep)] pub struct PositionedTrivium { pub kind: TriviaKind, pub offset: usize, pub width: usize, } pub type PositionedTrivia = Vec<PositionedTrivium>; impl PositionedTrivium { pub fn start_offset(&self) -> usize { self.offset } pub fn end_offset(&self) -> usize { self.offset + self.width - 1 } pub fn text_raw<'b>(&self, source_text: &'b SourceText<'_>) -> &'b [u8] { source_text.sub(self.start_offset(), self.width()) } } impl LexableTrivia for PositionedTrivia { type Trivium = PositionedTrivium; fn is_empty(&self) -> bool { self.is_empty() } fn has_kind(&self, kind: TriviaKind) -> bool { self.iter().any(|t| t.kind == kind) } fn push(&mut self, trivium: Self::Trivium) { self.push(trivium) } fn extend(&mut self, other: Self) { for trivium in other { self.push(trivium) } } } impl LexableTrivium for PositionedTrivium { fn kind(&self) -> TriviaKind { self.kind } fn width(&self) -> usize { self.width } fn make_whitespace(offset: usize, width: usize) -> Self { Self { kind: TriviaKind::WhiteSpace, offset, width, } } fn make_eol(offset: usize, width: usize) -> Self { Self { kind: TriviaKind::EndOfLine, offset, width, } } fn make_single_line_comment(offset: usize, width: usize) -> Self { Self { kind: TriviaKind::SingleLineComment, offset, width, } } fn make_fallthrough(offset: usize, width: usize) -> Self { Self { kind: TriviaKind::FallThrough, offset, width, } } fn make_fix_me(offset: usize, width: usize) -> Self { Self { kind: TriviaKind::FixMe, offset, width, } } fn make_ignore_error(offset: usize, width: usize) -> Self { Self { kind: TriviaKind::IgnoreError, offset, width, } } fn make_extra_token_error(offset: usize, width: usize) -> Self { Self { kind: TriviaKind::ExtraTokenError, offset, width, } } fn make_delimited_comment(offset: usize, width: usize) -> Self { Self { kind: TriviaKind::DelimitedComment, offset, width, } } }
OCaml
hhvm/hphp/hack/src/parser/pretty_printing_library.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) (* implementation of pretty printing library based on Philip Wadler's paper * titled "A Prettier Printer", and the strict ocaml implementation based on * Christian Lindig's paper "Strictly Pretty" *) (********************* copied definition from mli files ***********************) open Pretty_printing_library_sig (******************************************************************************) (* main functionality of pretty printing library *) module Make (C : DocCompare) : Library = struct type t = Pretty_printing_library_sig.doc (* constructor functions *) let nil = Nil let cons x y = match (x, y) with | (Nil, _) -> y | (_, Nil) -> x | (_, _) -> Cons (x, y) let ( ^^ ) = cons let nest n x = if x = Nil then Nil else Nest (n, x) let text s = Text s let break = Break " " let breakwith s = Break s let must_break = MustBreak (* create alternatives of original layout and one line layout * Isolate corner cases to improve performance *) let group = function | Nil -> Nil | Group x -> Group x | x -> Group x (* observation functions *) let rec layout = function | LNil -> "" | LText (s, x) -> s ^ layout x | LLine (n, x) -> let newline_string = "\n" in let space_string = String.make n ' ' in (* TODO optimize string concat *) newline_string ^ space_string ^ layout x let pretty k x = layout (C.best k x) let dump doc = let rec dump_doc level = let indent = String.make level ' ' in function | Nil -> "nil" | Cons (x, y) -> Printf.sprintf "cons \n %s (%s, %s)" indent (dump_doc (level + 1) x) (dump_doc (level + 1) y) | Nest (i, x) -> Printf.sprintf "nest \n %s (%d, %s)" indent i (dump_doc (level + 1) x) | Text s -> s | Break _ -> "Break" | MustBreak -> "Must" | Group x -> Printf.sprintf "group \n %s (%s)" indent (dump_doc (level + 1) x) in dump_doc 0 doc end
OCaml Interface
hhvm/hphp/hack/src/parser/pretty_printing_library.mli
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) open Pretty_printing_library_sig (* Functor to create the actual module containing defined functionality *) module Make (_ : DocCompare) : Library
OCaml
hhvm/hphp/hack/src/parser/pretty_printing_library_sig.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) (* implementation of pretty printing library based on Philip Wadler's paper * titled "A Prettier Printer", and the strict ocaml implementation based on * Christian Lindig's paper "Strictly Pretty" *) (* document type used during construction of multiple layout alternatives *) type doc = | Nil | Cons of doc * doc | Nest of int * doc | Text of string | Break of string | MustBreak (** [Group x] represent two alternative layouts of [x]: * vertical layout is where Breaks are considered newline in the group * horizontal layout is where Breaks are considered spaces in the group * This decision is made independently in subgroups * This implicity definition allows docs to be constructed in a linear * fashion, and the better layout is dynamically generated and selected *) | Group of doc (* represents one particular layout, used for printing *) type layout = | LNil | LText of string * layout | LLine of int * layout (* docs are lazily evaluated *) module type Library = sig (* document type as specified in prettier printer paper *) type t = doc val nil : t (* the unit document *) val cons : t -> t -> t (* put two DOC horizontally *) (* adopted notation from Lindig paper Strictly Pretty *) val ( ^^ ) : t -> t -> t (* same as cons *) val nest : int -> t -> t (* DOC with i amount of indentation *) val text : string -> t (* creates a DOC that contains string s *) val break : t (* a "linebreak" followed by a string. * Note that line breaks here can be turned into space *) val breakwith : string -> t val must_break : t val group : t -> t (* create choices of t *) (* TODO should string be some custom data type? *) (* [pretty k doc] pretty prints doc assuming an initial indentation of * [k]. [k] is useful when pretty printing partial trees *) val pretty : int -> t -> string val dump : t -> string end (* DOCCOMPARE uses some criteria to make decision. * For now the configuration is global: i.e. there are some parameters that * the comparator is initialized with, and the comparator makes decision * using them along with any information carried in type doc. * A alternative would be to let documents carry with them more context * and the comparator uses these context, instead of a global config to * compare documents *) module type DocCompare = sig type t = doc (* from the choices, select best layout, considering initial indent [k] *) val best : int -> t -> layout end
Rust
hhvm/hphp/hack/src/parser/readonly_check.rs
// Copyright (c) 2019, Facebook, Inc. // All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use aast::Expr_ as E_; use hash::HashMap; use hash::HashSet; use hh_autoimport_rust::is_hh_autoimport_fun; use naming_special_names_rust::special_idents; use naming_special_names_rust::typehints; use naming_special_names_rust::user_attributes; use oxidized::aast; use oxidized::aast_visitor::visit_mut; use oxidized::aast_visitor::AstParams; use oxidized::aast_visitor::NodeMut; use oxidized::aast_visitor::VisitorMut; use oxidized::ast::*; use oxidized::ast_defs; use oxidized::local_id; use oxidized::pos::Pos; use parser_core_types::syntax_error; use parser_core_types::syntax_error::Error as ErrorMsg; use parser_core_types::syntax_error::SyntaxError; // Local environment which keeps track of how many readonly values it has #[derive(PartialEq, Clone, Default)] struct Lenv { pub lenv: HashMap<String, Rty>, pub num_readonly: u32, } impl Lenv { pub fn insert(&mut self, var_name: String, rty: Rty) { let result = self.lenv.insert(var_name, rty); match (rty, result) { (Rty::Readonly, Some(Rty::Mutable)) => { self.num_readonly += 1; } (Rty::Readonly, None) => { self.num_readonly += 1; } (Rty::Mutable, Some(Rty::Readonly)) => { self.num_readonly -= 1; } _ => {} // otherwise number of readonly values does not change } } pub fn get(&self, var_name: &str) -> Option<&Rty> { self.lenv.get(var_name) } } #[derive(PartialEq, Copy, Clone)] pub enum Rty { Readonly, Mutable, } struct Context { locals: Lenv, readonly_return: Rty, this_ty: Rty, inout_params: HashSet<String>, #[allow(dead_code)] is_typechecker: bool, } impl Context { fn new(readonly_ret: Rty, this_ty: Rty, is_typechecker: bool) -> Self { Self { locals: Lenv::default(), readonly_return: readonly_ret, this_ty, inout_params: HashSet::default(), is_typechecker, } } pub fn add_local(&mut self, var_name: &str, rty: Rty) { self.locals.insert(var_name.to_string(), rty); } pub fn add_param(&mut self, var_name: &str, rty: Rty, inout_param: bool) { self.locals.insert(var_name.to_string(), rty); if inout_param { self.inout_params.insert(var_name.to_string()); } } pub fn get_rty(&self, var_name: &str) -> Rty { match self.locals.get(var_name) { Some(&x) => x, None => Rty::Mutable, } } } fn ro_expr_list(context: &mut Context, exprs: &[Expr]) -> Rty { if exprs.iter().any(|e| rty_expr(context, e) == Rty::Readonly) { Rty::Readonly } else { Rty::Mutable } } fn ro_expr_list2<T>(context: &mut Context, exprs: &[(T, Expr)]) -> Rty { if exprs .iter() .any(|e| rty_expr(context, &e.1) == Rty::Readonly) { Rty::Readonly } else { Rty::Mutable } } fn ro_kind_to_rty(ro: Option<oxidized::ast_defs::ReadonlyKind>) -> Rty { match ro { Some(oxidized::ast_defs::ReadonlyKind::Readonly) => Rty::Readonly, _ => Rty::Mutable, } } fn rty_expr(context: &mut Context, expr: &Expr) -> Rty { let aast::Expr(_, _, exp) = expr; use aast::Expr_::*; match exp { ReadonlyExpr(_) => Rty::Readonly, ObjGet(og) => { let (obj, _member_name, _null_flavor, _reffiness) = &**og; rty_expr(context, obj) } Lvar(id_orig) => { let var_name = local_id::get_name(&id_orig.1); let is_this = var_name == special_idents::THIS; if is_this { context.this_ty } else { context.get_rty(var_name) } } Darray(d) => { let (_, exprs) = &**d; ro_expr_list2(context, exprs) } Varray(v) => { let (_, exprs) = &**v; ro_expr_list(context, exprs) } Shape(fields) => ro_expr_list2(context, fields), ValCollection(v) => { let (_, _, exprs) = &**v; ro_expr_list(context, exprs) } KeyValCollection(kv) => { let (_, _, fields) = &**kv; if fields .iter() .any(|f| rty_expr(context, &f.1) == Rty::Readonly) { Rty::Readonly } else { Rty::Mutable } } Collection(c) => { let (_, _, fields) = &**c; if fields.iter().any(|f| match f { aast::Afield::AFvalue(e) => rty_expr(context, e) == Rty::Readonly, aast::Afield::AFkvalue(_, e) => rty_expr(context, e) == Rty::Readonly, }) { Rty::Readonly } else { Rty::Mutable } } Xml(_) | Efun(_) | Lfun(_) => Rty::Mutable, Tuple(t) => ro_expr_list(context, t), // Only list destructuring List(_) => Rty::Mutable, // Boolean statement always mutable Is(_) => Rty::Mutable, // As(a) => { // Readonlyness of inner expression let (exp, hint, _) = &**a; let hint_ = &*hint.1; match hint_ { // Primitives are always mutable // Unfortunately, we don't make Hprim as a hint type until naming // so we have to look at Happly aast::Hint_::Happly(cn, _) if typehints::PRIMITIVE_TYPEHINTS.contains(cn.name()) => { Rty::Mutable } _ => rty_expr(context, exp), } } Upcast(a) => { // Readonlyness of inner expression let (exp, _) = &**a; rty_expr(context, exp) } Eif(e) => { // $x ? a : b is readonly if either a or b are readonly let (_, exp1_opt, exp2) = &**e; if let Some(exp1) = exp1_opt { match (rty_expr(context, exp1), rty_expr(context, exp2)) { (_, Rty::Readonly) | (Rty::Readonly, _) => Rty::Readonly, (Rty::Mutable, Rty::Mutable) => Rty::Mutable, } } else { rty_expr(context, exp2) } } Pair(p) => { let (_, exp1, exp2) = &**p; match (rty_expr(context, exp1), rty_expr(context, exp2)) { (_, Rty::Readonly) | (Rty::Readonly, _) => Rty::Readonly, (Rty::Mutable, Rty::Mutable) => Rty::Mutable, } } Hole(h) => { let (expr, _, _, _) = &**h; rty_expr(context, expr) } Invalid(_e) => Rty::Mutable, Cast(_) => Rty::Mutable, // Casts are only valid on primitive types, so its always mutable New(_) => Rty::Mutable, // FWIW, this does not appear on the aast at this stage(it only appears after naming in typechecker), // but we can handle it for future in case that changes This => context.this_ty, ArrayGet(ag) => { let (expr, _) = &**ag; rty_expr(context, expr) } Await(expr) => { let expr = &**expr; rty_expr(context, expr) } // Primitive types are mutable Null | True | False | Omitted => Rty::Mutable, Int(_) | Float(_) | String(_) | String2(_) | PrefixedString(_) => Rty::Mutable, Id(_) => Rty::Mutable, Dollardollar(lid) => { let (id, dollardollar) = &lid.1; let var_name = format!("{}{}", dollardollar, id); context.get_rty(&var_name) } // First put it in typechecker, then HHVM Clone(e) => { // Clone only clones shallowly, so we need to respect readonly even if you clone it let expr = &**e; rty_expr(context, expr) } Call(c) => { if let aast::CallExpr { func: aast::Expr(_, _, Id(i)), args, .. } = &**c { if is_special_builtin(&i.1) && !args.is_empty() { // Take first argument let (_, expr) = &args[0]; rty_expr(context, expr) } else { Rty::Mutable } } else { Rty::Mutable } } // Mutable unless wrapped in a readonly expression ClassGet(_) | ClassConst(_) => Rty::Mutable, FunctionPointer(_) => Rty::Mutable, // This is really just a statement, does not have a value Yield(_) => Rty::Mutable, Binop(b) => { let aast::Binop { bop, lhs: e1, rhs: e2, } = &**b; match bop { ast_defs::Bop::QuestionQuestion => { match (rty_expr(context, e1), rty_expr(context, e2)) { (Rty::Readonly, _) | (_, Rty::Readonly) => Rty::Readonly, (Rty::Mutable, Rty::Mutable) => Rty::Mutable, } } // All other operators are all primitive in result _ => Rty::Mutable, } } // Unary operators are all primitive in result Unop(_) => Rty::Mutable, Pipe(p) => { let (lid, left, _) = &**p; // The only time the id number matters is for Dollardollar let (_, dollardollar) = &lid.1; let left_rty = rty_expr(context, left); context.add_local(dollardollar, left_rty); rty_expr(context, &p.2) } ExpressionTree(_) | EnumClassLabel(_) | ETSplice(_) => Rty::Mutable, Import(_) | Lplaceholder(_) => Rty::Mutable, // More function values which are always mutable MethodCaller(_) => Rty::Mutable, Package(_) => Rty::Mutable, } } fn strip_ns(name: &str) -> &str { match name.chars().next() { Some('\\') => &name[1..], _ => name, } } // Special builtins that can take readonly values and return the same readonlyness back // These are represented as bytecodes, so do not go through regular call enforcement fn is_special_builtin(f_name: &str) -> bool { let stripped = strip_ns(f_name); let namespaced_f_name = if is_hh_autoimport_fun(stripped) { format!("HH\\{}", f_name) } else { stripped.to_string() }; match &namespaced_f_name[..] { "HH\\dict" | "HH\\varray" | "HH\\darray" | "HH\\vec" | "hphp_array_idx" | "HH\\FIXME\\UNSAFE_NONNULL_CAST" | "HH\\FIXME\\UNSAFE_CAST" => true, /* all other special builtins listed in emit_expresion.rs return mutable: specifically, these: "array_key_exists" => Some((2, IMisc(AKExists))), "intval" => Some((1, IOp(CastInt))), "boolval" => Some((1, IOp(CastBool))), "strval" => Some((1, IOp(CastString))), "floatval" | "doubleval" => Some((1, IOp(CastDouble))), "HH\\global_get" => Some((1, IGet(CGetG))), "HH\\global_isset" => Some((1, IIsset(IssetG))), */ _ => false, } } fn explicit_readonly(expr: &mut Expr) { match &expr.2 { aast::Expr_::ReadonlyExpr(_) => {} _ => { let tmp = std::mem::replace(expr, Expr(expr.0, expr.1.clone(), Expr_::Null)); expr.2 = aast::Expr_::ReadonlyExpr(Box::new(tmp)); } } } // For assignments to nonlocals, i.e. // $x->prop[0] = new Foo(); fn check_assignment_nonlocal( context: &mut Context, checker: &mut Checker, pos: &Pos, lhs: &mut Expr, rhs: &mut Expr, ) { match &mut lhs.2 { aast::Expr_::ObjGet(o) => { let (obj, _get, _, _) = &**o; // If obj is readonly, throw error match rty_expr(context, obj) { Rty::Readonly => { checker.add_error(pos, syntax_error::assignment_to_readonly); } Rty::Mutable => { match rty_expr(context, rhs) { Rty::Readonly => { // make the readonly expression explicit, since if it is // readonly we need to make sure the property is a readonly prop explicit_readonly(rhs); } // Mutable case does not require special checks Rty::Mutable => {} } } } } // Support self::$x["x"] assignments // Here, if the rhs is readonly we need to be explicit aast::Expr_::ClassGet(_) => match rty_expr(context, rhs) { Rty::Readonly => { explicit_readonly(rhs); } _ => {} }, // On an array get <expr>[0] = <rhs>, recurse and check compatibility of // inner <expr> with <rhs> aast::Expr_::ArrayGet(ag) => { let (array, _) = &mut **ag; check_assignment_nonlocal(context, checker, pos, array, rhs); } _ => { // Base case: here we just check whether the lhs expression is readonly // compared to the rhs match (rty_expr(context, lhs), rty_expr(context, rhs)) { (Rty::Mutable, Rty::Readonly) => { // error, can't assign a readonly value to a mutable collection checker.add_error( &rhs.1, // Position of readonly expression syntax_error::assign_readonly_to_mutable_collection, ) } (Rty::Readonly, Rty::Readonly) => { // make rhs explicit (to make sure we are not writing a readonly // value to a mutable one) explicit_readonly(rhs); // make lhs readonly explicitly, to check that it's a readonly // copy on write array here the lefthandside is either a local // variable or a class_get. explicit_readonly(lhs); } (Rty::Readonly, Rty::Mutable) => { explicit_readonly(lhs); } // Assigning to a mutable value always succeeds, so no explicit checks // are needed (Rty::Mutable, Rty::Mutable) => {} } } } } // Merges two local environments together. Note that // because of conservativeness, the resulting Lenv's num_readonly is at // least the max of lenv1.num_readonly, lenv2.num_readonly fn merge_lenvs(lenv1: &Lenv, lenv2: &Lenv) -> Lenv { let mut new_lenv = lenv1.clone(); for (key, value) in lenv2.lenv.iter() { match (value, new_lenv.get(key)) { (_, Some(Rty::Readonly)) => {} (rty, _) => { new_lenv.insert(key.to_string(), *rty); } } } new_lenv } // Toplevel assignment check fn check_assignment_validity( context: &mut Context, checker: &mut Checker, pos: &Pos, lhs: &mut Expr, rhs: &mut Expr, ) { match &mut lhs.2 { aast::Expr_::Lvar(id_orig) => { let var_name = local_id::get_name(&id_orig.1).to_string(); let rhs_rty = rty_expr(context, rhs); if context.inout_params.contains(&var_name) && rhs_rty == Rty::Readonly { checker.add_error(pos, syntax_error::inout_readonly_assignment); } context.add_local(&var_name, rhs_rty); } // list assignment aast::Expr_::List(l) => { let exprs = &mut **l; for e in exprs.iter_mut() { check_assignment_validity(context, checker, &e.1.clone(), e, rhs); } } // directly assigning to a class static is always valid (locally) as long as // the rhs is explicit on its readonlyness aast::Expr_::ClassGet(_) => { let rhs_rty = rty_expr(context, rhs); match rhs_rty { Rty::Readonly => explicit_readonly(rhs), _ => {} } } _ => { check_assignment_nonlocal(context, checker, pos, lhs, rhs); } } } struct Checker { errors: Vec<SyntaxError>, is_typechecker: bool, // used for migration purposes } impl Checker { fn new(typechecker: bool) -> Self { Self { errors: vec![], is_typechecker: typechecker, } } fn add_error(&mut self, pos: &Pos, msg: ErrorMsg) { let (start_offset, end_offset) = pos.info_raw(); self.errors .push(SyntaxError::make(start_offset, end_offset, msg, vec![])); } fn subtype(&mut self, pos: &Pos, r_sub: &Rty, r_sup: &Rty, reason: &str) { use Rty::*; match (r_sub, r_sup) { (Readonly, Mutable) => self.add_error( pos, syntax_error::invalid_readonly("readonly", "mutable", reason), ), _ => {} } } fn handle_single_block( &mut self, context: &mut Context, lenv: Lenv, b: &mut aast::Block<(), ()>, ) -> Lenv { context.locals = lenv; let _ = b.recurse(context, self.object()); context.locals.clone() } // Handles analysis for a given loop // Will run b.recurse() up to X times, where X is the number // of readonly values in the local environment // on each loop, we check if the number of readonly values has changed // since each loop iteration will monotonically increase the number // of readonly values, the loop must end within that fixed number of iterations. fn handle_loop( &mut self, context: &mut Context, lenv: Lenv, b: &mut aast::Block<(), ()>, as_expr_var_info: Option<(String, Rty)>, ) -> Lenv { let mut new_lenv = lenv.clone(); // Reassign the as_expr_var_info on every iteration of the loop if let Some((ref var_name, rty)) = as_expr_var_info { new_lenv.insert(var_name.clone(), rty); } // run the block once and merge the environment let new_lenv = merge_lenvs(&lenv, &self.handle_single_block(context, new_lenv, b)); if new_lenv.num_readonly > lenv.num_readonly { self.handle_loop(context, new_lenv, b, as_expr_var_info) } else { new_lenv } } } impl<'ast> VisitorMut<'ast> for Checker { type Params = AstParams<Context, ()>; fn object(&mut self) -> &mut dyn VisitorMut<'ast, Params = Self::Params> { self } fn visit_method_( &mut self, _context: &mut Context, m: &mut aast::Method_<(), ()>, ) -> Result<(), ()> { if m.user_attributes .iter() .any(|ua| user_attributes::ignore_readonly_local_errors(&ua.name.1)) { return Ok(()); } let readonly_return = ro_kind_to_rty(m.readonly_ret); let readonly_this = if m.readonly_this { Rty::Readonly } else { Rty::Mutable }; let mut context = Context::new(readonly_return, readonly_this, self.is_typechecker); for p in m.params.iter() { let is_inout = match p.callconv { ast_defs::ParamKind::Pinout(_) => true, _ => false, }; if let Some(rhs) = &p.expr { let ro_rhs = rty_expr(&mut context, rhs); self.subtype( &rhs.1, &ro_rhs, &ro_kind_to_rty(p.readonly), "this parameter is not marked readonly", ); } if p.readonly.is_some() { if is_inout { self.add_error(&p.pos, syntax_error::inout_readonly_parameter); } context.add_param(&p.name, Rty::Readonly, is_inout) } else { context.add_param(&p.name, Rty::Mutable, is_inout) } } m.recurse(&mut context, self.object()) } fn visit_fun_(&mut self, context: &mut Context, f: &mut aast::Fun_<(), ()>) -> Result<(), ()> { // Is run on every function definition and closure definition if f.user_attributes .iter() .any(|ua| user_attributes::ignore_readonly_local_errors(&ua.name.1)) { return Ok(()); } let readonly_return = ro_kind_to_rty(f.readonly_ret); let readonly_this = ro_kind_to_rty(f.readonly_this); let mut new_context = Context::new(readonly_return, readonly_this, self.is_typechecker); // Add the old context's stuff into the new context, as readonly if needed for (local, rty) in context.locals.lenv.iter() { if readonly_this == Rty::Readonly { new_context.add_local(local, Rty::Readonly); } else { new_context.add_local(local, *rty); } } for p in f.params.iter() { let is_inout = match p.callconv { ast_defs::ParamKind::Pinout(_) => true, _ => false, }; if let Some(rhs) = &p.expr { let ro_rhs = rty_expr(&mut new_context, rhs); self.subtype( &rhs.1, &ro_rhs, &ro_kind_to_rty(p.readonly), "this parameter is not marked readonly", ); } if p.readonly.is_some() { if is_inout { self.add_error(&p.pos, syntax_error::inout_readonly_parameter) } new_context.add_param(&p.name, Rty::Readonly, is_inout) } else { new_context.add_param(&p.name, Rty::Mutable, is_inout) } } f.recurse(&mut new_context, self.object()) } fn visit_fun_def( &mut self, _context: &mut Context, f: &mut aast::FunDef<(), ()>, ) -> Result<(), ()> { // Clear the context completely on a fun_def let mut context = Context::new(Rty::Mutable, Rty::Mutable, self.is_typechecker); f.recurse(&mut context, self.object()) } fn visit_expr(&mut self, context: &mut Context, p: &mut aast::Expr<(), ()>) -> Result<(), ()> { // Pipe expressions have their own recursion method due to their weird evaluation rules if !p.2.is_pipe() { // recurse on inner members first, then assign to value p.recurse(context, self.object())?; } match &mut p.2 { aast::Expr_::Binop(x) => { let aast::Binop { bop, lhs: e_lhs, rhs: e_rhs, } = x.as_mut(); if let Bop::Eq(_) = bop { check_assignment_validity(context, self, &p.1, e_lhs, e_rhs); } } aast::Expr_::Call(x) => { let aast::CallExpr { func, args, .. } = &mut **x; match rty_expr(context, func) { Rty::Readonly => explicit_readonly(func), Rty::Mutable => {} }; for (callconv, param) in args.iter_mut() { match (callconv, rty_expr(context, param)) { (ast_defs::ParamKind::Pinout(_), Rty::Readonly) => { self.add_error(param.pos(), syntax_error::inout_readonly_argument) } (ast_defs::ParamKind::Pnormal, Rty::Readonly) => explicit_readonly(param), (_, Rty::Mutable) => {} } } } aast::Expr_::New(n) => { let (_, _targs, args, _variadic, _) = &mut **n; for param in args.iter_mut() { match rty_expr(context, param) { Rty::Readonly => explicit_readonly(param), Rty::Mutable => {} } } } aast::Expr_::Pipe(p) => { let (lid, left, right) = &mut **p; // The only time the id number matters is for Dollardollar let (_, dollardollar) = &lid.1; // Go left first, get the readonlyness, then go right self.visit_expr(context, left)?; let left_rty = rty_expr(context, left); context.add_local(dollardollar, left_rty); self.visit_expr(context, right)?; } aast::Expr_::Yield(y) => { // TODO: T128042708 Remove once typechecker change is landed if self.is_typechecker { let mut expect_mutable = |expr| match rty_expr(context, expr) { Rty::Readonly => { self.add_error(expr.pos(), syntax_error::yield_readonly); } Rty::Mutable => (), }; match &**y { aast::Afield::AFkvalue(k, v) => { expect_mutable(k); expect_mutable(v); } aast::Afield::AFvalue(v) => { expect_mutable(v); } }; } } _ => {} } Ok(()) } fn visit_xhp_simple( &mut self, context: &mut Context, p: &mut aast::XhpSimple<(), ()>, ) -> Result<(), ()> { if let Rty::Readonly = rty_expr(context, &p.expr) { self.add_error(&p.expr.1, syntax_error::readonly_on_xhp); } p.recurse(context, self.object()) } fn visit_stmt( &mut self, context: &mut Context, s: &mut aast::Stmt<(), ()>, ) -> std::result::Result<(), ()> { match &mut s.1 { aast::Stmt_::Return(r) => { if let Some(expr) = r.as_mut() { self.subtype(&expr.1, &rty_expr(context, expr), &context.readonly_return, "this function does not return readonly. Please mark it to return readonly if needed.") } s.recurse(context, self.object()) } aast::Stmt_::If(i) => { let (condition, if_, else_) = &mut **i; let old_lenv = context.locals.clone(); self.visit_expr(context, condition)?; let if_lenv = self.handle_single_block(context, old_lenv.clone(), if_); let else_lenv = self.handle_single_block(context, old_lenv, else_); let new_lenv = merge_lenvs(&if_lenv, &else_lenv); context.locals = new_lenv; Ok(()) } aast::Stmt_::Try(t) => { let (try_, catches, finally_) = &mut **t; let old_lenv = context.locals.clone(); try_.recurse(context, self.object())?; // Each catch should run with no assumptions about how much of the try ran, // i.e. with old_lenv. Start with the lenv right after the try block and merge let result_lenv = catches .iter_mut() .fold(context.locals.clone(), |result_lenv, catch| { let catch_lenv = self.handle_single_block(context, old_lenv.clone(), &mut catch.2); merge_lenvs(&result_lenv, &catch_lenv) }); // Update the lenv from the old lenv with the result of context.locals = result_lenv; finally_.recurse(context, self.object()) } aast::Stmt_::Switch(s) => { let (condition, cases, default) = &mut **s; self.visit_expr(context, condition)?; let old_lenv = context.locals.clone(); let result_lenv = context.locals.clone(); let result_lenv = cases.iter_mut().fold(result_lenv, |result_lenv, case| { let _ = self.visit_expr(context, &mut case.0); let case_lenv = self.handle_single_block(context, old_lenv.clone(), &mut case.1); merge_lenvs(&result_lenv, &case_lenv) }); let result_lenv = default.iter_mut().fold(result_lenv, |result_lenv, case| { let case_lenv = self.handle_single_block(context, old_lenv.clone(), &mut case.1); merge_lenvs(&result_lenv, &case_lenv) }); context.locals = result_lenv; Ok(()) } aast::Stmt_::Throw(t) => { let inner = &**t; match rty_expr(context, inner) { Rty::Readonly => { self.add_error(&inner.1, syntax_error::throw_readonly_exception); } Rty::Mutable => {} } t.recurse(context, self.object()) } aast::Stmt_::Foreach(f) => { let (e, as_expr, b) = &mut **f; // Tracks what variable is being assigned each iteration of the loop let mut as_expr_var_info = None; match as_expr { aast::AsExpr::AsV(aast::Expr(_, _, E_::Lvar(id))) => { let var_name = local_id::get_name(&id.1); let rty = rty_expr(context, e); as_expr_var_info = Some((var_name.to_string(), rty)); } aast::AsExpr::AsKv( _, // key is arraykey and does not need to be readonly aast::Expr(_, _, E_::Lvar(value_id)), ) => { let var_name = local_id::get_name(&value_id.1); let rty = rty_expr(context, e); as_expr_var_info = Some((var_name.to_string(), rty)); } aast::AsExpr::AwaitAsV(_, aast::Expr(_, _, E_::Lvar(id))) => { let var_name = local_id::get_name(&id.1); let rty = rty_expr(context, e); as_expr_var_info = Some((var_name.to_string(), rty)); } aast::AsExpr::AwaitAsKv( _, _, // key is arraykey and does not need to be readonly aast::Expr(_, _, E_::Lvar(value_id)), ) => { let var_name = local_id::get_name(&value_id.1); let rty = rty_expr(context, e); as_expr_var_info = Some((var_name.to_string(), rty)); } // Any other Foreach here would mean no Lvar // where an Lvar is needed. In those cases // we will parse error, but the parse tree might still exist // so we just ignore those cases and continue our analysis // knowing that a parse error will show up _ => {} }; self.visit_expr(context, e)?; as_expr.recurse(context, self.object())?; let old_lenv = context.locals.clone(); let new_lenv = self.handle_loop(context, old_lenv, b, as_expr_var_info); context.locals = new_lenv; Ok(()) } aast::Stmt_::Do(d) => { let (b, cond) = &mut **d; // loop runs at least once let new_lenv = self.handle_single_block(context, context.locals.clone(), b); let block_lenv = self.handle_loop(context, new_lenv, b, None); context.locals = block_lenv; self.visit_expr(context, cond) } aast::Stmt_::While(w) => { let (cond, b) = &mut **w; self.visit_expr(context, cond)?; let old_lenv = context.locals.clone(); let new_lenv = self.handle_loop(context, old_lenv, b, None); context.locals = new_lenv; Ok(()) } aast::Stmt_::For(f) => { let (initializers, term, increment, b) = &mut **f; for i in initializers { self.visit_expr(context, i)?; } match term { Some(t) => { self.visit_expr(context, t)?; } None => {} } for inc in increment { self.visit_expr(context, inc)?; } let old_lenv = context.locals.clone(); // Technically, for loops can have an as_expr_var_info as well, but it's // very rare to write one where this occurs, so we will just be conservative let new_lenv = self.handle_loop(context, old_lenv, b, None); context.locals = new_lenv; Ok(()) } aast::Stmt_::Awaitall(a) => { let (assignments, block) = &mut **a; for i in assignments { // if there's a temp local if let Some(lid) = &i.0 { let var_name = local_id::get_name(&lid.1).to_string(); let rhs_rty = rty_expr(context, &i.1); context.add_local(&var_name, rhs_rty); i.recurse(context, self.object())?; } } block.recurse(context, self.object()) } _ => s.recurse(context, self.object()), } } } pub fn check_program( program: &mut aast::Program<(), ()>, is_typechecker: bool, ) -> Vec<SyntaxError> { let mut checker = Checker::new(is_typechecker); let mut context = Context::new(Rty::Mutable, Rty::Mutable, is_typechecker); visit_mut(&mut checker, &mut context, program).unwrap(); checker.errors }
OCaml
hhvm/hphp/hack/src/parser/rust_aast_parser_types.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) type env = { codegen: bool; php5_compat_mode: bool; elaborate_namespaces: bool; include_line_comments: bool; quick_mode: bool; (* Show errors even in quick mode. * Hotfix until we can properly set up saved states to surface parse errors during * typechecking properly. *) show_all_errors: bool; is_systemlib: bool; for_debugger_eval: bool; parser_options: ParserOptions.t; scour_comments: bool; } type result = { file_mode: FileInfo.mode; scoured_comments: Scoured_comments.t; aast: (unit, unit) Aast.program; lowerer_parsing_errors: (Pos.t * string) list; syntax_errors: Full_fidelity_syntax_error.t list; errors: Errors.error list; lint_errors: Pos.t Lints_core.t list; } type error = | NotAHackFile | ParserFatal of Full_fidelity_syntax_error.t * Pos.t | Other of string
Rust
hhvm/hphp/hack/src/parser/rust_aast_parser_types.rs
// Copyright (c) Facebook, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use std::time::Duration; use file_info::Mode; use lint_rust::LintError; use ocamlrep::FromOcamlRep; use ocamlrep::ToOcamlRep; use oxidized::aast::Program; use oxidized::errors::Error; use oxidized::file_info; use oxidized::parser_options::ParserOptions; use oxidized::pos::Pos; use oxidized::scoured_comments::ScouredComments; use parser_core_types::syntax_error::SyntaxError; #[derive(Clone, Debug, FromOcamlRep, ToOcamlRep, Default)] pub struct Env { pub codegen: bool, pub php5_compat_mode: bool, pub elaborate_namespaces: bool, pub include_line_comments: bool, pub quick_mode: bool, pub show_all_errors: bool, pub is_systemlib: bool, pub for_debugger_eval: bool, pub parser_options: ParserOptions, pub scour_comments: bool, } #[derive(Debug, ToOcamlRep)] pub struct ParserResult { pub file_mode: Mode, pub scoured_comments: ScouredComments, pub aast: Program<(), ()>, pub lowerer_parsing_errors: Vec<(Pos, String)>, pub syntax_errors: Vec<SyntaxError>, pub errors: Vec<Error>, pub lint_errors: Vec<LintError>, #[ocamlrep(skip)] pub profile: ParserProfile, } #[derive(Debug, Default)] pub struct ParserProfile { pub parse_peak: u64, pub lower_peak: u64, pub error_peak: u64, pub arena_bytes: u64, pub parsing_t: Duration, pub lowering_t: Duration, pub elaboration_t: Duration, pub error_t: Duration, pub total_t: Duration, } impl ParserProfile { pub fn fold(self, b: Self) -> Self { Self { parse_peak: std::cmp::max(self.parse_peak, b.parse_peak), lower_peak: std::cmp::max(self.lower_peak, b.lower_peak), error_peak: std::cmp::max(self.error_peak, b.error_peak), arena_bytes: self.arena_bytes + b.arena_bytes, parsing_t: self.parsing_t + b.parsing_t, lowering_t: self.lowering_t + b.lowering_t, elaboration_t: self.elaboration_t + b.elaboration_t, error_t: self.error_t + b.error_t, total_t: self.total_t + b.total_t, } } }
OCaml
hhvm/hphp/hack/src/parser/rust_lazy_trivia_ffi.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) module SourceText = Full_fidelity_source_text module RustPositionedTrivium = struct type t = { kind: Full_fidelity_trivia_kind.t; offset: int; width: int; } [@@deriving show, eq] end external scan_leading_xhp_trivia : SourceText.t -> int -> int -> RustPositionedTrivium.t list = "scan_leading_xhp_trivia" external scan_trailing_xhp_trivia : SourceText.t -> int -> int -> RustPositionedTrivium.t list = "scan_trailing_xhp_trivia" external scan_leading_php_trivia : SourceText.t -> int -> int -> RustPositionedTrivium.t list = "scan_leading_php_trivia" external scan_trailing_php_trivia : SourceText.t -> int -> int -> RustPositionedTrivium.t list = "scan_trailing_php_trivia"
Rust
hhvm/hphp/hack/src/parser/rust_parser_errors.rs
// Copyright (c) Facebook, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use std::borrow::Cow; use std::collections::BTreeMap; use std::matches; use std::str::FromStr; use hash::HashMap; use hash::HashSet; use hh_autoimport_rust as hh_autoimport; use itertools::Itertools; use naming_special_names_rust as sn; use oxidized::parser_options::ParserOptions; use parser_core_types::indexed_source_text::IndexedSourceText; use parser_core_types::lexable_token::LexableToken; use parser_core_types::syntax_by_ref::positioned_syntax::PositionedSyntax; use parser_core_types::syntax_by_ref::positioned_token::PositionedToken; use parser_core_types::syntax_by_ref::positioned_value::PositionedValue; use parser_core_types::syntax_by_ref::syntax::Syntax; use parser_core_types::syntax_by_ref::syntax_variant_generated::ListItemChildren; use parser_core_types::syntax_by_ref::syntax_variant_generated::SyntaxVariant; use parser_core_types::syntax_by_ref::syntax_variant_generated::SyntaxVariant::*; use parser_core_types::syntax_error::Error; use parser_core_types::syntax_error::ErrorType; use parser_core_types::syntax_error::LvalRoot; use parser_core_types::syntax_error::SyntaxError; use parser_core_types::syntax_error::SyntaxQuickfix; use parser_core_types::syntax_error::{self as errors}; use parser_core_types::syntax_trait::SyntaxTrait; use parser_core_types::syntax_tree::SyntaxTree; use parser_core_types::token_kind::TokenKind; use strum::Display; use strum::EnumIter; use strum::EnumString; use strum::IntoEnumIterator; use strum::IntoStaticStr; #[derive(Clone, PartialEq, Debug)] struct Location { start_offset: usize, end_offset: usize, } #[derive(Clone, PartialEq, Debug)] enum NameKind { NameUse, // `use` construct NameDef, // definition e.g. `class` or `trait` NameImplicitUse, // implicit `use` e.g. HH type in type hint } enum LvalType { LvalTypeNone, LvalTypeNonFinal, LvalTypeFinal, LvalTypeNonFinalInout, } use LvalType::*; enum BinopAllowsAwaitInPositions { BinopAllowAwaitBoth, BinopAllowAwaitLeft, BinopAllowAwaitRight, BinopAllowAwaitNone, } #[allow(dead_code)] // Deprecated is currently unused #[derive(Eq, PartialEq)] enum FeatureStatus { Unstable, Preview, Migration, Deprecated, OngoingRelease, // TODO: add other modes like "Advanced" or "Deprecated" if necessary. // Those are just variants of "Preview" for the runtime's sake, though, // and likely only need to be distinguished in the lint rule rather than here } #[derive(Clone, Copy, Eq, Display, Hash, PartialEq)] #[derive(EnumIter, EnumString, IntoStaticStr)] #[strum(serialize_all = "snake_case")] pub enum UnstableFeatures { // TODO: rename this from unstable to something else UnionIntersectionTypeHints, ClassLevelWhere, ExpressionTrees, Ifc, Readonly, Modules, ModuleReferences, ClassConstDefault, TypeConstMultipleBounds, TypeConstSuperBound, TypeRefinements, ContextAliasDeclaration, ContextAliasDeclarationShort, MethodTraitDiamond, UpcastExpression, RequireClass, NewtypeSuperBounds, ExpressionTreeBlocks, Package, CaseTypes, ModuleLevelTraits, TypedLocalVariables, MatchStatements, } impl UnstableFeatures { // Preview features are allowed to run in prod. This function decides // whether the feature is considered Unstable or Preview. fn get_feature_status(&self) -> FeatureStatus { use FeatureStatus::*; match self { UnstableFeatures::UnionIntersectionTypeHints => Unstable, UnstableFeatures::ClassLevelWhere => Unstable, UnstableFeatures::ExpressionTrees => Unstable, UnstableFeatures::Ifc => Unstable, UnstableFeatures::Readonly => Preview, UnstableFeatures::Modules => OngoingRelease, UnstableFeatures::ModuleReferences => Unstable, UnstableFeatures::ContextAliasDeclaration => Unstable, UnstableFeatures::ContextAliasDeclarationShort => Preview, UnstableFeatures::TypeConstMultipleBounds => Preview, UnstableFeatures::TypeConstSuperBound => Unstable, UnstableFeatures::ClassConstDefault => Migration, UnstableFeatures::TypeRefinements => OngoingRelease, UnstableFeatures::MethodTraitDiamond => OngoingRelease, UnstableFeatures::UpcastExpression => Unstable, UnstableFeatures::RequireClass => OngoingRelease, UnstableFeatures::NewtypeSuperBounds => Unstable, UnstableFeatures::ExpressionTreeBlocks => OngoingRelease, UnstableFeatures::Package => Unstable, UnstableFeatures::CaseTypes => Unstable, UnstableFeatures::ModuleLevelTraits => Preview, UnstableFeatures::TypedLocalVariables => Unstable, UnstableFeatures::MatchStatements => Unstable, } } } use BinopAllowsAwaitInPositions::*; use NameKind::*; #[derive(Clone, Debug)] struct FirstUseOrDef { location: Location, kind: NameKind, name: String, global: bool, } #[derive(PartialEq)] enum NamespaceType { Unspecified, Bracketed(Location), Unbracketed(Location), } use NamespaceType::*; // TODO: is there a more Rust idiomatic way to write this? #[derive(Clone, Debug)] enum Strmap<X> { YesCase(HashMap<String, X>), NoCase(HashMap<String, X>), } impl<X> Strmap<X> { fn mem(&self, k: &str) -> bool { match &self { NoCase(m) => m.contains_key(&k.to_ascii_lowercase()), YesCase(m) => m.contains_key(k), } } fn add(&mut self, k: &str, v: X) { match self { NoCase(m) => m.insert(k.to_ascii_lowercase(), v), YesCase(m) => m.insert(k.to_string(), v), }; } fn get(&self, k: &str) -> Option<&X> { match &self { NoCase(m) => m.get(&k.to_ascii_lowercase()), YesCase(m) => m.get(k), } } fn filter<F>(self, f: F) -> Self where F: Fn(&X) -> bool, { match self { NoCase(m) => NoCase(m.into_iter().filter(|(_, x)| f(x)).collect()), YesCase(m) => YesCase(m.into_iter().filter(|(_, x)| f(x)).collect()), } } } use crate::Strmap::*; fn empty_trait_require_clauses() -> Strmap<TokenKind> { NoCase(HashMap::default()) } #[derive(Clone, Debug)] struct UsedNames { classes: Strmap<FirstUseOrDef>, // NoCase namespaces: Strmap<FirstUseOrDef>, // NoCase functions: Strmap<FirstUseOrDef>, // NoCase constants: Strmap<FirstUseOrDef>, // YesCase attributes: Strmap<FirstUseOrDef>, // YesCase } impl UsedNames { fn empty() -> Self { Self { classes: NoCase(HashMap::default()), namespaces: NoCase(HashMap::default()), functions: NoCase(HashMap::default()), constants: YesCase(HashMap::default()), attributes: YesCase(HashMap::default()), } } } type S<'a> = &'a Syntax<'a, PositionedToken<'a>, PositionedValue<'a>>; #[derive(Clone)] struct Context<'a> { pub active_classish: Option<S<'a>>, pub active_methodish: Option<S<'a>>, pub active_callable: Option<S<'a>>, pub active_callable_attr_spec: Option<S<'a>>, pub active_const: Option<S<'a>>, pub active_unstable_features: HashSet<UnstableFeatures>, pub active_expression_tree: bool, } struct Env<'a, State> { parser_options: ParserOptions, syntax_tree: &'a SyntaxTree<'a, Syntax<'a, PositionedToken<'a>, PositionedValue<'a>>, State>, text: IndexedSourceText<'a>, context: Context<'a>, hhvm_compat_mode: bool, hhi_mode: bool, codegen: bool, systemlib: bool, } impl<'a, State> Env<'a, State> { fn is_hhvm_compat(&self) -> bool { self.hhvm_compat_mode } fn is_typechecker(&self) -> bool { !self.codegen } fn is_hhi_mode(&self) -> bool { self.hhi_mode } fn is_systemlib(&self) -> bool { self.systemlib } } const GLOBAL_NAMESPACE_NAME: &str = "\\"; fn combine_names(n1: &str, n2: &str) -> String { let has_leading_slash = n2.starts_with('\\'); let has_trailing_slash = n1.ends_with('\\'); match (has_leading_slash, has_trailing_slash) { (true, true) => n1.to_string() + &n2[1..], (false, false) => n1.to_string() + "\\" + n2, _ => n1.to_string() + n2, } } fn make_first_use_or_def( is_method: bool, kind: NameKind, location: Location, namespace_name: &str, name: &str, ) -> FirstUseOrDef { FirstUseOrDef { location, kind, name: combine_names(namespace_name, name), global: !is_method && namespace_name == GLOBAL_NAMESPACE_NAME, } } struct ParserErrors<'a, State> { env: Env<'a, State>, errors: Vec<SyntaxError>, parents: Vec<S<'a>>, trait_require_clauses: Strmap<TokenKind>, is_in_concurrent_block: bool, names: UsedNames, // Named (not anonymous) namespaces that the current expression is enclosed within. nested_namespaces: Vec<S<'a>>, namespace_type: NamespaceType, namespace_name: String, uses_readonly: bool, in_module: bool, } fn strip_ns(name: &str) -> &str { match name.chars().next() { Some('\\') => &name[1..], _ => name, } } // test a node is a syntaxlist and that the list contains an element // satisfying a given predicate fn list_contains_predicate<P>(p: P, node: S<'_>) -> bool where P: Fn(S<'_>) -> bool, { if let SyntaxList(lst) = &node.children { lst.iter().any(p) } else { false } } fn modifiers_of_function_decl_header_exn<'a>(node: S<'a>) -> S<'a> { match &node.children { FunctionDeclarationHeader(x) => &x.modifiers, _ => panic!("expected to get FunctionDeclarationHeader"), } } fn get_modifiers_of_declaration<'a>(node: S<'a>) -> Option<S<'a>> { match &node.children { MethodishDeclaration(x) => Some(modifiers_of_function_decl_header_exn( &x.function_decl_header, )), FunctionDeclaration(x) => { Some(modifiers_of_function_decl_header_exn(&x.declaration_header)) } PropertyDeclaration(x) => Some(&x.modifiers), ConstDeclaration(x) => Some(&x.modifiers), TypeConstDeclaration(x) => Some(&x.modifiers), ClassishDeclaration(x) => Some(&x.modifiers), EnumClassDeclaration(x) => Some(&x.modifiers), EnumClassEnumerator(x) => Some(&x.modifiers), EnumDeclaration(x) => Some(&x.modifiers), AliasDeclaration(x) => Some(&x.modifiers), CaseTypeDeclaration(x) => Some(&x.modifiers), _ => None, } } fn declaration_is_toplevel<'a>(node: S<'a>) -> bool { match &node.children { FunctionDeclaration(_) | ClassishDeclaration(_) | EnumClassDeclaration(_) | EnumDeclaration(_) | CaseTypeDeclaration(_) | AliasDeclaration(_) => true, _ => false, } } // tests whether the node's modifiers contain one that satisfies `p`. fn has_modifier_helper<P>(p: P, node: S<'_>) -> bool where P: Fn(S<'_>) -> bool, { match get_modifiers_of_declaration(node) { Some(x) => list_contains_predicate(p, x), None => false, } } // does the node contain the Abstract keyword in its modifiers fn has_modifier_abstract(node: S<'_>) -> bool { has_modifier_helper(|x| x.is_abstract(), node) } // does the node contain the Static keyword in its modifiers fn has_modifier_static(node: S<'_>) -> bool { has_modifier_helper(|x| x.is_static(), node) } fn has_modifier_readonly(node: S<'_>) -> bool { has_modifier_helper(|x| x.is_readonly(), node) } // does the node contain the Private keyword in its modifiers fn has_modifier_private(node: S<'_>) -> bool { has_modifier_helper(|x| x.is_private(), node) } fn make_location(s: S<'_>, e: S<'_>) -> Location { let start_offset = start_offset(s); let end_offset = end_offset(e); Location { start_offset, end_offset, } } fn make_location_of_node(n: S<'_>) -> Location { make_location(n, n) } fn start_offset(n: S<'_>) -> usize { // TODO: this logic should be moved to SyntaxTrait::position, when implemented n.leading_start_offset() + n.leading_width() } fn end_offset(n: S<'_>) -> usize { // TODO: this logic should be moved to SyntaxTrait::position, when implemented let w = n.width(); n.leading_start_offset() + n.leading_width() + w } fn get_short_name_from_qualified_name<'a>(name: &'a str, alias: &'a str) -> &'a str { if !alias.is_empty() { return alias; } match name.rfind('\\') { Some(i) => &name[i + 1..], None => name, } } // Turns a syntax node into a list of nodes; if it is a separated syntax // list then the separators are filtered from the resulting list. fn syntax_to_list<'a>( include_separators: bool, node: S<'a>, ) -> impl DoubleEndedIterator<Item = S<'a>> { use std::iter::empty; use std::iter::once; use itertools::Either::Left; use itertools::Either::Right; let on_list_item = move |x: &'a ListItemChildren<'_, PositionedToken<'_>, PositionedValue<'_>>| { if include_separators { vec![&x.item, &x.separator].into_iter() } else { vec![&x.item].into_iter() } }; match &node.children { Missing => Left(Left(empty())), SyntaxList(s) => Left(Right(s.iter().flat_map(move |x| match &x.children { ListItem(x) => Left(on_list_item(x)), _ => Right(once(x)), }))), ListItem(x) => Right(Left(on_list_item(x))), _ => Right(Right(once(node))), } } fn syntax_to_list_no_separators<'a>(node: S<'a>) -> impl DoubleEndedIterator<Item = S<'a>> { syntax_to_list(false, node) } fn syntax_to_list_with_separators<'a>(node: S<'a>) -> impl DoubleEndedIterator<Item = S<'a>> { syntax_to_list(true, node) } fn assert_last_in_list<'a, F>(assert_fun: F, node: S<'a>) -> Option<S<'a>> where F: Fn(S<'a>) -> bool, { let mut iter = syntax_to_list_no_separators(node); iter.next_back(); iter.find(|x| assert_fun(x)) } fn attr_spec_to_node_list<'a>(node: S<'a>) -> impl DoubleEndedIterator<Item = S<'a>> { use itertools::Either::Left; use itertools::Either::Right; let f = |attrs| Left(syntax_to_list_no_separators(attrs)); match &node.children { AttributeSpecification(x) => f(&x.attributes), OldAttributeSpecification(x) => f(&x.attributes), FileAttributeSpecification(x) => f(&x.attributes), _ => Right(std::iter::empty()), } } fn attr_constructor_call<'a>( node: S<'a>, ) -> &'a SyntaxVariant<'_, PositionedToken<'a>, PositionedValue<'a>> { match &node.children { ConstructorCall(_) => &node.children, Attribute(x) => &x.attribute_name.children, _ => &Missing, } } fn is_decorated_expression<F>(node: S<'_>, f: F) -> bool where F: Fn(S<'_>) -> bool, { match &node.children { DecoratedExpression(x) => f(&x.decorator), _ => false, } } fn test_decorated_expression_child<F>(node: S<'_>, f: F) -> bool where F: Fn(S<'_>) -> bool, { match &node.children { DecoratedExpression(x) => f(&x.expression), _ => false, } } fn is_variadic_expression(node: S<'_>) -> bool { is_decorated_expression(node, |x| x.is_ellipsis()) || test_decorated_expression_child(node, is_variadic_expression) } fn is_double_variadic(node: S<'_>) -> bool { is_decorated_expression(node, |x| x.is_ellipsis()) && test_decorated_expression_child(node, is_variadic_expression) } fn is_variadic_parameter_variable(node: S<'_>) -> bool { // TODO: This shouldn't be a decorated *expression* because we are not // expecting an expression at all. We're expecting a declaration. is_variadic_expression(node) } fn is_variadic_parameter_declaration(node: S<'_>) -> bool { match &node.children { VariadicParameter(_) => true, ParameterDeclaration(x) => is_variadic_parameter_variable(&x.name), _ => false, } } fn misplaced_variadic_param<'a>(param: S<'a>) -> Option<S<'a>> { assert_last_in_list(is_variadic_parameter_declaration, param) } fn misplaced_variadic_arg<'a>(args: S<'a>) -> Option<S<'a>> { assert_last_in_list(is_variadic_expression, args) } // If a list ends with a variadic parameter followed by a comma, return it fn ends_with_variadic_comma<'a>(params: S<'a>) -> Option<S<'a>> { let mut iter = syntax_to_list_with_separators(params).rev(); let y = iter.next(); let x = iter.next(); match (x, y) { (Some(x), Some(y)) if is_variadic_parameter_declaration(x) && y.is_comma() => Some(y), _ => None, } } // Extract variadic parameter from a parameter list fn variadic_param<'a>(params: S<'a>) -> Option<S<'a>> { syntax_to_list_with_separators(params).find(|&x| is_variadic_parameter_declaration(x)) } fn is_parameter_with_default_value(param: S<'_>) -> bool { match &param.children { ParameterDeclaration(x) => !x.default_value.is_missing(), _ => false, } } fn list_first_duplicate_token<'a>(node: S<'a>) -> Option<S<'a>> { if let SyntaxList(lst) = &node.children { let mut seen = BTreeMap::new(); for node in lst.iter().rev() { if let Token(t) = &node.children { if let Some(dup) = seen.insert(t.kind(), node) { return Some(dup); } } } } None } fn token_kind(node: S<'_>) -> Option<TokenKind> { if let Token(t) = &node.children { return Some(t.kind()); } None } // Helper function for common code pattern fn is_token_kind(node: S<'_>, kind: TokenKind) -> bool { token_kind(node) == Some(kind) } fn get_modifier_final<'a>(modifiers: S<'a>) -> Option<S<'a>> { syntax_to_list_no_separators(modifiers).find(|x| x.is_final()) } fn is_visibility(x: S<'_>) -> bool { x.is_public() || x.is_private() || x.is_protected() || x.is_internal() } fn contains_async_not_last(mods: S<'_>) -> bool { let mut mod_list = syntax_to_list_no_separators(mods); match mod_list.next_back() { Some(x) if x.is_async() => false, _ => mod_list.any(|x| x.is_async()), } } fn promoted_params<'a>( params: impl DoubleEndedIterator<Item = S<'a>>, ) -> impl DoubleEndedIterator<Item = S<'a>> { params.filter(|node| match &node.children { ParameterDeclaration(x) => !x.visibility.is_missing(), _ => false, }) } // Given a function declaration header, confirm that it is NOT a constructor // and that the header containing it has visibility modifiers in parameters fn class_non_constructor_has_visibility_param(node: S<'_>) -> bool { match &node.children { FunctionDeclarationHeader(node) => { let params = syntax_to_list_no_separators(&node.parameter_list); (!&node.name.is_construct()) && promoted_params(params).next().is_some() } _ => false, } } fn class_constructor_has_tparams(node: S<'_>) -> bool { match &node.children { FunctionDeclarationHeader(node) => { node.name.is_construct() && !node.type_parameter_list.is_missing() } _ => false, } } // Ban parameter promotion in abstract constructors. fn abstract_class_constructor_has_visibility_param(node: S<'_>) -> bool { match &node.children { FunctionDeclarationHeader(node) => { let label = &node.name; let params = syntax_to_list_no_separators(&node.parameter_list); label.is_construct() && list_contains_predicate(|x| x.is_abstract(), &node.modifiers) && promoted_params(params).next().is_some() } _ => false, } } // whether a function decl has body fn function_declaration_is_external(node: S<'_>) -> bool { match &node.children { FunctionDeclaration(syntax) => syntax.body.is_external(), _ => false, } } // whether a methodish decl has body fn methodish_has_body(node: S<'_>) -> bool { match &node.children { MethodishDeclaration(syntax) => !syntax.function_body.is_missing(), _ => false, } } // Test whether node is a method that is both abstract and private fn methodish_abstract_conflict_with_private(node: S<'_>) -> bool { let is_abstract = has_modifier_abstract(node); let has_private = has_modifier_private(node); is_abstract && has_private } fn make_error_from_nodes( child: Option<SyntaxError>, start_node: S<'_>, end_node: S<'_>, error_type: ErrorType, error: errors::Error, ) -> SyntaxError { let s = start_offset(start_node); let e = end_offset(end_node); SyntaxError::make_with_child_and_type(child, s, e, error_type, error, vec![]) } fn make_error_from_node(node: S<'_>, error: errors::Error) -> SyntaxError { make_error_from_nodes(None, node, node, ErrorType::ParseError, error) } fn make_error_from_node_with_quickfix( node: S<'_>, error: errors::Error, quickfix_title: &str, quickfix_start: usize, quickfix_end: usize, new_text: &str, ) -> SyntaxError { let s = start_offset(node); let e = end_offset(node); let quickfixes = vec![SyntaxQuickfix { title: quickfix_title.into(), edits: vec![(quickfix_start, quickfix_end, new_text.into())], }]; SyntaxError::make_with_child_and_type(None, s, e, ErrorType::ParseError, error, quickfixes) } fn make_error_from_node_with_type( node: S<'_>, error: errors::Error, error_type: ErrorType, ) -> SyntaxError { make_error_from_nodes(None, node, node, error_type, error) } fn is_invalid_xhp_attr_enum_item_literal(literal_expression: S<'_>) -> bool { if let Token(t) = &literal_expression.children { match t.kind() { TokenKind::DecimalLiteral | TokenKind::SingleQuotedStringLiteral | TokenKind::DoubleQuotedStringLiteral => false, _ => true, } } else { true } } fn is_invalid_xhp_attr_enum_item(node: S<'_>) -> bool { if let LiteralExpression(x) = &node.children { is_invalid_xhp_attr_enum_item_literal(&x.expression) } else { true } } fn cant_be_reserved_type_name(name: &str) -> bool { // Keep in sync with test/reserved match name.to_ascii_lowercase().as_ref() { // reserved_global_name "callable" | "parent" | "self" => true, // reserved_hh_name "arraykey" | "bool" | "dynamic" | "float" | "int" | "mixed" | "nonnull" | "noreturn" | "nothing" | "null" | "num" | "resource" | "string" | "this" | "void" | "_" => true, // misc "darray" | "false" | "static" | "true" | "varray" => true, _ => false, } } // Given a declaration node, returns the modifier node matching the given // predicate from its list of modifiers, or None if there isn't one. fn extract_keyword<'a, F>(modifier: F, declaration_node: S<'a>) -> Option<S<'a>> where F: Fn(S<'a>) -> bool, { get_modifiers_of_declaration(declaration_node).and_then(|modifiers_list| { syntax_to_list_no_separators(modifiers_list).find(|x: &S<'a>| modifier(x)) }) } // Wrapper function that uses above extract_keyword function to test if node // contains is_abstract keyword fn is_abstract_declaration(declaration_node: S<'_>) -> bool { extract_keyword(|x| x.is_abstract(), declaration_node).is_some() } fn is_abstract_and_async_method(md_node: S<'_>) -> bool { is_abstract_declaration(md_node) && extract_keyword(|x| x.is_async(), md_node).is_some() } fn parameter_callconv<'a>(param: S<'a>) -> Option<S<'a>> { (match &param.children { ParameterDeclaration(x) => Some(&x.call_convention), ClosureParameterTypeSpecifier(x) => Some(&x.call_convention), VariadicParameter(x) => Some(&x.call_convention), _ => None, }) .filter(|node| !node.is_missing()) } fn is_parameter_with_callconv(param: S<'_>) -> bool { parameter_callconv(param).is_some() } fn make_name_already_used_error( node: S<'_>, name: &str, short_name: &str, original_location: &Location, report_error: &dyn Fn(&str, &str) -> Error, ) -> SyntaxError { let name = strip_ns(name); let original_location_error = SyntaxError::make( original_location.start_offset, original_location.end_offset, errors::original_definition, vec![], ); let s = start_offset(node); let e = end_offset(node); SyntaxError::make_with_child_and_type( Some(original_location_error), s, e, ErrorType::ParseError, report_error(name, short_name), vec![], ) } fn extract_callconv_node<'a>(node: S<'a>) -> Option<S<'a>> { match &node.children { ParameterDeclaration(x) => Some(&x.call_convention), ClosureParameterTypeSpecifier(x) => Some(&x.call_convention), VariadicParameter(x) => Some(&x.call_convention), _ => None, } } // Given a node, checks if it is a abstract ConstDeclaration fn is_abstract_const(declaration: S<'_>) -> bool { match &declaration.children { ConstDeclaration(_) => has_modifier_abstract(declaration), _ => false, } } // Given a node, checks if it is a concrete ConstDeclaration *) fn is_concrete_const(declaration: S<'_>) -> bool { match &declaration.children { ConstDeclaration(_) => !has_modifier_abstract(declaration), _ => false, } } // If a variadic parameter has a default value, return it fn variadic_param_with_default_value<'a>(params: S<'a>) -> Option<S<'a>> { variadic_param(params).filter(|x| is_parameter_with_default_value(x)) } // If a variadic parameter is marked inout, return it fn variadic_param_with_callconv<'a>(params: S<'a>) -> Option<S<'a>> { variadic_param(params).filter(|x| is_parameter_with_callconv(x)) } fn variadic_param_with_readonly<'a>(params: S<'a>) -> Option<S<'a>> { variadic_param(params).filter(|x| match &x.children { ParameterDeclaration(x) => x.readonly.is_readonly(), // A VariadicParameter cannot parse readonly, only decorated ... expressions can // so it would parse error anyways _ => false, }) } // If an inout parameter has a default, return the default fn param_with_callconv_has_default<'a>(node: S<'a>) -> Option<S<'a>> { match &node.children { ParameterDeclaration(x) if is_parameter_with_callconv(node) && is_parameter_with_default_value(node) => { Some(&x.default_value) } _ => None, } } fn does_unop_create_write(token_kind: Option<TokenKind>) -> bool { token_kind.map_or(false, |x| { matches!(x, TokenKind::PlusPlus | TokenKind::MinusMinus) }) } fn does_decorator_create_write(token_kind: Option<TokenKind>) -> bool { matches!(token_kind, Some(TokenKind::Inout)) } fn node_lval_type<'a, 'b>(node: S<'a>, parents: &'b [S<'a>]) -> LvalType { let is_in_final_lval_position = |mut node, parents: &[S<'a>]| { for &parent in parents.iter().rev() { match &parent.children { SyntaxList(_) | ListItem(_) => { node = parent; continue; } ExpressionStatement(_) => return true, ForStatement(x) if std::ptr::eq(node, &x.initializer) || std::ptr::eq(node, &x.end_of_loop) => { return true; } UsingStatementFunctionScoped(x) if std::ptr::eq(node, &x.expression) => { return true; } UsingStatementBlockScoped(x) if std::ptr::eq(node, &x.expressions) => { return true; } _ => return false, } } false }; let get_arg_call_node_with_parents = |mut node, parents: &'b [S<'a>]| { for i in (0..parents.len()).rev() { let parent = parents[i]; match &parent.children { SyntaxList(_) | ListItem(_) => { node = parent; continue; } FunctionCallExpression(x) if std::ptr::eq(node, &x.argument_list) => { if i == 0 { // probably unreachable, but just in case to avoid crashing on 0-1 return Some((parent, &parents[0..0])); } let grandparent = parents.get(i - 1).unwrap(); return match &grandparent.children { PrefixUnaryExpression(x) if token_kind(&x.operator) == Some(TokenKind::At) => { Some((grandparent, &parents[..i - 1])) } _ => Some((parent, &parents[..i])), }; } _ => return None, } } None }; let lval_ness_of_function_arg_for_inout = |node, parents| match get_arg_call_node_with_parents(node, parents) { None => LvalTypeNone, Some((call_node, parents)) => { if is_in_final_lval_position(call_node, parents) { return LvalTypeFinal; } match parents.last() { None => LvalTypeNonFinalInout, Some(parent) => match &parent.children { BinaryExpression(x) if std::ptr::eq(call_node, &x.right_operand) && does_binop_create_write_on_left(token_kind(&x.operator)) => { if is_in_final_lval_position(parent, &parents[..parents.len() - 1]) { LvalTypeFinal } else { LvalTypeNonFinalInout } } _ => LvalTypeNonFinalInout, }, } } }; let unary_expression_operator = |x: S<'a>| match &x.children { PrefixUnaryExpression(x) => &x.operator, PostfixUnaryExpression(x) => &x.operator, _ => panic!("expected expression operator"), }; let unary_expression_operand = |x: S<'a>| match &x.children { PrefixUnaryExpression(x) => &x.operand, PostfixUnaryExpression(x) => &x.operand, _ => panic!("expected expression operator"), }; if let Some(next_node) = parents.last() { let parents = &parents[..parents.len() - 1]; match &next_node.children { DecoratedExpression(x) if std::ptr::eq(node, &x.expression) && does_decorator_create_write(token_kind(&x.decorator)) => { lval_ness_of_function_arg_for_inout(next_node, parents) } PrefixUnaryExpression(_) | PostfixUnaryExpression(_) if std::ptr::eq(node, unary_expression_operand(next_node)) && does_unop_create_write(token_kind(unary_expression_operator(next_node))) => { if is_in_final_lval_position(next_node, parents) { LvalTypeFinal } else { LvalTypeNonFinal } } BinaryExpression(x) if std::ptr::eq(node, &x.left_operand) && does_binop_create_write_on_left(token_kind(&x.operator)) => { if is_in_final_lval_position(next_node, parents) { LvalTypeFinal } else { LvalTypeNonFinal } } ForeachStatement(x) if std::ptr::eq(node, &x.key) || std::ptr::eq(node, &x.value) => { LvalTypeFinal } _ => LvalTypeNone, } } else { LvalTypeNone } } fn is_foreach_in_for(for_initializer: S<'_>) -> bool { if let Some(Syntax { children: ListItem(x), .. }) = for_initializer.syntax_node_to_list().next() { x.item.is_as_expression() } else { false } } fn is_good_scope_resolution_qualifier(node: S<'_>, static_allowed: bool) -> bool { match &node.children { QualifiedName(_) => true, Token(token) => match token.kind() { TokenKind::Static => static_allowed, TokenKind::XHPClassName | TokenKind::Name | TokenKind::SelfToken | TokenKind::Parent => true, _ => false, }, _ => false, } } fn does_binop_create_write_on_left(token_kind: Option<TokenKind>) -> bool { token_kind.map_or(false, |x| match x { TokenKind::Equal | TokenKind::BarEqual | TokenKind::PlusEqual | TokenKind::StarEqual | TokenKind::StarStarEqual | TokenKind::SlashEqual | TokenKind::DotEqual | TokenKind::MinusEqual | TokenKind::PercentEqual | TokenKind::CaratEqual | TokenKind::AmpersandEqual | TokenKind::LessThanLessThanEqual | TokenKind::GreaterThanGreaterThanEqual | TokenKind::QuestionQuestionEqual => true, _ => false, }) } fn get_positions_binop_allows_await(t: S<'_>) -> BinopAllowsAwaitInPositions { use TokenKind::*; match token_kind(t) { None => BinopAllowAwaitNone, Some(t) => match t { BarBar | AmpersandAmpersand | QuestionColon | QuestionQuestion | BarGreaterThan => { BinopAllowAwaitLeft } Equal | BarEqual | PlusEqual | StarEqual | StarStarEqual | SlashEqual | DotEqual | MinusEqual | PercentEqual | CaratEqual | AmpersandEqual | LessThanLessThanEqual | GreaterThanGreaterThanEqual => BinopAllowAwaitRight, Plus | Minus | Star | Slash | StarStar | EqualEqualEqual | LessThan | GreaterThan | Percent | Dot | EqualEqual | ExclamationEqual | ExclamationEqualEqual | LessThanEqual | LessThanEqualGreaterThan | GreaterThanEqual | Ampersand | Bar | LessThanLessThan | GreaterThanGreaterThan | Carat => BinopAllowAwaitBoth, _ => BinopAllowAwaitNone, }, } } fn unop_allows_await(t: S<'_>) -> bool { use TokenKind::*; token_kind(t).map_or(false, |t| match t { Exclamation | Tilde | Plus | Minus | At | Clone | Print | Readonly | DotDotDot => true, _ => false, }) } fn check_prefix_unary_dollar(node: S<'_>) -> bool { match &node.children { PrefixUnaryExpression(x) if token_kind(&x.operator) == Some(TokenKind::Dollar) => { check_prefix_unary_dollar(&x.operand) } BracedExpression(_) | SubscriptExpression(_) | VariableExpression(_) => false, // these ones are valid LiteralExpression(_) | PipeVariableExpression(_) => false, // these ones get caught later _ => true, } } fn is_method_declaration(node: S<'_>) -> bool { if let MethodishDeclaration(_) = &node.children { true } else { false } } fn is_invalid_group_use_clause(kind: S<'_>, clause: S<'_>) -> bool { if let NamespaceUseClause(x) = &clause.children { let clause_kind = &x.clause_kind; if kind.is_missing() { match &clause_kind.children { Missing => false, Token(token) if token.kind() == TokenKind::Function || token.kind() == TokenKind::Const => { false } _ => true, } } else { !clause_kind.is_missing() } } else { false } } fn is_invalid_group_use_prefix(prefix: S<'_>) -> bool { !prefix.is_namespace_prefix() } /// Do these two nodes represent `parent` and `class` respectively fn is_parent_class_access<'a>(lhs: S<'a>, rhs: S<'a>) -> bool { match (&lhs.children, &rhs.children) { (Token(tl), Token(tr)) => tl.kind() == TokenKind::Parent && tr.kind() == TokenKind::Class, _ => false, } } // TODO: why do we need :'a everywhere? impl<'a, State: 'a + Clone> ParserErrors<'a, State> { fn new(env: Env<'a, State>) -> Self { Self { env, errors: vec![], parents: vec![], names: UsedNames::empty(), trait_require_clauses: empty_trait_require_clauses(), namespace_name: GLOBAL_NAMESPACE_NAME.to_string(), namespace_type: Unspecified, is_in_concurrent_block: false, nested_namespaces: vec![], uses_readonly: false, in_module: false, } } fn text(&self, node: S<'a>) -> &'a str { node.extract_text(self.env.syntax_tree.text()) .expect("<text_extraction_failure>") } fn enable_unstable_feature(&mut self, node: S<'a>, arg: S<'a>) { let error_invalid_argument = |self_: &mut Self, message| { self_.errors.push(make_error_from_node( arg, errors::invalid_use_of_enable_unstable_feature(message), )) }; match &arg.children { LiteralExpression(x) => { let text = self.text(&x.expression); match UnstableFeatures::from_str(escaper::unquote_str(text)) { Ok(feature) => { if !self.env.parser_options.po_allow_unstable_features && !self.env.is_hhi_mode() && feature.get_feature_status() == FeatureStatus::Unstable { self.errors.push(make_error_from_node( node, errors::cannot_enable_unstable_feature( format!( "{} is unstable and unstable features are disabled", text ) .as_str(), ), )) } else { self.env.context.active_unstable_features.insert(feature); } } Err(_) => error_invalid_argument( self, format!( "there is no feature named {}.\nAvailable features are:\n\t{}", text, UnstableFeatures::iter().join("\n\t") ) .as_str(), ), } } _ => error_invalid_argument(self, "this is not a literal string expression"), }; } fn mark_uses_readonly(&mut self) { self.uses_readonly = true; } fn check_can_use_feature(&mut self, node: S<'a>, feature: &UnstableFeatures) { let parser_options = &self.env.parser_options; let enabled = match feature { UnstableFeatures::UnionIntersectionTypeHints => { parser_options.tco_union_intersection_type_hints } UnstableFeatures::ClassLevelWhere => parser_options.po_enable_class_level_where_clauses, UnstableFeatures::Ifc => { let file_path = format!("/{}", self.env.text.source_text().file_path().path_str()); parser_options .tco_ifc_enabled .iter() .any(|prefix| file_path.find(prefix) == Some(0)) } _ => false, } || self.env.context.active_unstable_features.contains(feature) // Preview features with an ongoing release should be allowed by the // runtime, but not the typechecker || (feature.get_feature_status() == FeatureStatus::OngoingRelease && self.env.codegen); if !enabled { self.errors.push(make_error_from_node( node, errors::cannot_use_feature(feature.into()), )) } } fn attr_name(&self, node: S<'a>) -> Option<&'a str> { if let ConstructorCall(x) = attr_constructor_call(node) { Some(self.text(&x.type_)) } else { None } } fn attr_args(&self, node: S<'a>) -> Option<impl DoubleEndedIterator<Item = S<'a>>> { if let ConstructorCall(x) = attr_constructor_call(node) { Some(syntax_to_list_no_separators(&x.argument_list)) } else { None } } fn attribute_specification_contains(&self, node: S<'a>, name: &str) -> bool { match &node.children { AttributeSpecification(_) | OldAttributeSpecification(_) | FileAttributeSpecification(_) => { attr_spec_to_node_list(node).any(|node| self.attr_name(node) == Some(name)) } _ => false, } } fn methodish_contains_attribute(&self, node: S<'a>, attribute: &str) -> bool { match &node.children { MethodishDeclaration(x) => { self.attribute_specification_contains(&x.attribute, attribute) } _ => false, } } // whether a methodish decl is native fn methodish_is_native(&self, node: S<'_>) -> bool { self.methodish_contains_attribute(node, sn::user_attributes::NATIVE) } // By checking the third parent of a methodish node, tests whether the methodish // node is inside an interface. fn methodish_inside_interface(&self) -> bool { self.env .context .active_classish .iter() .any(|parent_classish| match &parent_classish.children { ClassishDeclaration(cd) => token_kind(&cd.keyword) == Some(TokenKind::Interface), _ => false, }) } // Test whether node is an external function and not native. fn function_declaration_external_not_native(&self, node: S<'_>) -> bool { let in_hhi = self.env.is_hhi_mode(); let is_external = function_declaration_is_external(node); let is_native = self.function_declaration_is_native(node); !in_hhi && is_external && !is_native } // Test whether node is a non-abstract method without a body and not native. // Here node is the methodish node // And methods inside interfaces are inherently considered abstract *) fn methodish_non_abstract_without_body_not_native(&self, node: S<'a>) -> bool { let non_abstract = !(has_modifier_abstract(node) || self.methodish_inside_interface()); let not_has_body = !methodish_has_body(node); let not_native = !self.methodish_is_native(node); let not_hhi = !self.env.is_hhi_mode(); not_hhi && non_abstract && not_has_body && not_native } fn active_classish_kind(&self) -> Option<TokenKind> { self.env .context .active_classish .and_then(|x| match &x.children { ClassishDeclaration(cd) => token_kind(&cd.keyword), _ => None, }) } fn has_this(&self) -> bool { if !self.is_in_active_class_scope() { return false; } match self.env.context.active_methodish { Some(x) if has_modifier_static(x) => false, _ => true, } } fn is_clone(&self, label: S<'_>) -> bool { self.text(label).eq_ignore_ascii_case(sn::members::__CLONE) } fn class_constructor_has_static(&self, node: S<'_>) -> bool { self.has_static(node, |x| x.is_construct()) } fn clone_cannot_be_static(&self, node: S<'_>) -> bool { self.has_static(node, |x| self.is_clone(x)) } fn has_static<F>(&self, node: S<'_>, f: F) -> bool where F: Fn(S<'_>) -> bool, { match &node.children { FunctionDeclarationHeader(node) => { let label = &node.name; f(label) && self .env .context .active_methodish .iter() .any(|&x| has_modifier_static(x)) } _ => false, } } // Ban parameter promotion in interfaces and traits. fn interface_or_trait_has_visibility_param(&self, node: S<'_>) -> bool { match &node.children { FunctionDeclarationHeader(node) => { let is_interface_or_trait = self.env .context .active_classish .map_or(false, |parent_classish| match &parent_classish.children { ClassishDeclaration(cd) => { let kind = token_kind(&cd.keyword); kind == Some(TokenKind::Interface) || kind == Some(TokenKind::Trait) } _ => false, }); let params = syntax_to_list_no_separators(&node.parameter_list); promoted_params(params).next().is_some() && is_interface_or_trait } _ => false, } } fn async_magic_method(&self, node: S<'_>) -> bool { match &node.children { FunctionDeclarationHeader(node) => { let name = self.text(&node.name).to_ascii_lowercase(); match name { _ if name.eq_ignore_ascii_case(sn::members::__DISPOSE_ASYNC) => false, _ if sn::members::AS_LOWERCASE_SET.contains(&name) => { list_contains_predicate(|x| x.is_async(), &node.modifiers) } _ => false, } } _ => false, } } fn reified_parameter_errors(&mut self, node: S<'a>) { if let FunctionDeclarationHeader(x) = &node.children { if let TypeParameters(x) = &x.type_parameter_list.children { self.get_type_params_and_emit_shadowing_errors(&x.parameters); } } } fn using_statement_function_scoped_is_legal(&self) -> bool { // using is allowed in the toplevel, and also in toplevel async blocks let len = self.parents.len(); if len < 3 { return false; } match (self.parents.get(len - 2), self.parents.get(len - 3)) { ( Some(Syntax { children: CompoundStatement(_), .. }), Some(x), ) => match &x.children { FunctionDeclaration(_) | MethodishDeclaration(_) | AnonymousFunction(_) | LambdaExpression(_) | AwaitableCreationExpression(_) => true, _ => false, }, _ => false, } } // Don't allow a promoted parameter in a constructor if the class // already has a property with the same name. Return the clashing name found. fn class_constructor_param_promotion_clash(&self, node: S<'a>) -> Option<&str> { use itertools::Either::Left; use itertools::Either::Right; let class_elts = |node: Option<S<'a>>| match node.map(|x| &x.children) { Some(ClassishDeclaration(cd)) => match &cd.body.children { ClassishBody(cb) => Left(syntax_to_list_no_separators(&cb.elements)), _ => Right(std::iter::empty()), }, _ => Right(std::iter::empty()), }; // A property declaration may include multiple property names: // public int $x, $y; let prop_names = |elt: S<'a>| match &elt.children { PropertyDeclaration(x) => Left( syntax_to_list_no_separators(&x.declarators).filter_map(|decl| { match &decl.children { PropertyDeclarator(x) => Some(self.text(&x.name)), _ => None, } }), ), _ => Right(std::iter::empty()), }; let param_name = |p: S<'a>| match &p.children { ParameterDeclaration(x) => Some(self.text(&x.name)), _ => None, }; match &node.children { FunctionDeclarationHeader(node) if node.name.is_construct() => { let class_var_names: Vec<_> = class_elts(self.env.context.active_classish) .flat_map(prop_names) .collect(); let params = syntax_to_list_no_separators(&node.parameter_list); let mut promoted_param_names = promoted_params(params).filter_map(param_name); promoted_param_names.find(|name| class_var_names.contains(name)) } _ => None, } } // check that a constructor is type annotated fn class_constructor_has_non_void_type(&self, node: S<'a>) -> bool { if !self.env.is_typechecker() { false } else { match &node.children { FunctionDeclarationHeader(node) => { let label = &node.name; let type_ano = &node.type_; let function_colon = &node.colon; let is_missing = type_ano.is_missing() && function_colon.is_missing(); let is_void = match &type_ano.children { SimpleTypeSpecifier(spec) => spec.specifier.is_void(), _ => false, }; label.is_construct() && !(is_missing || is_void) } _ => false, } } } fn unsupported_magic_method_errors(&mut self, node: S<'a>) { if let FunctionDeclarationHeader(x) = &node.children { let name = self.text(&x.name).to_ascii_lowercase(); let unsupported = sn::members::UNSUPPORTED_MAP.get(&name); if let Some(unsupported) = unsupported { self.errors.push(make_error_from_node( node, errors::unsupported_magic_method(unsupported), )); } } } fn xhp_errors(&mut self, node: S<'a>) { match &node.children { XHPEnumType(enum_type) => { if self.env.is_typechecker() && enum_type.values.is_missing() { self.errors .push(make_error_from_node(&enum_type.values, errors::error2055)) } else if self.env.is_typechecker() { syntax_to_list_no_separators(&enum_type.values) .filter(|&x| is_invalid_xhp_attr_enum_item(x)) .for_each(|item| { self.errors .push(make_error_from_node(item, errors::error2063)) }) } } XHPExpression(x) => { if let XHPOpen(xhp_open) = &x.open.children { if let XHPClose(xhp_close) = &x.close.children { let open_tag = self.text(&xhp_open.name); let close_tag = self.text(&xhp_close.name); if open_tag != close_tag { self.errors.push(make_error_from_node( node, errors::error2070(open_tag, close_tag), )) } } } } _ => {} } } fn invalid_modifier_errors<F>(&mut self, decl_name: &str, node: S<'a>, ok: F) where F: Fn(TokenKind) -> bool, { if let Some(modifiers) = get_modifiers_of_declaration(node) { let toplevel = declaration_is_toplevel(node); for modifier in syntax_to_list_no_separators(modifiers) { if let Some(kind) = token_kind(modifier) { if kind == TokenKind::Readonly { self.mark_uses_readonly() } if kind == TokenKind::Internal { if !self.in_module { self.errors.push(make_error_from_node( modifier, errors::internal_outside_of_module, )) } } else if kind == TokenKind::Public && toplevel { if !self.in_module { self.errors.push(make_error_from_node( modifier, errors::public_toplevel_outside_of_module, )) } } if !ok(kind) { self.errors.push(make_error_from_node( modifier, errors::invalid_modifier_for_declaration( decl_name, self.text(modifier), ), )); } } } if let Some(duplicate) = list_first_duplicate_token(modifiers) { self.errors.push(make_error_from_node( duplicate, errors::duplicate_modifiers_for_declaration(decl_name), )) } if let SyntaxList(modifiers) = &modifiers.children { let modifiers: Vec<S<'a>> = modifiers .iter() .filter(|x: &S<'a>| is_visibility(x)) .collect(); if modifiers.len() > 1 { self.errors.push(make_error_from_node( modifiers.last().unwrap(), errors::multiple_visibility_modifiers_for_declaration(decl_name), )); } } } } // helper since there are so many kinds of errors fn produce_error<F, E, X>( &mut self, check: F, node: X, error: E, // closure to avoid constant premature concatenation of error strings error_node: S<'a>, ) where F: Fn(&mut Self, X) -> bool, E: Fn() -> Error, { if check(self, node) { self.errors.push(make_error_from_node(error_node, error())) } } // helper since there are so many kinds of errors fn produce_error_from_check<F, E>(&mut self, check: F, node: S<'a>, error: E) where F: Fn(S<'a>) -> Option<S<'a>>, E: Fn() -> Error, { if let Some(error_node) = check(node) { self.errors.push(make_error_from_node(error_node, error())) } } // Given a function_declaration_header node, returns its function_name // as a string opt. fn extract_function_name(&self, header_node: S<'a>) -> Option<&'a str> { // The '_' arm of this match will never be reached, but the type checker // doesn't allow a direct extraction of function_name from // function_declaration_header. *) match &header_node.children { FunctionDeclarationHeader(fdh) => Some(self.text(&fdh.name)), _ => None, } } // Return, as a string opt, the name of the function or method given the context *) fn first_parent_function_name(&self) -> Option<&str> { // Note: matching on either is sound because functions and/or methods cannot be nested match self.env.context.active_methodish { Some(Syntax { children: FunctionDeclaration(x), .. }) => self.extract_function_name(&x.declaration_header), Some(Syntax { children: MethodishDeclaration(x), .. }) => self.extract_function_name(&x.function_decl_header), _ => None, } } // Given a particular TokenKind::(Trait/Interface), tests if a given // classish_declaration node is both of that kind and declared abstract. fn is_classish_kind_declared_abstract(&self, cd_node: S<'a>) -> bool { match &cd_node.children { ClassishDeclaration(x) if is_token_kind(&x.keyword, TokenKind::Trait) || is_token_kind(&x.keyword, TokenKind::Interface) => { list_contains_predicate(|x| x.is_abstract(), &x.modifiers) } _ => false, } } fn is_immediately_in_lambda(&self) -> bool { self.env .context .active_callable .map_or(false, |node| match &node.children { AnonymousFunction(_) | LambdaExpression(_) | AwaitableCreationExpression(_) => true, _ => false, }) } // Returns the whether the current context is in an active class scope fn is_in_active_class_scope(&self) -> bool { self.env.context.active_classish.is_some() } // Returns the first ClassishDeclaration node or // None if there isn't one or classish_kind does not match. *) fn first_parent_classish_node(&self, classish_kind: TokenKind) -> Option<S<'a>> { self.env .context .active_classish .and_then(|node| match &node.children { ClassishDeclaration(cd) if is_token_kind(&cd.keyword, classish_kind) => Some(node), _ => None, }) } // Return, as a string opt, the name of the closest enclosing classish entity in // the given context (not just Classes ) fn active_classish_name(&self) -> Option<&'a str> { self.env.context.active_classish.and_then(|node| { if let ClassishDeclaration(cd) = &node.children { cd.name.extract_text(self.env.syntax_tree.text()) } else { None } }) } // Return, as a string opt, the name of the Class in the given context fn first_parent_class_name(&self) -> Option<&'a str> { self.env .context .active_classish .and_then(|parent_classish| { if let ClassishDeclaration(cd) = &parent_classish.children { if token_kind(&cd.keyword) == Some(TokenKind::Class) { return self.active_classish_name(); } else { return None; // This arm is never reached } } None }) } // Tests if the immediate classish parent is an interface. fn is_inside_interface(&self) -> bool { self.first_parent_classish_node(TokenKind::Interface) .is_some() } fn is_interface_and_async_method(&self, md_node: S<'a>) -> bool { self.is_inside_interface() && extract_keyword(|x| x.is_async(), md_node).is_some() } fn get_params_for_enclosing_callable(&self) -> Option<S<'a>> { let from_header = |header: S<'a>| match &header.children { FunctionDeclarationHeader(fdh) => Some(&fdh.parameter_list), _ => None, }; self.env .context .active_callable .and_then(|callable| match &callable.children { FunctionDeclaration(x) => from_header(&x.declaration_header), MethodishDeclaration(x) => from_header(&x.function_decl_header), LambdaExpression(x) => match &x.signature.children { LambdaSignature(x) => Some(&x.parameters), _ => None, }, _ => None, }) } fn first_parent_function_attributes_contains(&self, name: &str) -> bool { let from_attr_spec = |attr_spec| { attr_spec_to_node_list(attr_spec).any(|node| self.attr_name(node) == Some(name)) }; match self.env.context.active_methodish { Some(Syntax { children: FunctionDeclaration(x), .. }) => from_attr_spec(&x.attribute_spec), Some(Syntax { children: MethodishDeclaration(x), .. }) => from_attr_spec(&x.attribute), _ => false, } } fn has_inout_params(&self) -> bool { self.get_params_for_enclosing_callable() .map_or(false, |function_parameter_list| { syntax_to_list_no_separators(function_parameter_list) .any(is_parameter_with_callconv) }) } fn is_inside_async_method(&self) -> bool { let from_header = |header: S<'a>| match &header.children { FunctionDeclarationHeader(fdh) => { syntax_to_list_no_separators(&fdh.modifiers).any(|x| x.is_async()) } _ => false, }; self.env .context .active_callable .map_or(false, |node| match &node.children { FunctionDeclaration(x) => from_header(&x.declaration_header), MethodishDeclaration(x) => from_header(&x.function_decl_header), AnonymousFunction(x) => !x.async_keyword.is_missing(), LambdaExpression(x) => !x.async_.is_missing(), AwaitableCreationExpression(_) => true, _ => false, }) } fn check_type_name_reference(&mut self, name_text: &str, location: Location) { if hh_autoimport::is_hh_autoimport(name_text) && !self.names.classes.mem(name_text) { let def = make_first_use_or_def(false, NameImplicitUse, location, "HH", name_text); self.names.classes.add(name_text, def) } } fn check_type_hint(&mut self, node: S<'a>) { for x in node.iter_children() { self.check_type_hint(x) } let check_type_name = |self_: &mut Self, s| { self_.check_type_name_reference(self_.text(s), make_location_of_node(node)) }; match &node.children { SimpleTypeSpecifier(x) => check_type_name(self, &x.specifier), GenericTypeSpecifier(x) => check_type_name(self, &x.class_type), _ => {} } } // Given a ConstDeclarator node, test whether it is abstract, but has an // initializer. fn constant_abstract_with_initializer(&self, init: S<'a>) -> bool { let is_abstract = match self.env.context.active_const { Some(p_const_declaration) if is_abstract_const(p_const_declaration) => true, _ => false, }; let has_initializer = !init.is_missing(); is_abstract && has_initializer } // Given a ConstDeclarator node, test whether it is concrete, but has no // initializer. fn constant_concrete_without_initializer(&self, init: S<'a>) -> bool { let is_concrete = match self.env.context.active_const { Some(p_const_declaration) if is_concrete_const(p_const_declaration) => true, _ => false, }; is_concrete && !self.env.is_hhi_mode() && init.is_missing() } fn methodish_memoize_lsb_on_non_static(&mut self, node: S<'a>) { if self.methodish_contains_attribute(node, sn::user_attributes::MEMOIZE_LSB) && !has_modifier_static(node) { self.errors.push(make_error_from_node( node, errors::memoize_lsb_on_non_static, )); } } fn methodish_readonly_check(&mut self, node: S<'a>) { if has_modifier_readonly(node) && has_modifier_static(node) { self.errors .push(make_error_from_node(node, errors::readonly_static_method)) } } fn function_declaration_contains_attribute(&self, node: S<'a>, attribute: &str) -> bool { match &node.children { FunctionDeclaration(x) => { self.attribute_specification_contains(&x.attribute_spec, attribute) } _ => false, } } fn clone_takes_no_arguments(&self, node: S<'_>) -> bool { match &node.children { FunctionDeclarationHeader(x) => { let mut params = syntax_to_list_no_separators(&x.parameter_list); self.is_clone(&x.name) && params.next().is_some() } _ => false, } } fn function_declaration_is_native(&self, node: S<'a>) -> bool { self.function_declaration_contains_attribute(node, sn::user_attributes::NATIVE) } fn methodish_contains_memoize(&self, node: S<'a>) -> bool { self.env.is_typechecker() && self.is_inside_interface() && self.methodish_contains_attribute(node, sn::user_attributes::MEMOIZE) } fn check_cross_package_args_are_string_literals(&mut self, node: S<'a>) { let mut crossed_packages_count = 0; if let Some(args) = self.attr_args(node) { for arg in args.peekable() { crossed_packages_count += 1; if let LiteralExpression(x) = &arg.children { if let Token(t) = &x.expression.children { if t.kind() == TokenKind::SingleQuotedStringLiteral || t.kind() == TokenKind::DoubleQuotedStringLiteral { continue; } } } self.errors.push(make_error_from_node( arg, errors::invalid_cross_package_argument( "this is not a literal string expression", ), )) } if crossed_packages_count == 1 { return; } } self.errors.push(make_error_from_node( node, errors::cross_package_wrong_arity(crossed_packages_count), )) } fn check_attr_enabled(&mut self, attrs: S<'a>) { for node in attr_spec_to_node_list(attrs) { match self.attr_name(node) { Some(n) => { if sn::user_attributes::is_ifc(n) { self.check_can_use_feature(node, &UnstableFeatures::Ifc) } if (sn::user_attributes::ignore_readonly_local_errors(n) || sn::user_attributes::ignore_coeffect_local_errors(n) || sn::user_attributes::is_native(n)) && !self.env.is_systemlib() // The typechecker has its own implementation of this that // allows its own testing and better error messaging. // see --tco_is_systemlib && !self.env.is_typechecker() { self.errors.push(make_error_from_node( node, errors::invalid_attribute_reserved, )); } if sn::user_attributes::is_cross_package(n) { self.check_can_use_feature(node, &UnstableFeatures::Package); self.check_cross_package_args_are_string_literals(node); } } None => {} } } } fn function_declaration_header_memoize_lsb(&mut self) { if let (Some(node), None) = ( self.env.context.active_methodish, self.env.context.active_classish, ) { // a function, not a method if self.function_declaration_contains_attribute(node, sn::user_attributes::MEMOIZE_LSB) { self.errors.push(make_error_from_node( node, errors::memoize_lsb_on_non_method, )) } } } fn is_in_enum_class(&self) -> bool { let active_classish = match self.env.context.active_classish { Some(x) => x, _ => return false, }; if let ClassishDeclaration(cd) = &active_classish.children { return self.attr_spec_contains_enum_class(&cd.attribute); } false } fn is_in_reified_class(&self) -> bool { let active_classish = match self.env.context.active_classish { Some(x) => x, _ => return false, }; if let ClassishDeclaration(x) = &active_classish.children { if let TypeParameters(x) = &x.type_parameters.children { return syntax_to_list_no_separators(&x.parameters).any(|p| match &p.children { TypeParameter(x) => !x.reified.is_missing(), _ => false, }); } }; false } fn methodish_errors(&mut self, node: S<'a>) { match &node.children { FunctionDeclarationHeader(x) => { let function_parameter_list = &x.parameter_list; let function_type = &x.type_; if x.readonly_return.is_readonly() { self.mark_uses_readonly() } self.produce_error( |self_, x| Self::class_constructor_has_non_void_type(self_, x), node, || errors::error2018, function_type, ); self.produce_error( |_, x| class_non_constructor_has_visibility_param(x), node, || errors::error2010, function_parameter_list, ); self.produce_error( |_, x| class_constructor_has_tparams(x), node, || errors::no_generics_on_constructors, &x.type_parameter_list, ); if let Some(clashing_name) = self.class_constructor_param_promotion_clash(node) { let class_name = self.active_classish_name().unwrap_or(""); let error_msg = errors::error2025(class_name, clashing_name); self.errors .push(make_error_from_node(function_parameter_list, error_msg)) } self.produce_error( |_, x| abstract_class_constructor_has_visibility_param(x), node, || errors::error2023, function_parameter_list, ); self.produce_error( |self_, x| Self::interface_or_trait_has_visibility_param(self_, x), node, || errors::error2024, function_parameter_list, ); self.function_declaration_header_memoize_lsb(); } FunctionDeclaration(fd) => { let function_attrs = &fd.attribute_spec; let body = &fd.body; self.check_attr_enabled(function_attrs); self.invalid_modifier_errors("Top-level functions", node, |kind| { kind == TokenKind::Async || kind == TokenKind::Internal || kind == TokenKind::Public }); self.produce_error( |self_, x| self_.function_declaration_external_not_native(x), node, || errors::missing_fn_def_body, body, ); } MethodishDeclaration(md) => { let header_node = &md.function_decl_header; let modifiers = modifiers_of_function_decl_header_exn(header_node); let class_name = self.active_classish_name().unwrap_or(""); let method_name = self .extract_function_name(&md.function_decl_header) .unwrap_or(""); let method_attrs = &md.attribute; self.check_attr_enabled(method_attrs); self.produce_error( |self_, x| self_.methodish_contains_memoize(x), node, || errors::interface_with_memoize, header_node, ); self.produce_error( |self_, x| self_.class_constructor_has_static(x), header_node, || errors::error2009(class_name, method_name), modifiers, ); self.unsupported_magic_method_errors(header_node); self.produce_error( |self_, x| self_.async_magic_method(x), header_node, || errors::async_magic_method(method_name), modifiers, ); self.produce_error( |self_, x| self_.clone_takes_no_arguments(x), header_node, || errors::clone_takes_no_arguments(class_name, method_name), modifiers, ); self.produce_error( |self_, x| self_.clone_cannot_be_static(x), header_node, || errors::clone_cannot_be_static(class_name, method_name), modifiers, ); self.invalid_modifier_errors("Methods", node, |kind| { kind == TokenKind::Abstract || kind == TokenKind::Final || kind == TokenKind::Static || kind == TokenKind::Private || kind == TokenKind::Protected || kind == TokenKind::Internal || kind == TokenKind::Public || kind == TokenKind::Async || kind == TokenKind::Readonly }); if self.is_inside_interface() { self.invalid_modifier_errors("Interface methods", node, |kind| { kind != TokenKind::Final && kind != TokenKind::Abstract }); }; let fun_semicolon = &md.semicolon; self.produce_error( |self_, x| self_.methodish_non_abstract_without_body_not_native(x), node, || errors::error2015, fun_semicolon, ); self.produce_error( |_, x| methodish_abstract_conflict_with_private(x), node, || errors::error2016(class_name, method_name), modifiers, ); if let Some(modifier) = get_modifier_final(modifiers) { self.produce_error( |_, x| has_modifier_abstract(x), node, || errors::error2019(class_name, method_name), modifier, ); } self.methodish_readonly_check(node); self.methodish_memoize_lsb_on_non_static(node); let async_annotation = extract_keyword(|x| x.is_async(), node).unwrap_or(node); if self.is_interface_and_async_method(node) { let quickfix_start = start_offset(async_annotation); let quickfix_end = end_offset(async_annotation); self.errors.push(make_error_from_node_with_quickfix( async_annotation, errors::error2046("a method in an interface"), "Remove `async`", quickfix_start, quickfix_end, "", )) } self.produce_error( |_, x| is_abstract_and_async_method(x), node, || errors::error2046("an `abstract` method"), async_annotation, ); if self.env.is_typechecker() { self.produce_error( |_, x| contains_async_not_last(x), modifiers, || errors::async_not_last, modifiers, ); } } _ => {} } } fn is_in_construct_method(&self) -> bool { if self.is_immediately_in_lambda() { false } else { self.first_parent_function_name() .map_or(false, |s| s.eq_ignore_ascii_case(sn::members::__CONSTRUCT)) } } fn params_errors(&mut self, params: S<'a>) { self.produce_error_from_check(ends_with_variadic_comma, params, || errors::error2022); self.produce_error_from_check(misplaced_variadic_param, params, || errors::error2021); self.produce_error_from_check(variadic_param_with_default_value, params, || { errors::error2065 }); self.produce_error_from_check(variadic_param_with_callconv, params, || errors::error2073); self.produce_error_from_check(variadic_param_with_readonly, params, || { errors::variadic_readonly_param }); } fn decoration_errors(&mut self, node: S<'a>) { self.produce_error( |_, x| is_double_variadic(x), node, || errors::double_variadic, node, ); } fn check_parameter_this(&mut self, node: S<'a>) { let mut this_param = None; if let ParameterDeclaration(p) = &node.children { match &p.name.children { Token(_) => { // normal parameter $foo if self.text(&p.name) == sn::special_idents::THIS { this_param = Some(&p.name); } } DecoratedExpression(de) => { // variadic parameter ...$foo if let Token(_) = de.expression.children { if self.text(&de.expression) == sn::special_idents::THIS { this_param = Some(&de.expression); } } } _ => {} } } if let Some(this_param) = this_param { self.errors .push(make_error_from_node(this_param, errors::reassign_this)); } } fn check_parameter_ifc(&mut self, node: S<'a>) { if let ParameterDeclaration(x) = &node.children { let attr = &x.attribute; if self.attribute_specification_contains(attr, sn::user_attributes::EXTERNAL) { self.check_can_use_feature(attr, &UnstableFeatures::Ifc); } } } fn check_parameter_readonly(&mut self, node: S<'a>) { if let ParameterDeclaration(x) = &node.children { if x.readonly.is_readonly() { self.mark_uses_readonly() } } } fn lval_errors(&mut self, syntax_node: S<'a>) { if self.env.parser_options.po_disable_lval_as_an_expression { if let LvalTypeNonFinal = node_lval_type(syntax_node, &self.parents) { self.errors.push(make_error_from_node( syntax_node, errors::lval_as_expression, )) } } } fn parameter_errors(&mut self, node: S<'a>) { let param_errors = |self_: &mut Self, params| { for x in syntax_to_list_no_separators(params) { self_.check_parameter_this(x); self_.check_parameter_ifc(x); self_.check_parameter_readonly(x); } self_.params_errors(params) }; match &node.children { ParameterDeclaration(p) => { let callconv_text = self.text(extract_callconv_node(node).unwrap_or(node)); self.produce_error_from_check(param_with_callconv_has_default, node, || { errors::error2074(callconv_text) }); self.check_type_hint(&p.type_); self.check_parameter_ifc(node); self.check_parameter_readonly(node); if let Some(inout_modifier) = parameter_callconv(node) { if self.is_inside_async_method() { self.errors.push(make_error_from_node_with_type( inout_modifier, errors::inout_param_in_async, ErrorType::RuntimeError, )) } if self.is_in_construct_method() { self.errors.push(make_error_from_node( inout_modifier, errors::inout_param_in_construct, )) } let in_memoize = self .first_parent_function_attributes_contains(sn::user_attributes::MEMOIZE); let in_memoize_lsb = self.first_parent_function_attributes_contains( sn::user_attributes::MEMOIZE_LSB, ); if (in_memoize || in_memoize_lsb) && !self.is_immediately_in_lambda() { self.errors.push(make_error_from_node_with_type( inout_modifier, errors::memoize_with_inout, ErrorType::RuntimeError, )) } } } FunctionDeclarationHeader(x) => param_errors(self, &x.parameter_list), AnonymousFunction(x) => param_errors(self, &x.parameters), ClosureTypeSpecifier(x) => param_errors(self, &x.parameter_list), LambdaExpression(x) => { if let LambdaSignature(x) = &x.signature.children { param_errors(self, &x.parameters) } } DecoratedExpression(_) => self.decoration_errors(node), _ => {} } } // Only check the functions; invalid attributes on methods (like <<__EntryPoint>>) are caught elsewhere fn multiple_entrypoint_attribute_errors(&mut self, node: S<'a>) { match &node.children { FunctionDeclaration(f) if self.attribute_specification_contains( &f.attribute_spec, sn::user_attributes::ENTRY_POINT, ) => { // Get the location of the <<...>> annotation let location = match &f.attribute_spec.children { AttributeSpecification(x) => make_location_of_node(&x.attributes), OldAttributeSpecification(x) => make_location_of_node(&x.attributes), _ => panic!("Expected attribute specification node"), }; let def = make_first_use_or_def( false, NameDef, location, &self.namespace_name, sn::user_attributes::ENTRY_POINT, ); match self.names.attributes.get(sn::user_attributes::ENTRY_POINT) { Some(prev_def) => { let (line_num, _) = self .env .text .offset_to_position(prev_def.location.start_offset as isize); let path = self.env.text.source_text().file_path().path_str(); let loc = String::from(path) + ":" + &line_num.to_string(); let err = errors::multiple_entrypoints(&loc); let err_type = ErrorType::ParseError; self.errors .push(make_error_from_node_with_type(node, err, err_type)) } _ => {} }; self.names .attributes .add(sn::user_attributes::ENTRY_POINT, def) } _ => {} } } fn redeclaration_errors(&mut self, node: S<'a>) { match &node.children { FunctionDeclarationHeader(f) if !f.name.is_missing() => { let mut it = self.parents.iter().rev(); let p1 = it.next(); let _ = it.next(); let p3 = it.next(); let p4 = it.next(); match (p1, p3, p4) { ( Some(Syntax { children: FunctionDeclaration(_), .. }), Some(Syntax { children: NamespaceBody(_), .. }), _, ) | ( Some(Syntax { children: FunctionDeclaration(_), .. }), _, None, ) | ( Some(Syntax { children: MethodishDeclaration(_), .. }), _, _, ) | ( Some(Syntax { children: MethodishTraitResolution(_), .. }), _, _, ) => { let function_name: &str = self.text(&f.name); let location = make_location_of_node(&f.name); let is_method = match p1 { Some(Syntax { children: MethodishDeclaration(_), .. }) => true, _ => false, }; let def = make_first_use_or_def( is_method, NameDef, location, &self.namespace_name, function_name, ); match self.names.functions.get(function_name) { Some(prev_def) if prev_def.global == def.global && prev_def.kind == NameDef => { let (line_num, _) = self .env .text .offset_to_position(prev_def.location.start_offset as isize); let path = self.env.text.source_text().file_path().path_str(); let loc = String::from(path) + ":" + &line_num.to_string(); let (err, err_type) = match self.first_parent_class_name() { None => ( errors::redeclaration_of_function(function_name, &loc), ErrorType::RuntimeError, ), Some(class_name) => { let full_name = String::from(class_name) + "::" + function_name; ( errors::redeclaration_of_method(&full_name), ErrorType::ParseError, ) } }; self.errors .push(make_error_from_node_with_type(node, err, err_type)) } Some(prev_def) if (prev_def.kind != NameDef) => { let (line_num, _) = self .env .text .offset_to_position(prev_def.location.start_offset as isize); let line_num = line_num as usize; self.errors.push(make_name_already_used_error( &f.name, &combine_names(&self.namespace_name, function_name), function_name, &def.location, &|x, y| errors::declared_name_is_already_in_use(line_num, x, y), )) } _ => {} }; self.names.functions.add(function_name, def) } _ if self.env.is_typechecker() => self.errors.push(make_error_from_node( node, errors::decl_outside_global_scope, )), _ => {} } } _ => {} } } fn statement_errors(&mut self, node: S<'a>) { let expect_colon = |colon: S<'a>| match &colon.children { Token(m) if self.env.is_typechecker() && m.kind() != TokenKind::Colon => { Some((colon, errors::error1020)) } _ => None, }; (match &node.children { TryStatement(x) if x.catch_clauses.is_missing() && x.finally_clause.is_missing() => { Some((node, errors::error2007)) } UsingStatementFunctionScoped(_) if !self.using_statement_function_scoped_is_legal() => { Some((node, errors::using_st_function_scoped_top_level)) } ForStatement(x) if is_foreach_in_for(&x.initializer) => { Some((node, errors::for_with_as_expression)) } CaseLabel(x) => expect_colon(&x.colon), DefaultLabel(x) => expect_colon(&x.colon), _ => None, }) .into_iter() .for_each(|(error_node, error_message)| { self.errors .push(make_error_from_node(error_node, error_message)) }) } fn invalid_shape_initializer_name(&mut self, node: S<'a>) { match &node.children { LiteralExpression(x) => { let is_str = match token_kind(&x.expression) { Some(TokenKind::SingleQuotedStringLiteral) => true, // TODO: Double quoted string are only legal // if they contain no encapsulated expressions. Some(TokenKind::DoubleQuotedStringLiteral) => true, _ => false, }; if !is_str { self.errors .push(make_error_from_node(node, errors::invalid_shape_field_name)) } } ScopeResolutionExpression(_) => {} QualifiedName(_) => { if self.env.is_typechecker() { self.errors .push(make_error_from_node(node, errors::invalid_shape_field_name)) } } Token(_) if node.is_name() => { if self.env.is_typechecker() { self.errors .push(make_error_from_node(node, errors::invalid_shape_field_name)) } } _ => self .errors .push(make_error_from_node(node, errors::invalid_shape_field_name)), } } fn invalid_shape_field_check(&mut self, node: S<'a>) { if let FieldInitializer(x) = &node.children { self.invalid_shape_initializer_name(&x.name) } else { self.errors .push(make_error_from_node(node, errors::invalid_shape_field_name)) } } fn is_in_unyieldable_magic_method(&self) -> bool { self.first_parent_function_name().map_or(false, |s| { let s = s.to_ascii_lowercase(); match s { _ if s == sn::members::__INVOKE => false, _ => sn::members::AS_LOWERCASE_SET.contains(&s), } }) } fn check_disallowed_variables(&mut self, node: S<'a>) { match &node.children { VariableExpression(x) => { // TODO(T75820862): Allow $GLOBALS to be used as a variable name if self.text(&x.expression) == sn::superglobals::GLOBALS { self.errors .push(make_error_from_node(node, errors::globals_disallowed)) } else if self.text(&x.expression) == sn::special_idents::THIS && !self.has_this() { // If we are in the special top level debugger function, lets not check for $this since // it will be properly lifted in closure convert if self .first_parent_function_name() .map_or(true, |s| s == "include") { return {}; } self.errors .push(make_error_from_node(node, errors::invalid_this)) } } _ => {} } } fn function_call_on_xhp_name_errors(&mut self, node: S<'a>) { let check = |self_: &mut Self, member_object: S<'a>, name: S<'a>| { if let XHPExpression(_) = &member_object.children { if self_.env.is_typechecker() { self_.errors.push(make_error_from_node( node, errors::method_calls_on_xhp_expression, )) } } if let Token(token) = &name.children { if token.kind() == TokenKind::XHPClassName { self_.errors.push(make_error_from_node( node, errors::method_calls_on_xhp_attributes, )) } } }; match &node.children { MemberSelectionExpression(x) => check(self, &x.object, &x.name), SafeMemberSelectionExpression(x) => check(self, &x.object, &x.name), _ => {} } } fn no_async_before_lambda_body(&mut self, body_node: S<'a>) { if let AwaitableCreationExpression(_) = &body_node.children { if self.env.is_typechecker() { self.errors.push(make_error_from_node( body_node, errors::no_async_before_lambda_body, )) } } } fn no_memoize_attribute_on_lambda(&mut self, node: S<'a>) { match &node.children { OldAttributeSpecification(_) | AttributeSpecification(_) => { for node in attr_spec_to_node_list(node) { match self.attr_name(node) { Some(n) if sn::user_attributes::is_memoized(n) => self .errors .push(make_error_from_node(node, errors::memoize_on_lambda)), _ => {} } } } _ => {} } } fn new_variable_errors_(&mut self, node: S<'a>, inside_scope_resolution: bool) { match &node.children { SimpleTypeSpecifier(_) | VariableExpression(_) | GenericTypeSpecifier(_) | PipeVariableExpression(_) => {} SubscriptExpression(x) if x.index.is_missing() => self.errors.push( make_error_from_node(node, errors::instanceof_missing_subscript_index), ), SubscriptExpression(x) => { self.new_variable_errors_(&x.receiver, inside_scope_resolution) } MemberSelectionExpression(x) => { if inside_scope_resolution { self.errors.push(make_error_from_node( node, errors::instanceof_memberselection_inside_scoperesolution, )) } else { self.new_variable_errors_(&x.object, inside_scope_resolution) } } ScopeResolutionExpression(x) => { if let Token(name) = &x.name.children { if is_good_scope_resolution_qualifier( &x.qualifier, /* allow static */ true, ) && name.kind() == TokenKind::Variable { // OK } else if name.kind() == TokenKind::Variable { self.new_variable_errors_(&x.qualifier, true) } else { self.errors.push(make_error_from_node( node, errors::instanceof_invalid_scope_resolution, )) } } else { self.errors.push(make_error_from_node( node, errors::instanceof_invalid_scope_resolution, )) } } _ => { self.errors.push(make_error_from_node( node, errors::new_unknown_node(node.kind().to_string()), )); } } } fn new_variable_errors(&mut self, node: S<'a>) { self.new_variable_errors_(node, false) } fn class_type_designator_errors(&mut self, node: S<'a>) { if !is_good_scope_resolution_qualifier(node, /* allow static */ true) { match &node.children { ParenthesizedExpression(_) => {} _ => self.new_variable_errors(node), } } } fn rec_walk_impl<F, X>(&self, parents: &mut Vec<S<'a>>, f: &F, node: S<'a>, mut acc: X) -> X where F: Fn(S<'a>, &Vec<S<'a>>, X) -> (bool, X), { let (continue_walk, new_acc) = f(node, parents, acc); acc = new_acc; if continue_walk { parents.push(node); for child in node.iter_children() { acc = self.rec_walk_impl(parents, f, child, acc); } parents.pop(); } acc } fn rec_walk<F, X>(&self, f: F, node: S<'a>, acc: X) -> X where F: Fn(S<'a>, &Vec<S<'a>>, X) -> (bool, X), { self.rec_walk_impl(&mut vec![], &f, node, acc) } fn find_invalid_lval_usage(&self, node: S<'a>) -> Vec<SyntaxError> { self.rec_walk( |node, parents, mut acc| match &node.children { AnonymousFunction(_) | LambdaExpression(_) | AwaitableCreationExpression(_) => { (false, acc) } _ => { match node_lval_type(node, parents) { LvalTypeFinal | LvalTypeNone => {} LvalTypeNonFinalInout | LvalTypeNonFinal => { acc.push(make_error_from_node(node, errors::lval_as_expression)) } }; (true, acc) } }, node, vec![], ) } fn await_as_an_expression_errors(&mut self, await_node: S<'a>) { let mut prev = None; let mut node = await_node; for n in self.parents.iter().rev() { if let Some(prev) = prev { node = prev; } prev = Some(n); match &n.children { // statements that root for the concurrently executed await expressions ExpressionStatement(_) | ReturnStatement(_) | UnsetStatement(_) | EchoStatement(_) | ThrowStatement(_) | DeclareLocalStatement(_) => break, IfStatement(x) if std::ptr::eq(node, &x.condition) => break, ForStatement(x) if std::ptr::eq(node, &x.initializer) => break, SwitchStatement(x) if std::ptr::eq(node, &x.expression) => break, ForeachStatement(x) if std::ptr::eq(node, &x.collection) => { break; } UsingStatementBlockScoped(x) if std::ptr::eq(node, &x.expressions) => { break; } UsingStatementFunctionScoped(x) if std::ptr::eq(node, &x.expression) => { break; } LambdaExpression(x) if std::ptr::eq(node, &x.body) => break, // Dependent awaits are not allowed currently PrefixUnaryExpression(x) if token_kind(&x.operator) == Some(TokenKind::Await) => { self.errors.push(make_error_from_node( await_node, errors::invalid_await_position_dependent, )); break; } // Unary based expressions have their own custom fanout PrefixUnaryExpression(x) if unop_allows_await(&x.operator) => { continue; } PostfixUnaryExpression(x) if unop_allows_await(&x.operator) => { continue; } DecoratedExpression(x) if unop_allows_await(&x.decorator) => { continue; } // Special case the pipe operator error message BinaryExpression(x) if std::ptr::eq(node, &x.right_operand) && token_kind(&x.operator) == Some(TokenKind::BarGreaterThan) => { self.errors.push(make_error_from_node( await_node, errors::invalid_await_position_pipe, )); break; } // left or right operand of binary expressions are considered legal locations // if operator is not short-circuiting and containing expression // is in legal location BinaryExpression(x) if (match get_positions_binop_allows_await(&x.operator) { BinopAllowAwaitBoth => true, BinopAllowAwaitLeft => std::ptr::eq(node, &x.left_operand), BinopAllowAwaitRight => std::ptr::eq(node, &x.right_operand), BinopAllowAwaitNone => false, }) => { continue; } // test part of conditional expression is considered legal location if // onditional expression itself is in legal location ConditionalExpression(x) if std::ptr::eq(node, &x.test) => { continue; } FunctionCallExpression(x) if std::ptr::eq(node, &x.receiver) || std::ptr::eq(node, &x.argument_list) && !x.receiver.is_safe_member_selection_expression() => { continue; } // object of member selection expression or safe member selection expression // is in legal position if member selection expression itself is in legal position SafeMemberSelectionExpression(x) if std::ptr::eq(node, &x.object) => { continue; } // These are nodes where any position is valid CastExpression(_) | MemberSelectionExpression(_) | ScopeResolutionExpression(_) | IsExpression(_) | AsExpression(_) | NullableAsExpression(_) | IssetExpression(_) | ParenthesizedExpression(_) | BracedExpression(_) | EmbeddedBracedExpression(_) | CollectionLiteralExpression(_) | ObjectCreationExpression(_) | ConstructorCall(_) | ShapeExpression(_) | TupleExpression(_) | DarrayIntrinsicExpression(_) | DictionaryIntrinsicExpression(_) | KeysetIntrinsicExpression(_) | VarrayIntrinsicExpression(_) | VectorIntrinsicExpression(_) | ElementInitializer(_) | FieldInitializer(_) | SimpleInitializer(_) | SubscriptExpression(_) | EmbeddedSubscriptExpression(_) | YieldExpression(_) | XHPExpression(_) | XHPOpen(_) | XHPSimpleAttribute(_) | XHPSpreadAttribute(_) | SyntaxList(_) | ListItem(_) => continue, // otherwise report error and bail out _ => { self.errors.push(make_error_from_node( await_node, errors::invalid_await_position, )); break; } } } let is_in_concurrent = self .parents .iter() .rev() .any(|parent| match &parent.children { ConcurrentStatement(_) => true, _ => false, }); if !is_in_concurrent { let await_node_statement_parent = self.parents .iter() .rev() .find(|parent| match &parent.children { ExpressionStatement(_) | ReturnStatement(_) | UnsetStatement(_) | EchoStatement(_) | ThrowStatement(_) | IfStatement(_) | ForStatement(_) | SwitchStatement(_) | ForeachStatement(_) => true, _ => false, }); if let Some(x) = await_node_statement_parent { for error in self.find_invalid_lval_usage(x) { self.errors.push(error) } } else { // We must have already errored in for loop } } } fn node_has_await_child(&mut self, node: S<'a>) -> bool { self.rec_walk( |node, _parents, acc| { let is_new_scope = match &node.children { AnonymousFunction(_) | LambdaExpression(_) | AwaitableCreationExpression(_) => { true } _ => false, }; if is_new_scope { (false, false) } else { let is_await = |n: S<'a>| match &n.children { PrefixUnaryExpression(x) if token_kind(&x.operator) == Some(TokenKind::Await) => { true } _ => false, }; let found_await = acc || is_await(node); (!found_await, found_await) } }, node, false, ) } fn expression_errors(&mut self, node: S<'a>) { let check_is_as_expression = |self_: &mut Self, hint: S<'a>| { let n = match &node.children { IsExpression(_) => "is", _ => "as", }; match &hint.children { ClosureTypeSpecifier(_) if self_.env.is_hhvm_compat() => { self_.errors.push(make_error_from_node( hint, errors::invalid_is_as_expression_hint(n, "__Callable"), )); } SoftTypeSpecifier(_) => { self_.errors.push(make_error_from_node( hint, errors::invalid_is_as_expression_hint(n, "__Soft"), )); } AttributizedSpecifier(x) if self_.attribute_specification_contains(&x.attribute_spec, "__Soft") => { self_.errors.push(make_error_from_node( hint, errors::invalid_is_as_expression_hint(n, "__Soft"), )); } _ => {} } }; match &node.children { // We parse the right hand side of `new` as a generic expression, but PHP // (and therefore Hack) only allow a certain subset of expressions, so we // should verify here that the expression we parsed is in that subset. // Refer: https://github.com/php/php-langspec/blob/master/spec/10-expressions.md#instanceof-operator*) ConstructorCall(ctr_call) => { for p in syntax_to_list_no_separators(&ctr_call.argument_list) { if let DecoratedExpression(e) = &p.children { if let Token(t) = &e.decorator.children { if t.kind() == TokenKind::Inout { self.errors.push(make_error_from_node( p, errors::inout_param_in_construct, )); } } } } self.class_type_designator_errors(&ctr_call.type_); if self.env.is_typechecker() { // attr or list item -> syntax list -> attribute match self.parents.iter().rev().nth(2) { Some(a) if a.is_attribute_specification() || a.is_old_attribute_specification() || a.is_file_attribute_specification() => {} _ => { if ctr_call.left_paren.is_missing() || ctr_call.right_paren.is_missing() { let node = &ctr_call.type_; let constructor_name = self.text(&ctr_call.type_); self.errors.push(make_error_from_node( node, errors::error2038(constructor_name), )); } } } }; } LiteralExpression(x) => { if let Token(token) = &x.expression.children { if token.kind() == TokenKind::DecimalLiteral || token.kind() == TokenKind::DecimalLiteral { let text = self.text(&x.expression).replace('_', ""); if text.parse::<i64>().is_err() { let error_text = if token.kind() == TokenKind::DecimalLiteral { errors::error2071(&text) } else { errors::error2072(&text) }; self.errors.push(make_error_from_node(node, error_text)) } } } } SubscriptExpression(x) if self.env.is_typechecker() && x.left_bracket.is_left_brace() => { self.errors .push(make_error_from_node(node, errors::error2020)) } FunctionCallExpression(x) => { let arg_list = &x.argument_list; if let Some(h) = misplaced_variadic_arg(arg_list) { self.errors.push(make_error_from_node(h, errors::error2033)) } let recv = &x.receiver; self.function_call_on_xhp_name_errors(recv); if strip_ns(self.text(recv)) == strip_ns(sn::readonly::AS_MUT) { self.mark_uses_readonly() } } ETSpliceExpression(_) => { if !self.env.context.active_expression_tree { self.errors .push(make_error_from_node(node, errors::splice_outside_et)) } } ListExpression(x) if x.members.is_missing() && self.env.is_hhvm_compat() => { if let Some(Syntax { children: ForeachStatement(x), .. }) = self.parents.last() { if std::ptr::eq(node, &x.value) { self.errors.push(make_error_from_node_with_type( node, errors::error2077, ErrorType::RuntimeError, )) } } } ListExpression(_) => { if self .parents .last() .map_or(false, |e| e.is_return_statement()) { self.errors .push(make_error_from_node(node, errors::list_must_be_lvar)) } } ShapeExpression(x) => { for f in syntax_to_list_no_separators(&x.fields).rev() { self.invalid_shape_field_check(f) } } DecoratedExpression(x) => { let decorator = &x.decorator; if token_kind(decorator) == Some(TokenKind::Await) { self.await_as_an_expression_errors(node) } } YieldExpression(_) => { if self.is_in_unyieldable_magic_method() { self.errors .push(make_error_from_node(node, errors::yield_in_magic_methods)) } if self.env.context.active_callable.is_none() { self.errors .push(make_error_from_node(node, errors::yield_outside_function)) } if self.has_inout_params() { let e = if self.is_inside_async_method() { errors::inout_param_in_async_generator } else { errors::inout_param_in_generator }; self.errors.push(make_error_from_node_with_type( node, e, ErrorType::RuntimeError, )) } } ScopeResolutionExpression(x) => { let qualifier = &x.qualifier; let name = &x.name; let (is_dynamic_name, is_self_or_parent, is_valid) = // PHP langspec allows string literals, variables // qualified names, static, self and parent as valid qualifiers // We do not allow string literals in hack match (&qualifier.children, token_kind(qualifier)) { (LiteralExpression(_), _) => (false, false, false), (QualifiedName(_), _) => (false, false, true), (_, Some(TokenKind::Name)) | (_, Some(TokenKind::XHPClassName)) | (_, Some(TokenKind::Static)) => (false, false, true), (_, Some(TokenKind::SelfToken)) | (_, Some(TokenKind::Parent)) => { (false, true, true) } // ${}::class (PrefixUnaryExpression(x), _) if token_kind(&x.operator) == Some(TokenKind::Dollar) => { (true, false, true) } (PipeVariableExpression(_), _) | (VariableExpression(_), _) | (SimpleTypeSpecifier(_), _) | (GenericTypeSpecifier(_), _) => (true, false, true), _ => (true, false, false), }; if !is_valid { self.errors.push(make_error_from_node( node, errors::invalid_scope_resolution_qualifier, )) } let is_name_class = self.text(name).eq_ignore_ascii_case("class"); if (is_dynamic_name || !is_valid) && is_name_class { self.errors.push(make_error_from_node( node, errors::coloncolonclass_on_dynamic, )) } let text_name = self.text(qualifier); let is_name_namespace = text_name.eq_ignore_ascii_case("namespace"); if is_name_namespace { self.errors.push(make_error_from_node( node, errors::namespace_not_a_classname, )) } if is_self_or_parent && is_name_class && !self.is_in_active_class_scope() { self.errors.push(make_error_from_node_with_type( node, errors::self_or_parent_colon_colon_class_outside_of_class(text_name), ErrorType::RuntimeError, )) } } PrefixUnaryExpression(x) if token_kind(&x.operator) == Some(TokenKind::Dollar) => { if check_prefix_unary_dollar(node) { self.errors .push(make_error_from_node(node, errors::dollar_unary)) } } // TODO(T21285960): Remove this bug-port, stemming from T22184312 LambdaExpression(x) if self.env.is_hhvm_compat() && !x.async_.is_missing() && x.async_.trailing_width() == 0 && x.signature.leading_width() == 0 => { self.errors .push(make_error_from_node(node, errors::error1057("==>"))) } // End of bug-port IsExpression(x) => check_is_as_expression(self, &x.right_operand), AsExpression(x) => check_is_as_expression(self, &x.right_operand), ConditionalExpression(x) => { if x.consequence.is_missing() && self.env.is_typechecker() { self.errors .push(make_error_from_node(node, errors::elvis_operator_space)) } if x.test.is_conditional_expression() && self.env.is_typechecker() { self.errors .push(make_error_from_node(node, errors::nested_ternary)) } match &x.alternative.children { LambdaExpression(x) if x.body.is_conditional_expression() && self.env.is_typechecker() => { self.errors .push(make_error_from_node(node, errors::nested_ternary)) } _ => {} } } LambdaExpression(x) => { self.no_memoize_attribute_on_lambda(&x.attribute_spec); self.no_async_before_lambda_body(&x.body); } AnonymousFunction(x) => self.no_memoize_attribute_on_lambda(&x.attribute_spec), AwaitableCreationExpression(x) => { self.no_memoize_attribute_on_lambda(&x.attribute_spec) } CollectionLiteralExpression(x) => { enum Status { ValidClass(String), InvalidClass, InvalidBraceKind, } use Status::*; let n = &x.name; let initializers = &x.initializers; let is_standard_collection = |lc_name: &str| { lc_name.eq_ignore_ascii_case("pair") || lc_name.eq_ignore_ascii_case("vector") || lc_name.eq_ignore_ascii_case("map") || lc_name.eq_ignore_ascii_case("set") || lc_name.eq_ignore_ascii_case("immvector") || lc_name.eq_ignore_ascii_case("immmap") || lc_name.eq_ignore_ascii_case("immset") }; let use_key_value_initializers = |lc_name: &str| { lc_name.eq_ignore_ascii_case("map") || lc_name.eq_ignore_ascii_case("immmap") }; let is_qualified_std_collection = |l, r| { token_kind(l) == Some(TokenKind::Name) && token_kind(r) == Some(TokenKind::Name) && self.text(l).eq_ignore_ascii_case("hh") && is_standard_collection(self.text(r)) }; let check_type_specifier = |n, t: &PositionedToken<'a>| { if t.kind() == TokenKind::Name { match self.text(n).to_ascii_lowercase().as_ref() { "dict" | "vec" | "keyset" => InvalidBraceKind, n => { if is_standard_collection(n) { ValidClass(n.to_string()) } else { InvalidClass } } } } else { InvalidClass } }; let check_qualified_name = |parts| { let mut parts = syntax_to_list(false, parts); let p1 = parts.next(); let p2 = parts.next(); let p3 = parts.next(); let p4 = parts.next(); match (p1, p2, p3, p4) { (Some(l), Some(r), None, None) if self.namespace_name == GLOBAL_NAMESPACE_NAME && is_qualified_std_collection(l, r) => { // HH\Vector in global namespace ValidClass(self.text(r).to_ascii_lowercase()) } (Some(missing), Some(l), Some(r), None) if missing.is_missing() && is_qualified_std_collection(l, r) => { // \HH\Vector ValidClass(self.text(r).to_ascii_lowercase()) } _ => InvalidClass, } }; let status = match &n.children { // non-qualified name SimpleTypeSpecifier(x) => match &x.specifier.children { Token(t) => check_type_specifier(&x.specifier, t), QualifiedName(x) => check_qualified_name(&x.parts), _ => InvalidClass, }, GenericTypeSpecifier(x) => match &x.class_type.children { Token(t) => check_type_specifier(&x.class_type, t), QualifiedName(x) => check_qualified_name(&x.parts), _ => InvalidClass, }, _ => InvalidClass, }; let is_key_value = |s: S<'a>| { if let ElementInitializer(_) = s.children { true } else { false } }; let initializer_list = || syntax_to_list_no_separators(initializers); let num_initializers = initializer_list().count(); match &status { ValidClass(name) if use_key_value_initializers(name) && initializer_list().any(|i| !is_key_value(i)) => { self.errors.push(make_error_from_node( node, errors::invalid_value_initializer(self.text(n)), )); } ValidClass(name) if !use_key_value_initializers(name) && initializer_list().any(is_key_value) => { self.errors.push(make_error_from_node( node, errors::invalid_key_value_initializer(self.text(n)), )); } ValidClass(pair) if pair == "pair" && num_initializers != 2 => { let msg = if num_initializers == 0 { errors::pair_initializer_needed } else { errors::pair_initializer_arity }; self.errors.push(make_error_from_node_with_type( node, msg, ErrorType::RuntimeError, )); } ValidClass(_) => {} InvalidBraceKind => self.errors.push(make_error_from_node( node, errors::invalid_brace_kind_in_collection_initializer, )), InvalidClass => self.errors.push(make_error_from_node( node, errors::invalid_class_in_collection_initializer, )), } } PrefixUnaryExpression(x) if token_kind(&x.operator) == Some(TokenKind::Await) => { self.await_as_an_expression_errors(node) } PrefixUnaryExpression(x) if token_kind(&x.operator) == Some(TokenKind::Readonly) => { self.mark_uses_readonly() } // Other kinds of expressions currently produce no expr errors. _ => {} } } fn check_repeated_properties_tconst_const( &mut self, full_name: &str, prop: S<'a>, p_names: &mut HashSet<String>, c_names: &mut HashSet<String>, xhp_names: &mut HashSet<String>, ) { let mut check = |sname, names: &mut HashSet<String>| { let name = self.text(sname); // If the name is empty, then there was an earlier // parsing error that should supercede this one. if name.is_empty() { } else if names.contains(name) { self.errors.push(make_error_from_node( prop, errors::redeclaration_error(&(strip_ns(full_name).to_string() + "::" + name)), )) } else { names.insert(name.to_owned()); } }; match &prop.children { PropertyDeclaration(x) => { for prop in syntax_to_list_no_separators(&x.declarators) { if let PropertyDeclarator(x) = &prop.children { check(&x.name, p_names) } } } ConstDeclaration(x) => { for prop in syntax_to_list_no_separators(&x.declarators) { if let ConstantDeclarator(x) = &prop.children { check(&x.name, c_names) } } } TypeConstDeclaration(x) => check(&x.name, c_names), ContextConstDeclaration(x) => check(&x.name, c_names), XHPClassAttributeDeclaration(x) => { for attr in syntax_to_list_no_separators(&x.attributes) { if let XHPClassAttribute(x) = &attr.children { check(&x.name, xhp_names) } } } _ => {} } } fn require_errors(&mut self, node: S<'a>) { if let RequireClause(p) = &node.children { let name = self.text(&p.name); let req_kind = token_kind(&p.kind); match (self.trait_require_clauses.get(name), req_kind) { (None, Some(tk)) => self.trait_require_clauses.add(name, tk), (Some(tk1), Some(tk2)) if *tk1 == tk2 => // duplicate, it is okay {} _ => { // Conflicting entry self.errors.push(make_error_from_node( node, errors::conflicting_trait_require_clauses(name), )) } }; match (self.active_classish_kind(), req_kind) { (Some(TokenKind::Interface), Some(TokenKind::Implements)) | (Some(TokenKind::Class), Some(TokenKind::Implements)) => self .errors .push(make_error_from_node(node, errors::error2030)), _ => {} } } } fn check_alias_name(&mut self, name: S<'a>, name_text: &str, location: Location) { self.produce_error( |_, x| cant_be_reserved_type_name(x), name_text, || errors::reserved_keyword_as_type_name(name_text), name, ); self.check_use_type_name(name, name_text, location); } /// This reports "name already in use" relating to namespace use statements. fn check_use_type_name(&mut self, name: S<'a>, name_text: &str, location: Location) { match self.names.classes.get(name_text) { Some(FirstUseOrDef { location, kind, name: def_name, .. }) if &combine_names(&self.namespace_name, name_text) != def_name && *kind != NameDef => { let (line_num, _) = self .env .text .offset_to_position(location.start_offset as isize); let line_num = line_num as usize; let long_name_text = combine_names(&self.namespace_name, name_text); self.errors.push(make_name_already_used_error( name, &long_name_text, name_text, location, &|x, y| match kind { NameImplicitUse => { errors::declared_name_is_already_in_use_implicit_hh(line_num, x, y) } NameUse => errors::declared_name_is_already_in_use(line_num, x, y), NameDef => errors::type_name_is_already_in_use(x, y), }, )) } _ => { let def = make_first_use_or_def( false, NameDef, location, &self.namespace_name, name_text, ); self.names.classes.add(name_text, def) } } } fn get_type_params_and_emit_shadowing_errors( &mut self, l: S<'a>, ) -> (HashSet<&'a str>, HashSet<&'a str>) { let mut res: HashSet<&'a str> = HashSet::default(); let mut notreified: HashSet<&'a str> = HashSet::default(); for p in syntax_to_list_no_separators(l).rev() { match &p.children { TypeParameter(x) => { let name = self.text(&x.name); if !x.reified.is_missing() { if res.contains(&name) { self.errors .push(make_error_from_node(p, errors::shadowing_reified)) } else { res.insert(name); } } else { notreified.insert(name); } } _ => {} } } (res, notreified) } fn class_reified_param_errors(&mut self, node: S<'a>) { match &node.children { ClassishDeclaration(cd) => { let (reified, non_reified) = match &cd.type_parameters.children { TypeParameters(x) => { self.get_type_params_and_emit_shadowing_errors(&x.parameters) } _ => (HashSet::default(), HashSet::default()), }; let tparams: HashSet<&'a str> = reified .union(&non_reified) .cloned() .collect::<HashSet<&'a str>>(); let add_error = |self_: &mut Self, e: S<'a>| { if let TypeParameter(x) = &e.children { if !x.reified.is_missing() && tparams.contains(&self_.text(&x.name)) { self_ .errors .push(make_error_from_node(e, errors::shadowing_reified)) } } }; let check_method = |e: S<'a>| { if let MethodishDeclaration(x) = &e.children { if let FunctionDeclarationHeader(x) = &x.function_decl_header.children { if let TypeParameters(x) = &x.type_parameter_list.children { syntax_to_list_no_separators(&x.parameters) .rev() .for_each(|x| add_error(self, x)) } } } }; if let ClassishBody(x) = &cd.body.children { syntax_to_list_no_separators(&x.elements) .rev() .for_each(check_method) } if !reified.is_empty() { if is_token_kind(&cd.keyword, TokenKind::Interface) { self.errors.push(make_error_from_node( node, errors::reified_in_invalid_classish("an interface"), )) } else if is_token_kind(&cd.keyword, TokenKind::Trait) { self.errors.push(make_error_from_node( node, errors::reified_in_invalid_classish("a trait"), )) } } } PropertyDeclaration(_) => { if has_modifier_static(node) && self.is_in_reified_class() { self.errors.push(make_error_from_node( node, errors::static_property_in_reified_class, )); } } _ => {} } } fn attr_spec_contains_sealed(&self, node: S<'a>) -> bool { self.attribute_specification_contains(node, sn::user_attributes::SEALED) } fn attr_spec_contains_enum_class(&self, node: S<'a>) -> bool { self.attribute_specification_contains(node, sn::user_attributes::ENUM_CLASS) } fn attr_spec_contains_const(&self, node: S<'a>) -> bool { self.attribute_specification_contains(node, sn::user_attributes::CONST) } // If there's more than one XHP category, report an error on the last one. fn duplicate_xhp_category_errors<I>(&mut self, elts: I) where I: Iterator<Item = S<'a>>, { let mut iter = elts.filter(|x| matches!(&x.children, XHPCategoryDeclaration(_))); iter.next(); if let Some(node) = iter.last() { self.errors.push(make_error_from_node( node, errors::xhp_class_multiple_category_decls, )) } } // If there's more than one XHP children declaration, report an error // on the last one. fn duplicate_xhp_children_errors<I>(&mut self, elts: I) where I: Iterator<Item = S<'a>>, { let mut iter = elts.filter(|x| matches!(&x.children, XHPChildrenDeclaration(_))); iter.next(); if let Some(node) = iter.last() { self.errors.push(make_error_from_node( node, errors::xhp_class_multiple_children_decls, )) } } fn interface_private_method_errors<I>(&mut self, elts: I) where I: Iterator<Item = S<'a>>, { for elt in elts { if let Some(modifiers) = get_modifiers_of_declaration(elt) { for modifier in syntax_to_list_no_separators(modifiers) { if modifier.is_private() { self.errors.push(make_error_from_node( modifier, errors::interface_has_private_method, )) } } } } } fn enum_class_errors(&mut self, node: S<'a>) { if let EnumClassDeclaration(c) = &node.children { let name = self.text(&c.name); self.produce_error( |_, x| cant_be_reserved_type_name(x), name, || errors::reserved_keyword_as_type_name(name), &c.name, ); self.invalid_modifier_errors("Enum classes", node, |kind| { kind == TokenKind::Abstract || kind == TokenKind::Internal || kind == TokenKind::Public }); } } fn enum_class_enumerator_errors(&mut self, node: S<'a>) { if let EnumClassEnumerator(e) = node.children { // only allow abstract as modifier + detect modifier duplication self.invalid_modifier_errors("Enum class constants", node, |kind| { kind == TokenKind::Abstract }); let is_abstract = has_modifier_abstract(node); let has_initializer = !e.initializer.is_missing(); if is_abstract && has_initializer { self.errors.push(make_error_from_node( node, errors::enum_class_abstract_constant_with_value, )) } if !is_abstract && !has_initializer { self.errors.push(make_error_from_node( node, errors::enum_class_constant_missing_initializer, )) } // prevent constants to be named `class` if self.text(&e.name).eq_ignore_ascii_case("class") { self.errors.push(make_error_from_node( node, errors::enum_class_elem_name_is_class, )) } } } fn classish_errors(&mut self, node: S<'a>) { if let ClassishDeclaration(cd) = &node.children { // Given a ClassishDeclaration node, test whether or not it's a trait // invoking the 'extends' keyword. let classish_invalid_extends_keyword = |_| { // Invalid if uses 'extends' and is a trait. token_kind(&cd.extends_keyword) == Some(TokenKind::Extends) && token_kind(&cd.keyword) == Some(TokenKind::Trait) }; let abstract_keyword = extract_keyword(|x| x.is_abstract(), node).unwrap_or(node); self.produce_error( |self_, x| self_.is_classish_kind_declared_abstract(x), node, || errors::error2042, abstract_keyword, ); // Given a sealed ClassishDeclaration node, test whether all the params // are classnames. let classish_sealed_arg_not_classname = |self_: &mut Self| { attr_spec_to_node_list(&cd.attribute).any(|node| { self_.attr_name(node) == Some(sn::user_attributes::SEALED) && self_.attr_args(node).map_or(false, |mut args| { args.any(|arg_node| match &arg_node.children { ScopeResolutionExpression(x) => self_.text(&x.name) != "class", _ => true, }) }) }) }; // Only "regular" class names are allowed in `__Sealed()` // attributes. for node in attr_spec_to_node_list(&cd.attribute) { if (self.attr_name(node)) == Some(sn::user_attributes::SEALED) { match self.attr_args(node) { Some(args) => { for arg in args { match &arg.children { ScopeResolutionExpression(x) => { let txt = self.text(&x.qualifier); let excludes = vec![ sn::classes::SELF, sn::classes::PARENT, sn::classes::STATIC, ]; if excludes.iter().any(|&e| txt == e) { self.errors.push(make_error_from_node( &x.qualifier, errors::sealed_qualifier_invalid, )); } } _ => {} } } } None => {} } } } self.check_attr_enabled(&cd.attribute); let classish_is_sealed = self.attr_spec_contains_sealed(&cd.attribute); // Given a ClassishDeclaration node, test whether or not length of // extends_list is appropriate for the classish_keyword. *) let classish_invalid_extends_list = |self_: &mut Self| { // Invalid if is a class and has list of length greater than one. self_.env.is_typechecker() && token_kind(&cd.keyword) == Some(TokenKind::Class) && token_kind(&cd.extends_keyword) == Some(TokenKind::Extends) && syntax_to_list_no_separators(&cd.extends_list).count() != 1 }; // Given a ClassishDeclaration node, test whether it is sealed and final. let classish_sealed_final = |_| list_contains_predicate(|x| x.is_final(), &cd.modifiers) && classish_is_sealed; self.produce_error( |self_, _| classish_invalid_extends_list(self_), &(), || errors::error2037, &cd.extends_list, ); self.invalid_modifier_errors("Classes, interfaces, and traits", node, |kind| { kind == TokenKind::Abstract || kind == TokenKind::Final || kind == TokenKind::XHP || kind == TokenKind::Internal || kind == TokenKind::Public }); self.produce_error( |self_, _| classish_sealed_arg_not_classname(self_), &(), || errors::sealed_val_not_classname, &cd.attribute, ); self.produce_error( |_, x| classish_invalid_extends_keyword(x), &(), || errors::error2036, &cd.extends_keyword, ); self.produce_error( |_, x| classish_sealed_final(x), &(), || errors::sealed_final, &cd.attribute, ); let classish_name = self.text(&cd.name); self.produce_error( |_, x| cant_be_reserved_type_name(x), classish_name, || errors::reserved_keyword_as_type_name(classish_name), &cd.name, ); if is_token_kind(&cd.keyword, TokenKind::Interface) && !cd.implements_keyword.is_missing() { self.errors .push(make_error_from_node(node, errors::interface_implements)) }; if self.attr_spec_contains_const(&cd.attribute) && (is_token_kind(&cd.keyword, TokenKind::Interface) || is_token_kind(&cd.keyword, TokenKind::Trait)) { self.errors.push(make_error_from_node( node, errors::no_const_interfaces_traits_enums, )) } if self.attr_spec_contains_const(&cd.attribute) && is_token_kind(&cd.keyword, TokenKind::Class) && list_contains_predicate(|x| x.is_abstract(), &cd.modifiers) && list_contains_predicate(|x| x.is_final(), &cd.modifiers) { self.errors.push(make_error_from_node( node, errors::no_const_abstract_final_class, )) } if list_contains_predicate(|x| x.is_final(), &cd.modifiers) { match token_kind(&cd.keyword) { Some(TokenKind::Interface) => self.errors.push(make_error_from_node( node, errors::declared_final("Interfaces"), )), Some(TokenKind::Trait) => self .errors .push(make_error_from_node(node, errors::declared_final("Traits"))), _ => {} } } if token_kind(&cd.xhp) == Some(TokenKind::XHP) { match token_kind(&cd.keyword) { Some(TokenKind::Interface) => self.errors.push(make_error_from_node( node, errors::invalid_xhp_classish("Interfaces"), )), Some(TokenKind::Trait) => self.errors.push(make_error_from_node( node, errors::invalid_xhp_classish("Traits"), )), Some(TokenKind::Enum) => self.errors.push(make_error_from_node( node, errors::invalid_xhp_classish("Enums"), )), _ => {} } } let name = self.text(&cd.name); if let ClassishBody(cb) = &cd.body.children { let declared_name_str = self.text(&cd.name); let full_name = combine_names(&self.namespace_name, declared_name_str); let class_body_elts = || syntax_to_list_no_separators(&cb.elements); let class_body_methods = || class_body_elts().filter(|x| is_method_declaration(x)); let mut p_names = HashSet::<String>::default(); let mut c_names = HashSet::<String>::default(); let mut xhp_names = HashSet::<String>::default(); for elt in class_body_elts() { self.check_repeated_properties_tconst_const( &full_name, elt, &mut p_names, &mut c_names, &mut xhp_names, ); } let has_abstract_fn = class_body_methods().any(&has_modifier_abstract); if has_abstract_fn && is_token_kind(&cd.keyword, TokenKind::Class) && !list_contains_predicate(|x| x.is_abstract(), &cd.modifiers) { self.errors.push(make_error_from_node( &cd.name, errors::class_with_abstract_method(name), )) } if is_token_kind(&cd.keyword, TokenKind::Interface) { self.interface_private_method_errors(class_body_elts()); } self.duplicate_xhp_category_errors(class_body_elts()); self.duplicate_xhp_children_errors(class_body_elts()); } match token_kind(&cd.keyword) { Some(TokenKind::Class) | Some(TokenKind::Trait) if !cd.name.is_missing() => { let location = make_location_of_node(&cd.name); self.check_use_type_name(&cd.name, name, location) } _ => {} } } } // Checks for modifiers on class constants fn class_constant_modifier_errors(&mut self, node: S<'a>) { self.invalid_modifier_errors("Constants", node, |kind| kind == TokenKind::Abstract); } fn type_const_modifier_errors(&mut self, node: S<'a>) { self.invalid_modifier_errors("Type constants", node, |kind| kind == TokenKind::Abstract); } fn type_const_bounds_errors(&mut self, node: S<'a>) { if self.env.is_typechecker() { // HackC & HHVM don't see bounds, so it's pointless to ban (then unban later) if let TypeConstDeclaration(tc) = node.children { let (super_count, as_count) = tc.type_constraints.iter_children().fold( (0, 0), |(super_count, as_count), node| { if let TypeConstraint(c) = &node.children { match token_kind(&c.keyword) { Some(TokenKind::As) => return (super_count, as_count + 1), Some(TokenKind::Super) => return (super_count + 1, as_count), _ => (), } } (super_count, as_count) }, ); if super_count != 0 { self.check_can_use_feature(node, &UnstableFeatures::TypeConstSuperBound); } if super_count > 1 || as_count > 1 { self.check_can_use_feature(node, &UnstableFeatures::TypeConstMultipleBounds); } } } } fn type_refinement_errors(&mut self, node: S<'a>) { #[derive(Eq, PartialEq, Hash)] enum MemberKind { Type, Ctx, } fn member_id<'a>(member: S<'a>) -> Option<(MemberKind, S<'a>)> { match &member.children { TypeInRefinement(m) => Some((MemberKind::Type, &m.name)), CtxInRefinement(m) => Some((MemberKind::Ctx, &m.name)), _ => None, } } fn member_bounded<'a>(member: S<'a>) -> bool { let nonempty_constraints = |cs| syntax_to_list_no_separators(cs).next().is_some(); match &member.children { TypeInRefinement(m) => !m.type_.is_missing() ^ nonempty_constraints(&m.constraints), CtxInRefinement(m) => { !m.ctx_list.is_missing() ^ nonempty_constraints(&m.constraints) } _ => false, /* unreachable */ } } if let TypeRefinement(r) = &node.children { // TODO(type-refinements): err when type_parameters is non-empty. // Alternatively, we can just avoid parsing them in the first time. let mut seen_members = HashSet::default(); for member in syntax_to_list_no_separators(&r.members) { if let Some((kind, node)) = member_id(member) { let name = self.text(node); if !seen_members.insert((kind, name)) { self.errors.push(make_error_from_node( member, errors::duplicate_refinement_member_of(name), )) } } if !member_bounded(member) { self.errors.push(make_error_from_node( member, errors::unbounded_refinement_member_of(self.text(&r.type_)), )); } } } } fn alias_errors(&mut self, node: S<'a>) { if let AliasDeclaration(ad) = &node.children { let attrs = &ad.attribute_spec; self.check_attr_enabled(attrs); // Module newtype errors if !ad.module_kw_opt.is_missing() { if !self.in_module { self.errors.push(make_error_from_node( &ad.module_kw_opt, errors::module_newtype_outside_of_module, )); } } self.invalid_modifier_errors("Type aliases", node, |kind| { kind == TokenKind::Internal || kind == TokenKind::Public }); if token_kind(&ad.keyword) == Some(TokenKind::Type) && !ad.constraint.is_missing() { self.errors .push(make_error_from_node(&ad.keyword, errors::error2034)) } if token_kind(&ad.keyword) == Some(TokenKind::Newtype) { for n in ad.constraint.syntax_node_to_list_skip_separator() { if let TypeConstraint(c) = &n.children { if let Some(TokenKind::Super) = token_kind(&c.keyword) { self.check_can_use_feature(n, &UnstableFeatures::NewtypeSuperBounds); break; } }; } } if !ad.name.is_missing() { let name = self.text(&ad.name); let location = make_location_of_node(&ad.name); if let TypeConstant(_) = &ad.type_.children { if self.env.is_typechecker() { self.errors.push(make_error_from_node( &ad.type_, errors::type_alias_to_type_constant, )) } } self.check_alias_name(&ad.name, name, location) } } else if let ContextAliasDeclaration(cad) = &node.children { if cad.equal.is_missing() { // short newctx X as []; syntax self.check_can_use_feature(node, &UnstableFeatures::ContextAliasDeclarationShort); } else { self.check_can_use_feature(node, &UnstableFeatures::ContextAliasDeclaration); } let attrs = &cad.attribute_spec; self.check_attr_enabled(attrs); if token_kind(&cad.keyword) == Some(TokenKind::Type) && !cad.as_constraint.is_missing() { self.errors .push(make_error_from_node(&cad.keyword, errors::error2034)) } if !cad.name.is_missing() { let name = self.text(&cad.name); let location = make_location_of_node(&cad.name); if let TypeConstant(_) = &cad.context.children { if self.env.is_typechecker() { self.errors.push(make_error_from_node( &cad.context, errors::type_alias_to_type_constant, )) } } self.check_alias_name(&cad.name, name, location) } } else if let CaseTypeDeclaration(ctd) = &node.children { self.check_can_use_feature(node, &UnstableFeatures::CaseTypes); let attrs = &ctd.attribute_spec; self.check_attr_enabled(attrs); self.invalid_modifier_errors("Case types", node, |kind| { kind == TokenKind::Internal || kind == TokenKind::Public }); if !ctd.name.is_missing() { let name = self.text(&ctd.name); let location = make_location_of_node(&ctd.name); self.check_alias_name(&ctd.name, name, location) } } } fn case_type_variant_errors(&mut self, node: S<'a>) { if let CaseTypeVariant(ctv) = &node.children { if let TypeConstant(_) = &ctv.type_.children { if self.env.is_typechecker() { self.errors.push(make_error_from_node( &ctv.type_, errors::type_alias_to_type_constant, )) } } } } fn group_use_errors(&mut self, node: S<'a>) { if let NamespaceGroupUseDeclaration(x) = &node.children { let prefix = &x.prefix; let clauses = &x.clauses; let kind = &x.kind; syntax_to_list_no_separators(clauses) .filter(|x| is_invalid_group_use_clause(kind, x)) .for_each(|clause| { self.errors .push(make_error_from_node(clause, errors::error2049)) }); self.produce_error( |_, x| is_invalid_group_use_prefix(x), prefix, || errors::error2048, prefix, ) } } fn use_class_or_namespace_clause_errors( &mut self, namespace_prefix: Option<&str>, kind: S<'a>, cl: S<'a>, ) { match &cl.children { NamespaceUseClause(x) if !&x.name.is_missing() => { let name = &x.name; let kind = if kind.is_missing() { &x.clause_kind } else { kind }; let name_text = self.text(name); let qualified_name = match namespace_prefix { None => combine_names(GLOBAL_NAMESPACE_NAME, name_text), Some(p) => combine_names(p, name_text), }; let short_name = get_short_name_from_qualified_name(name_text, self.text(&x.alias)); let do_check = |self_: &mut Self, error_on_global_redefinition, get_names: &dyn Fn(&mut UsedNames) -> &mut Strmap<FirstUseOrDef>, report_error| { let is_global_namespace = self_.is_global_namespace(); let names = get_names(&mut self_.names); match names.get(short_name) { Some(FirstUseOrDef { location, kind, global, .. }) => { if *kind != NameDef || error_on_global_redefinition && (is_global_namespace || *global) { self_.errors.push(make_name_already_used_error( name, name_text, short_name, location, report_error, )) } } None => { let new_use = make_first_use_or_def( false, NameUse, make_location_of_node(name), GLOBAL_NAMESPACE_NAME, &qualified_name, ); names.add(short_name, new_use) } } }; match &kind.children { Token(token) => match token.kind() { TokenKind::Namespace => do_check( self, false, &|x: &mut UsedNames| &mut x.namespaces, &errors::namespace_name_is_already_in_use, ), TokenKind::Type => do_check( self, false, &|x: &mut UsedNames| &mut x.classes, &errors::type_name_is_already_in_use, ), TokenKind::Function => do_check( self, true, &|x: &mut UsedNames| &mut x.functions, &errors::function_name_is_already_in_use, ), TokenKind::Const => do_check( self, true, &|x: &mut UsedNames| &mut x.constants, &errors::const_name_is_already_in_use, ), _ => {} }, Missing => { if name_text == "strict" { self.errors .push(make_error_from_node(name, errors::strict_namespace_hh)) } let location = make_location_of_node(name); match self.names.classes.get(short_name) { Some(FirstUseOrDef { location: loc, name: def_name, kind, .. }) => { if &qualified_name != def_name || kind != &NameDef { let (line_num, _) = self.env.text.offset_to_position(loc.start_offset as isize); let err_msg = |x: &str, y: &str| -> Error { if kind != &NameDef { if kind == &NameImplicitUse { errors::name_is_already_in_use_implicit_hh( line_num, x, y, ) } else { errors::name_is_already_in_use_hh(line_num, x, y) } } else { errors::name_is_already_in_use_php(x, y) } }; self.errors.push(make_name_already_used_error( name, name_text, short_name, loc, &err_msg, )) } } None => { let new_use = make_first_use_or_def( false, NameUse, location, GLOBAL_NAMESPACE_NAME, &qualified_name, ); if !self.names.namespaces.mem(short_name) { self.names.namespaces.add(short_name, new_use.clone()); self.names.classes.add(short_name, new_use); } else { self.names.classes.add(short_name, new_use); } } } } _ => {} } } _ => {} } } fn namespace_use_declaration_errors(&mut self, node: S<'a>) { match &node.children { NamespaceUseDeclaration(x) => { syntax_to_list_no_separators(&x.clauses).for_each(|clause| { self.use_class_or_namespace_clause_errors(None, &x.kind, clause) }) } NamespaceGroupUseDeclaration(x) => { syntax_to_list_no_separators(&x.clauses).for_each(|clause| { match &clause.children { NamespaceUseClause(x) if !x.name.is_missing() => { self.check_preceding_backslashes_qualified_name(&x.name) } _ => {} } self.use_class_or_namespace_clause_errors( Some(self.text(&x.prefix)), &x.kind, clause, ) }) } _ => {} } } fn token_text(&self, token: &PositionedToken<'a>) -> &'a str { self.env.text.source_text().sub_as_str( token.leading_start_offset().unwrap() + token.leading_width(), token.width(), ) } fn check_constant_expression_ban_static(&mut self, node: S<'a>) { self.check_constant_expression(node, false) } fn check_constant_expression_allow_static(&mut self, node: S<'a>) { self.check_constant_expression(node, true) } /// Checks whether this expression is valid in a constant position, such as a property initializer. /// For example: /// /// ``` /// vec[vec["foo"]] // allowed /// UNSAFE_CAST<?int, int>(NULLABLE_CONST) // allowed /// foo() // not allowed /// ``` /// /// When `static_allowed` is true, late static bound accesses like `static::class` and /// `static::FOO` are considered constant. fn check_constant_expression(&mut self, node: S<'a>, static_allowed: bool) { // __FUNCTION_CREDENTIAL__ emits an object, // so it cannot be used in a constant expression let not_function_credential = |self_: &Self, token: &PositionedToken<'a>| { !self_ .token_text(token) .eq_ignore_ascii_case("__FUNCTION_CREDENTIAL__") }; let is_whitelisted_function = |self_: &Self, receiver_token| { let text = self_.text(receiver_token); (text == sn::std_lib_functions::ARRAY_MARK_LEGACY) || (text == strip_ns(sn::std_lib_functions::ARRAY_MARK_LEGACY)) || (text == sn::std_lib_functions::ARRAY_UNMARK_LEGACY) || (text == strip_ns(sn::std_lib_functions::ARRAY_UNMARK_LEGACY)) || (text == sn::pseudo_functions::UNSAFE_CAST) || (text == strip_ns(sn::pseudo_functions::UNSAFE_CAST)) || (text == sn::pseudo_functions::UNSAFE_NONNULL_CAST) || (text == strip_ns(sn::pseudo_functions::UNSAFE_NONNULL_CAST)) }; let is_namey = |self_: &Self, token: &PositionedToken<'a>| -> bool { token.kind() == TokenKind::Name && not_function_credential(self_, token) }; let is_good_scope_resolution_name = |node: S<'a>| match &node.children { QualifiedName(_) => true, Token(token) => { use TokenKind::*; match token.kind() { Name | Trait | Extends | Implements | Static | Abstract | Final | Private | Protected | Public | Global | Instanceof | Insteadof | Interface | Namespace | New | Try | Use | Var | List | Clone | Include | Include_once | Throw | Tuple | Print | Echo | Require | Require_once | Return | Else | Default | Break | Continue | Switch | Yield | Function | If | Finally | For | Foreach | Case | Do | While | As | Catch | Empty | Using | Class | NullLiteral | Super | Where => true, _ => false, } } _ => false, }; let default = |self_: &mut Self| { self_.errors.push(make_error_from_node( node, errors::invalid_constant_initializer, )) }; let check_type_specifier = |self_: &mut Self, x: S<'a>, initializer| { if let Token(token) = &x.children { if is_namey(self_, token) { return syntax_to_list_no_separators(initializer) .for_each(|x| self_.check_constant_expression(x, static_allowed)); } }; default(self_) }; let check_collection_members = |self_: &mut Self, x| { syntax_to_list_no_separators(x) .for_each(|x| self_.check_constant_expression(x, static_allowed)) }; match &node.children { Missing | QualifiedName(_) | LiteralExpression(_) => {} Token(token) => { if !is_namey(self, token) { default(self) } } PrefixUnaryExpression(x) => { if let Token(token) = &x.operator.children { use TokenKind::*; match token.kind() { Exclamation | Plus | Minus | Tilde => { self.check_constant_expression(&x.operand, static_allowed) } _ => default(self), } } else { default(self) } } UpcastExpression(x) => self.check_constant_expression(&x.left_operand, static_allowed), BinaryExpression(x) => { if let Token(token) = &x.operator.children { use TokenKind::*; match token.kind() { BarBar | AmpersandAmpersand | Carat | Bar | Ampersand | Dot | Plus | Minus | Star | Slash | Percent | LessThanLessThan | GreaterThanGreaterThan | StarStar | EqualEqual | EqualEqualEqual | ExclamationEqual | ExclamationEqualEqual | GreaterThan | GreaterThanEqual | LessThan | LessThanEqual | LessThanEqualGreaterThan | QuestionColon => { self.check_constant_expression(&x.left_operand, static_allowed); self.check_constant_expression(&x.right_operand, static_allowed); } _ => default(self), } } else { default(self) } } ConditionalExpression(x) => { self.check_constant_expression(&x.test, static_allowed); self.check_constant_expression(&x.consequence, static_allowed); self.check_constant_expression(&x.alternative, static_allowed); } SimpleInitializer(x) => { if let LiteralExpression(y) = &x.value.children { if let SyntaxList(_) = &y.expression.children { self.errors.push(make_error_from_node( node, errors::invalid_constant_initializer, )) } self.check_constant_expression(&x.value, static_allowed) } else { self.check_constant_expression(&x.value, static_allowed) } } ParenthesizedExpression(x) => { self.check_constant_expression(&x.expression, static_allowed) } CollectionLiteralExpression(x) => { if let SimpleTypeSpecifier(y) = &x.name.children { check_type_specifier(self, &y.specifier, &x.initializers) } else if let GenericTypeSpecifier(y) = &x.name.children { check_type_specifier(self, &y.class_type, &x.initializers) } else { default(self) }; } TupleExpression(x) => check_collection_members(self, &x.items), KeysetIntrinsicExpression(x) => check_collection_members(self, &x.members), VarrayIntrinsicExpression(x) => check_collection_members(self, &x.members), DarrayIntrinsicExpression(x) => check_collection_members(self, &x.members), VectorIntrinsicExpression(x) => check_collection_members(self, &x.members), DictionaryIntrinsicExpression(x) => check_collection_members(self, &x.members), ShapeExpression(x) => check_collection_members(self, &x.fields), ElementInitializer(x) => { self.check_constant_expression(&x.key, static_allowed); self.check_constant_expression(&x.value, static_allowed); } FieldInitializer(x) => { self.check_constant_expression(&x.name, static_allowed); self.check_constant_expression(&x.value, static_allowed); } // Allow `ClassName::foo` in a constant, but don't allow `parent::class` and // only allow `static::foo` when `static_allowed` is set. ScopeResolutionExpression(x) if is_good_scope_resolution_qualifier(&x.qualifier, static_allowed) && is_good_scope_resolution_name(&x.name) && !is_parent_class_access(&x.qualifier, &x.name) => {} FunctionCallExpression(x) => { let mut check_receiver_and_arguments = |receiver| { if is_whitelisted_function(self, receiver) { for node in syntax_to_list_no_separators(&x.argument_list) { self.check_constant_expression(node, static_allowed) } } else { default(self) } }; match &x.receiver.children { Token(tok) if tok.kind() == TokenKind::Name => { check_receiver_and_arguments(&x.receiver) } QualifiedName(_) => check_receiver_and_arguments(&x.receiver), _ => default(self), } } FunctionPointerExpression(_) => { // Bans the equivalent of inst_meth as well as class_meth and fun if self.env.parser_options.po_disallow_func_ptrs_in_constants { default(self) } } ObjectCreationExpression(_) => { // We allow "enum class" constants to be initialized via new. if !self.is_in_enum_class() { default(self); } } _ => default(self), } } fn const_decl_errors(&mut self, node: S<'a>) { if let ConstantDeclarator(cd) = &node.children { if self.constant_abstract_with_initializer(&cd.initializer) { self.check_can_use_feature(node, &UnstableFeatures::ClassConstDefault); } self.produce_error( |self_, x| self_.constant_concrete_without_initializer(x), &cd.initializer, || errors::error2050, &cd.initializer, ); self.check_constant_expression_ban_static(&cd.initializer); if !cd.name.is_missing() { let constant_name = self.text(&cd.name); let location = make_location_of_node(&cd.name); let def = make_first_use_or_def( false, NameDef, location, &self.namespace_name, constant_name, ); match ( self.names.constants.get(constant_name), self.first_parent_class_name(), ) { // Only error if this is inside a class (Some(_), Some(class_name)) => { let full_name = class_name.to_string() + "::" + constant_name; self.errors.push(make_error_from_node( node, errors::redeclaration_error(&full_name), )) } (Some(prev_def), None) if prev_def.kind != NameDef => { let (line_num, _) = self .env .text .offset_to_position(prev_def.location.start_offset as isize); let line_num = line_num as usize; self.errors.push(make_name_already_used_error( &cd.name, &combine_names(&self.namespace_name, constant_name), constant_name, &def.location, &|x, y| errors::declared_name_is_already_in_use(line_num, x, y), )) } _ => {} } self.names.constants.add(constant_name, def) } } } fn class_property_modifiers_errors(&mut self, node: S<'a>) { if let PropertyDeclaration(x) = &node.children { let property_modifiers = &x.modifiers; let abstract_static_props = self.env.parser_options.po_abstract_static_props; self.invalid_modifier_errors("Properties", node, |kind| { if kind == TokenKind::Abstract { return abstract_static_props; } kind == TokenKind::Static || kind == TokenKind::Private || kind == TokenKind::Protected || kind == TokenKind::Internal || kind == TokenKind::Public || kind == TokenKind::Readonly }); self.produce_error( |_, x| !syntax_to_list_no_separators(x).any(is_visibility), property_modifiers, || errors::property_requires_visibility, node, ); if self.env.parser_options.po_abstract_static_props { self.produce_error( |_, n| has_modifier_abstract(n) && !has_modifier_static(n), node, || errors::abstract_instance_property, node, ); } if has_modifier_abstract(node) && has_modifier_private(node) { self.errors.push(make_error_from_node( node, errors::elt_abstract_private("properties"), )); } } } fn class_property_const_errors(&mut self, node: S<'a>) { if let PropertyDeclaration(x) = &node.children { if self.attr_spec_contains_const(&x.attribute_spec) && self.attribute_specification_contains( &x.attribute_spec, sn::user_attributes::LATE_INIT, ) { // __LateInit together with const just doesn't make sense. self.errors .push(make_error_from_node(node, errors::no_const_late_init_props)) } } } fn class_property_declarator_errors(&mut self, node: S<'a>) { let check_decls = |self_: &mut Self, f: &dyn Fn(S<'a>) -> bool, error: errors::Error, property_declarators| { syntax_to_list_no_separators(property_declarators).for_each(|decl| { if let PropertyDeclarator(x) = &decl.children { if f(&x.initializer) { self_.errors.push(make_error_from_node(node, error.clone())) } } }) }; if let PropertyDeclaration(x) = &node.children { if self.env.parser_options.tco_const_static_props && has_modifier_static(node) { if self.env.parser_options.po_abstract_static_props && has_modifier_abstract(node) { check_decls( self, &|n| !n.is_missing(), errors::abstract_prop_init, &x.declarators, ) } else if self.attr_spec_contains_const(&x.attribute_spec) { check_decls( self, &|n| n.is_missing(), errors::const_static_prop_init, &x.declarators, ) } } } } fn mixed_namespace_errors(&mut self, node: S<'a>) { match &node.children { NamespaceBody(x) => { let s = start_offset(&x.left_brace); let e = end_offset(&x.right_brace); if let NamespaceType::Unbracketed(Location { start_offset, end_offset, }) = self.namespace_type { let child = Some(SyntaxError::make( start_offset, end_offset, errors::error2057, vec![], )); self.errors.push(SyntaxError::make_with_child_and_type( child, s, e, ErrorType::ParseError, errors::error2052, vec![], )) } } NamespaceEmptyBody(x) => { let s = start_offset(&x.semicolon); let e = end_offset(&x.semicolon); if let NamespaceType::Bracketed(Location { start_offset, end_offset, }) = self.namespace_type { let child = Some(SyntaxError::make( start_offset, end_offset, errors::error2056, vec![], )); self.errors.push(SyntaxError::make_with_child_and_type( child, s, e, ErrorType::ParseError, errors::error2052, vec![], )) } } NamespaceDeclaration(x) => { let mut is_first_decl = true; let mut has_code_outside_namespace = false; if let [ Syntax { children: Script(_), .. }, syntax_list, ] = self.parents.as_slice() { if let SyntaxList(_) = syntax_list.children { is_first_decl = false; for decl in syntax_to_list_no_separators(syntax_list) { match &decl.children { MarkupSection(_) => {} NamespaceUseDeclaration(_) | FileAttributeSpecification(_) | ModuleMembershipDeclaration(_) => {} NamespaceDeclaration(_) => { is_first_decl = true; break; } _ => break, } } has_code_outside_namespace = !(x.body.is_namespace_empty_body()) && syntax_to_list_no_separators(syntax_list).any(|decl| { match &decl.children { MarkupSection(_) => false, NamespaceDeclaration(_) | FileAttributeSpecification(_) | ModuleMembershipDeclaration(_) | EndOfFile(_) | NamespaceUseDeclaration(_) => false, _ => true, } }) } } if !is_first_decl { self.errors.push(make_error_from_node( node, errors::namespace_decl_first_statement, )) } if has_code_outside_namespace { self.errors .push(make_error_from_node(node, errors::code_outside_namespace)) } } _ => {} } } fn enumerator_errors(&mut self, node: S<'a>) { if let Enumerator(x) = &node.children { if self.text(&x.name).eq_ignore_ascii_case("class") { self.errors .push(make_error_from_node(node, errors::enum_elem_name_is_class)) } self.check_constant_expression_ban_static(&x.value); } } fn enum_decl_errors(&mut self, node: S<'a>) { if let EnumDeclaration(x) = &node.children { let attrs = &x.attribute_spec; self.check_attr_enabled(attrs); if self.attr_spec_contains_const(attrs) { self.errors.push(make_error_from_node( node, errors::no_const_interfaces_traits_enums, )) } self.invalid_modifier_errors("Enums", node, |kind| { kind == TokenKind::Internal || kind == TokenKind::Public }); if !x.name.is_missing() { let name = self.text(&x.name); let location = make_location_of_node(&x.name); self.check_use_type_name(&x.name, name, location); self.produce_error( |_, x| cant_be_reserved_type_name(x), name, || errors::reserved_keyword_as_type_name(name), &x.name, ); if x.base.is_missing() { // Create a zero width region to insert the new text. let quickfix_start = end_offset(&x.name); let quickfix_end = end_offset(&x.name); self.errors.push(make_error_from_node_with_quickfix( &x.name, errors::enum_missing_base_type, "Add `arraykey` base type", quickfix_start, quickfix_end, ": arraykey", )) } } } } /// Checks whether `loperand` is valid syntax to appear in the context represented by /// `lval_root`. This is meant to span any context in which we're mutating some value. See /// `LvalRoot` for an accounting of the different lvalue contexts in Hack. /// Notably, this includes `inout` expressions, which are lvalues by way of being assignment. fn check_lvalue_and_inout(&mut self, loperand: S<'a>, lval_root: LvalRoot) { let append_errors = |self_: &mut Self, node, error| self_.errors.push(make_error_from_node(node, error)); let err = |self_: &mut Self, error| append_errors(self_, loperand, error); let check_unary_expression = |self_: &mut Self, op| match token_kind(op) { Some(TokenKind::At) | Some(TokenKind::Dollar) => {} _ => err(self_, errors::not_allowed_in_write("Unary expression")), }; let check_variable = |self_: &mut Self, text| { if text == sn::special_idents::THIS { err(self_, errors::invalid_lval(lval_root)) } }; match &loperand.children { // There's some syntax that is never allowed as part of an `inout` expression, so we // match against it specially. // - `list( ... )` is nonsensical as the argument to an `inout` function; `inout` // expressions must be both valid lvalues *and* rvalues: `list( ... )` is only valid // as an lvalue. // - class member access (static or instance) is disallowed to avoid unexpected behavior // around ref-counting and dangling references to class members. MemberSelectionExpression(_) | ListExpression(_) | ScopeResolutionExpression(_) if lval_root == LvalRoot::Inout => { err(self, errors::fun_arg_invalid_arg) } ListExpression(x) => syntax_to_list_no_separators(&x.members) .for_each(|n| self.check_lvalue_and_inout(n, lval_root)), SafeMemberSelectionExpression(_) => { err(self, errors::not_allowed_in_write("`?->` operator")) } MemberSelectionExpression(x) => { if token_kind(&x.name) == Some(TokenKind::XHPClassName) { err(self, errors::not_allowed_in_write("`->:` operator")); } } CatchClause(x) => check_variable(self, self.text(&x.variable)), VariableExpression(x) => { let txt = self.text(&x.expression); check_variable(self, txt); if lval_root == LvalRoot::Inout && sn::superglobals::is_any_global(txt) { err(self, errors::fun_arg_invalid_arg); } } DecoratedExpression(x) => match token_kind(&x.decorator) { Some(TokenKind::Clone) => err(self, errors::not_allowed_in_write("`clone`")), Some(TokenKind::Await) => err(self, errors::not_allowed_in_write("`await`")), Some(TokenKind::QuestionQuestion) => { err(self, errors::not_allowed_in_write("`??` operator")) } Some(TokenKind::BarGreaterThan) => { err(self, errors::not_allowed_in_write("`|>` operator")) } Some(TokenKind::Inout) => err(self, errors::not_allowed_in_write("`inout`")), _ => {} }, ParenthesizedExpression(x) => self.check_lvalue_and_inout(&x.expression, lval_root), SubscriptExpression(x) => { self.check_lvalue_and_inout(&x.receiver, lval_root); if lval_root == LvalRoot::Inout && x.index.is_missing() { err(self, errors::fun_arg_invalid_arg); } } PrefixUnaryExpression(x) => check_unary_expression(self, &x.operator), PostfixUnaryExpression(x) => check_unary_expression(self, &x.operator), // Potentially un-intuitive; `missing` is perfectly valid in LHS positions, for example: // // list( , $_) = ...; // ^ this is "missing" // // $x[ ] = 42; // ^ this is "missing", though we don't end up scanning for it in this function Missing => {} // A scope resolution expression is a valid lvalue if we're referencing a static // variable, otherwise it's nonsense. ScopeResolutionExpression(e) => { // Foo::$bar = ...; // OK, as this is a static member assignment if Some(TokenKind::Variable) == token_kind(&e.name) { return; } // Foo::{_} = ...; // OK, as this is some form of static member assignment. if let BracedExpression(_) = e.name.children { return; } // Foo::BAR = ...; // Not OK, this is an assignment to a constant err(self, errors::invalid_lval(lval_root)) } _ => err(self, errors::invalid_lval(lval_root)), } } fn assignment_errors(&mut self, node: S<'a>) { let check_unary_expression = |self_: &mut Self, op, loperand: S<'a>| { if does_unop_create_write(token_kind(op)) { self_.check_lvalue_and_inout(loperand, LvalRoot::IncrementOrDecrement); } }; match &node.children { PrefixUnaryExpression(x) => check_unary_expression(self, &x.operator, &x.operand), PostfixUnaryExpression(x) => check_unary_expression(self, &x.operator, &x.operand), DecoratedExpression(x) => { let loperand = &x.expression; if does_decorator_create_write(token_kind(&x.decorator)) { self.check_lvalue_and_inout(loperand, LvalRoot::Inout) } } BinaryExpression(x) => { let loperand = &x.left_operand; if does_binop_create_write_on_left(token_kind(&x.operator)) { self.check_lvalue_and_inout(loperand, LvalRoot::Assignment); } } ForeachStatement(x) => { self.check_lvalue_and_inout(&x.value, LvalRoot::Foreach); self.check_lvalue_and_inout(&x.key, LvalRoot::Foreach); } CatchClause(_) => { self.check_lvalue_and_inout(node, LvalRoot::CatchClause); } _ => {} } } fn dynamic_method_call_errors(&mut self, node: S<'a>) { match &node.children { FunctionCallExpression(x) if !x.type_args.is_missing() => { let is_variable = |x| is_token_kind(x, TokenKind::Variable); let is_dynamic = match &x.receiver.children { ScopeResolutionExpression(x) => is_variable(&x.name), MemberSelectionExpression(x) => is_variable(&x.name), SafeMemberSelectionExpression(x) => is_variable(&x.name), _ => false, }; if is_dynamic { self.errors.push(make_error_from_node( node, errors::no_type_parameters_on_dynamic_method_calls, )) } } _ => {} } } fn get_namespace_name(&self) -> String { if let Some(node) = self.nested_namespaces.last() { if let NamespaceDeclaration(x) = &node.children { if let NamespaceDeclarationHeader(x) = &x.header.children { let ns = &x.name; if !ns.is_missing() { return combine_names(&self.namespace_name, self.text(ns)); } } } } self.namespace_name.clone() } fn disabled_legacy_soft_typehint_errors(&mut self, node: S<'a>) { if let SoftTypeSpecifier(_) = node.children { if self.env.parser_options.po_disable_legacy_soft_typehints { self.errors .push(make_error_from_node(node, errors::no_legacy_soft_typehints)) } } } fn disabled_legacy_attribute_syntax_errors(&mut self, node: S<'a>) { match node.children { OldAttributeSpecification(_) if self.env.parser_options.po_disable_legacy_attribute_syntax => { self.errors.push(make_error_from_node( node, errors::no_legacy_attribute_syntax, )) } _ => {} } } fn param_default_decl_errors(&mut self, node: S<'a>) { if let ParameterDeclaration(x) = &node.children { if self.env.parser_options.po_const_default_lambda_args { match self.env.context.active_callable { Some(node) => match node.children { AnonymousFunction(_) | LambdaExpression(_) => { self.check_constant_expression_ban_static(&x.default_value); } _ => {} }, _ => {} } } if self.env.parser_options.po_const_default_func_args { self.check_constant_expression( &x.default_value, // `static` in constant !self .env .parser_options .po_disallow_static_constants_in_default_func_args, ) } } } fn concurrent_statement_errors(&mut self, node: S<'a>) { if let ConcurrentStatement(x) = &node.children { // issue error if concurrent blocks are nested if self.is_in_concurrent_block { self.errors .push(make_error_from_node(node, errors::nested_concurrent_blocks)) }; if let CompoundStatement(x) = &x.statement.children { let statement_list = || syntax_to_list_no_separators(&x.statements); if statement_list().nth(1).is_none() { self.errors.push(make_error_from_node( node, errors::fewer_than_two_statements_in_concurrent_block, )) } for n in statement_list() { if let ExpressionStatement(x) = &n.children { if !self.node_has_await_child(&x.expression) { self.errors.push(make_error_from_node( n, errors::statement_without_await_in_concurrent_block, )) } } else if let DeclareLocalStatement(x) = &n.children { if !self.node_has_await_child(&x.initializer) && !x.initializer.is_missing() { self.errors.push(make_error_from_node( n, errors::statement_without_await_in_concurrent_block, )) } } else { self.errors.push(make_error_from_node( n, errors::invalid_syntax_concurrent_block, )) } } for n in statement_list() { for error in self.find_invalid_lval_usage(n) { self.errors.push(error) } } } else { self.errors.push(make_error_from_node( node, errors::invalid_syntax_concurrent_block, )) } } } fn check_qualified_name(&mut self, node: S<'a>) { // The last segment in a qualified name should not have a trailing backslash // i.e. `Foospace\Bar\` except as the prefix of a GroupUseClause if let Some(Syntax { children: NamespaceGroupUseDeclaration(_), .. }) = self.parents.last() { // Ok } else if let QualifiedName(x) = &node.children { let name_parts = &x.parts; let mut parts = syntax_to_list_with_separators(name_parts); let last_part = parts.nth_back(0); match last_part { Some(t) if token_kind(t) == Some(TokenKind::Backslash) => { self.errors.push(make_error_from_node(t, errors::error0008)) } _ => {} } } } fn check_preceding_backslashes_qualified_name(&mut self, node: S<'a>) { // Qualified names as part of file level declarations // (group use, namespace use, namespace declarations) should not have preceding backslashes // `use namespace A\{\B}` will throw this error. if let QualifiedName(x) = &node.children { let name_parts = &x.parts; let mut parts = syntax_to_list_with_separators(name_parts); let first_part = parts.find(|x| !x.is_missing()); match first_part { Some(t) if token_kind(t) == Some(TokenKind::Backslash) => self .errors .push(make_error_from_node(node, errors::preceding_backslash)), _ => {} } } } fn is_global_namespace(&self) -> bool { self.namespace_name == GLOBAL_NAMESPACE_NAME } fn folder(&mut self, node: S<'a>) { let mut prev_context = None; let mut pushed_nested_namespace = false; match &node.children { ConstDeclaration(_) => { prev_context = Some(self.env.context.clone()); self.env.context.active_const = Some(node) } FunctionDeclaration(x) => { self.named_function_context(node, &x.attribute_spec, &mut prev_context) } MethodishDeclaration(x) => { self.named_function_context(node, &x.attribute, &mut prev_context) } NamespaceDeclaration(x) => { if let NamespaceDeclarationHeader(x) = &x.header.children { let namespace_name = &x.name; if !namespace_name.is_missing() && !self.text(namespace_name).is_empty() { pushed_nested_namespace = true; self.nested_namespaces.push(node) } } } AnonymousFunction(x) => self.lambda_context(node, &x.attribute_spec, &mut prev_context), LambdaExpression(x) => self.lambda_context(node, &x.attribute_spec, &mut prev_context), AwaitableCreationExpression(x) => { self.lambda_context(node, &x.attribute_spec, &mut prev_context) } ClassishDeclaration(_) => { prev_context = Some(self.env.context.clone()); self.env.context.active_classish = Some(node) } TypeRefinement(_) => { self.type_refinement_errors(node); } FileAttributeSpecification(_) => self.file_attribute_spec(node), ModuleDeclaration(x) => { if !x.exports.is_missing() || !x.imports.is_missing() { self.check_can_use_feature(node, &UnstableFeatures::ModuleReferences); } } ModuleMembershipDeclaration(_) => { self.in_module = true; } _ => {} }; self.parameter_errors(node); match &node.children { TryStatement(_) | UsingStatementFunctionScoped(_) | ForStatement(_) | CaseLabel(_) | DefaultLabel(_) => self.statement_errors(node), MethodishDeclaration(_) | FunctionDeclaration(_) | FunctionDeclarationHeader(_) => { self.reified_parameter_errors(node); self.redeclaration_errors(node); self.multiple_entrypoint_attribute_errors(node); self.methodish_errors(node); } LiteralExpression(_) | SafeMemberSelectionExpression(_) | FunctionCallExpression(_) | ListExpression(_) | ShapeExpression(_) | DecoratedExpression(_) | VectorIntrinsicExpression(_) | DictionaryIntrinsicExpression(_) | KeysetIntrinsicExpression(_) | VarrayIntrinsicExpression(_) | DarrayIntrinsicExpression(_) | YieldExpression(_) | ScopeResolutionExpression(_) | PrefixUnaryExpression(_) | LambdaExpression(_) | IsExpression(_) | AsExpression(_) | AnonymousFunction(_) | SubscriptExpression(_) | ConstructorCall(_) | AwaitableCreationExpression(_) | PipeVariableExpression(_) | ConditionalExpression(_) | CollectionLiteralExpression(_) | VariableExpression(_) => { self.check_disallowed_variables(node); self.dynamic_method_call_errors(node); self.expression_errors(node); self.assignment_errors(node); } ParameterDeclaration(_) => self.param_default_decl_errors(node), RequireClause(_) => self.require_errors(node), ClassishDeclaration(_) => { self.classish_errors(node); self.class_reified_param_errors(node); } EnumClassDeclaration(_) => { self.enum_class_errors(node); } EnumClassEnumerator(_) => self.enum_class_enumerator_errors(node), ConstDeclaration(_) => self.class_constant_modifier_errors(node), TypeConstDeclaration(_) => { self.type_const_modifier_errors(node); self.type_const_bounds_errors(node); } AliasDeclaration(_) | ContextAliasDeclaration(_) | CaseTypeDeclaration(_) => { self.alias_errors(node) } CaseTypeVariant(_) => self.case_type_variant_errors(node), ConstantDeclarator(_) => self.const_decl_errors(node), NamespaceBody(_) | NamespaceEmptyBody(_) | NamespaceDeclaration(_) => { self.mixed_namespace_errors(node) } NamespaceUseDeclaration(_) | NamespaceGroupUseDeclaration(_) => { self.group_use_errors(node); self.namespace_use_declaration_errors(node); } PropertyDeclaration(_) => { self.class_property_modifiers_errors(node); self.class_reified_param_errors(node); self.class_property_const_errors(node); self.class_property_declarator_errors(node); } EnumDeclaration(_) => self.enum_decl_errors(node), Enumerator(_) => self.enumerator_errors(node), PostfixUnaryExpression(_) | BinaryExpression(_) | ForeachStatement(_) | CatchClause(_) => self.assignment_errors(node), XHPEnumType(_) | XHPExpression(_) => self.xhp_errors(node), PropertyDeclarator(x) => self.check_constant_expression_ban_static(&x.initializer), XHPClassAttribute(x) => { // TODO(hgoldstein) I suspect that this is a bug: why would we // allow `static::_` in XHP properties but not in normal class // properties ... self.check_constant_expression_allow_static(&x.initializer); } OldAttributeSpecification(_) => self.disabled_legacy_attribute_syntax_errors(node), SoftTypeSpecifier(_) => self.disabled_legacy_soft_typehint_errors(node), QualifiedName(_) => self.check_qualified_name(node), UnsetStatement(x) => { for expr in syntax_to_list_no_separators(&x.variables) { self.check_lvalue_and_inout(expr, LvalRoot::Unset); } } DeclareLocalStatement(x) => { if self.text(&x.variable) == sn::special_idents::THIS { self.errors.push(make_error_from_node( node, Cow::Owned("You cannot declare $this as a typed local.".to_string()), )); } } PackageExpression(_) => { self.check_can_use_feature(node, &UnstableFeatures::Package); } _ => {} } self.lval_errors(node); match &node.children { // todo: lambda LambdaExpression(_) | AwaitableCreationExpression(_) | AnonymousFunction(_) => { self.lambda(node) } ConcurrentStatement(_) => self.concurrent_stmt(node), NamespaceBody(x) => self.namespace_body(node, &x.left_brace, &x.right_brace), NamespaceEmptyBody(x) => self.namespace_empty_body(node, &x.semicolon), ClassishDeclaration(_) | AnonymousClass(_) => self.classes(node), PrefixedCodeExpression(_) => self.prefixed_code_expr(node, &mut prev_context), ETSpliceExpression(_) => self.et_splice_expr(node), _ => self.fold_child_nodes(node), } match &node.children { UnionTypeSpecifier(_) | IntersectionTypeSpecifier(_) => { self.check_can_use_feature(node, &UnstableFeatures::UnionIntersectionTypeHints) } DeclareLocalStatement(_) => { self.check_can_use_feature(node, &UnstableFeatures::TypedLocalVariables) } ClassishDeclaration(x) => match &x.where_clause.children { WhereClause(_) => { self.check_can_use_feature(&x.where_clause, &UnstableFeatures::ClassLevelWhere) } _ => {} }, UpcastExpression(_) => { self.check_can_use_feature(node, &UnstableFeatures::UpcastExpression) } OldAttributeSpecification(x) => { self.old_attr_spec(node, &x.attributes); } MatchStatement(_) => { self.check_can_use_feature(node, &UnstableFeatures::MatchStatements); } _ => {} } if let Some(prev_context) = prev_context { self.env.context = prev_context; } if pushed_nested_namespace { self.check_nested_namespace(node); } } fn file_attribute_spec(&mut self, node: S<'a>) { for node in attr_spec_to_node_list(node) { match self.attr_name(node) { Some(sn::user_attributes::ENABLE_UNSTABLE_FEATURES) => { if let Some(args) = self.attr_args(node) { let mut args = args.peekable(); if args.peek().is_none() { self.errors.push(make_error_from_node( node, errors::invalid_use_of_enable_unstable_feature( format!( "you didn't select a feature. Available features are:\n\t{}", UnstableFeatures::iter().join("\n\t") ) .as_str(), ), )) } else { args.for_each(|arg| self.enable_unstable_feature(node, arg)) } } } Some(_) | None => {} } } } fn named_function_context( &mut self, node: S<'a>, s: S<'a>, prev_context: &mut Option<Context<'a>>, ) { *prev_context = Some(self.env.context.clone()); // a _single_ variable suffices as they cannot be nested self.env.context.active_methodish = Some(node); self.env.context.active_callable = Some(node); self.env.context.active_callable_attr_spec = Some(s); } fn lambda_context(&mut self, node: S<'a>, s: S<'a>, prev_context: &mut Option<Context<'a>>) { *prev_context = Some(self.env.context.clone()); // preserve context when entering lambdas (and anonymous functions) self.env.context.active_callable = Some(node); self.env.context.active_callable_attr_spec = Some(s); } fn lambda(&mut self, node: S<'a>) { let prev_is_in_concurrent_block = self.is_in_concurrent_block; // reset is_in_concurrent_block for functions self.is_in_concurrent_block = false; // analyze the body of lambda block self.fold_child_nodes(node); // adjust is_in_concurrent_block in final result self.is_in_concurrent_block = prev_is_in_concurrent_block; } fn concurrent_stmt(&mut self, node: S<'a>) { self.concurrent_statement_errors(node); // adjust is_in_concurrent_block in accumulator to dive into the let prev_is_in_concurrent_block = self.is_in_concurrent_block; self.is_in_concurrent_block = true; // analyze the body of concurrent block self.fold_child_nodes(node); // adjust is_in_concurrent_block in final result self.is_in_concurrent_block = prev_is_in_concurrent_block; } fn namespace_body(&mut self, node: S<'a>, left_brace: S<'a>, right_brace: S<'a>) { if self.namespace_type == Unspecified { self.namespace_type = Bracketed(make_location(left_brace, right_brace)) } let old_namespace_name = self.namespace_name.clone(); let old_names = self.names.clone(); // reset names before diving into namespace body, // keeping global function names self.namespace_name = self.get_namespace_name(); let names_copy = std::mem::replace(&mut self.names, UsedNames::empty()); self.names.functions = names_copy.functions.filter(|x| x.global); self.fold_child_nodes(node); // resume with old set of names and pull back // accumulated errors/last seen namespace type self.names = old_names; self.namespace_name = old_namespace_name; } fn namespace_empty_body(&mut self, node: S<'a>, semi: S<'a>) { if self.namespace_type == Unspecified { self.namespace_type = Unbracketed(make_location_of_node(semi)) } self.namespace_name = self.get_namespace_name(); self.names = UsedNames::empty(); self.fold_child_nodes(node); } fn classes(&mut self, node: S<'a>) { // Reset the trait require clauses // Reset the const declarations // Reset the function declarations let constants = std::mem::replace(&mut self.names.constants, YesCase(HashMap::default())); let functions = std::mem::replace(&mut self.names.functions, NoCase(HashMap::default())); let trait_require_clauses = std::mem::replace( &mut self.trait_require_clauses, empty_trait_require_clauses(), ); self.fold_child_nodes(node); self.trait_require_clauses = trait_require_clauses; self.names.functions = functions; self.names.constants = constants; } fn prefixed_code_expr(&mut self, node: S<'a>, prev_context: &mut Option<Context<'a>>) { *prev_context = Some(self.env.context.clone()); self.env.context.active_expression_tree = true; self.fold_child_nodes(node) } fn et_splice_expr(&mut self, node: S<'a>) { let previous_state = self.env.context.active_expression_tree; self.env.context.active_expression_tree = false; self.fold_child_nodes(node); self.env.context.active_expression_tree = previous_state; } fn old_attr_spec(&mut self, node: S<'a>, attributes: S<'a>) { let attributes = self.text(attributes).split(','); attributes.for_each(|attr| match attr.trim() { sn::user_attributes::MODULE_LEVEL_TRAIT => { self.check_can_use_feature(node, &UnstableFeatures::ModuleLevelTraits) } _ => {} }); } fn check_nested_namespace(&mut self, node: S<'a>) { assert_eq!( self.nested_namespaces.pop().map(|x| x as *const _), Some(node as *const _) ); } fn fold_child_nodes(&mut self, node: S<'a>) { stack_limit::maybe_grow(|| { self.parents.push(node); for c in node.iter_children() { self.folder(c); } assert_eq!( self.parents.pop().map(|x| x as *const _), Some(node as *const _) ); }) } fn parse_errors_impl(mut self) -> (Vec<SyntaxError>, bool) { self.fold_child_nodes(self.env.syntax_tree.root()); self.errors.reverse(); (self.errors, self.uses_readonly) } fn parse_errors( tree: &'a SyntaxTree<'a, Syntax<'a, PositionedToken<'a>, PositionedValue<'a>>, State>, text: IndexedSourceText<'a>, parser_options: ParserOptions, hhvm_compat_mode: bool, hhi_mode: bool, codegen: bool, systemlib: bool, default_unstable_features: HashSet<UnstableFeatures>, ) -> (Vec<SyntaxError>, bool) { let env = Env { parser_options, syntax_tree: tree, text, context: Context { active_classish: None, active_methodish: None, active_callable: None, active_callable_attr_spec: None, active_const: None, active_unstable_features: default_unstable_features, active_expression_tree: false, }, hhvm_compat_mode, hhi_mode, codegen, systemlib, }; Self::new(env).parse_errors_impl() } } pub fn parse_errors<'a, State: Clone>( tree: &'a SyntaxTree<'a, PositionedSyntax<'a>, State>, parser_options: ParserOptions, hhvm_compat_mode: bool, hhi_mode: bool, codegen: bool, systemlib: bool, default_unstable_features: HashSet<UnstableFeatures>, ) -> (Vec<SyntaxError>, bool) { <ParserErrors<'a, State>>::parse_errors( tree, IndexedSourceText::new(tree.text().clone()), parser_options, hhvm_compat_mode, hhi_mode, codegen, systemlib, default_unstable_features, ) } pub fn parse_errors_with_text<'a, State: Clone>( tree: &'a SyntaxTree<'a, PositionedSyntax<'a>, State>, text: IndexedSourceText<'a>, parser_options: ParserOptions, hhvm_compat_mode: bool, hhi_mode: bool, codegen: bool, systemlib: bool, default_unstable_features: HashSet<UnstableFeatures>, ) -> (Vec<SyntaxError>, bool) { <ParserErrors<'a, State>>::parse_errors( tree, text, parser_options, hhvm_compat_mode, hhi_mode, codegen, systemlib, default_unstable_features, ) }
OCaml
hhvm/hphp/hack/src/parser/rust_parser_ffi.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) module SourceText = Full_fidelity_source_text module SyntaxError = Full_fidelity_syntax_error module Env = Full_fidelity_parser_env module PositionedSyntax = Full_fidelity_positioned_syntax external parse_mode : SourceText.t -> FileInfo.mode option = "rust_parse_mode" type ('a, 'b) result = 'a * 'b * SyntaxError.t list * Rust_pointer.t option external parse_positioned : SourceText.t -> Env.t -> (unit, PositionedSyntax.t) result = "parse_positioned_by_ref" let parse_positioned text env = parse_positioned text env let init () = Full_fidelity_positioned_syntax.rust_parse_ref := parse_positioned; ()
Rust
hhvm/hphp/hack/src/parser/rust_parser_ffi.rs
// Copyright (c) 2019, Facebook, Inc. // All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use bumpalo::Bump; use mode_parser::parse_mode; use ocamlrep::ptr::UnsafeOcamlPtr; use ocamlrep::Allocator; use ocamlrep::FromOcamlRep; use ocamlrep::ToOcamlRep; use ocamlrep_ocamlpool::ocaml_ffi; use ocamlrep_ocamlpool::to_ocaml; use ocamlrep_ocamlpool::Pool; use operator::Assoc; use operator::Operator; use oxidized::file_info; use oxidized::full_fidelity_parser_env::FullFidelityParserEnv; use parser_core_types::parser_env::ParserEnv; use parser_core_types::source_text::SourceText; use parser_core_types::syntax_by_ref::positioned_trivia::PositionedTrivia; use parser_core_types::syntax_error::SyntaxError; use parser_core_types::syntax_tree::SyntaxTree; use parser_core_types::token_kind::TokenKind; use to_ocaml_impl::*; pub fn parse<'a, ParseFn, Node, State>( ocaml_source_text_ptr: UnsafeOcamlPtr, env: FullFidelityParserEnv, parse_fn: ParseFn, ) -> UnsafeOcamlPtr where ParseFn: Fn(&'a Bump, &SourceText<'a>, ParserEnv) -> (Node, Vec<SyntaxError>, State) + Clone + Send + Sync + std::panic::UnwindSafe + std::panic::RefUnwindSafe + 'static, Node: ToOcaml + 'a, State: ToOcamlRep + 'a, { let ocaml_source_text = ocaml_source_text_ptr.as_usize(); let leak_rust_tree = env.leak_rust_tree; let env = ParserEnv::from(env); // Safety: Requires no concurrent interaction with OCaml runtime // from other threads. let pool = unsafe { Pool::new() }; let arena = Bump::new(); // Safety: Similarly, the arena just needs to outlive the returned // Node and State (which may reference it). We ensure this by // not destroying the arena until after converting the node and // state to OCaml values. let arena_ref: &'a Bump = unsafe { (&arena as *const Bump).as_ref().unwrap() }; // We only convert the source text from OCaml in this innermost // closure because it contains an Rc. If we converted it // earlier, we'd need to pass it across an unwind boundary or // send it between threads, but it has internal mutablility and // is not Send. let source_text = unsafe { SourceText::from_ocaml(ocaml_source_text).unwrap() }; let (root, errors, state) = parse_fn(arena_ref, &source_text, env); // traversing the parsed syntax tree uses about 1/3 of the stack let ocaml_root = root.to_ocaml(&pool, ocaml_source_text_ptr).to_bits(); let ocaml_errors = pool.add(&errors).to_bits(); let ocaml_state = pool.add(&state).to_bits(); let tree = if leak_rust_tree { let (_, mode) = parse_mode(&source_text); let tree = Box::new(SyntaxTree::build( &source_text, root, errors, mode.map(Into::into), (), )); // A rust pointer of (&SyntaxTree, &Arena) is passed to Ocaml, // Ocaml will pass it back to `rust_parser_errors::rust_parser_errors_positioned` // PLEASE ENSURE TYPE SAFETY MANUALLY!!! let tree = Box::leak(tree) as *const SyntaxTree<'_, _, ()> as usize; let arena = Box::leak(Box::new(arena)) as *const Bump as usize; Some(Box::leak(Box::new((tree, arena))) as *const (usize, usize) as usize) } else { None }; let ocaml_tree = pool.add(&tree); let mut res = pool.block_with_size(4); // SAFETY: The to_bits/from_bits dance works around a lifetime issue: // we're not allowed to drop `root`, `errors`, or `state` while the // `Pool` is in scope (because otherwise, its memoization behavior would // work incorrectly in `ocamlrep::Allocator::add_root`). We are moving // those values, but since we're not using `add_root` here, it should be // okay. pool.set_field(&mut res, 0, unsafe { ocamlrep::Value::from_bits(ocaml_state) }); pool.set_field(&mut res, 1, unsafe { ocamlrep::Value::from_bits(ocaml_root) }); pool.set_field(&mut res, 2, unsafe { ocamlrep::Value::from_bits(ocaml_errors) }); pool.set_field(&mut res, 3, ocaml_tree); // Safety: The UnsafeOcamlPtr must point to the first field in // the block. It must be handed back to OCaml before the garbage // collector is given an opportunity to run. unsafe { UnsafeOcamlPtr::new(res.build().to_bits()) } } pub fn scan_trivia<'a, F>( source_text: SourceText<'a>, offset: usize, width: usize, f: F, ) -> UnsafeOcamlPtr where F: for<'b> Fn(&'b Bump, &'b SourceText<'b>, usize, usize) -> PositionedTrivia<'b>, { let arena = Bump::new(); let r = f(&arena, &source_text, offset, width); unsafe { UnsafeOcamlPtr::new(to_ocaml(r.as_slice())) } } ocaml_ffi! { fn rust_parse_mode(source_text: SourceText<'_>) -> Option<file_info::Mode> { let (_, mode) = parse_mode(&source_text); mode.map(Into::into) } fn scan_leading_xhp_trivia( source_text: SourceText<'_>, offset: usize, width: usize, ) -> UnsafeOcamlPtr { scan_trivia( source_text, offset, width, positioned_by_ref_parser::scan_leading_xhp_trivia, ) } fn scan_trailing_xhp_trivia( source_text: SourceText<'_>, offset: usize, width: usize, ) -> UnsafeOcamlPtr { scan_trivia( source_text, offset, width, positioned_by_ref_parser::scan_trailing_xhp_trivia, ) } fn scan_leading_php_trivia( source_text: SourceText<'_>, offset: usize, width: usize, ) -> UnsafeOcamlPtr { scan_trivia( source_text, offset, width, positioned_by_ref_parser::scan_leading_php_trivia, ) } fn scan_trailing_php_trivia( source_text: SourceText<'_>, offset: usize, width: usize, ) -> UnsafeOcamlPtr { scan_trivia( source_text, offset, width, positioned_by_ref_parser::scan_trailing_php_trivia, ) } fn trailing_from_token(token: TokenKind) -> Operator { Operator::trailing_from_token(token) } fn prefix_unary_from_token(token: TokenKind) -> Operator { Operator::prefix_unary_from_token(token) } fn is_trailing_operator_token(token: TokenKind) -> bool { Operator::is_trailing_operator_token(token) } fn is_binary_operator_token(token: TokenKind) -> bool { Operator::is_binary_operator_token(token) } fn is_comparison(op: Operator) -> bool { op.is_comparison() } fn is_assignment(op: Operator) -> bool { op.is_assignment() } fn rust_precedence_helper(op: Operator) -> usize { // NOTE: ParserEnv is not used in operator::precedence(), so we just create an empty ParserEnv // If operator::precedence() starts using ParserEnv, this function and the callsites in OCaml must be updated use parser_core_types::parser_env::ParserEnv; op.precedence(&ParserEnv::default()) } fn rust_precedence_for_assignment_in_expressions_helper() -> usize { Operator::precedence_for_assignment_in_expressions() } fn rust_associativity_helper(op: Operator) -> Assoc { // NOTE: ParserEnv is not used in operator::associativity(), so we just create an empty ParserEnv // If operator::associativity() starts using ParserEnv, this function and the callsites in OCaml must be updated use parser_core_types::parser_env::ParserEnv; op.associativity(&ParserEnv::default()) } }
OCaml
hhvm/hphp/hack/src/parser/rust_pointer.ml
(* * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) open Sexplib.Std type t = int option [@@deriving show, sexp_of] external drop_tree_positioned : t -> unit = "drop_tree_positioned" let leaked_pointer = ref None let free_leaked_pointer ?(warn = true) () = match !leaked_pointer with | Some pointer -> leaked_pointer := None; if warn then Hh_logger.log "Warning: freeing leaked Rust pointer"; drop_tree_positioned pointer | None -> () let register_leaked_pointer pointer = begin match !leaked_pointer with | Some pointer -> leaked_pointer := None; Hh_logger.log "Warning: leaking second Rust pointer before using first one"; drop_tree_positioned pointer | None -> () end; leaked_pointer := Some pointer let unregister_leaked_pointer pointer = begin match !leaked_pointer with | Some p when p != pointer -> leaked_pointer := None; Hh_logger.log "Warning: unregistering pointer that was not leaked before"; drop_tree_positioned pointer | _ -> () end; leaked_pointer := None
OCaml Interface
hhvm/hphp/hack/src/parser/rust_pointer.mli
(* * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) type t [@@deriving show, sexp_of] (* Assumptions: * - the only pointers we leak are pointers to positioned syntax trees * - we only leak one pointer at a time, calling register_leaked_pointer() immediately * after, and unregister_leaked_pointer() immediately before passing it back to * Rust function that will consume it * * This is meant as a temporary safeguard against memory leaks stemming from FFI * until entire parser (parser + error checker + lowerer) are in Rust. *) val free_leaked_pointer : ?warn:bool -> unit -> unit val register_leaked_pointer : t -> unit val unregister_leaked_pointer : t -> unit
OCaml
hhvm/hphp/hack/src/parser/scoured_comments.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) open Hh_prelude type fixmes = Pos.t IMap.t IMap.t [@@deriving show, eq] type t = { sc_comments: (Pos.t * Prim_defs.comment) list; sc_fixmes: fixmes; sc_misuses: fixmes; sc_error_pos: Pos.t list; sc_bad_ignore_pos: Pos.t list; } [@@deriving show, eq] let get_fixme_pos (fixmes : fixmes) (pos : Pos.t) (code : int) : Pos.t option = let (line, _, _) = Pos.info_pos pos in Option.bind (IMap.find_opt line fixmes) ~f:(IMap.find_opt code)
Rust
hhvm/hphp/hack/src/parser/smart_constructors.rs
// Copyright (c) 2019, Facebook, Inc. // All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. pub mod smart_constructors_generated; pub mod smart_constructors_wrappers; use ocamlrep::FromOcamlRep; use ocamlrep::ToOcamlRep; use parser_core_types::lexable_token::LexableToken; use parser_core_types::syntax_by_ref::syntax::Syntax; use parser_core_types::syntax_by_ref::syntax_variant_generated::SyntaxVariant; use parser_core_types::syntax_kind::SyntaxKind; use parser_core_types::token_kind::TokenKind; pub use crate::smart_constructors_generated::*; pub use crate::smart_constructors_wrappers::*; #[derive(Clone, FromOcamlRep, ToOcamlRep)] pub struct NoState; // zero-overhead placeholder when there is no state pub trait NodeType { type Output; fn extract(self) -> Self::Output; fn is_missing(&self) -> bool; fn is_abstract(&self) -> bool; fn is_variable_expression(&self) -> bool; fn is_subscript_expression(&self) -> bool; fn is_member_selection_expression(&self) -> bool; fn is_scope_resolution_expression(&self) -> bool; fn is_object_creation_expression(&self) -> bool; fn is_qualified_name(&self) -> bool; fn is_safe_member_selection_expression(&self) -> bool; fn is_function_call_expression(&self) -> bool; fn is_list_expression(&self) -> bool; fn is_name(&self) -> bool; fn is_prefix_unary_expression(&self) -> bool; } impl<R> NodeType for (SyntaxKind, R) { type Output = R; fn extract(self) -> Self::Output { self.1 } fn is_missing(&self) -> bool { match self.0 { SyntaxKind::Missing => true, _ => false, } } fn is_abstract(&self) -> bool { match &self.0 { SyntaxKind::Token(TokenKind::Abstract) => true, _ => false, } } fn is_name(&self) -> bool { match &self.0 { SyntaxKind::Token(TokenKind::Name) => true, _ => false, } } // Note: we could generate ~150 methods like those below but most would be dead fn is_variable_expression(&self) -> bool { match &self.0 { SyntaxKind::VariableExpression { .. } => true, _ => false, } } fn is_subscript_expression(&self) -> bool { match &self.0 { SyntaxKind::SubscriptExpression { .. } => true, _ => false, } } fn is_member_selection_expression(&self) -> bool { match &self.0 { SyntaxKind::MemberSelectionExpression { .. } => true, _ => false, } } fn is_scope_resolution_expression(&self) -> bool { match &self.0 { SyntaxKind::ScopeResolutionExpression { .. } => true, _ => false, } } fn is_object_creation_expression(&self) -> bool { match &self.0 { SyntaxKind::ObjectCreationExpression { .. } => true, _ => false, } } fn is_qualified_name(&self) -> bool { match &self.0 { SyntaxKind::QualifiedName { .. } => true, _ => false, } } fn is_safe_member_selection_expression(&self) -> bool { match &self.0 { SyntaxKind::SafeMemberSelectionExpression { .. } => true, _ => false, } } fn is_function_call_expression(&self) -> bool { match &self.0 { SyntaxKind::FunctionCallExpression { .. } => true, _ => false, } } fn is_list_expression(&self) -> bool { match &self.0 { SyntaxKind::ListExpression { .. } => true, _ => false, } } fn is_prefix_unary_expression(&self) -> bool { match &self.0 { SyntaxKind::PrefixUnaryExpression { .. } => true, _ => false, } } } impl<'a, T: LexableToken, V> NodeType for Syntax<'a, T, V> { type Output = Self; fn extract(self) -> Self::Output { self } fn is_missing(&self) -> bool { match self.children { SyntaxVariant::Missing => true, SyntaxVariant::SyntaxList(l) if l.is_empty() => true, _ => false, } } fn is_abstract(&self) -> bool { matches!(&self.children, SyntaxVariant::Token(t) if t.kind() == TokenKind::Abstract) } fn is_variable_expression(&self) -> bool { matches!(self.children, SyntaxVariant::VariableExpression { .. }) } fn is_subscript_expression(&self) -> bool { matches!(self.children, SyntaxVariant::SubscriptExpression { .. }) } fn is_member_selection_expression(&self) -> bool { matches!( self.children, SyntaxVariant::MemberSelectionExpression { .. } ) } fn is_scope_resolution_expression(&self) -> bool { matches!( self.children, SyntaxVariant::ScopeResolutionExpression { .. } ) } fn is_object_creation_expression(&self) -> bool { matches!( self.children, SyntaxVariant::ObjectCreationExpression { .. } ) } fn is_qualified_name(&self) -> bool { matches!(self.children, SyntaxVariant::QualifiedName { .. }) } fn is_safe_member_selection_expression(&self) -> bool { matches!( self.children, SyntaxVariant::SafeMemberSelectionExpression { .. } ) } fn is_function_call_expression(&self) -> bool { matches!(self.children, SyntaxVariant::FunctionCallExpression { .. }) } fn is_list_expression(&self) -> bool { matches!(self.children, SyntaxVariant::ListExpression { .. }) } fn is_name(&self) -> bool { matches!(&self.children, SyntaxVariant::Token(t) if t.kind() == TokenKind::Name) } fn is_prefix_unary_expression(&self) -> bool { matches!(self.children, SyntaxVariant::PrefixUnaryExpression { .. }) } }
Rust
hhvm/hphp/hack/src/parser/smart_constructors_generated.rs
/** * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. An additional * directory. * ** * * THIS FILE IS @generated; DO NOT EDIT IT * To regenerate this file, run * * buck run //hphp/hack/src:generate_full_fidelity * ** * */ use parser_core_types::token_factory::TokenFactory; use parser_core_types::lexable_token::LexableToken; pub type Token<S> = <<S as SmartConstructors>::Factory as TokenFactory>::Token; pub type Trivia<S> = <Token<S> as LexableToken>::Trivia; pub trait SmartConstructors: Clone { type Factory: TokenFactory; type State; type Output; fn state_mut(&mut self) -> &mut Self::State; fn into_state(self) -> Self::State; fn token_factory_mut(&mut self) -> &mut Self::Factory; fn make_missing(&mut self, offset : usize) -> Self::Output; fn make_token(&mut self, arg0: Token<Self>) -> Self::Output; fn make_list(&mut self, arg0: Vec<Self::Output>, offset: usize) -> Self::Output; fn begin_enumerator(&mut self) {} fn begin_enum_class_enumerator(&mut self) {} fn begin_constant_declarator(&mut self) {} fn make_end_of_file(&mut self, arg0: Self::Output) -> Self::Output; fn make_script(&mut self, arg0: Self::Output) -> Self::Output; fn make_qualified_name(&mut self, arg0: Self::Output) -> Self::Output; fn make_module_name(&mut self, arg0: Self::Output) -> Self::Output; fn make_simple_type_specifier(&mut self, arg0: Self::Output) -> Self::Output; fn make_literal_expression(&mut self, arg0: Self::Output) -> Self::Output; fn make_prefixed_string_expression(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_prefixed_code_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_variable_expression(&mut self, arg0: Self::Output) -> Self::Output; fn make_pipe_variable_expression(&mut self, arg0: Self::Output) -> Self::Output; fn make_file_attribute_specification(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_enum_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output, arg9: Self::Output, arg10: Self::Output) -> Self::Output; fn make_enum_use(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_enumerator(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_enum_class_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output, arg9: Self::Output, arg10: Self::Output, arg11: Self::Output) -> Self::Output; fn make_enum_class_enumerator(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_alias_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output, arg9: Self::Output) -> Self::Output; fn make_context_alias_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output) -> Self::Output; fn make_case_type_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output, arg9: Self::Output, arg10: Self::Output) -> Self::Output; fn make_case_type_variant(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_property_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_property_declarator(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_namespace_declaration(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_namespace_declaration_header(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_namespace_body(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_namespace_empty_body(&mut self, arg0: Self::Output) -> Self::Output; fn make_namespace_use_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_namespace_group_use_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output) -> Self::Output; fn make_namespace_use_clause(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_function_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_function_declaration_header(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output, arg9: Self::Output, arg10: Self::Output, arg11: Self::Output) -> Self::Output; fn make_contexts(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_where_clause(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_where_constraint(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_methodish_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_methodish_trait_resolution(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_classish_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output, arg9: Self::Output, arg10: Self::Output, arg11: Self::Output) -> Self::Output; fn make_classish_body(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_trait_use(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_require_clause(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_const_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output) -> Self::Output; fn make_constant_declarator(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_type_const_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output, arg9: Self::Output) -> Self::Output; fn make_context_const_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output) -> Self::Output; fn make_decorated_expression(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_parameter_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output) -> Self::Output; fn make_variadic_parameter(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_old_attribute_specification(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_attribute_specification(&mut self, arg0: Self::Output) -> Self::Output; fn make_attribute(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_inclusion_expression(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_inclusion_directive(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_compound_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_expression_statement(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_markup_section(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_markup_suffix(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_unset_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_declare_local_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output) -> Self::Output; fn make_using_statement_block_scoped(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output) -> Self::Output; fn make_using_statement_function_scoped(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_while_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_if_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output) -> Self::Output; fn make_else_clause(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_try_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_catch_clause(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output) -> Self::Output; fn make_finally_clause(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_do_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output) -> Self::Output; fn make_for_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output) -> Self::Output; fn make_foreach_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output, arg9: Self::Output) -> Self::Output; fn make_switch_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output) -> Self::Output; fn make_switch_section(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_switch_fallthrough(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_case_label(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_default_label(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_match_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output) -> Self::Output; fn make_match_statement_arm(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_return_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_yield_break_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_throw_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_break_statement(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_continue_statement(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_echo_statement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_concurrent_statement(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_simple_initializer(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_anonymous_class(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output) -> Self::Output; fn make_anonymous_function(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output, arg9: Self::Output, arg10: Self::Output, arg11: Self::Output) -> Self::Output; fn make_anonymous_function_use_clause(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_variable_pattern(&mut self, arg0: Self::Output) -> Self::Output; fn make_constructor_pattern(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_refinement_pattern(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_lambda_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_lambda_signature(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output) -> Self::Output; fn make_cast_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_scope_resolution_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_member_selection_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_safe_member_selection_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_embedded_member_selection_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_yield_expression(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_prefix_unary_expression(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_postfix_unary_expression(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_binary_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_is_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_as_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_nullable_as_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_upcast_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_conditional_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_eval_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_isset_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_function_call_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_function_pointer_expression(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_parenthesized_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_braced_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_et_splice_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_embedded_braced_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_list_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_collection_literal_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_object_creation_expression(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_constructor_call(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_darray_intrinsic_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_dictionary_intrinsic_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_keyset_intrinsic_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_varray_intrinsic_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_vector_intrinsic_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_element_initializer(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_subscript_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_embedded_subscript_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_awaitable_creation_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_xhp_children_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_xhp_children_parenthesized_list(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_xhp_category_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_xhp_enum_type(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_xhp_lateinit(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_xhp_required(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_xhp_class_attribute_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_xhp_class_attribute(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_xhp_simple_class_attribute(&mut self, arg0: Self::Output) -> Self::Output; fn make_xhp_simple_attribute(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_xhp_spread_attribute(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_xhp_open(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_xhp_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_xhp_close(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_type_constant(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_vector_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_keyset_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_tuple_type_explicit_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_varray_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_function_ctx_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_type_parameter(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output) -> Self::Output; fn make_type_constraint(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_context_constraint(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_darray_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output) -> Self::Output; fn make_dictionary_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_closure_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output, arg8: Self::Output, arg9: Self::Output, arg10: Self::Output) -> Self::Output; fn make_closure_parameter_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_type_refinement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_type_in_refinement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output) -> Self::Output; fn make_ctx_in_refinement(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output) -> Self::Output; fn make_classname_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_field_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_field_initializer(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_shape_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output) -> Self::Output; fn make_shape_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_tuple_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_generic_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_nullable_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_like_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_soft_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_attributized_specifier(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_reified_type_argument(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_type_arguments(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_type_parameters(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_tuple_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_union_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_intersection_type_specifier(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_error(&mut self, arg0: Self::Output) -> Self::Output; fn make_list_item(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; fn make_enum_class_label_expression(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_module_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output, arg4: Self::Output, arg5: Self::Output, arg6: Self::Output, arg7: Self::Output) -> Self::Output; fn make_module_exports(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_module_imports(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output, arg3: Self::Output) -> Self::Output; fn make_module_membership_declaration(&mut self, arg0: Self::Output, arg1: Self::Output, arg2: Self::Output) -> Self::Output; fn make_package_expression(&mut self, arg0: Self::Output, arg1: Self::Output) -> Self::Output; }
Rust
hhvm/hphp/hack/src/parser/smart_constructors_wrappers.rs
/** * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. An additional * directory. * ** * * THIS FILE IS @generated; DO NOT EDIT IT * To regenerate this file, run * * buck run //hphp/hack/src:generate_full_fidelity * ** * */ // This module contains smart constructors implementation that can be used to // build AST. use parser_core_types::{ lexable_token::LexableToken, syntax_kind::SyntaxKind, token_factory::TokenFactory, }; use crate::SmartConstructors; #[derive(Clone)] pub struct WithKind<S> { s: S, } impl<S> WithKind<S> { pub fn new(s: S) -> Self { Self { s } } } impl<S, St> SmartConstructors for WithKind<S> where S: SmartConstructors<State = St>, { type Factory = S::Factory; type State = St; type Output = (SyntaxKind, S::Output); fn state_mut(&mut self) -> &mut St { self.s.state_mut() } fn into_state(self) -> St { self.s.into_state() } fn token_factory_mut(&mut self) -> &mut Self::Factory { self.s.token_factory_mut() } fn make_token(&mut self, token: <Self::Factory as TokenFactory>::Token) -> Self::Output { compose(SyntaxKind::Token(token.kind()), self.s.make_token(token)) } fn make_missing(&mut self, p: usize) -> Self::Output { compose(SyntaxKind::Missing, self.s.make_missing(p)) } fn make_list(&mut self, items: Vec<Self::Output>, p: usize) -> Self::Output { let kind = if items.is_empty() { SyntaxKind::Missing } else { SyntaxKind::SyntaxList }; compose(kind, self.s.make_list(items.into_iter().map(|x| x.1).collect(), p)) } fn make_end_of_file(&mut self, arg0 : Self::Output) -> Self::Output { compose(SyntaxKind::EndOfFile, self.s.make_end_of_file(arg0.1)) } fn make_script(&mut self, arg0 : Self::Output) -> Self::Output { compose(SyntaxKind::Script, self.s.make_script(arg0.1)) } fn make_qualified_name(&mut self, arg0 : Self::Output) -> Self::Output { compose(SyntaxKind::QualifiedName, self.s.make_qualified_name(arg0.1)) } fn make_module_name(&mut self, arg0 : Self::Output) -> Self::Output { compose(SyntaxKind::ModuleName, self.s.make_module_name(arg0.1)) } fn make_simple_type_specifier(&mut self, arg0 : Self::Output) -> Self::Output { compose(SyntaxKind::SimpleTypeSpecifier, self.s.make_simple_type_specifier(arg0.1)) } fn make_literal_expression(&mut self, arg0 : Self::Output) -> Self::Output { compose(SyntaxKind::LiteralExpression, self.s.make_literal_expression(arg0.1)) } fn make_prefixed_string_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::PrefixedStringExpression, self.s.make_prefixed_string_expression(arg0.1, arg1.1)) } fn make_prefixed_code_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::PrefixedCodeExpression, self.s.make_prefixed_code_expression(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_variable_expression(&mut self, arg0 : Self::Output) -> Self::Output { compose(SyntaxKind::VariableExpression, self.s.make_variable_expression(arg0.1)) } fn make_pipe_variable_expression(&mut self, arg0 : Self::Output) -> Self::Output { compose(SyntaxKind::PipeVariableExpression, self.s.make_pipe_variable_expression(arg0.1)) } fn make_file_attribute_specification(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::FileAttributeSpecification, self.s.make_file_attribute_specification(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_enum_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output, arg9 : Self::Output, arg10 : Self::Output) -> Self::Output { compose(SyntaxKind::EnumDeclaration, self.s.make_enum_declaration(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1, arg7.1, arg8.1, arg9.1, arg10.1)) } fn make_enum_use(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::EnumUse, self.s.make_enum_use(arg0.1, arg1.1, arg2.1)) } fn make_enumerator(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::Enumerator, self.s.make_enumerator(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_enum_class_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output, arg9 : Self::Output, arg10 : Self::Output, arg11 : Self::Output) -> Self::Output { compose(SyntaxKind::EnumClassDeclaration, self.s.make_enum_class_declaration(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1, arg7.1, arg8.1, arg9.1, arg10.1, arg11.1)) } fn make_enum_class_enumerator(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::EnumClassEnumerator, self.s.make_enum_class_enumerator(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_alias_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output, arg9 : Self::Output) -> Self::Output { compose(SyntaxKind::AliasDeclaration, self.s.make_alias_declaration(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1, arg7.1, arg8.1, arg9.1)) } fn make_context_alias_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output) -> Self::Output { compose(SyntaxKind::ContextAliasDeclaration, self.s.make_context_alias_declaration(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1, arg7.1)) } fn make_case_type_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output, arg9 : Self::Output, arg10 : Self::Output) -> Self::Output { compose(SyntaxKind::CaseTypeDeclaration, self.s.make_case_type_declaration(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1, arg7.1, arg8.1, arg9.1, arg10.1)) } fn make_case_type_variant(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::CaseTypeVariant, self.s.make_case_type_variant(arg0.1, arg1.1)) } fn make_property_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::PropertyDeclaration, self.s.make_property_declaration(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_property_declarator(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::PropertyDeclarator, self.s.make_property_declarator(arg0.1, arg1.1)) } fn make_namespace_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::NamespaceDeclaration, self.s.make_namespace_declaration(arg0.1, arg1.1)) } fn make_namespace_declaration_header(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::NamespaceDeclarationHeader, self.s.make_namespace_declaration_header(arg0.1, arg1.1)) } fn make_namespace_body(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::NamespaceBody, self.s.make_namespace_body(arg0.1, arg1.1, arg2.1)) } fn make_namespace_empty_body(&mut self, arg0 : Self::Output) -> Self::Output { compose(SyntaxKind::NamespaceEmptyBody, self.s.make_namespace_empty_body(arg0.1)) } fn make_namespace_use_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::NamespaceUseDeclaration, self.s.make_namespace_use_declaration(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_namespace_group_use_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output) -> Self::Output { compose(SyntaxKind::NamespaceGroupUseDeclaration, self.s.make_namespace_group_use_declaration(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1)) } fn make_namespace_use_clause(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::NamespaceUseClause, self.s.make_namespace_use_clause(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_function_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::FunctionDeclaration, self.s.make_function_declaration(arg0.1, arg1.1, arg2.1)) } fn make_function_declaration_header(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output, arg9 : Self::Output, arg10 : Self::Output, arg11 : Self::Output) -> Self::Output { compose(SyntaxKind::FunctionDeclarationHeader, self.s.make_function_declaration_header(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1, arg7.1, arg8.1, arg9.1, arg10.1, arg11.1)) } fn make_contexts(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::Contexts, self.s.make_contexts(arg0.1, arg1.1, arg2.1)) } fn make_where_clause(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::WhereClause, self.s.make_where_clause(arg0.1, arg1.1)) } fn make_where_constraint(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::WhereConstraint, self.s.make_where_constraint(arg0.1, arg1.1, arg2.1)) } fn make_methodish_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::MethodishDeclaration, self.s.make_methodish_declaration(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_methodish_trait_resolution(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::MethodishTraitResolution, self.s.make_methodish_trait_resolution(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_classish_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output, arg9 : Self::Output, arg10 : Self::Output, arg11 : Self::Output) -> Self::Output { compose(SyntaxKind::ClassishDeclaration, self.s.make_classish_declaration(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1, arg7.1, arg8.1, arg9.1, arg10.1, arg11.1)) } fn make_classish_body(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::ClassishBody, self.s.make_classish_body(arg0.1, arg1.1, arg2.1)) } fn make_trait_use(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::TraitUse, self.s.make_trait_use(arg0.1, arg1.1, arg2.1)) } fn make_require_clause(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::RequireClause, self.s.make_require_clause(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_const_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output) -> Self::Output { compose(SyntaxKind::ConstDeclaration, self.s.make_const_declaration(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1)) } fn make_constant_declarator(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::ConstantDeclarator, self.s.make_constant_declarator(arg0.1, arg1.1)) } fn make_type_const_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output, arg9 : Self::Output) -> Self::Output { compose(SyntaxKind::TypeConstDeclaration, self.s.make_type_const_declaration(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1, arg7.1, arg8.1, arg9.1)) } fn make_context_const_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output) -> Self::Output { compose(SyntaxKind::ContextConstDeclaration, self.s.make_context_const_declaration(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1, arg7.1, arg8.1)) } fn make_decorated_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::DecoratedExpression, self.s.make_decorated_expression(arg0.1, arg1.1)) } fn make_parameter_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output) -> Self::Output { compose(SyntaxKind::ParameterDeclaration, self.s.make_parameter_declaration(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1)) } fn make_variadic_parameter(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::VariadicParameter, self.s.make_variadic_parameter(arg0.1, arg1.1, arg2.1)) } fn make_old_attribute_specification(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::OldAttributeSpecification, self.s.make_old_attribute_specification(arg0.1, arg1.1, arg2.1)) } fn make_attribute_specification(&mut self, arg0 : Self::Output) -> Self::Output { compose(SyntaxKind::AttributeSpecification, self.s.make_attribute_specification(arg0.1)) } fn make_attribute(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::Attribute, self.s.make_attribute(arg0.1, arg1.1)) } fn make_inclusion_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::InclusionExpression, self.s.make_inclusion_expression(arg0.1, arg1.1)) } fn make_inclusion_directive(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::InclusionDirective, self.s.make_inclusion_directive(arg0.1, arg1.1)) } fn make_compound_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::CompoundStatement, self.s.make_compound_statement(arg0.1, arg1.1, arg2.1)) } fn make_expression_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::ExpressionStatement, self.s.make_expression_statement(arg0.1, arg1.1)) } fn make_markup_section(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::MarkupSection, self.s.make_markup_section(arg0.1, arg1.1)) } fn make_markup_suffix(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::MarkupSuffix, self.s.make_markup_suffix(arg0.1, arg1.1)) } fn make_unset_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::UnsetStatement, self.s.make_unset_statement(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_declare_local_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output) -> Self::Output { compose(SyntaxKind::DeclareLocalStatement, self.s.make_declare_local_statement(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1)) } fn make_using_statement_block_scoped(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output) -> Self::Output { compose(SyntaxKind::UsingStatementBlockScoped, self.s.make_using_statement_block_scoped(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1)) } fn make_using_statement_function_scoped(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::UsingStatementFunctionScoped, self.s.make_using_statement_function_scoped(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_while_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::WhileStatement, self.s.make_while_statement(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_if_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output) -> Self::Output { compose(SyntaxKind::IfStatement, self.s.make_if_statement(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1)) } fn make_else_clause(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::ElseClause, self.s.make_else_clause(arg0.1, arg1.1)) } fn make_try_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::TryStatement, self.s.make_try_statement(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_catch_clause(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output) -> Self::Output { compose(SyntaxKind::CatchClause, self.s.make_catch_clause(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1)) } fn make_finally_clause(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::FinallyClause, self.s.make_finally_clause(arg0.1, arg1.1)) } fn make_do_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output) -> Self::Output { compose(SyntaxKind::DoStatement, self.s.make_do_statement(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1)) } fn make_for_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output) -> Self::Output { compose(SyntaxKind::ForStatement, self.s.make_for_statement(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1, arg7.1, arg8.1)) } fn make_foreach_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output, arg9 : Self::Output) -> Self::Output { compose(SyntaxKind::ForeachStatement, self.s.make_foreach_statement(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1, arg7.1, arg8.1, arg9.1)) } fn make_switch_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output) -> Self::Output { compose(SyntaxKind::SwitchStatement, self.s.make_switch_statement(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1)) } fn make_switch_section(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::SwitchSection, self.s.make_switch_section(arg0.1, arg1.1, arg2.1)) } fn make_switch_fallthrough(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::SwitchFallthrough, self.s.make_switch_fallthrough(arg0.1, arg1.1)) } fn make_case_label(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::CaseLabel, self.s.make_case_label(arg0.1, arg1.1, arg2.1)) } fn make_default_label(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::DefaultLabel, self.s.make_default_label(arg0.1, arg1.1)) } fn make_match_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output) -> Self::Output { compose(SyntaxKind::MatchStatement, self.s.make_match_statement(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1)) } fn make_match_statement_arm(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::MatchStatementArm, self.s.make_match_statement_arm(arg0.1, arg1.1, arg2.1)) } fn make_return_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::ReturnStatement, self.s.make_return_statement(arg0.1, arg1.1, arg2.1)) } fn make_yield_break_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::YieldBreakStatement, self.s.make_yield_break_statement(arg0.1, arg1.1, arg2.1)) } fn make_throw_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::ThrowStatement, self.s.make_throw_statement(arg0.1, arg1.1, arg2.1)) } fn make_break_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::BreakStatement, self.s.make_break_statement(arg0.1, arg1.1)) } fn make_continue_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::ContinueStatement, self.s.make_continue_statement(arg0.1, arg1.1)) } fn make_echo_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::EchoStatement, self.s.make_echo_statement(arg0.1, arg1.1, arg2.1)) } fn make_concurrent_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::ConcurrentStatement, self.s.make_concurrent_statement(arg0.1, arg1.1)) } fn make_simple_initializer(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::SimpleInitializer, self.s.make_simple_initializer(arg0.1, arg1.1)) } fn make_anonymous_class(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output) -> Self::Output { compose(SyntaxKind::AnonymousClass, self.s.make_anonymous_class(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1, arg7.1, arg8.1)) } fn make_anonymous_function(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output, arg9 : Self::Output, arg10 : Self::Output, arg11 : Self::Output) -> Self::Output { compose(SyntaxKind::AnonymousFunction, self.s.make_anonymous_function(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1, arg7.1, arg8.1, arg9.1, arg10.1, arg11.1)) } fn make_anonymous_function_use_clause(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::AnonymousFunctionUseClause, self.s.make_anonymous_function_use_clause(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_variable_pattern(&mut self, arg0 : Self::Output) -> Self::Output { compose(SyntaxKind::VariablePattern, self.s.make_variable_pattern(arg0.1)) } fn make_constructor_pattern(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::ConstructorPattern, self.s.make_constructor_pattern(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_refinement_pattern(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::RefinementPattern, self.s.make_refinement_pattern(arg0.1, arg1.1, arg2.1)) } fn make_lambda_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::LambdaExpression, self.s.make_lambda_expression(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_lambda_signature(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output) -> Self::Output { compose(SyntaxKind::LambdaSignature, self.s.make_lambda_signature(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1)) } fn make_cast_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::CastExpression, self.s.make_cast_expression(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_scope_resolution_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::ScopeResolutionExpression, self.s.make_scope_resolution_expression(arg0.1, arg1.1, arg2.1)) } fn make_member_selection_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::MemberSelectionExpression, self.s.make_member_selection_expression(arg0.1, arg1.1, arg2.1)) } fn make_safe_member_selection_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::SafeMemberSelectionExpression, self.s.make_safe_member_selection_expression(arg0.1, arg1.1, arg2.1)) } fn make_embedded_member_selection_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::EmbeddedMemberSelectionExpression, self.s.make_embedded_member_selection_expression(arg0.1, arg1.1, arg2.1)) } fn make_yield_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::YieldExpression, self.s.make_yield_expression(arg0.1, arg1.1)) } fn make_prefix_unary_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::PrefixUnaryExpression, self.s.make_prefix_unary_expression(arg0.1, arg1.1)) } fn make_postfix_unary_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::PostfixUnaryExpression, self.s.make_postfix_unary_expression(arg0.1, arg1.1)) } fn make_binary_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::BinaryExpression, self.s.make_binary_expression(arg0.1, arg1.1, arg2.1)) } fn make_is_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::IsExpression, self.s.make_is_expression(arg0.1, arg1.1, arg2.1)) } fn make_as_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::AsExpression, self.s.make_as_expression(arg0.1, arg1.1, arg2.1)) } fn make_nullable_as_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::NullableAsExpression, self.s.make_nullable_as_expression(arg0.1, arg1.1, arg2.1)) } fn make_upcast_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::UpcastExpression, self.s.make_upcast_expression(arg0.1, arg1.1, arg2.1)) } fn make_conditional_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::ConditionalExpression, self.s.make_conditional_expression(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_eval_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::EvalExpression, self.s.make_eval_expression(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_isset_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::IssetExpression, self.s.make_isset_expression(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_function_call_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::FunctionCallExpression, self.s.make_function_call_expression(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_function_pointer_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::FunctionPointerExpression, self.s.make_function_pointer_expression(arg0.1, arg1.1)) } fn make_parenthesized_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::ParenthesizedExpression, self.s.make_parenthesized_expression(arg0.1, arg1.1, arg2.1)) } fn make_braced_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::BracedExpression, self.s.make_braced_expression(arg0.1, arg1.1, arg2.1)) } fn make_et_splice_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::ETSpliceExpression, self.s.make_et_splice_expression(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_embedded_braced_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::EmbeddedBracedExpression, self.s.make_embedded_braced_expression(arg0.1, arg1.1, arg2.1)) } fn make_list_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::ListExpression, self.s.make_list_expression(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_collection_literal_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::CollectionLiteralExpression, self.s.make_collection_literal_expression(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_object_creation_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::ObjectCreationExpression, self.s.make_object_creation_expression(arg0.1, arg1.1)) } fn make_constructor_call(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::ConstructorCall, self.s.make_constructor_call(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_darray_intrinsic_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::DarrayIntrinsicExpression, self.s.make_darray_intrinsic_expression(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_dictionary_intrinsic_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::DictionaryIntrinsicExpression, self.s.make_dictionary_intrinsic_expression(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_keyset_intrinsic_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::KeysetIntrinsicExpression, self.s.make_keyset_intrinsic_expression(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_varray_intrinsic_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::VarrayIntrinsicExpression, self.s.make_varray_intrinsic_expression(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_vector_intrinsic_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::VectorIntrinsicExpression, self.s.make_vector_intrinsic_expression(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_element_initializer(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::ElementInitializer, self.s.make_element_initializer(arg0.1, arg1.1, arg2.1)) } fn make_subscript_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::SubscriptExpression, self.s.make_subscript_expression(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_embedded_subscript_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::EmbeddedSubscriptExpression, self.s.make_embedded_subscript_expression(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_awaitable_creation_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::AwaitableCreationExpression, self.s.make_awaitable_creation_expression(arg0.1, arg1.1, arg2.1)) } fn make_xhp_children_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::XHPChildrenDeclaration, self.s.make_xhp_children_declaration(arg0.1, arg1.1, arg2.1)) } fn make_xhp_children_parenthesized_list(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::XHPChildrenParenthesizedList, self.s.make_xhp_children_parenthesized_list(arg0.1, arg1.1, arg2.1)) } fn make_xhp_category_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::XHPCategoryDeclaration, self.s.make_xhp_category_declaration(arg0.1, arg1.1, arg2.1)) } fn make_xhp_enum_type(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::XHPEnumType, self.s.make_xhp_enum_type(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_xhp_lateinit(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::XHPLateinit, self.s.make_xhp_lateinit(arg0.1, arg1.1)) } fn make_xhp_required(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::XHPRequired, self.s.make_xhp_required(arg0.1, arg1.1)) } fn make_xhp_class_attribute_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::XHPClassAttributeDeclaration, self.s.make_xhp_class_attribute_declaration(arg0.1, arg1.1, arg2.1)) } fn make_xhp_class_attribute(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::XHPClassAttribute, self.s.make_xhp_class_attribute(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_xhp_simple_class_attribute(&mut self, arg0 : Self::Output) -> Self::Output { compose(SyntaxKind::XHPSimpleClassAttribute, self.s.make_xhp_simple_class_attribute(arg0.1)) } fn make_xhp_simple_attribute(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::XHPSimpleAttribute, self.s.make_xhp_simple_attribute(arg0.1, arg1.1, arg2.1)) } fn make_xhp_spread_attribute(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::XHPSpreadAttribute, self.s.make_xhp_spread_attribute(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_xhp_open(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::XHPOpen, self.s.make_xhp_open(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_xhp_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::XHPExpression, self.s.make_xhp_expression(arg0.1, arg1.1, arg2.1)) } fn make_xhp_close(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::XHPClose, self.s.make_xhp_close(arg0.1, arg1.1, arg2.1)) } fn make_type_constant(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::TypeConstant, self.s.make_type_constant(arg0.1, arg1.1, arg2.1)) } fn make_vector_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::VectorTypeSpecifier, self.s.make_vector_type_specifier(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_keyset_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::KeysetTypeSpecifier, self.s.make_keyset_type_specifier(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_tuple_type_explicit_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::TupleTypeExplicitSpecifier, self.s.make_tuple_type_explicit_specifier(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_varray_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::VarrayTypeSpecifier, self.s.make_varray_type_specifier(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_function_ctx_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::FunctionCtxTypeSpecifier, self.s.make_function_ctx_type_specifier(arg0.1, arg1.1)) } fn make_type_parameter(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output) -> Self::Output { compose(SyntaxKind::TypeParameter, self.s.make_type_parameter(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1)) } fn make_type_constraint(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::TypeConstraint, self.s.make_type_constraint(arg0.1, arg1.1)) } fn make_context_constraint(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::ContextConstraint, self.s.make_context_constraint(arg0.1, arg1.1)) } fn make_darray_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output) -> Self::Output { compose(SyntaxKind::DarrayTypeSpecifier, self.s.make_darray_type_specifier(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1)) } fn make_dictionary_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::DictionaryTypeSpecifier, self.s.make_dictionary_type_specifier(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_closure_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output, arg9 : Self::Output, arg10 : Self::Output) -> Self::Output { compose(SyntaxKind::ClosureTypeSpecifier, self.s.make_closure_type_specifier(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1, arg7.1, arg8.1, arg9.1, arg10.1)) } fn make_closure_parameter_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::ClosureParameterTypeSpecifier, self.s.make_closure_parameter_type_specifier(arg0.1, arg1.1, arg2.1)) } fn make_type_refinement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::TypeRefinement, self.s.make_type_refinement(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_type_in_refinement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output) -> Self::Output { compose(SyntaxKind::TypeInRefinement, self.s.make_type_in_refinement(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1)) } fn make_ctx_in_refinement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output) -> Self::Output { compose(SyntaxKind::CtxInRefinement, self.s.make_ctx_in_refinement(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1)) } fn make_classname_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::ClassnameTypeSpecifier, self.s.make_classname_type_specifier(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_field_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::FieldSpecifier, self.s.make_field_specifier(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_field_initializer(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::FieldInitializer, self.s.make_field_initializer(arg0.1, arg1.1, arg2.1)) } fn make_shape_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { compose(SyntaxKind::ShapeTypeSpecifier, self.s.make_shape_type_specifier(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1)) } fn make_shape_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::ShapeExpression, self.s.make_shape_expression(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_tuple_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::TupleExpression, self.s.make_tuple_expression(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_generic_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::GenericTypeSpecifier, self.s.make_generic_type_specifier(arg0.1, arg1.1)) } fn make_nullable_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::NullableTypeSpecifier, self.s.make_nullable_type_specifier(arg0.1, arg1.1)) } fn make_like_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::LikeTypeSpecifier, self.s.make_like_type_specifier(arg0.1, arg1.1)) } fn make_soft_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::SoftTypeSpecifier, self.s.make_soft_type_specifier(arg0.1, arg1.1)) } fn make_attributized_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::AttributizedSpecifier, self.s.make_attributized_specifier(arg0.1, arg1.1)) } fn make_reified_type_argument(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::ReifiedTypeArgument, self.s.make_reified_type_argument(arg0.1, arg1.1)) } fn make_type_arguments(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::TypeArguments, self.s.make_type_arguments(arg0.1, arg1.1, arg2.1)) } fn make_type_parameters(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::TypeParameters, self.s.make_type_parameters(arg0.1, arg1.1, arg2.1)) } fn make_tuple_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::TupleTypeSpecifier, self.s.make_tuple_type_specifier(arg0.1, arg1.1, arg2.1)) } fn make_union_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::UnionTypeSpecifier, self.s.make_union_type_specifier(arg0.1, arg1.1, arg2.1)) } fn make_intersection_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::IntersectionTypeSpecifier, self.s.make_intersection_type_specifier(arg0.1, arg1.1, arg2.1)) } fn make_error(&mut self, arg0 : Self::Output) -> Self::Output { compose(SyntaxKind::ErrorSyntax, self.s.make_error(arg0.1)) } fn make_list_item(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::ListItem, self.s.make_list_item(arg0.1, arg1.1)) } fn make_enum_class_label_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::EnumClassLabelExpression, self.s.make_enum_class_label_expression(arg0.1, arg1.1, arg2.1)) } fn make_module_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output) -> Self::Output { compose(SyntaxKind::ModuleDeclaration, self.s.make_module_declaration(arg0.1, arg1.1, arg2.1, arg3.1, arg4.1, arg5.1, arg6.1, arg7.1)) } fn make_module_exports(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::ModuleExports, self.s.make_module_exports(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_module_imports(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { compose(SyntaxKind::ModuleImports, self.s.make_module_imports(arg0.1, arg1.1, arg2.1, arg3.1)) } fn make_module_membership_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { compose(SyntaxKind::ModuleMembershipDeclaration, self.s.make_module_membership_declaration(arg0.1, arg1.1, arg2.1)) } fn make_package_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { compose(SyntaxKind::PackageExpression, self.s.make_package_expression(arg0.1, arg1.1)) } } #[inline(always)] fn compose<R>(kind: SyntaxKind, r: R) -> (SyntaxKind, R) { (kind, r) }
Rust
hhvm/hphp/hack/src/parser/source_text.rs
// Copyright (c) 2019, Facebook, Inc. // All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use std::rc::Rc; use std::sync::Arc; use ocamlrep::ptr::UnsafeOcamlPtr; use ocamlrep::FromOcamlRep; use ocamlrep::ToOcamlRep; use relative_path::RelativePath; pub const INVALID: char = '\x00'; #[derive(Debug)] struct SourceTextImpl<'a> { // All the indices in existing implementation are byte based, instead of unicode // char boundary based. This is bad experience for non-ASCII source files, but don't want to // change it now and deal with tracking all the dependencies of it. // Additionally, Rust assumes that &strs are valid UTF-8", but "test/slow/labels/74.php" suggests // that invalid unicode sequence can be a valid Hack program. // Using byte slice instead of &str looks ugly, but prevents us from constantly fighting // with compiler trying to guide us towards unicode semantics. text: &'a [u8], file_path: Arc<RelativePath>, ocaml_source_text: Option<UnsafeOcamlPtr>, } #[derive(Debug, Clone)] pub struct SourceText<'a>(Rc<SourceTextImpl<'a>>); impl<'a> SourceText<'a> { pub fn make(file_path: Arc<RelativePath>, text: &'a [u8]) -> Self { Self::make_with_raw(file_path, text, 0) } pub fn make_with_raw( file_path: Arc<RelativePath>, text: &'a [u8], ocaml_source_text: usize, ) -> Self { Self(Rc::new(SourceTextImpl { file_path, text, ocaml_source_text: if ocaml_source_text == 0 { None } else { unsafe { Some(UnsafeOcamlPtr::new(ocaml_source_text)) } }, })) } pub fn file_path(&self) -> &RelativePath { self.0.file_path.as_ref() } pub fn file_path_rc(&self) -> Arc<RelativePath> { Arc::clone(&self.0.file_path) } pub fn text(&self) -> &'a [u8] { self.0.text } pub fn text_as_str(&self) -> &'a str { unsafe { std::str::from_utf8_unchecked(self.0.text) } } pub fn length(&self) -> usize { self.text().len() } pub fn ocaml_source_text(&self) -> Option<UnsafeOcamlPtr> { self.0.ocaml_source_text } pub fn get(&self, index: usize) -> char { self.text().get(index).map_or(INVALID, |x| *x as char) } pub fn sub(&self, start: usize, length: usize) -> &'a [u8] { let len = self.length(); if start >= len { b"" } else if start + length > len { &self.text()[start..] } else { &self.text()[start..(start + length)] } } pub fn sub_as_str(&self, start: usize, length: usize) -> &'a str { unsafe { std::str::from_utf8_unchecked(self.sub(start, length)) } } } impl<'content> ToOcamlRep for SourceText<'content> { fn to_ocamlrep<'a, A: ocamlrep::Allocator>(&'a self, alloc: &'a A) -> ocamlrep::Value<'a> { // A SourceText with no associated ocaml_source_text cannot be converted // to OCaml yet (we'd need to construct the OffsetMap). We still // construct some in test cases, so just panic upon attempts to convert. alloc.add_copy(self.0.ocaml_source_text.unwrap()) } } impl<'content> FromOcamlRep for SourceText<'content> { fn from_ocamlrep(value: ocamlrep::Value<'_>) -> Result<Self, ocamlrep::FromError> { let block = ocamlrep::from::expect_tuple(value, 4)?; let file_path: Arc<RelativePath> = ocamlrep::from::field(block, 0)?; // Unsafely transmute away the lifetime of `value` and allow the caller // to choose the lifetime. This is no more unsafe than what we already // do by storing the ocaml_source_text pointer--if the OCaml source text // is collected, our text field and ocaml_source_text field will both be // invalid. The caller must take care not to let the OCaml source text // be collected while a Rust SourceText exists. let text: &'content [u8] = unsafe { std::mem::transmute( ocamlrep::bytes_from_ocamlrep(block[2]) .map_err(|e| ocamlrep::FromError::ErrorInField(2, Box::new(e)))?, ) }; let ocaml_source_text = Some(UnsafeOcamlPtr::from_ocamlrep(value)?); Ok(Self(Rc::new(SourceTextImpl { file_path, text, ocaml_source_text, }))) } }
Rust
hhvm/hphp/hack/src/parser/syntax.rs
// Copyright (c) 2019, Facebook, Inc. // All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use std::fmt::Debug; use std::iter::empty; use std::iter::once; use std::ops::ControlFlow; use itertools::Either::Left; use itertools::Either::Right; use crate::lexable_token::LexableToken; pub use crate::syntax_generated::*; use crate::syntax_kind::SyntaxKind; pub use crate::syntax_type::*; use crate::token_kind::TokenKind; pub trait SyntaxValueType<T> where Self: Sized, { fn from_values<'a>(child_values: impl Iterator<Item = &'a Self>) -> Self where Self: 'a; fn from_children<'a>( kind: SyntaxKind, offset: usize, nodes: impl Iterator<Item = &'a Self>, ) -> Self where Self: 'a; fn from_token(token: T) -> Self; } pub trait SyntaxValueWithKind where Self: Debug, { fn is_missing(&self) -> bool; fn token_kind(&self) -> Option<TokenKind>; } #[derive(Debug, Clone)] pub struct Syntax<T, V> { pub syntax: SyntaxVariant<T, V>, pub value: V, } pub trait SyntaxTypeBase<C> { type Token: LexableToken; type Value; fn make_missing(ctx: &C, offset: usize) -> Self; fn make_token(ctx: &C, arg: Self::Token) -> Self; fn make_list(ctx: &C, arg: Vec<Self>, offset: usize) -> Self where Self: Sized; fn value(&self) -> &Self::Value; } impl<T, V, C> SyntaxTypeBase<C> for Syntax<T, V> where T: LexableToken, V: SyntaxValueType<T>, { type Token = T; type Value = V; fn make_missing(_: &C, offset: usize) -> Self { let value = V::from_children(SyntaxKind::Missing, offset, empty()); let syntax = SyntaxVariant::Missing; Self::make(syntax, value) } fn make_token(_: &C, arg: T) -> Self { Self::make_token(arg) } fn make_list(ctx: &C, arg: Vec<Self>, offset: usize) -> Self { // An empty list is represented by Missing; everything else is a // SyntaxList, even if the list has only one item. if arg.is_empty() { Self::make_missing(ctx, offset) } else { let nodes = arg.iter().map(|x| &x.value); let value = V::from_children(SyntaxKind::SyntaxList, offset, nodes); let syntax = SyntaxVariant::SyntaxList(arg); Self::make(syntax, value) } } fn value(&self) -> &Self::Value { &self.value } } impl<T, V> Syntax<T, V> where T: LexableToken, V: SyntaxValueType<T>, { pub fn make_token(arg: T) -> Self { let value = V::from_token(arg.clone()); let syntax = SyntaxVariant::Token(Box::new(arg)); Self::make(syntax, value) } } impl<T, V> Syntax<T, V> where T: LexableToken, { pub fn make(syntax: SyntaxVariant<T, V>, value: V) -> Self { Self { syntax, value } } fn is_specific_token(&self, kind: TokenKind) -> bool { match &self.syntax { SyntaxVariant::Token(t) => t.kind() == kind, _ => false, } } pub fn is_public(&self) -> bool { self.is_specific_token(TokenKind::Public) } pub fn is_private(&self) -> bool { self.is_specific_token(TokenKind::Private) } pub fn is_protected(&self) -> bool { self.is_specific_token(TokenKind::Protected) } pub fn is_abstract(&self) -> bool { self.is_specific_token(TokenKind::Abstract) } pub fn is_static(&self) -> bool { self.is_specific_token(TokenKind::Static) } pub fn is_ampersand(&self) -> bool { self.is_specific_token(TokenKind::Ampersand) } pub fn is_ellipsis(&self) -> bool { self.is_specific_token(TokenKind::DotDotDot) } pub fn is_final(&self) -> bool { self.is_specific_token(TokenKind::Final) } pub fn is_xhp(&self) -> bool { self.is_specific_token(TokenKind::XHP) } pub fn is_async(&self) -> bool { self.is_specific_token(TokenKind::Async) } pub fn is_yield(&self) -> bool { self.is_specific_token(TokenKind::Yield) } pub fn is_construct(&self) -> bool { self.is_specific_token(TokenKind::Construct) } pub fn is_void(&self) -> bool { self.is_specific_token(TokenKind::Void) } pub fn is_left_brace(&self) -> bool { self.is_specific_token(TokenKind::LeftBrace) } pub fn is_comma(&self) -> bool { self.is_specific_token(TokenKind::Comma) } pub fn is_inout(&self) -> bool { self.is_specific_token(TokenKind::Inout) } pub fn is_this(&self) -> bool { self.is_specific_token(TokenKind::This) } pub fn is_name(&self) -> bool { self.is_specific_token(TokenKind::Name) } pub fn is_class(&self) -> bool { self.is_specific_token(TokenKind::Class) } pub fn is_as_expression(&self) -> bool { self.kind() == SyntaxKind::AsExpression } pub fn is_missing(&self) -> bool { self.kind() == SyntaxKind::Missing } pub fn is_external(&self) -> bool { self.is_specific_token(TokenKind::Semicolon) || self.is_missing() } pub fn is_namespace_empty_body(&self) -> bool { self.kind() == SyntaxKind::NamespaceEmptyBody } pub fn is_attribute_specification(&self) -> bool { self.kind() == SyntaxKind::AttributeSpecification } pub fn is_old_attribute_specification(&self) -> bool { self.kind() == SyntaxKind::OldAttributeSpecification } pub fn is_file_attribute_specification(&self) -> bool { self.kind() == SyntaxKind::FileAttributeSpecification } pub fn is_return_statement(&self) -> bool { self.kind() == SyntaxKind::ReturnStatement } pub fn is_conditional_expression(&self) -> bool { self.kind() == SyntaxKind::ConditionalExpression } pub fn is_safe_member_selection_expression(&self) -> bool { self.kind() == SyntaxKind::SafeMemberSelectionExpression } pub fn is_object_creation_expression(&self) -> bool { self.kind() == SyntaxKind::ObjectCreationExpression } pub fn is_compound_statement(&self) -> bool { self.kind() == SyntaxKind::CompoundStatement } pub fn is_methodish_declaration(&self) -> bool { self.kind() == SyntaxKind::MethodishDeclaration } pub fn is_function_declaration(&self) -> bool { self.kind() == SyntaxKind::FunctionDeclaration } pub fn is_xhp_open(&self) -> bool { self.kind() == SyntaxKind::XHPOpen } pub fn is_braced_expression(&self) -> bool { self.kind() == SyntaxKind::BracedExpression } pub fn is_syntax_list(&self) -> bool { self.kind() == SyntaxKind::SyntaxList } pub fn syntax_node_to_list<'a>(&'a self) -> impl DoubleEndedIterator<Item = &'a Self> { match &self.syntax { SyntaxVariant::SyntaxList(x) => Left(x.iter()), SyntaxVariant::Missing => Right(Left(empty())), _ => Right(Right(once(self))), } } pub fn syntax_node_into_list(self) -> impl DoubleEndedIterator<Item = Self> { match self.syntax { SyntaxVariant::SyntaxList(x) => Left(x.into_iter()), SyntaxVariant::Missing => Right(Left(empty())), _ => Right(Right(once(self))), } } pub fn syntax_node_to_list_skip_separator<'a>( &'a self, ) -> impl DoubleEndedIterator<Item = &'a Self> { match &self.syntax { SyntaxVariant::SyntaxList(l) => Left(l.iter().map(|n| match &n.syntax { SyntaxVariant::ListItem(i) => &i.list_item, _ => n, })), SyntaxVariant::Missing => Right(Left(empty())), _ => Right(Right(once(self))), } } pub fn is_namespace_prefix(&self) -> bool { if let SyntaxVariant::QualifiedName(x) = &self.syntax { x.qualified_name_parts .syntax_node_to_list() .last() .map_or(false, |p| match &p.syntax { SyntaxVariant::ListItem(x) => !&x.list_separator.is_missing(), _ => false, }) } else { false } } pub fn drain_children(&mut self) -> Vec<Self> { let f = |node: Self, mut acc: Vec<Self>| { acc.push(node); acc }; let syntax = std::mem::replace(&mut self.syntax, SyntaxVariant::Missing); Self::fold_over_children_owned(&f, vec![], syntax) } pub fn get_token(&self) -> Option<&T> { match &self.syntax { SyntaxVariant::Token(t) => Some(t), _ => None, } } pub fn leading_token(&self) -> Option<&T> { match self.get_token() { Some(token) => Some(token), None => { for node in self.iter_children() { if let Some(token) = node.leading_token() { return Some(token); } } None } } } pub fn trailing_token(&self) -> Option<&T> { match self.get_token() { Some(token) => Some(token), None => { for node in self.iter_children().rev() { if let Some(token) = node.trailing_token() { return Some(token); } } None } } } pub fn iter_children<'a>(&'a self) -> SyntaxChildrenIterator<'a, T, V> { self.syntax.iter_children() } pub fn all_tokens(&self) -> Vec<&T> { let mut acc = vec![]; self.iter_pre(|node| { if let Some(t) = node.get_token() { acc.push(t) } }); acc } /// Invoke `f` on every node in the tree in a preorder traversal. pub fn iter_pre<'a, F: FnMut(&'a Self)>(&'a self, mut f: F) { self.iter_pre_impl(&mut f) } fn iter_pre_impl<'a, F: FnMut(&'a Self)>(&'a self, f: &mut F) { f(self); for child in self.children() { child.iter_pre_impl(f); } } /// Invoke `f` on every node in the tree in a preorder traversal. pub fn try_iter_pre<'a, F, E>(&'a self, mut f: F) -> Result<(), E> where F: FnMut(&'a Self) -> Result<(), E>, { self.try_iter_pre_impl(&mut f) } fn try_iter_pre_impl<'a, F, E>(&'a self, f: &mut F) -> Result<(), E> where F: FnMut(&'a Self) -> Result<(), E>, { f(self)?; for child in self.children() { child.try_iter_pre_impl(f)?; } Ok(()) } /// Invoke `f` on every node in the tree in a preorder traversal. pub fn rewrite_pre<F: FnMut(&mut Self)>(&mut self, mut f: F) { self.rewrite_pre_impl(&mut f) } fn rewrite_pre_impl<F: FnMut(&mut Self)>(&mut self, f: &mut F) { f(self); for child in self.children_mut() { child.rewrite_pre_impl(f); } } /// Invoke `f` on every node in the tree in a preorder traversal. If `f` /// returns `ControlFlow::Break`, do not recurse into that node's children /// (but do continue traversing the rest of the tree). pub fn rewrite_pre_and_stop<F: FnMut(&mut Self) -> ControlFlow<()>>(&mut self, mut f: F) { self.rewrite_pre_and_stop_impl(&mut f) } fn rewrite_pre_and_stop_impl<F: FnMut(&mut Self) -> ControlFlow<()>>(&mut self, f: &mut F) { if let ControlFlow::Continue(()) = f(self) { for child in self.children_mut() { child.rewrite_pre_and_stop_impl(f); } } } } pub struct SyntaxChildrenIterator<'a, T, V> { pub syntax: &'a SyntaxVariant<T, V>, pub index: usize, pub index_back: usize, } impl<T, V> SyntaxVariant<T, V> { pub fn iter_children<'a>(&'a self) -> SyntaxChildrenIterator<'a, T, V> { SyntaxChildrenIterator { syntax: self, index: 0, index_back: 0, } } } impl<'a, T, V> Iterator for SyntaxChildrenIterator<'a, T, V> { type Item = &'a Syntax<T, V>; fn next(&mut self) -> Option<Self::Item> { self.next_impl(true) } } impl<'a, T, V> DoubleEndedIterator for SyntaxChildrenIterator<'a, T, V> { fn next_back(&mut self) -> Option<Self::Item> { self.next_impl(false) } }
OCaml
hhvm/hphp/hack/src/parser/syntaxTransforms.ml
(* * Copyright (c) 2018, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) module ES = Full_fidelity_editable_syntax module PS = Full_fidelity_positioned_syntax module ET = ES.Token module PT = PS.Token module PositionedSyntaxTree = Full_fidelity_syntax_tree.WithSyntax (PS) let editable_from_positioned tree = let rec aux text positioned_node offset = match PS.syntax positioned_node with | PS.Token token -> let source_text = PT.source_text token in let width = PT.width token in let leading = Full_fidelity_editable_trivia.from_positioned_list source_text (PT.leading token) offset in let trailing = Full_fidelity_editable_trivia.from_positioned_list source_text (PT.trailing token) (offset + PT.leading_width token + width) in let editable_token = ET.make (PT.kind token) source_text (PT.leading_start_offset token) width leading trailing in let syntax = ES.Token editable_token in ES.make syntax ES.Value.NoValue | _ -> let folder (acc, offset) child = let new_child = aux text child offset in let w = PS.full_width child in (new_child :: acc, offset + w) in let kind = PS.kind positioned_node in let positioneds = PS.children positioned_node in let (editables, _) = List.fold_left folder ([], offset) positioneds in let editables = List.rev editables in let syntax = ES.syntax_from_children kind editables in ES.make syntax ES.Value.NoValue in aux (PositionedSyntaxTree.text tree) (PositionedSyntaxTree.root tree) 0
Rust
hhvm/hphp/hack/src/parser/syntax_error.rs
#![allow(non_upper_case_globals)] // Copyright (c) 2019, Facebook, Inc. // All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. // use std::borrow::Cow; use std::cmp::Ordering; use ocamlrep::FromOcamlRep; use ocamlrep::ToOcamlRep; use crate::token_kind::TokenKind; // many errors are static strings, but not all of them pub type Error = Cow<'static, str>; #[derive(Debug, Clone, FromOcamlRep, ToOcamlRep, PartialEq, Eq)] pub enum ErrorType { ParseError, RuntimeError, } #[derive(Clone, Copy, PartialEq, Eq)] pub enum LvalRoot { Unset, Assignment, Inout, IncrementOrDecrement, CatchClause, Foreach, } /// Equivalent to `Quickfix` but uses offsets rather than the `Pos` type, /// so this type is Send. #[derive(Debug, Clone, FromOcamlRep, ToOcamlRep, PartialEq, Eq)] pub struct SyntaxQuickfix { pub title: String, pub edits: Vec<(usize, usize, String)>, } #[derive(Debug, Clone, FromOcamlRep, ToOcamlRep, PartialEq, Eq)] pub struct SyntaxError { pub child: Option<Box<SyntaxError>>, pub start_offset: usize, pub end_offset: usize, pub error_type: ErrorType, pub message: Error, pub quickfixes: Vec<SyntaxQuickfix>, } impl SyntaxError { pub fn make_with_child_and_type( child: Option<SyntaxError>, start_offset: usize, end_offset: usize, error_type: ErrorType, message: Error, quickfixes: Vec<SyntaxQuickfix>, ) -> Self { Self { child: child.map(Box::new), start_offset, end_offset, error_type, message, quickfixes, } } pub fn make( start_offset: usize, end_offset: usize, message: Error, quickfixes: Vec<SyntaxQuickfix>, ) -> Self { Self::make_with_child_and_type( None, start_offset, end_offset, ErrorType::ParseError, message, quickfixes, ) } pub fn compare_offset(e1: &Self, e2: &Self) -> Ordering { (e1.start_offset, e1.end_offset).cmp(&(e2.start_offset, e2.end_offset)) } pub fn equal_offset(e1: &Self, e2: &Self) -> bool { Self::compare_offset(e1, e2) == Ordering::Equal } pub fn weak_equal(e1: &Self, e2: &Self) -> bool { e1.start_offset == e2.start_offset && e1.end_offset == e2.end_offset && e1.message == e2.message } } // Lexical errors pub const error0001: Error = Cow::Borrowed("A hexadecimal literal needs at least one digit."); pub const error0002: Error = Cow::Borrowed("A binary literal needs at least one digit."); pub const error0003: Error = Cow::Borrowed(concat!( "A floating point literal with an exponent needs at least ", "one digit in the exponent." )); pub const error0006: Error = Cow::Borrowed("This character is invalid."); pub const error0007: Error = Cow::Borrowed("This delimited comment is not terminated."); pub const error0008: Error = Cow::Borrowed("A name is expected here."); pub const error0010: Error = Cow::Borrowed("A single quote is expected here."); pub const error0011: Error = Cow::Borrowed("A newline is expected here."); pub const error0012: Error = Cow::Borrowed("This string literal is not terminated."); pub const error0013: Error = Cow::Borrowed("This XHP body is not terminated."); pub const error0014: Error = Cow::Borrowed("This XHP comment is not terminated."); // Syntactic errors pub const error1001: Error = Cow::Borrowed("A .php file must begin with `<?hh`."); pub const error1003: Error = Cow::Borrowed("The `function` keyword is expected here."); pub const error1004: Error = Cow::Borrowed("A name is expected here."); pub const error1006: Error = Cow::Borrowed("A right brace `}` is expected here."); pub const error1007: Error = Cow::Borrowed("A type specifier is expected here."); pub const error1008: Error = Cow::Borrowed("A variable name is expected here."); pub const error1010: Error = Cow::Borrowed("A semicolon `;` is expected here."); pub const error1011: Error = Cow::Borrowed("A right parenthesis `)` is expected here."); pub const error1013: Error = Cow::Borrowed("A closing angle bracket `>` is expected here."); pub const error1014: Error = Cow::Borrowed("A closing angle bracket `>` or comma is expected here."); pub const error1015: Error = Cow::Borrowed("An expression is expected here."); pub const error1016: Error = Cow::Borrowed("An assignment is expected here."); pub const error1017: Error = Cow::Borrowed("An XHP attribute value is expected here."); pub const error1018: Error = Cow::Borrowed("The `while` keyword is expected here."); pub const error1019: Error = Cow::Borrowed("A left parenthesis `(` is expected here."); pub const error1020: Error = Cow::Borrowed("A colon `:` is expected here."); pub const error1021: Error = Cow::Borrowed("An opening angle bracket `<` is expected here."); // TODO: Remove this; redundant to 1009. pub const error1022: Error = Cow::Borrowed("A right parenthesis `)` or comma `,` is expected here."); pub const error1023: Error = Cow::Borrowed("An `as` keyword is expected here."); pub const error1025: Error = Cow::Borrowed("A shape field name is expected here."); pub const error1026: Error = Cow::Borrowed("An opening square bracket `[` is expected here."); pub const error1028: Error = Cow::Borrowed("An arrow `=>` is expected here."); pub const error1029: Error = Cow::Borrowed("A closing double angle bracket `>>` is expected here."); pub const error1031: Error = Cow::Borrowed("A comma `,` or a closing square bracket `]` is expected here."); pub const error1032: Error = Cow::Borrowed("A closing square bracket `]` is expected here."); // TODO: Break this up according to classish type pub const error1033: Error = Cow::Borrowed(concat!( "A class member, method, type, trait usage, trait require, ", "xhp attribute, xhp use, or xhp category is expected here." )); pub const error1034: Error = Cow::Borrowed("A left brace `{` is expected here."); pub const error1035: Error = Cow::Borrowed("The `class` keyword is expected here."); pub const error1036: Error = Cow::Borrowed("An equals sign `=` is expected here."); pub const error1037: Error = Cow::Borrowed("The `record` keyword is expected here."); pub const error1038: Error = Cow::Borrowed("A semicolon `;` or a namespace body is expected here."); pub const error1039: Error = Cow::Borrowed("A closing XHP tag is expected here."); pub const error1041: Error = Cow::Borrowed("A function body or a semicolon `;` is expected here."); pub const error1044: Error = Cow::Borrowed("A name or `__construct` keyword is expected here."); pub const error1045: Error = Cow::Borrowed("An `extends` or `implements` keyword is expected here."); pub const error1046: Error = Cow::Borrowed("A lambda arrow `==>` is expected here."); pub const error1047: Error = Cow::Borrowed("A scope resolution operator `::` is expected here."); pub const error1048: Error = Cow::Borrowed("A name, variable name or `class` is expected here."); pub const error1050: Error = Cow::Borrowed("A name or variable name is expected here."); pub const error1051: Error = Cow::Borrowed("The `required` or `lateinit` keyword is expected here."); pub const error1052: Error = Cow::Borrowed("An XHP category name beginning with a `%` is expected here."); pub const error1053: Error = Cow::Borrowed("An XHP name or category name is expected here."); pub const error1054: Error = Cow::Borrowed("A comma `,` is expected here."); pub const error1055: Error = Cow::Borrowed(concat!( "A fallthrough directive can only appear at the end of", " a `switch` section." )); pub fn error1056(text: &str) -> Error { Cow::Owned(format!( "This token `{}` is not valid as part of a function declaration.", text )) } pub fn error1057(text: &str) -> Error { // TODO (kasper): T52404885: why does removing to_string() here segfaults Cow::Owned(format!("Encountered unexpected token `{}`.", text)) } pub fn uppercase_kw(text: &str) -> Error { Cow::Owned(format!("Keyword `{}` must be written in lowercase", text)) } pub fn error1058(received: &str, required: &str) -> Error { Cow::Owned(format!( "Encountered unexpected token `{}`. Did you mean `{}`?", received, required )) } pub fn error1059(terminator: TokenKind) -> Error { Cow::Owned(format!( "An `{}` is required when using alternate block syntax.", terminator.to_string(), )) } pub fn error1060(extension: &str) -> Error { let kind = if extension == "hack" { "strict" } else { "partial" }; Cow::Owned(format!( "Leading markup and `<?hh` are not permitted in `.{}` files, which are always `{}`.", extension, kind )) } pub const error1063: Error = Cow::Borrowed("Expected matching separator here."); pub const error1064: Error = Cow::Borrowed("XHP children declarations are no longer supported."); pub const error1065: Error = Cow::Borrowed("A backtick ``` is expected here."); pub const error1066: Error = Cow::Borrowed("Only one 'exports to' is allowed."); pub const error1067: Error = Cow::Borrowed("Only one 'imports from' is allowed."); pub const error2001: Error = Cow::Borrowed("A type annotation is required in `strict` mode."); pub const error2003: Error = Cow::Borrowed("A `case` statement may only appear directly inside a `switch`."); pub const error2004: Error = Cow::Borrowed("A `default` statement may only appear directly inside a `switch`."); pub const error2005: Error = Cow::Borrowed("A `break` statement may only appear inside a `switch` or loop."); pub const error2006: Error = Cow::Borrowed("A `continue` statement may only appear inside a loop."); pub const error2007: Error = Cow::Borrowed("A `try` statement requires a `catch` or a `finally` clause."); pub const error2008: Error = Cow::Borrowed(concat!( "The first statement inside a `switch` statement must ", "be a `case` or `default` label statement." )); pub fn error2009(class_name: &str, method_name: &str) -> Error { Cow::Owned(format!( "Constructor `{}::{}()` cannot be static", class_name, method_name, )) } pub const error2010: Error = Cow::Borrowed(concat!( "Parameters cannot have visibility modifiers (except in ", "parameter lists of constructors)." )); pub const error2014: Error = Cow::Borrowed("An abstract method cannot have a method body."); pub const error2015: Error = Cow::Borrowed("A method must have a body or be marked `abstract`."); pub fn error2016(class_name: &str, method_name: &str) -> Error { Cow::Owned(format!( "Cannot declare abstract method `{}::{}` `private`", class_name, method_name, )) } pub const error2018: Error = Cow::Borrowed("A constructor cannot have a non-`void` type annotation."); pub fn error2019(class_name: &str, method_name: &str) -> Error { Cow::Owned(format!( "Cannot declare abstract method `{}::{}` `final`", class_name, method_name, )) } pub const error2020: Error = Cow::Borrowed(concat!( "Use of the `{}` subscript operator is deprecated; ", " use `[]` instead." )); pub const error2021: Error = Cow::Borrowed(concat!( "A variadic parameter `...` may only appear at the end of ", "a parameter list." )); pub const error2023: Error = Cow::Borrowed("Abstract constructors cannot have parameters with visibility modifiers"); pub const error2024: Error = Cow::Borrowed("Traits or interfaces cannot have parameters with visibility modifiers"); pub const error2022: Error = Cow::Borrowed("A variadic parameter `...` may not be followed by a comma."); pub fn error2025(class_name: &str, prop_name: &str) -> Error { Cow::Owned(format!("Cannot redeclare `{}::{}`", class_name, prop_name)) } pub const error2029: Error = Cow::Borrowed("Only traits and interfaces may use `require extends`."); pub const error2030: Error = Cow::Borrowed("Only traits may use `require implements`."); pub const error2032: Error = Cow::Borrowed("The array type is not allowed in `strict` mode."); pub const error2033: Error = Cow::Borrowed(concat!( "The splat operator `...` for unpacking variadic arguments ", "may only appear at the **end** of an argument list." )); pub const error2034: Error = Cow::Borrowed(concat!( "A type alias declaration cannot both use `type` and have a ", "constraint. Did you mean `newtype`?" )); pub const error2035: Error = Cow::Borrowed("Only classes may implement interfaces."); pub const error2036: Error = Cow::Borrowed(concat!( "Only interfaces and classes may extend other interfaces and ", "classes." )); pub const error2037: Error = Cow::Borrowed("A class may extend at most **one** other class."); pub fn error2038(constructor_name: &str) -> Error { Cow::Owned(format!( concat!( "A constructor initializing an object must be passed a (possibly empty) ", "list of arguments. Did you mean `new {}()`?", ), constructor_name )) } pub const error2040: Error = Cow::Borrowed(concat!( "Invalid use of `list(...)`. A list expression may only be ", "used as the left side of a simple assignment, the value clause of a ", "`foreach` loop, or a list item nested inside another list expression." )); pub const error2041: Error = Cow::Borrowed(concat!( "Unexpected method body: interfaces may contain only", " method signatures, and **not** method implementations." )); pub const error2042: Error = Cow::Borrowed("Only classes may be declared `abstract`."); pub fn error2046(method_type: &str) -> Error { Cow::Owned(format!( "`async` cannot be used on {}. Use an `Awaitable<...>` return type instead.", method_type )) } pub const error2048: Error = Cow::Borrowed("Expected group `use` prefix to end with `\\`"); pub const error2049: Error = Cow::Borrowed("A namespace `use` clause may not specify the kind here."); pub const error2050: Error = Cow::Borrowed("A concrete constant declaration must have an initializer."); pub const error2052: Error = Cow::Borrowed(concat!( "Cannot mix bracketed namespace declarations with ", "unbracketed namespace declarations" )); pub const error2053: Error = Cow::Borrowed(concat!( "Use of `var` as synonym for `public` in declaration disallowed in Hack. ", "Use `public` instead." )); pub const error2054: Error = Cow::Borrowed(concat!( "Method declarations require a visibility modifier ", "such as `public`, `private` or `protected`." )); pub const error2055: Error = Cow::Borrowed("At least one enumerated item is expected."); pub const error2056: Error = Cow::Borrowed("First unbracketed namespace occurrence here"); pub const error2057: Error = Cow::Borrowed("First bracketed namespace occurrence here"); pub const invalid_shape_field_name: Error = Cow::Borrowed("Shape field name must be a nonempty single-quoted string or a class constant"); pub const shape_field_int_like_string: Error = Cow::Borrowed("Shape field name must not be an int-like string (i.e. \"123\")"); pub const error2061: Error = Cow::Borrowed(concat!( "Non-static instance variables are not allowed in abstract ", "final classes." )); pub const error2062: Error = Cow::Borrowed("Non-static methods are not allowed in `abstract final` classes."); pub const error2063: Error = Cow::Borrowed("Expected integer or string literal."); pub const error2065: Error = Cow::Borrowed("A variadic parameter `...` must not have a default value."); // This was typing error 4077. pub const error2066: Error = Cow::Borrowed(concat!( "A previous parameter has a default value. Remove all the ", "default values for the preceding parameters, or add a default value to ", "this one." )); pub const error2068: Error = Cow::Borrowed("`hh` blocks and `php` blocks cannot be mixed."); pub fn invalid_integer_digit(int_kind: ocaml_helper::IntKind) -> Error { Cow::Owned(format!("Invalid digit for {} integers", int_kind)) } pub const prefixed_invalid_string_kind: Error = Cow::Borrowed("Only double-quoted strings may be prefixed."); pub const illegal_interpolated_brace_with_embedded_dollar_expression: Error = Cow::Borrowed(concat!( "The only legal expressions inside a `{$...}`-expression embedded in a string are ", "variables, function calls, subscript expressions, and member access expressions" )); pub const expected_dotdotdot: Error = Cow::Borrowed("`...` is expected here."); pub const invalid_foreach_element: Error = Cow::Borrowed( "An arrow `=>` or right parenthesis `)` \ is expected here.", ); pub const inline_function_def: Error = Cow::Borrowed("Inline function definitions are not supported in Hack"); pub const decl_outside_global_scope: Error = Cow::Borrowed("Declarations are not supported outside global scope"); pub const type_keyword: Error = Cow::Borrowed("The `type` keyword is expected here."); pub fn unbounded_refinement_member_of(type_name: &str) -> Error { Cow::Owned(format!( concat!( "A member that belongs to a refinement of type {} must be constrained either by ", "an exact bound (`=`) or by at least one `as`/`super` bound." ), type_name )) } pub fn duplicate_refinement_member_of(type_or_ctx: &str) -> Error { Cow::Owned(format!( "Member {} is involved in multiple refinement constraints. Members must be constrained at most once, consider fusing constraints (e.g., `Cls with {{ type T as A as B super C; }}`)", type_or_ctx )) } pub const expected_refinement_member: Error = Cow::Borrowed(concat!( "Expected `type` or `ctx` member(s) within the refinement that ends with `}`, ", "e.g.: `type T as U`, `type T = X`, `ctx C super [defaults]`." )); pub const cannot_chain_type_refinements: Error = Cow::Borrowed(concat!( "A type refinement cannot be chained (e.g., `Cls with { ... } with { type T2 ... }`), ", "consider combining members into a single with-block." )); pub const expected_simple_offset_expression: Error = Cow::Borrowed("A simple offset expression is expected here"); pub const expected_user_attribute: Error = Cow::Borrowed("A user attribute is expected here."); pub const expected_as_or_insteadof: Error = Cow::Borrowed("The `as` keyword or the `insteadof` keyword is expected here."); pub const missing_double_quote: Error = /* error0010 analogue */ Cow::Borrowed("A double quote is expected here."); pub const instanceof_disabled: Error = Cow::Borrowed( "The `instanceof` operator is not supported in Hack; use the `is` operator or `is_a()`", ); pub const abstract_instance_property: Error = Cow::Borrowed("Instance property may not be abstract."); pub const memoize_lsb_on_non_static: Error = Cow::Borrowed("`<<__MemoizeLSB>>` can only be applied to static methods"); pub const memoize_lsb_on_non_method: Error = Cow::Borrowed("`<<__MemoizeLSB>>` can only be applied to methods"); pub const expression_as_attribute_arguments: Error = Cow::Borrowed("Attribute arguments must be literals"); pub const instanceof_invalid_scope_resolution: Error = Cow::Borrowed(concat!( "A scope resolution `::` on the right side of an ", "`instanceof` operator must start with a class name, `self`, `parent`, or `static`, and end with ", "a variable", )); pub const instanceof_memberselection_inside_scoperesolution: Error = Cow::Borrowed(concat!( "A scope resolution `::` on the right ", "side of an instanceof operator cannot contain a member selection `->`", )); pub const instanceof_missing_subscript_index: Error = Cow::Borrowed(concat!( "A subscript expression `[]` on the right side of an ", "instanceof operator must have an index", )); pub fn new_unknown_node(msg: &str) -> Error { Cow::Owned(format!( "`new` requires a class name or local variable, but got: `{}`", msg )) } pub const invalid_async_return_hint: Error = Cow::Borrowed("`async` functions must have an `Awaitable` return type."); pub const invalid_awaitable_arity: Error = Cow::Borrowed("`Awaitable<_>` takes exactly one type argument."); pub const invalid_await_use: Error = Cow::Borrowed("`await` cannot be used as an expression"); pub const toplevel_await_use: Error = Cow::Borrowed("`await` cannot be used in a toplevel statement"); pub const invalid_constructor_method_call: Error = Cow::Borrowed( "Method call following immediate constructor call requires parentheses around constructor call.", ); pub const invalid_scope_resolution_qualifier: Error = Cow::Borrowed("Only classnames and variables are allowed before `::`."); pub const invalid_variable_name: Error = Cow::Borrowed( "A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores", ); pub const invalid_yield: Error = Cow::Borrowed("`yield` can only appear as a statement or on the right of an assignment"); pub const invalid_class_in_collection_initializer: Error = Cow::Borrowed("Cannot use collection initialization for non-collection class."); pub const invalid_brace_kind_in_collection_initializer: Error = Cow::Borrowed( "Initializers of `vec`, `dict` and `keyset` should use `[...]` instead of `{...}`.", ); pub fn invalid_value_initializer(name: &str) -> Error { Cow::Owned(format!( "Cannot use value initializer for `{}`. It requires `key => value`.", name )) } pub fn invalid_key_value_initializer(name: &str) -> Error { Cow::Owned(format!( "Cannot use key value initializer for `{}`. It does not allow keys.", name )) } pub const nested_ternary: Error = Cow::Borrowed( "Nested ternary expressions inside ternary expressions are ambiguous. Please add parentheses", ); pub const alternate_control_flow: Error = Cow::Borrowed("Alternate control flow syntax is not allowed in Hack files"); pub const execution_operator: Error = Cow::Borrowed("The execution operator is not allowed in Hack files"); pub const non_re_prefix: Error = Cow::Borrowed("Only `re`-prefixed strings allowed."); pub const collection_intrinsic_generic: Error = Cow::Borrowed("Cannot initialize collection builtins with type parameters"); pub const collection_intrinsic_many_typeargs: Error = Cow::Borrowed("Collection expression must have less than three type arguments"); pub const pair_initializer_needed: Error = Cow::Borrowed("Initializer needed for Pair object"); pub const pair_initializer_arity: Error = Cow::Borrowed("Pair objects must have exactly 2 elements"); pub const toplevel_statements: Error = Cow::Borrowed( "Hack does not support top level statements. Use the `__EntryPoint` attribute on a function instead", ); pub const invalid_reified: Error = Cow::Borrowed("`reify` keyword can only appear at function or class type parameter position"); pub fn reified_in_invalid_classish(s: &str) -> Error { Cow::Owned(format!( "Invalid to use a reified type within {}'s type parameters", s )) } pub const shadowing_reified: Error = Cow::Borrowed("You may not shadow a reified parameter"); pub const static_property_in_reified_class: Error = Cow::Borrowed("You may not use static properties in a class with reified type parameters"); pub const cls_reified_generic_in_static_method: Error = Cow::Borrowed("You may not use reified generics of the class in a static method"); pub const static_method_reified_obj_creation: Error = Cow::Borrowed( "You may not use object creation for potentially reified `self` or `parent` from a static method", ); pub const non_invariant_reified_generic: Error = Cow::Borrowed("Reified generics cannot be covariant or contravariant"); pub const no_generics_on_constructors: Error = Cow::Borrowed( "Generic type parameters are not allowed on constructors. Consider adding a type parameter to the class", ); pub const no_type_parameters_on_dynamic_method_calls: Error = Cow::Borrowed("Generics type parameters are disallowed on dynamic method calls"); pub const dollar_unary: Error = Cow::Borrowed("The dollar sign `$` cannot be used as a unary operator"); pub const type_alias_to_type_constant: Error = Cow::Borrowed("Type aliases to type constants are not supported"); pub const interface_with_memoize: Error = Cow::Borrowed("`__Memoize` is not allowed on interface methods"); pub const nested_concurrent_blocks: Error = Cow::Borrowed("`concurrent` blocks cannot be nested."); pub const fewer_than_two_statements_in_concurrent_block: Error = Cow::Borrowed(concat!( "Expected 2 or more statements in concurrent block. `concurrent` wrapping ", "nothing or a single statement is not useful or already implied.", )); pub const invalid_syntax_concurrent_block: Error = Cow::Borrowed(concat!( "`concurrent` block must contain a compound statement of two or ", "more expression statements, IE concurrent `{ <expr>; <expr>; }`.", )); pub const statement_without_await_in_concurrent_block: Error = Cow::Borrowed("Statement without an `await` in a concurrent block"); pub const concurrent_is_disabled: Error = Cow::Borrowed("`concurrent` is disabled"); pub const invalid_await_position: Error = Cow::Borrowed(concat!( "`await` cannot be used as an expression in this ", "location because it's conditionally executed.", )); pub const invalid_await_position_dependent: Error = Cow::Borrowed(concat!( "`await` cannot be used as an expression inside another await expression. ", "Pull the inner `await` out into its own statement.", )); pub const tparams_in_tconst: Error = Cow::Borrowed("Type parameters are not allowed on class type constants"); pub const targs_not_allowed: Error = Cow::Borrowed("Type arguments are not allowed in this position"); pub const reified_attribute: Error = Cow::Borrowed( "`__Reified` and `__HasReifiedParent` attributes may not be provided by the user", ); pub const lval_as_expression: Error = Cow::Borrowed( "Assignments can no longer be used as expressions. Pull the assignment out into a separate statement.", ); pub fn elt_abstract_private(elt: &str) -> Error { Cow::Owned(format!("Cannot declare abstract {} `private`.", elt)) } pub const only_soft_allowed: Error = Cow::Borrowed("Only the `__Soft` attribute is allowed here."); pub const soft_no_arguments: Error = Cow::Borrowed("The `__Soft` attribute does not take arguments."); pub const no_legacy_soft_typehints: Error = Cow::Borrowed( "The `@` syntax for soft typehints is not allowed. Use the `__Soft` attribute instead.", ); pub const outside_dollar_str_interp: Error = Cow::Borrowed("The `${x}` syntax is disallowed in Hack. Use `{$x}` instead."); pub const no_const_interfaces_traits_enums: Error = Cow::Borrowed("Interfaces, traits and enums may not be declared `__Const`"); pub const no_const_late_init_props: Error = Cow::Borrowed("`__Const` properties may not also be `__LateInit`"); pub const no_const_abstract_final_class: Error = Cow::Borrowed("Cannot apply `__Const` attribute to an abstract final class"); pub const no_legacy_attribute_syntax: Error = Cow::Borrowed( "The `<<...>>` syntax for user attributes is not allowed. Use the `@` syntax instead.", ); pub const no_silence: Error = Cow::Borrowed("The error suppression operator `@` is not allowed"); pub const const_mutation: Error = Cow::Borrowed("Cannot mutate a class constant"); pub const no_attributes_on_variadic_parameter: Error = Cow::Borrowed("Attributes on variadic parameters are not allowed"); pub const no_attributes_on_enum_class_enumerator: Error = Cow::Borrowed("Attributes on enum class enumerators are not allowed"); pub const invalid_constant_initializer: Error = Cow::Borrowed("Expected constant expression for initializer"); pub const parent_static_prop_decl: Error = Cow::Borrowed("Cannot use `static` or `parent::class` in property declaration"); pub fn error2070(open_tag: &str, close_tag: &str) -> Error { Cow::Owned(format!( "XHP: mismatched tag: `{}` not the same as `{}`", close_tag, open_tag )) } pub fn error2071(s: &str) -> Error { Cow::Owned(format!("Decimal number is too big: `{}`", s)) } pub fn error2072(s: &str) -> Error { Cow::Owned(format!("Hexadecimal number is too big: `{}`", s)) } pub const error2073: Error = Cow::Borrowed(concat!( "A variadic parameter `...` cannot have a modifier ", "that changes the calling convention, like `inout`.", )); pub fn error2074(call_modifier: &str) -> Error { Cow::Owned(format!( "An `{}` parameter must not have a default value.", call_modifier )) } pub const error2077: Error = Cow::Borrowed("Cannot use empty list"); pub const reassign_this: Error = Cow::Borrowed("Cannot re-assign `$this`"); pub fn not_allowed_in_write(what: &str) -> Error { Cow::Owned(format!("{} is not allowed in write context", what)) } pub fn invalid_lval(root: LvalRoot) -> Error { Cow::Owned(format!( "You cannot use this syntax {}", match root { LvalRoot::Unset => "in an `unset()` expression.", LvalRoot::Assignment => "on the left-hand side of an assignment.", LvalRoot::Inout => "with `inout`.", LvalRoot::IncrementOrDecrement => "with an increment or decrement statement.", LvalRoot::CatchClause => "where a `catch` variable is expected.", LvalRoot::Foreach => "as the iterator variable in a `foreach` loop.", } )) } pub const enum_elem_name_is_class: Error = Cow::Borrowed("Enum element cannot be named `class`"); pub const enum_class_elem_name_is_class: Error = Cow::Borrowed("Enum class members cannot be named `class`"); pub const property_requires_visibility: Error = Cow::Borrowed(concat!( "Property declarations require a visibility modifier ", "such as `public`, `private` or `protected`.", )); pub const abstract_prop_init: Error = Cow::Borrowed("An `abstract` property must not have an initializer."); pub const const_static_prop_init: Error = Cow::Borrowed("A `const static` property must have an initializer."); pub fn namespace_name_is_already_in_use(name: &str, short_name: &str) -> Error { Cow::Owned(format!( "Cannot use namespace `{}` as `{}` because the name is already in use", name, short_name )) } pub const strict_namespace_hh: Error = Cow::Borrowed(concat!( "To use strict Hack, place `// strict` after the open tag. ", "If it's already there, remove this line. ", "Hack is strict already.", )); pub fn name_is_already_in_use_hh(line_num: isize, name: &str, short_name: &str) -> Error { Cow::Owned(format!( "Cannot use `{}` as `{}` because the name was explicitly used earlier via a `use` statement on line {}", name, short_name, line_num )) } pub fn name_is_already_in_use_implicit_hh(line_num: isize, name: &str, short_name: &str) -> Error { Cow::Owned(format!( concat!( "Cannot use `{}` as `{}` because the name was implicitly used on line {}", "; implicit use of names from the HH namespace can be suppressed by adding an explicit", " `use` statement earlier in the current namespace block", ), name, short_name, line_num )) } pub fn name_is_already_in_use_php(name: &str, short_name: &str) -> Error { Cow::Owned(format!( "Cannot use `{}` as `{}` because the name is already in use", name, short_name, )) } pub const original_definition: Error = Cow::Borrowed("Original definition"); pub fn function_name_is_already_in_use(name: &str, short_name: &str) -> Error { Cow::Owned(format!( "Cannot use function `{}` as `{}` because the name is already in use", name, short_name )) } pub fn const_name_is_already_in_use(name: &str, short_name: &str) -> Error { Cow::Owned(format!( "Cannot use const `{}` as `{}` because the name is already in use", name, short_name )) } pub fn type_name_is_already_in_use(name: &str, short_name: &str) -> Error { Cow::Owned(format!( "Cannot use type `{}` as `{}` because the name is already in use", name, short_name )) } pub const namespace_decl_first_statement: Error = Cow::Borrowed( "Namespace declaration statement has to be the very first statement in the script", ); pub const code_outside_namespace: Error = Cow::Borrowed("No code may exist outside of namespace {}"); pub const global_in_const_decl: Error = Cow::Borrowed("Cannot have globals in constant declaration"); pub const parent_static_const_decl: Error = Cow::Borrowed("Cannot use `static` or `parent::class` in constant declaration"); pub const no_async_before_lambda_body: Error = Cow::Borrowed("Don't use `() ==> async { ... }`. Instead, use: `async () ==> { ... }`"); pub fn invalid_number_of_args(name: &str, n: usize) -> Error { Cow::Owned(format!( "Method `{}` must take exactly {} arguments", name, n, )) } pub fn invalid_inout_args(name: &str) -> Error { Cow::Owned(format!("Method `{}` cannot take inout arguments", name)) } pub fn redeclaration_error(name: &str) -> Error { Cow::Owned(format!("Cannot redeclare `{}`", name)) } pub fn declared_name_is_already_in_use_implicit_hh( line_num: usize, name: &str, _short_name: &str, ) -> Error { Cow::Owned(format!( concat!( "Cannot declare `{}` because the name was implicitly used on line {}; ", "implicit use of names from the HH namespace can be suppressed by adding an explicit ", "`use` statement earlier in the current namespace block", ), name, line_num )) } pub fn declared_name_is_already_in_use(line_num: usize, name: &str, _short_name: &str) -> Error { Cow::Owned(format!( concat!( "Cannot declare `{}` because the name was explicitly used earlier via a `use` ", "statement on line {}", ), name, line_num )) } pub const sealed_val_not_classname: Error = Cow::Borrowed("Values in sealed allowlist must be classname constants."); pub const sealed_qualifier_invalid: Error = Cow::Borrowed("`__Sealed` can only be used with named types, e.g. `Foo::class`"); pub const list_must_be_lvar: Error = Cow::Borrowed("`list()` can only be used as an lvar. Did you mean to use `tuple()`?"); pub const async_not_last: Error = Cow::Borrowed("The `async` modifier must be directly before the `function` keyword."); pub const using_st_function_scoped_top_level: Error = Cow::Borrowed(concat!( "Using statement in function scoped form may only be used at the top ", "level of a function or a method", )); pub const double_variadic: Error = Cow::Borrowed("Parameter redundantly marked as variadic `...`."); pub fn conflicting_trait_require_clauses(name: &str) -> Error { Cow::Owned(format!("Conflicting requirements for `{}`", name)) } pub const shape_type_ellipsis_without_trailing_comma: Error = Cow::Borrowed("A comma is required before the `...` in a shape type"); pub const yield_in_magic_methods: Error = Cow::Borrowed("`yield` is not allowed in constructors or magic methods"); pub const yield_outside_function: Error = Cow::Borrowed("`yield` can only be used inside a function"); pub const coloncolonclass_on_dynamic: Error = Cow::Borrowed("Dynamic class names are not allowed in compile-time `::class` fetch"); pub const this_in_static: Error = Cow::Borrowed("Don't use `$this` in a static method, use `static::` instead"); pub fn async_magic_method(name: &str) -> Error { Cow::Owned(format!( "Cannot declare constructors and magic methods like `{}` as `async`", name )) } pub fn unsupported_magic_method(name: &str) -> Error { Cow::Owned(format!("Magic `{}` methods are no longer supported", name)) } pub fn reserved_keyword_as_type_name(name: &str) -> Error { Cow::Owned(format!( "Cannot use `{}` as a type name as it is reserved", name )) } pub const xhp_class_multiple_category_decls: Error = Cow::Borrowed("An XHP class cannot have multiple category declarations"); pub const xhp_class_multiple_children_decls: Error = Cow::Borrowed("An XHP class cannot have multiple children declarations"); pub const inout_param_in_generator: Error = Cow::Borrowed("Parameters may not be marked `inout` on generators"); pub const inout_param_in_async_generator: Error = Cow::Borrowed("Parameters may not be marked `inout` on `async` generators"); pub const inout_param_in_async: Error = Cow::Borrowed("Parameters may not be marked `inout` on `async` functions"); pub const inout_param_in_construct: Error = Cow::Borrowed("Parameters may not be marked `inout` on constructors"); pub const fun_arg_inout_set: Error = Cow::Borrowed("You cannot set an `inout` decorated argument while calling a function"); pub const fun_arg_inout_const: Error = Cow::Borrowed("You cannot decorate a constant as `inout`"); pub const fun_arg_invalid_arg: Error = Cow::Borrowed("You cannot decorate this argument as `inout`"); pub const fun_arg_inout_containers: Error = Cow::Borrowed(concat!( "Parameters marked `inout` must be contained in locals, vecs, dicts, keysets,", " and arrays", )); pub const memoize_with_inout: Error = Cow::Borrowed("`<<__Memoize>>` cannot be used on functions with `inout` parameters"); pub const method_calls_on_xhp_attributes: Error = Cow::Borrowed("Method calls are not allowed on XHP attributes"); pub const method_calls_on_xhp_expression: Error = Cow::Borrowed("Please add parentheses around the XHP component"); pub fn class_with_abstract_method(name: &str) -> Error { Cow::Owned(format!( concat!( "Class `{}` contains an abstract method and must ", "therefore be declared `abstract`", ), name )) } pub const interface_has_private_method: Error = Cow::Borrowed("Interface methods must be `public` or `protected`"); pub fn redeclaration_of_function(name: &str, loc: &str) -> Error { Cow::Owned(format!( "Cannot redeclare `{}()` (previously declared in {})", name, loc )) } pub fn redeclaration_of_method(name: &str) -> Error { Cow::Owned(format!("Redeclared method `{}`", name,)) } pub fn self_or_parent_colon_colon_class_outside_of_class(name: &str) -> Error { Cow::Owned(format!( "Cannot access `{}::class` when no class scope is active", name, )) } pub fn invalid_is_as_expression_hint(n: &str, hint: &str) -> Error { Cow::Owned(format!( "`{}` typehints cannot be used with `{}` expressions", hint, n, )) } pub const elvis_operator_space: Error = Cow::Borrowed("An Elvis operator `?:` is expected here."); pub fn clone_takes_no_arguments(class_name: &str, method_name: &str) -> Error { Cow::Owned(format!( "Method `{}::{}` cannot accept any arguments", class_name, method_name )) } pub fn clone_cannot_be_static(class_name: &str, method_name: &str) -> Error { Cow::Owned(format!( "Clone method `{}::{}()` cannot be static", class_name, method_name )) } pub const namespace_not_a_classname: Error = Cow::Borrowed("Namespace cannot be used as a classname"); pub const for_with_as_expression: Error = Cow::Borrowed("For loops can not use `as` expressions. Did you mean `foreach`?"); pub const sealed_final: Error = Cow::Borrowed("Classes cannot be both `final` and `sealed`."); pub const interface_implements: Error = Cow::Borrowed("Interfaces may not implement other interfaces or classes"); pub const memoize_on_lambda: Error = Cow::Borrowed("`<<__Memoize>>` attribute is not allowed on lambdas or anonymous functions."); pub fn declared_final(elt: &str) -> Error { Cow::Owned(format!("{} cannot be declared `final`.", elt)) } pub fn invalid_xhp_classish(elt: &str) -> Error { Cow::Owned(format!("{} are not valid xhp classes.", elt)) } pub const empty_method_name: Error = Cow::Borrowed("Expected a method name"); pub fn lowering_parsing_error(text: &str, syntax: &str) -> Error { Cow::Owned(format!( "Encountered unexpected text `{}`, was expecting a {}.", text, syntax )) } pub const xhp_class_attribute_type_constant: Error = Cow::Borrowed("Type constants are not allowed on xhp class attributes"); pub const globals_disallowed: Error = Cow::Borrowed("`$GLOBALS` variable is removed from the language. Use HH\\global functions"); pub const invalid_this: Error = Cow::Borrowed("`$this` cannot be used in functions and static methods"); pub const cannot_unset_this: Error = Cow::Borrowed("`$this` cannot be unset"); pub const invalid_await_position_pipe: Error = Cow::Borrowed("`await` cannot be used as an expression right of a pipe operator."); pub fn invalid_modifier_for_declaration(decl: &str, modifier: &str) -> Error { Cow::Owned(format!("{} cannot be declared `{}`", decl, modifier)) } pub fn duplicate_modifiers_for_declaration(decl: &str) -> Error { Cow::Owned(format!("{} cannot have duplicate modifiers", decl)) } pub fn multiple_visibility_modifiers_for_declaration(decl: &str) -> Error { Cow::Owned(format!( "{} cannot have multiple visibility modifiers", decl, )) } pub const break_continue_n_not_supported: Error = Cow::Borrowed("`break`/`continue N` operators are not supported."); pub const function_pointer_bad_recv: Error = Cow::Borrowed(concat!( "Function pointers `<>` can only be created with toplevel functions and explicitly named static methods. ", "Use lambdas `(...) ==> {...}` for other cases." )); pub const local_variable_with_type: Error = Cow::Borrowed("Local variables cannot have type annotations in Hack."); pub const empty_expression_illegal: Error = Cow::Borrowed("The `empty()` expression has been removed from Hack."); pub const empty_switch_cases: Error = Cow::Borrowed("`switch` statements need to have at least one `case` or a `default` block"); pub const empty_match_statement: Error = Cow::Borrowed("`match` statements need to have at least one arm"); pub const expected_pattern: Error = Cow::Borrowed("A pattern is expected here."); pub const variable_patterns_nyi: Error = Cow::Borrowed("Binding a variable in a pattern is not yet supported."); pub const destructuring_patterns_nyi: Error = Cow::Borrowed("Destructuring values in patterns is not yet supported."); pub const constructor_patterns_nyi: Error = Cow::Borrowed( "Constructor patterns are not yet supported. Use a type refinement pattern `_: T` instead.", ); pub fn wildcard_underscore(name: &str) -> Error { Cow::Owned(format!( "Wildcard patterns must begin with the `_` character. To bind a variable, use a `$` character (`${name}`).", )) } pub const preceding_backslash: Error = Cow::Borrowed("Unnecessary preceding backslash"); pub fn multiple_entrypoints(loc: &str) -> Error { Cow::Owned(format!( "Only one `__EntryPoint` annotation is permitted per file (previous `__EntryPoint` annotation in {})", loc )) } pub fn cannot_use_feature(feature: &str) -> Error { Cow::Owned(format!("Cannot use unstable feature: `{}`", feature)) } pub fn cannot_enable_unstable_feature(message: &str) -> Error { Cow::Owned(format!("Cannot enable unstable feature: {}", message)) } pub fn invalid_use_of_enable_unstable_feature(message: &str) -> Error { Cow::Owned(format!( "This is an invalid use of `__EnableUnstableFeatures` because {}", message )) } pub const splice_outside_et: Error = Cow::Borrowed("Splicing can only occur inside expression tree literals (between backticks)"); pub const invalid_enum_class_enumerator: Error = Cow::Borrowed("Invalid enum class constant"); pub fn fun_disabled(func_name: &str) -> Error { Cow::Owned(format!( "`fun()` is disabled; switch to first-class references like `{}<>`", func_name.trim_end_matches('\'').trim_start_matches('\'') )) } pub const fun_requires_const_string: Error = Cow::Borrowed("Constant string expected in fun()"); pub const class_meth_disabled: Error = Cow::Borrowed("`class_meth()` is disabled; switch to first-class references like `C::bar<>`"); pub fn ctx_var_invalid_parameter(param_name: &str) -> Error { Cow::Owned(format!( "Could not find parameter {} for dependent context", param_name )) } pub fn ctx_var_missing_type_hint(param_name: &str) -> Error { Cow::Owned(format!( "Parameter {} used for dependent context must have a type hint", param_name )) } pub fn ctx_var_variadic(param_name: &str) -> Error { Cow::Owned(format!( "Parameter {} used for dependent context cannot be variadic", param_name )) } pub fn ctx_var_invalid_type_hint(param_name: &str) -> Error { Cow::Owned(format!( "Type hint for parameter {} used for dependent context must be a class or a generic", param_name )) } pub fn ctx_fun_invalid_type_hint(param_name: &str) -> Error { Cow::Owned(format!( "Type hint for parameter {} used for contextful function must be a function type hint whose context is exactly `[_]`, e.g. `(function (ts)[_]: t)`", param_name )) } pub fn ctx_generic_invalid(tparam_name: &str, ctx: String) -> Error { Cow::Owned(format!( "Type parameter {} used for dependent context {} must be reified", tparam_name, ctx )) } pub fn effect_polymorphic_memoized(kind: &str) -> Error { Cow::Owned(format!( "This {} cannot be memoized because it has a polymorphic context", kind )) } pub fn effect_policied_memoized(kind: &str) -> Error { Cow::Owned(format!( "This {} can only be memoized using __Memoize(#KeyedByIC) or __MemoizeLSB(#KeyedByIC) because it has zoned context", kind )) } pub fn policy_sharded_memoized_without_policied(kind: &str) -> Error { Cow::Owned(format!( "This {} requires a zoned context to be memoized using __Memoize(#KeyedByIC) or __MemoizeLSB(#KeyedByIC)", kind )) } pub fn memoize_make_ic_inaccessible_without_defaults(kind: &str) -> Error { Cow::Owned(format!( "This {} requires the defaults, leak_safe_shallow, or leak_safe_local context to be memoized using #MakeICInaccessible or #SoftMakeICInaccessible", kind )) } pub fn memoize_category_without_implicit_policy_capability(kind: &str) -> Error { Cow::Owned(format!( "{}s that can neither directly nor indirectly call a function requiring [zoned] do not need to and cannot pass arguments to __Memoize or __MemoizeLSB", kind )) } pub fn memoize_invalid_arity(attr: &str, num_args: usize, label: &str) -> Error { Cow::Owned(format!( "`{}` takes {} argument{} when using `{}`.", attr, num_args, if num_args == 1 { "" } else { "s" }, label )) } pub const memoize_invalid_sample_rate: Error = Cow::Borrowed("Expected a valid 32-bit integer as a sample rate."); pub fn memoize_invalid_label(attr: &str) -> Error { Cow::Owned(format!("Invalid label for `{}`.", attr)) } pub fn memoize_requires_label(attr: &str) -> Error { Cow::Owned(format!( "The first argument to `{}` must be a label, e.g. `#KeyedByIC`.", attr )) } pub fn lambda_effect_polymorphic(kind: &str) -> Error { Cow::Owned(format!("{} cannot have a polymorphic context", kind)) } pub const inst_meth_disabled: Error = Cow::Borrowed("`inst_meth()` is disabled; use a lambda `(...) ==> {...}` instead"); pub const as_mut_single_argument: Error = Cow::Borrowed("HH\\Readonly\\as_mut takes a single value-typed expression as an argument."); pub fn out_of_int_range(int: &str) -> Error { Cow::Owned(format!( "{} is out of the range of 64-bit float values", int, )) } pub fn out_of_float_range(float: &str) -> Error { Cow::Owned(format!( "{} is out of the range of 64-bit float values", float, )) } pub fn user_ctx_should_be_caps(ctx_name: &str) -> Error { Cow::Owned(format!( "Context {} should begin with an uppercase letter", ctx_name )) } pub fn user_ctx_require_as(ctx_name: &str) -> Error { Cow::Owned(format!( "Context {} must declare a context constraint e.g. `as [write_props]`", ctx_name )) } pub const assignment_to_readonly: Error = Cow::Borrowed("This expression is readonly, its members cannot be modified"); pub const assign_readonly_to_mutable_collection: Error = Cow::Borrowed( "This expression is readonly, but the collection you're modifying is mutable, which isn't allowed.", ); pub fn invalid_readonly(r1: &str, r2: &str, reason: &str) -> Error { Cow::Owned(format!( "This expression is {}, but we expected a {} value because {}", r1, r2, reason )) } pub const inout_readonly_assignment: Error = Cow::Borrowed("Cannot write a readonly value to an inout parameter"); pub const inout_readonly_parameter: Error = Cow::Borrowed("Inout readonly parameters are not currently supported"); pub const inout_readonly_argument: Error = Cow::Borrowed( "This expression is readonly. We currently do not support passing readonly values to an inout parameter.", ); pub const yield_readonly: Error = Cow::Borrowed( "This expression is readonly. We currently do not support yielding readonly values.", ); pub const enum_class_constant_missing_initializer: Error = Cow::Borrowed("Concrete enum class constants must have an initial value"); pub const enum_class_abstract_constant_with_value: Error = Cow::Borrowed("Abstract enum class constants must not provide any initial value"); pub const enum_with_modifiers: Error = Cow::Borrowed("Enums can't have any modifiers"); pub const enum_missing_base_type: Error = Cow::Borrowed("Enums must have a base type, such as `arraykey` or `int`."); pub const readonly_static_method: Error = Cow::Borrowed("Static methods do not need to be marked readonly"); pub const variadic_readonly_param: Error = Cow::Borrowed("Variadic parameters cannot be marked readonly"); pub const throw_readonly_exception: Error = Cow::Borrowed( "This exception is readonly; throwing readonly exceptions is not currently supported.", ); pub const direct_coeffects_reference: Error = Cow::Borrowed("Direct references to coeffects namespaces are not allowed"); pub const invalid_attribute_reserved: Error = Cow::Borrowed("This attribute is reserved and cannot be used in user code."); pub const readonly_on_xhp: Error = Cow::Borrowed("Readonly values cannot be written to xhp attributes at this time."); pub const write_props_without_capability: Error = Cow::Borrowed( "Writing to object properties requires the capability WriteProperty, which is not provided by the context. Add the context `[write_props]` after the function parameter list (or amend an existing context with a new comma delineated entry `write_props`).", ); pub const closure_in_local_context: Error = Cow::Borrowed( "Closures in local contexts require explicit annotation. Consider adding explicit contexts to this closure e.g. [leak_safe_local] or [zoned_local] or [defaults].", ); pub const read_globals_without_capability: Error = Cow::Borrowed( "Reading static properties requires the capability ReadGlobals, which is not provided by the context. Add the context `[read_globals]` after the function parameter list (or amend an existing context with a new comma delineated entry `read_globals`).", ); pub const access_globals_without_capability: Error = Cow::Borrowed( "Writing to static properties requires the capability Globals, which is not provided by the context. Add the context `[globals]` after the function parameter list (or amend an existing context with a new comma delineated entry `globals`).", ); pub fn module_attr_arity(len: usize) -> Error { Cow::Owned(format!("`__Module` takes 1 argument, but got {}", len)) } pub const read_globals_without_readonly: Error = Cow::Borrowed( "Creating mutable references to static properties requires the capability Globals, which is not provided by the context. Enclose the static in a readonly expression.", ); pub const missing_fn_def_body: Error = Cow::Borrowed("Non-native functions must have a body"); pub const multiple_defaults_in_switch: Error = Cow::Borrowed("There can be only one `default` case in `switch`"); pub const default_switch_case_not_last: Error = Cow::Borrowed("Default case in `switch` must be terminal"); pub const dollar_sign_in_meth_caller_argument: Error = Cow::Borrowed("`meth_caller` cannot be called on strings that contain `$`"); pub const require_class_applied_to_generic: Error = Cow::Borrowed("Require class cannot be used with a generic class"); pub const invalid_enum_class_label_qualifier: Error = Cow::Borrowed( "Invalid label qualifier. Only names or qualified names are allowed at this position.", ); pub const internal_outside_of_module: Error = Cow::Borrowed( "`internal` cannot be used outside of a module. Please define a module for this file.", ); pub const module_newtype_outside_of_module: Error = Cow::Borrowed( "`module newtype` type aliases cannot be used outside of a module. Please define a module for this file.", ); pub const public_toplevel_outside_of_module: Error = Cow::Borrowed( "`public` on toplevel entities cannot be used outside of a module. Please define a module for this file.", ); pub fn module_first_in_file(name: &str) -> Error { Cow::Owned(format!( "`module {};` must be unique, and precede any other declarations in a file.", name )) } pub const module_declaration_in_module: Error = Cow::Borrowed("You cannot declare new modules within an existing module"); pub fn invalid_cross_package_argument(message: &str) -> Error { Cow::Owned(format!( "This is an invalid use of '__CrossPackage' because {}", message )) } pub fn cross_package_wrong_arity(count: usize) -> Error { Cow::Owned(format!( "The '__CrossPackage' attribute expects exactly 1 argument, {} given.", count )) } pub const expected_bar_or_semicolon: Error = Cow::Borrowed( "Either the token `|` or `;` is expected here. Use `|` to specify additional variant types for this case type or use `;` to terminate the declaration.", );
Rust
hhvm/hphp/hack/src/parser/syntax_generated.rs
/** * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. An additional * directory. * ** * * THIS FILE IS @generated; DO NOT EDIT IT * To regenerate this file, run * * buck run //hphp/hack/src:generate_full_fidelity * ** * */ use crate::lexable_token::LexableToken; use crate::syntax::*; use crate::syntax_kind::SyntaxKind; impl<T, V, C> SyntaxType<C> for Syntax<T, V> where T: LexableToken, V: SyntaxValueType<T>, { fn make_end_of_file(_: &C, end_of_file_token: Self) -> Self { let syntax = SyntaxVariant::EndOfFile(Box::new(EndOfFileChildren { end_of_file_token, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_script(_: &C, script_declarations: Self) -> Self { let syntax = SyntaxVariant::Script(Box::new(ScriptChildren { script_declarations, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_qualified_name(_: &C, qualified_name_parts: Self) -> Self { let syntax = SyntaxVariant::QualifiedName(Box::new(QualifiedNameChildren { qualified_name_parts, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_module_name(_: &C, module_name_parts: Self) -> Self { let syntax = SyntaxVariant::ModuleName(Box::new(ModuleNameChildren { module_name_parts, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_simple_type_specifier(_: &C, simple_type_specifier: Self) -> Self { let syntax = SyntaxVariant::SimpleTypeSpecifier(Box::new(SimpleTypeSpecifierChildren { simple_type_specifier, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_literal_expression(_: &C, literal_expression: Self) -> Self { let syntax = SyntaxVariant::LiteralExpression(Box::new(LiteralExpressionChildren { literal_expression, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_prefixed_string_expression(_: &C, prefixed_string_name: Self, prefixed_string_str: Self) -> Self { let syntax = SyntaxVariant::PrefixedStringExpression(Box::new(PrefixedStringExpressionChildren { prefixed_string_name, prefixed_string_str, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_prefixed_code_expression(_: &C, prefixed_code_prefix: Self, prefixed_code_left_backtick: Self, prefixed_code_body: Self, prefixed_code_right_backtick: Self) -> Self { let syntax = SyntaxVariant::PrefixedCodeExpression(Box::new(PrefixedCodeExpressionChildren { prefixed_code_prefix, prefixed_code_left_backtick, prefixed_code_body, prefixed_code_right_backtick, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_variable_expression(_: &C, variable_expression: Self) -> Self { let syntax = SyntaxVariant::VariableExpression(Box::new(VariableExpressionChildren { variable_expression, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_pipe_variable_expression(_: &C, pipe_variable_expression: Self) -> Self { let syntax = SyntaxVariant::PipeVariableExpression(Box::new(PipeVariableExpressionChildren { pipe_variable_expression, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_file_attribute_specification(_: &C, file_attribute_specification_left_double_angle: Self, file_attribute_specification_keyword: Self, file_attribute_specification_colon: Self, file_attribute_specification_attributes: Self, file_attribute_specification_right_double_angle: Self) -> Self { let syntax = SyntaxVariant::FileAttributeSpecification(Box::new(FileAttributeSpecificationChildren { file_attribute_specification_left_double_angle, file_attribute_specification_keyword, file_attribute_specification_colon, file_attribute_specification_attributes, file_attribute_specification_right_double_angle, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_enum_declaration(_: &C, enum_attribute_spec: Self, enum_modifiers: Self, enum_keyword: Self, enum_name: Self, enum_colon: Self, enum_base: Self, enum_type: Self, enum_left_brace: Self, enum_use_clauses: Self, enum_enumerators: Self, enum_right_brace: Self) -> Self { let syntax = SyntaxVariant::EnumDeclaration(Box::new(EnumDeclarationChildren { enum_attribute_spec, enum_modifiers, enum_keyword, enum_name, enum_colon, enum_base, enum_type, enum_left_brace, enum_use_clauses, enum_enumerators, enum_right_brace, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_enum_use(_: &C, enum_use_keyword: Self, enum_use_names: Self, enum_use_semicolon: Self) -> Self { let syntax = SyntaxVariant::EnumUse(Box::new(EnumUseChildren { enum_use_keyword, enum_use_names, enum_use_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_enumerator(_: &C, enumerator_name: Self, enumerator_equal: Self, enumerator_value: Self, enumerator_semicolon: Self) -> Self { let syntax = SyntaxVariant::Enumerator(Box::new(EnumeratorChildren { enumerator_name, enumerator_equal, enumerator_value, enumerator_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_enum_class_declaration(_: &C, enum_class_attribute_spec: Self, enum_class_modifiers: Self, enum_class_enum_keyword: Self, enum_class_class_keyword: Self, enum_class_name: Self, enum_class_colon: Self, enum_class_base: Self, enum_class_extends: Self, enum_class_extends_list: Self, enum_class_left_brace: Self, enum_class_elements: Self, enum_class_right_brace: Self) -> Self { let syntax = SyntaxVariant::EnumClassDeclaration(Box::new(EnumClassDeclarationChildren { enum_class_attribute_spec, enum_class_modifiers, enum_class_enum_keyword, enum_class_class_keyword, enum_class_name, enum_class_colon, enum_class_base, enum_class_extends, enum_class_extends_list, enum_class_left_brace, enum_class_elements, enum_class_right_brace, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_enum_class_enumerator(_: &C, enum_class_enumerator_modifiers: Self, enum_class_enumerator_type: Self, enum_class_enumerator_name: Self, enum_class_enumerator_initializer: Self, enum_class_enumerator_semicolon: Self) -> Self { let syntax = SyntaxVariant::EnumClassEnumerator(Box::new(EnumClassEnumeratorChildren { enum_class_enumerator_modifiers, enum_class_enumerator_type, enum_class_enumerator_name, enum_class_enumerator_initializer, enum_class_enumerator_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_alias_declaration(_: &C, alias_attribute_spec: Self, alias_modifiers: Self, alias_module_kw_opt: Self, alias_keyword: Self, alias_name: Self, alias_generic_parameter: Self, alias_constraint: Self, alias_equal: Self, alias_type: Self, alias_semicolon: Self) -> Self { let syntax = SyntaxVariant::AliasDeclaration(Box::new(AliasDeclarationChildren { alias_attribute_spec, alias_modifiers, alias_module_kw_opt, alias_keyword, alias_name, alias_generic_parameter, alias_constraint, alias_equal, alias_type, alias_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_context_alias_declaration(_: &C, ctx_alias_attribute_spec: Self, ctx_alias_keyword: Self, ctx_alias_name: Self, ctx_alias_generic_parameter: Self, ctx_alias_as_constraint: Self, ctx_alias_equal: Self, ctx_alias_context: Self, ctx_alias_semicolon: Self) -> Self { let syntax = SyntaxVariant::ContextAliasDeclaration(Box::new(ContextAliasDeclarationChildren { ctx_alias_attribute_spec, ctx_alias_keyword, ctx_alias_name, ctx_alias_generic_parameter, ctx_alias_as_constraint, ctx_alias_equal, ctx_alias_context, ctx_alias_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_case_type_declaration(_: &C, case_type_attribute_spec: Self, case_type_modifiers: Self, case_type_case_keyword: Self, case_type_type_keyword: Self, case_type_name: Self, case_type_generic_parameter: Self, case_type_as: Self, case_type_bounds: Self, case_type_equal: Self, case_type_variants: Self, case_type_semicolon: Self) -> Self { let syntax = SyntaxVariant::CaseTypeDeclaration(Box::new(CaseTypeDeclarationChildren { case_type_attribute_spec, case_type_modifiers, case_type_case_keyword, case_type_type_keyword, case_type_name, case_type_generic_parameter, case_type_as, case_type_bounds, case_type_equal, case_type_variants, case_type_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_case_type_variant(_: &C, case_type_variant_bar: Self, case_type_variant_type: Self) -> Self { let syntax = SyntaxVariant::CaseTypeVariant(Box::new(CaseTypeVariantChildren { case_type_variant_bar, case_type_variant_type, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_property_declaration(_: &C, property_attribute_spec: Self, property_modifiers: Self, property_type: Self, property_declarators: Self, property_semicolon: Self) -> Self { let syntax = SyntaxVariant::PropertyDeclaration(Box::new(PropertyDeclarationChildren { property_attribute_spec, property_modifiers, property_type, property_declarators, property_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_property_declarator(_: &C, property_name: Self, property_initializer: Self) -> Self { let syntax = SyntaxVariant::PropertyDeclarator(Box::new(PropertyDeclaratorChildren { property_name, property_initializer, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_namespace_declaration(_: &C, namespace_header: Self, namespace_body: Self) -> Self { let syntax = SyntaxVariant::NamespaceDeclaration(Box::new(NamespaceDeclarationChildren { namespace_header, namespace_body, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_namespace_declaration_header(_: &C, namespace_keyword: Self, namespace_name: Self) -> Self { let syntax = SyntaxVariant::NamespaceDeclarationHeader(Box::new(NamespaceDeclarationHeaderChildren { namespace_keyword, namespace_name, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_namespace_body(_: &C, namespace_left_brace: Self, namespace_declarations: Self, namespace_right_brace: Self) -> Self { let syntax = SyntaxVariant::NamespaceBody(Box::new(NamespaceBodyChildren { namespace_left_brace, namespace_declarations, namespace_right_brace, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_namespace_empty_body(_: &C, namespace_semicolon: Self) -> Self { let syntax = SyntaxVariant::NamespaceEmptyBody(Box::new(NamespaceEmptyBodyChildren { namespace_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_namespace_use_declaration(_: &C, namespace_use_keyword: Self, namespace_use_kind: Self, namespace_use_clauses: Self, namespace_use_semicolon: Self) -> Self { let syntax = SyntaxVariant::NamespaceUseDeclaration(Box::new(NamespaceUseDeclarationChildren { namespace_use_keyword, namespace_use_kind, namespace_use_clauses, namespace_use_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_namespace_group_use_declaration(_: &C, namespace_group_use_keyword: Self, namespace_group_use_kind: Self, namespace_group_use_prefix: Self, namespace_group_use_left_brace: Self, namespace_group_use_clauses: Self, namespace_group_use_right_brace: Self, namespace_group_use_semicolon: Self) -> Self { let syntax = SyntaxVariant::NamespaceGroupUseDeclaration(Box::new(NamespaceGroupUseDeclarationChildren { namespace_group_use_keyword, namespace_group_use_kind, namespace_group_use_prefix, namespace_group_use_left_brace, namespace_group_use_clauses, namespace_group_use_right_brace, namespace_group_use_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_namespace_use_clause(_: &C, namespace_use_clause_kind: Self, namespace_use_name: Self, namespace_use_as: Self, namespace_use_alias: Self) -> Self { let syntax = SyntaxVariant::NamespaceUseClause(Box::new(NamespaceUseClauseChildren { namespace_use_clause_kind, namespace_use_name, namespace_use_as, namespace_use_alias, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_function_declaration(_: &C, function_attribute_spec: Self, function_declaration_header: Self, function_body: Self) -> Self { let syntax = SyntaxVariant::FunctionDeclaration(Box::new(FunctionDeclarationChildren { function_attribute_spec, function_declaration_header, function_body, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_function_declaration_header(_: &C, function_modifiers: Self, function_keyword: Self, function_name: Self, function_type_parameter_list: Self, function_left_paren: Self, function_parameter_list: Self, function_right_paren: Self, function_contexts: Self, function_colon: Self, function_readonly_return: Self, function_type: Self, function_where_clause: Self) -> Self { let syntax = SyntaxVariant::FunctionDeclarationHeader(Box::new(FunctionDeclarationHeaderChildren { function_modifiers, function_keyword, function_name, function_type_parameter_list, function_left_paren, function_parameter_list, function_right_paren, function_contexts, function_colon, function_readonly_return, function_type, function_where_clause, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_contexts(_: &C, contexts_left_bracket: Self, contexts_types: Self, contexts_right_bracket: Self) -> Self { let syntax = SyntaxVariant::Contexts(Box::new(ContextsChildren { contexts_left_bracket, contexts_types, contexts_right_bracket, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_where_clause(_: &C, where_clause_keyword: Self, where_clause_constraints: Self) -> Self { let syntax = SyntaxVariant::WhereClause(Box::new(WhereClauseChildren { where_clause_keyword, where_clause_constraints, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_where_constraint(_: &C, where_constraint_left_type: Self, where_constraint_operator: Self, where_constraint_right_type: Self) -> Self { let syntax = SyntaxVariant::WhereConstraint(Box::new(WhereConstraintChildren { where_constraint_left_type, where_constraint_operator, where_constraint_right_type, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_methodish_declaration(_: &C, methodish_attribute: Self, methodish_function_decl_header: Self, methodish_function_body: Self, methodish_semicolon: Self) -> Self { let syntax = SyntaxVariant::MethodishDeclaration(Box::new(MethodishDeclarationChildren { methodish_attribute, methodish_function_decl_header, methodish_function_body, methodish_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_methodish_trait_resolution(_: &C, methodish_trait_attribute: Self, methodish_trait_function_decl_header: Self, methodish_trait_equal: Self, methodish_trait_name: Self, methodish_trait_semicolon: Self) -> Self { let syntax = SyntaxVariant::MethodishTraitResolution(Box::new(MethodishTraitResolutionChildren { methodish_trait_attribute, methodish_trait_function_decl_header, methodish_trait_equal, methodish_trait_name, methodish_trait_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_classish_declaration(_: &C, classish_attribute: Self, classish_modifiers: Self, classish_xhp: Self, classish_keyword: Self, classish_name: Self, classish_type_parameters: Self, classish_extends_keyword: Self, classish_extends_list: Self, classish_implements_keyword: Self, classish_implements_list: Self, classish_where_clause: Self, classish_body: Self) -> Self { let syntax = SyntaxVariant::ClassishDeclaration(Box::new(ClassishDeclarationChildren { classish_attribute, classish_modifiers, classish_xhp, classish_keyword, classish_name, classish_type_parameters, classish_extends_keyword, classish_extends_list, classish_implements_keyword, classish_implements_list, classish_where_clause, classish_body, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_classish_body(_: &C, classish_body_left_brace: Self, classish_body_elements: Self, classish_body_right_brace: Self) -> Self { let syntax = SyntaxVariant::ClassishBody(Box::new(ClassishBodyChildren { classish_body_left_brace, classish_body_elements, classish_body_right_brace, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_trait_use(_: &C, trait_use_keyword: Self, trait_use_names: Self, trait_use_semicolon: Self) -> Self { let syntax = SyntaxVariant::TraitUse(Box::new(TraitUseChildren { trait_use_keyword, trait_use_names, trait_use_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_require_clause(_: &C, require_keyword: Self, require_kind: Self, require_name: Self, require_semicolon: Self) -> Self { let syntax = SyntaxVariant::RequireClause(Box::new(RequireClauseChildren { require_keyword, require_kind, require_name, require_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_const_declaration(_: &C, const_attribute_spec: Self, const_modifiers: Self, const_keyword: Self, const_type_specifier: Self, const_declarators: Self, const_semicolon: Self) -> Self { let syntax = SyntaxVariant::ConstDeclaration(Box::new(ConstDeclarationChildren { const_attribute_spec, const_modifiers, const_keyword, const_type_specifier, const_declarators, const_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_constant_declarator(_: &C, constant_declarator_name: Self, constant_declarator_initializer: Self) -> Self { let syntax = SyntaxVariant::ConstantDeclarator(Box::new(ConstantDeclaratorChildren { constant_declarator_name, constant_declarator_initializer, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_type_const_declaration(_: &C, type_const_attribute_spec: Self, type_const_modifiers: Self, type_const_keyword: Self, type_const_type_keyword: Self, type_const_name: Self, type_const_type_parameters: Self, type_const_type_constraints: Self, type_const_equal: Self, type_const_type_specifier: Self, type_const_semicolon: Self) -> Self { let syntax = SyntaxVariant::TypeConstDeclaration(Box::new(TypeConstDeclarationChildren { type_const_attribute_spec, type_const_modifiers, type_const_keyword, type_const_type_keyword, type_const_name, type_const_type_parameters, type_const_type_constraints, type_const_equal, type_const_type_specifier, type_const_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_context_const_declaration(_: &C, context_const_modifiers: Self, context_const_const_keyword: Self, context_const_ctx_keyword: Self, context_const_name: Self, context_const_type_parameters: Self, context_const_constraint: Self, context_const_equal: Self, context_const_ctx_list: Self, context_const_semicolon: Self) -> Self { let syntax = SyntaxVariant::ContextConstDeclaration(Box::new(ContextConstDeclarationChildren { context_const_modifiers, context_const_const_keyword, context_const_ctx_keyword, context_const_name, context_const_type_parameters, context_const_constraint, context_const_equal, context_const_ctx_list, context_const_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_decorated_expression(_: &C, decorated_expression_decorator: Self, decorated_expression_expression: Self) -> Self { let syntax = SyntaxVariant::DecoratedExpression(Box::new(DecoratedExpressionChildren { decorated_expression_decorator, decorated_expression_expression, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_parameter_declaration(_: &C, parameter_attribute: Self, parameter_visibility: Self, parameter_call_convention: Self, parameter_readonly: Self, parameter_type: Self, parameter_name: Self, parameter_default_value: Self) -> Self { let syntax = SyntaxVariant::ParameterDeclaration(Box::new(ParameterDeclarationChildren { parameter_attribute, parameter_visibility, parameter_call_convention, parameter_readonly, parameter_type, parameter_name, parameter_default_value, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_variadic_parameter(_: &C, variadic_parameter_call_convention: Self, variadic_parameter_type: Self, variadic_parameter_ellipsis: Self) -> Self { let syntax = SyntaxVariant::VariadicParameter(Box::new(VariadicParameterChildren { variadic_parameter_call_convention, variadic_parameter_type, variadic_parameter_ellipsis, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_old_attribute_specification(_: &C, old_attribute_specification_left_double_angle: Self, old_attribute_specification_attributes: Self, old_attribute_specification_right_double_angle: Self) -> Self { let syntax = SyntaxVariant::OldAttributeSpecification(Box::new(OldAttributeSpecificationChildren { old_attribute_specification_left_double_angle, old_attribute_specification_attributes, old_attribute_specification_right_double_angle, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_attribute_specification(_: &C, attribute_specification_attributes: Self) -> Self { let syntax = SyntaxVariant::AttributeSpecification(Box::new(AttributeSpecificationChildren { attribute_specification_attributes, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_attribute(_: &C, attribute_at: Self, attribute_attribute_name: Self) -> Self { let syntax = SyntaxVariant::Attribute(Box::new(AttributeChildren { attribute_at, attribute_attribute_name, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_inclusion_expression(_: &C, inclusion_require: Self, inclusion_filename: Self) -> Self { let syntax = SyntaxVariant::InclusionExpression(Box::new(InclusionExpressionChildren { inclusion_require, inclusion_filename, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_inclusion_directive(_: &C, inclusion_expression: Self, inclusion_semicolon: Self) -> Self { let syntax = SyntaxVariant::InclusionDirective(Box::new(InclusionDirectiveChildren { inclusion_expression, inclusion_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_compound_statement(_: &C, compound_left_brace: Self, compound_statements: Self, compound_right_brace: Self) -> Self { let syntax = SyntaxVariant::CompoundStatement(Box::new(CompoundStatementChildren { compound_left_brace, compound_statements, compound_right_brace, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_expression_statement(_: &C, expression_statement_expression: Self, expression_statement_semicolon: Self) -> Self { let syntax = SyntaxVariant::ExpressionStatement(Box::new(ExpressionStatementChildren { expression_statement_expression, expression_statement_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_markup_section(_: &C, markup_hashbang: Self, markup_suffix: Self) -> Self { let syntax = SyntaxVariant::MarkupSection(Box::new(MarkupSectionChildren { markup_hashbang, markup_suffix, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_markup_suffix(_: &C, markup_suffix_less_than_question: Self, markup_suffix_name: Self) -> Self { let syntax = SyntaxVariant::MarkupSuffix(Box::new(MarkupSuffixChildren { markup_suffix_less_than_question, markup_suffix_name, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_unset_statement(_: &C, unset_keyword: Self, unset_left_paren: Self, unset_variables: Self, unset_right_paren: Self, unset_semicolon: Self) -> Self { let syntax = SyntaxVariant::UnsetStatement(Box::new(UnsetStatementChildren { unset_keyword, unset_left_paren, unset_variables, unset_right_paren, unset_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_declare_local_statement(_: &C, declare_local_keyword: Self, declare_local_variable: Self, declare_local_colon: Self, declare_local_type: Self, declare_local_initializer: Self, declare_local_semicolon: Self) -> Self { let syntax = SyntaxVariant::DeclareLocalStatement(Box::new(DeclareLocalStatementChildren { declare_local_keyword, declare_local_variable, declare_local_colon, declare_local_type, declare_local_initializer, declare_local_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_using_statement_block_scoped(_: &C, using_block_await_keyword: Self, using_block_using_keyword: Self, using_block_left_paren: Self, using_block_expressions: Self, using_block_right_paren: Self, using_block_body: Self) -> Self { let syntax = SyntaxVariant::UsingStatementBlockScoped(Box::new(UsingStatementBlockScopedChildren { using_block_await_keyword, using_block_using_keyword, using_block_left_paren, using_block_expressions, using_block_right_paren, using_block_body, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_using_statement_function_scoped(_: &C, using_function_await_keyword: Self, using_function_using_keyword: Self, using_function_expression: Self, using_function_semicolon: Self) -> Self { let syntax = SyntaxVariant::UsingStatementFunctionScoped(Box::new(UsingStatementFunctionScopedChildren { using_function_await_keyword, using_function_using_keyword, using_function_expression, using_function_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_while_statement(_: &C, while_keyword: Self, while_left_paren: Self, while_condition: Self, while_right_paren: Self, while_body: Self) -> Self { let syntax = SyntaxVariant::WhileStatement(Box::new(WhileStatementChildren { while_keyword, while_left_paren, while_condition, while_right_paren, while_body, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_if_statement(_: &C, if_keyword: Self, if_left_paren: Self, if_condition: Self, if_right_paren: Self, if_statement: Self, if_else_clause: Self) -> Self { let syntax = SyntaxVariant::IfStatement(Box::new(IfStatementChildren { if_keyword, if_left_paren, if_condition, if_right_paren, if_statement, if_else_clause, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_else_clause(_: &C, else_keyword: Self, else_statement: Self) -> Self { let syntax = SyntaxVariant::ElseClause(Box::new(ElseClauseChildren { else_keyword, else_statement, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_try_statement(_: &C, try_keyword: Self, try_compound_statement: Self, try_catch_clauses: Self, try_finally_clause: Self) -> Self { let syntax = SyntaxVariant::TryStatement(Box::new(TryStatementChildren { try_keyword, try_compound_statement, try_catch_clauses, try_finally_clause, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_catch_clause(_: &C, catch_keyword: Self, catch_left_paren: Self, catch_type: Self, catch_variable: Self, catch_right_paren: Self, catch_body: Self) -> Self { let syntax = SyntaxVariant::CatchClause(Box::new(CatchClauseChildren { catch_keyword, catch_left_paren, catch_type, catch_variable, catch_right_paren, catch_body, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_finally_clause(_: &C, finally_keyword: Self, finally_body: Self) -> Self { let syntax = SyntaxVariant::FinallyClause(Box::new(FinallyClauseChildren { finally_keyword, finally_body, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_do_statement(_: &C, do_keyword: Self, do_body: Self, do_while_keyword: Self, do_left_paren: Self, do_condition: Self, do_right_paren: Self, do_semicolon: Self) -> Self { let syntax = SyntaxVariant::DoStatement(Box::new(DoStatementChildren { do_keyword, do_body, do_while_keyword, do_left_paren, do_condition, do_right_paren, do_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_for_statement(_: &C, for_keyword: Self, for_left_paren: Self, for_initializer: Self, for_first_semicolon: Self, for_control: Self, for_second_semicolon: Self, for_end_of_loop: Self, for_right_paren: Self, for_body: Self) -> Self { let syntax = SyntaxVariant::ForStatement(Box::new(ForStatementChildren { for_keyword, for_left_paren, for_initializer, for_first_semicolon, for_control, for_second_semicolon, for_end_of_loop, for_right_paren, for_body, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_foreach_statement(_: &C, foreach_keyword: Self, foreach_left_paren: Self, foreach_collection: Self, foreach_await_keyword: Self, foreach_as: Self, foreach_key: Self, foreach_arrow: Self, foreach_value: Self, foreach_right_paren: Self, foreach_body: Self) -> Self { let syntax = SyntaxVariant::ForeachStatement(Box::new(ForeachStatementChildren { foreach_keyword, foreach_left_paren, foreach_collection, foreach_await_keyword, foreach_as, foreach_key, foreach_arrow, foreach_value, foreach_right_paren, foreach_body, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_switch_statement(_: &C, switch_keyword: Self, switch_left_paren: Self, switch_expression: Self, switch_right_paren: Self, switch_left_brace: Self, switch_sections: Self, switch_right_brace: Self) -> Self { let syntax = SyntaxVariant::SwitchStatement(Box::new(SwitchStatementChildren { switch_keyword, switch_left_paren, switch_expression, switch_right_paren, switch_left_brace, switch_sections, switch_right_brace, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_switch_section(_: &C, switch_section_labels: Self, switch_section_statements: Self, switch_section_fallthrough: Self) -> Self { let syntax = SyntaxVariant::SwitchSection(Box::new(SwitchSectionChildren { switch_section_labels, switch_section_statements, switch_section_fallthrough, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_switch_fallthrough(_: &C, fallthrough_keyword: Self, fallthrough_semicolon: Self) -> Self { let syntax = SyntaxVariant::SwitchFallthrough(Box::new(SwitchFallthroughChildren { fallthrough_keyword, fallthrough_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_case_label(_: &C, case_keyword: Self, case_expression: Self, case_colon: Self) -> Self { let syntax = SyntaxVariant::CaseLabel(Box::new(CaseLabelChildren { case_keyword, case_expression, case_colon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_default_label(_: &C, default_keyword: Self, default_colon: Self) -> Self { let syntax = SyntaxVariant::DefaultLabel(Box::new(DefaultLabelChildren { default_keyword, default_colon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_match_statement(_: &C, match_statement_keyword: Self, match_statement_left_paren: Self, match_statement_expression: Self, match_statement_right_paren: Self, match_statement_left_brace: Self, match_statement_arms: Self, match_statement_right_brace: Self) -> Self { let syntax = SyntaxVariant::MatchStatement(Box::new(MatchStatementChildren { match_statement_keyword, match_statement_left_paren, match_statement_expression, match_statement_right_paren, match_statement_left_brace, match_statement_arms, match_statement_right_brace, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_match_statement_arm(_: &C, match_statement_arm_pattern: Self, match_statement_arm_arrow: Self, match_statement_arm_body: Self) -> Self { let syntax = SyntaxVariant::MatchStatementArm(Box::new(MatchStatementArmChildren { match_statement_arm_pattern, match_statement_arm_arrow, match_statement_arm_body, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_return_statement(_: &C, return_keyword: Self, return_expression: Self, return_semicolon: Self) -> Self { let syntax = SyntaxVariant::ReturnStatement(Box::new(ReturnStatementChildren { return_keyword, return_expression, return_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_yield_break_statement(_: &C, yield_break_keyword: Self, yield_break_break: Self, yield_break_semicolon: Self) -> Self { let syntax = SyntaxVariant::YieldBreakStatement(Box::new(YieldBreakStatementChildren { yield_break_keyword, yield_break_break, yield_break_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_throw_statement(_: &C, throw_keyword: Self, throw_expression: Self, throw_semicolon: Self) -> Self { let syntax = SyntaxVariant::ThrowStatement(Box::new(ThrowStatementChildren { throw_keyword, throw_expression, throw_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_break_statement(_: &C, break_keyword: Self, break_semicolon: Self) -> Self { let syntax = SyntaxVariant::BreakStatement(Box::new(BreakStatementChildren { break_keyword, break_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_continue_statement(_: &C, continue_keyword: Self, continue_semicolon: Self) -> Self { let syntax = SyntaxVariant::ContinueStatement(Box::new(ContinueStatementChildren { continue_keyword, continue_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_echo_statement(_: &C, echo_keyword: Self, echo_expressions: Self, echo_semicolon: Self) -> Self { let syntax = SyntaxVariant::EchoStatement(Box::new(EchoStatementChildren { echo_keyword, echo_expressions, echo_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_concurrent_statement(_: &C, concurrent_keyword: Self, concurrent_statement: Self) -> Self { let syntax = SyntaxVariant::ConcurrentStatement(Box::new(ConcurrentStatementChildren { concurrent_keyword, concurrent_statement, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_simple_initializer(_: &C, simple_initializer_equal: Self, simple_initializer_value: Self) -> Self { let syntax = SyntaxVariant::SimpleInitializer(Box::new(SimpleInitializerChildren { simple_initializer_equal, simple_initializer_value, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_anonymous_class(_: &C, anonymous_class_class_keyword: Self, anonymous_class_left_paren: Self, anonymous_class_argument_list: Self, anonymous_class_right_paren: Self, anonymous_class_extends_keyword: Self, anonymous_class_extends_list: Self, anonymous_class_implements_keyword: Self, anonymous_class_implements_list: Self, anonymous_class_body: Self) -> Self { let syntax = SyntaxVariant::AnonymousClass(Box::new(AnonymousClassChildren { anonymous_class_class_keyword, anonymous_class_left_paren, anonymous_class_argument_list, anonymous_class_right_paren, anonymous_class_extends_keyword, anonymous_class_extends_list, anonymous_class_implements_keyword, anonymous_class_implements_list, anonymous_class_body, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_anonymous_function(_: &C, anonymous_attribute_spec: Self, anonymous_async_keyword: Self, anonymous_function_keyword: Self, anonymous_left_paren: Self, anonymous_parameters: Self, anonymous_right_paren: Self, anonymous_ctx_list: Self, anonymous_colon: Self, anonymous_readonly_return: Self, anonymous_type: Self, anonymous_use: Self, anonymous_body: Self) -> Self { let syntax = SyntaxVariant::AnonymousFunction(Box::new(AnonymousFunctionChildren { anonymous_attribute_spec, anonymous_async_keyword, anonymous_function_keyword, anonymous_left_paren, anonymous_parameters, anonymous_right_paren, anonymous_ctx_list, anonymous_colon, anonymous_readonly_return, anonymous_type, anonymous_use, anonymous_body, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_anonymous_function_use_clause(_: &C, anonymous_use_keyword: Self, anonymous_use_left_paren: Self, anonymous_use_variables: Self, anonymous_use_right_paren: Self) -> Self { let syntax = SyntaxVariant::AnonymousFunctionUseClause(Box::new(AnonymousFunctionUseClauseChildren { anonymous_use_keyword, anonymous_use_left_paren, anonymous_use_variables, anonymous_use_right_paren, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_variable_pattern(_: &C, variable_pattern_variable: Self) -> Self { let syntax = SyntaxVariant::VariablePattern(Box::new(VariablePatternChildren { variable_pattern_variable, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_constructor_pattern(_: &C, constructor_pattern_constructor: Self, constructor_pattern_left_paren: Self, constructor_pattern_members: Self, constructor_pattern_right_paren: Self) -> Self { let syntax = SyntaxVariant::ConstructorPattern(Box::new(ConstructorPatternChildren { constructor_pattern_constructor, constructor_pattern_left_paren, constructor_pattern_members, constructor_pattern_right_paren, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_refinement_pattern(_: &C, refinement_pattern_variable: Self, refinement_pattern_colon: Self, refinement_pattern_specifier: Self) -> Self { let syntax = SyntaxVariant::RefinementPattern(Box::new(RefinementPatternChildren { refinement_pattern_variable, refinement_pattern_colon, refinement_pattern_specifier, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_lambda_expression(_: &C, lambda_attribute_spec: Self, lambda_async: Self, lambda_signature: Self, lambda_arrow: Self, lambda_body: Self) -> Self { let syntax = SyntaxVariant::LambdaExpression(Box::new(LambdaExpressionChildren { lambda_attribute_spec, lambda_async, lambda_signature, lambda_arrow, lambda_body, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_lambda_signature(_: &C, lambda_left_paren: Self, lambda_parameters: Self, lambda_right_paren: Self, lambda_contexts: Self, lambda_colon: Self, lambda_readonly_return: Self, lambda_type: Self) -> Self { let syntax = SyntaxVariant::LambdaSignature(Box::new(LambdaSignatureChildren { lambda_left_paren, lambda_parameters, lambda_right_paren, lambda_contexts, lambda_colon, lambda_readonly_return, lambda_type, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_cast_expression(_: &C, cast_left_paren: Self, cast_type: Self, cast_right_paren: Self, cast_operand: Self) -> Self { let syntax = SyntaxVariant::CastExpression(Box::new(CastExpressionChildren { cast_left_paren, cast_type, cast_right_paren, cast_operand, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_scope_resolution_expression(_: &C, scope_resolution_qualifier: Self, scope_resolution_operator: Self, scope_resolution_name: Self) -> Self { let syntax = SyntaxVariant::ScopeResolutionExpression(Box::new(ScopeResolutionExpressionChildren { scope_resolution_qualifier, scope_resolution_operator, scope_resolution_name, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_member_selection_expression(_: &C, member_object: Self, member_operator: Self, member_name: Self) -> Self { let syntax = SyntaxVariant::MemberSelectionExpression(Box::new(MemberSelectionExpressionChildren { member_object, member_operator, member_name, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_safe_member_selection_expression(_: &C, safe_member_object: Self, safe_member_operator: Self, safe_member_name: Self) -> Self { let syntax = SyntaxVariant::SafeMemberSelectionExpression(Box::new(SafeMemberSelectionExpressionChildren { safe_member_object, safe_member_operator, safe_member_name, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_embedded_member_selection_expression(_: &C, embedded_member_object: Self, embedded_member_operator: Self, embedded_member_name: Self) -> Self { let syntax = SyntaxVariant::EmbeddedMemberSelectionExpression(Box::new(EmbeddedMemberSelectionExpressionChildren { embedded_member_object, embedded_member_operator, embedded_member_name, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_yield_expression(_: &C, yield_keyword: Self, yield_operand: Self) -> Self { let syntax = SyntaxVariant::YieldExpression(Box::new(YieldExpressionChildren { yield_keyword, yield_operand, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_prefix_unary_expression(_: &C, prefix_unary_operator: Self, prefix_unary_operand: Self) -> Self { let syntax = SyntaxVariant::PrefixUnaryExpression(Box::new(PrefixUnaryExpressionChildren { prefix_unary_operator, prefix_unary_operand, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_postfix_unary_expression(_: &C, postfix_unary_operand: Self, postfix_unary_operator: Self) -> Self { let syntax = SyntaxVariant::PostfixUnaryExpression(Box::new(PostfixUnaryExpressionChildren { postfix_unary_operand, postfix_unary_operator, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_binary_expression(_: &C, binary_left_operand: Self, binary_operator: Self, binary_right_operand: Self) -> Self { let syntax = SyntaxVariant::BinaryExpression(Box::new(BinaryExpressionChildren { binary_left_operand, binary_operator, binary_right_operand, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_is_expression(_: &C, is_left_operand: Self, is_operator: Self, is_right_operand: Self) -> Self { let syntax = SyntaxVariant::IsExpression(Box::new(IsExpressionChildren { is_left_operand, is_operator, is_right_operand, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_as_expression(_: &C, as_left_operand: Self, as_operator: Self, as_right_operand: Self) -> Self { let syntax = SyntaxVariant::AsExpression(Box::new(AsExpressionChildren { as_left_operand, as_operator, as_right_operand, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_nullable_as_expression(_: &C, nullable_as_left_operand: Self, nullable_as_operator: Self, nullable_as_right_operand: Self) -> Self { let syntax = SyntaxVariant::NullableAsExpression(Box::new(NullableAsExpressionChildren { nullable_as_left_operand, nullable_as_operator, nullable_as_right_operand, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_upcast_expression(_: &C, upcast_left_operand: Self, upcast_operator: Self, upcast_right_operand: Self) -> Self { let syntax = SyntaxVariant::UpcastExpression(Box::new(UpcastExpressionChildren { upcast_left_operand, upcast_operator, upcast_right_operand, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_conditional_expression(_: &C, conditional_test: Self, conditional_question: Self, conditional_consequence: Self, conditional_colon: Self, conditional_alternative: Self) -> Self { let syntax = SyntaxVariant::ConditionalExpression(Box::new(ConditionalExpressionChildren { conditional_test, conditional_question, conditional_consequence, conditional_colon, conditional_alternative, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_eval_expression(_: &C, eval_keyword: Self, eval_left_paren: Self, eval_argument: Self, eval_right_paren: Self) -> Self { let syntax = SyntaxVariant::EvalExpression(Box::new(EvalExpressionChildren { eval_keyword, eval_left_paren, eval_argument, eval_right_paren, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_isset_expression(_: &C, isset_keyword: Self, isset_left_paren: Self, isset_argument_list: Self, isset_right_paren: Self) -> Self { let syntax = SyntaxVariant::IssetExpression(Box::new(IssetExpressionChildren { isset_keyword, isset_left_paren, isset_argument_list, isset_right_paren, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_function_call_expression(_: &C, function_call_receiver: Self, function_call_type_args: Self, function_call_left_paren: Self, function_call_argument_list: Self, function_call_right_paren: Self) -> Self { let syntax = SyntaxVariant::FunctionCallExpression(Box::new(FunctionCallExpressionChildren { function_call_receiver, function_call_type_args, function_call_left_paren, function_call_argument_list, function_call_right_paren, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_function_pointer_expression(_: &C, function_pointer_receiver: Self, function_pointer_type_args: Self) -> Self { let syntax = SyntaxVariant::FunctionPointerExpression(Box::new(FunctionPointerExpressionChildren { function_pointer_receiver, function_pointer_type_args, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_parenthesized_expression(_: &C, parenthesized_expression_left_paren: Self, parenthesized_expression_expression: Self, parenthesized_expression_right_paren: Self) -> Self { let syntax = SyntaxVariant::ParenthesizedExpression(Box::new(ParenthesizedExpressionChildren { parenthesized_expression_left_paren, parenthesized_expression_expression, parenthesized_expression_right_paren, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_braced_expression(_: &C, braced_expression_left_brace: Self, braced_expression_expression: Self, braced_expression_right_brace: Self) -> Self { let syntax = SyntaxVariant::BracedExpression(Box::new(BracedExpressionChildren { braced_expression_left_brace, braced_expression_expression, braced_expression_right_brace, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_et_splice_expression(_: &C, et_splice_expression_dollar: Self, et_splice_expression_left_brace: Self, et_splice_expression_expression: Self, et_splice_expression_right_brace: Self) -> Self { let syntax = SyntaxVariant::ETSpliceExpression(Box::new(ETSpliceExpressionChildren { et_splice_expression_dollar, et_splice_expression_left_brace, et_splice_expression_expression, et_splice_expression_right_brace, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_embedded_braced_expression(_: &C, embedded_braced_expression_left_brace: Self, embedded_braced_expression_expression: Self, embedded_braced_expression_right_brace: Self) -> Self { let syntax = SyntaxVariant::EmbeddedBracedExpression(Box::new(EmbeddedBracedExpressionChildren { embedded_braced_expression_left_brace, embedded_braced_expression_expression, embedded_braced_expression_right_brace, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_list_expression(_: &C, list_keyword: Self, list_left_paren: Self, list_members: Self, list_right_paren: Self) -> Self { let syntax = SyntaxVariant::ListExpression(Box::new(ListExpressionChildren { list_keyword, list_left_paren, list_members, list_right_paren, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_collection_literal_expression(_: &C, collection_literal_name: Self, collection_literal_left_brace: Self, collection_literal_initializers: Self, collection_literal_right_brace: Self) -> Self { let syntax = SyntaxVariant::CollectionLiteralExpression(Box::new(CollectionLiteralExpressionChildren { collection_literal_name, collection_literal_left_brace, collection_literal_initializers, collection_literal_right_brace, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_object_creation_expression(_: &C, object_creation_new_keyword: Self, object_creation_object: Self) -> Self { let syntax = SyntaxVariant::ObjectCreationExpression(Box::new(ObjectCreationExpressionChildren { object_creation_new_keyword, object_creation_object, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_constructor_call(_: &C, constructor_call_type: Self, constructor_call_left_paren: Self, constructor_call_argument_list: Self, constructor_call_right_paren: Self) -> Self { let syntax = SyntaxVariant::ConstructorCall(Box::new(ConstructorCallChildren { constructor_call_type, constructor_call_left_paren, constructor_call_argument_list, constructor_call_right_paren, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_darray_intrinsic_expression(_: &C, darray_intrinsic_keyword: Self, darray_intrinsic_explicit_type: Self, darray_intrinsic_left_bracket: Self, darray_intrinsic_members: Self, darray_intrinsic_right_bracket: Self) -> Self { let syntax = SyntaxVariant::DarrayIntrinsicExpression(Box::new(DarrayIntrinsicExpressionChildren { darray_intrinsic_keyword, darray_intrinsic_explicit_type, darray_intrinsic_left_bracket, darray_intrinsic_members, darray_intrinsic_right_bracket, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_dictionary_intrinsic_expression(_: &C, dictionary_intrinsic_keyword: Self, dictionary_intrinsic_explicit_type: Self, dictionary_intrinsic_left_bracket: Self, dictionary_intrinsic_members: Self, dictionary_intrinsic_right_bracket: Self) -> Self { let syntax = SyntaxVariant::DictionaryIntrinsicExpression(Box::new(DictionaryIntrinsicExpressionChildren { dictionary_intrinsic_keyword, dictionary_intrinsic_explicit_type, dictionary_intrinsic_left_bracket, dictionary_intrinsic_members, dictionary_intrinsic_right_bracket, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_keyset_intrinsic_expression(_: &C, keyset_intrinsic_keyword: Self, keyset_intrinsic_explicit_type: Self, keyset_intrinsic_left_bracket: Self, keyset_intrinsic_members: Self, keyset_intrinsic_right_bracket: Self) -> Self { let syntax = SyntaxVariant::KeysetIntrinsicExpression(Box::new(KeysetIntrinsicExpressionChildren { keyset_intrinsic_keyword, keyset_intrinsic_explicit_type, keyset_intrinsic_left_bracket, keyset_intrinsic_members, keyset_intrinsic_right_bracket, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_varray_intrinsic_expression(_: &C, varray_intrinsic_keyword: Self, varray_intrinsic_explicit_type: Self, varray_intrinsic_left_bracket: Self, varray_intrinsic_members: Self, varray_intrinsic_right_bracket: Self) -> Self { let syntax = SyntaxVariant::VarrayIntrinsicExpression(Box::new(VarrayIntrinsicExpressionChildren { varray_intrinsic_keyword, varray_intrinsic_explicit_type, varray_intrinsic_left_bracket, varray_intrinsic_members, varray_intrinsic_right_bracket, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_vector_intrinsic_expression(_: &C, vector_intrinsic_keyword: Self, vector_intrinsic_explicit_type: Self, vector_intrinsic_left_bracket: Self, vector_intrinsic_members: Self, vector_intrinsic_right_bracket: Self) -> Self { let syntax = SyntaxVariant::VectorIntrinsicExpression(Box::new(VectorIntrinsicExpressionChildren { vector_intrinsic_keyword, vector_intrinsic_explicit_type, vector_intrinsic_left_bracket, vector_intrinsic_members, vector_intrinsic_right_bracket, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_element_initializer(_: &C, element_key: Self, element_arrow: Self, element_value: Self) -> Self { let syntax = SyntaxVariant::ElementInitializer(Box::new(ElementInitializerChildren { element_key, element_arrow, element_value, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_subscript_expression(_: &C, subscript_receiver: Self, subscript_left_bracket: Self, subscript_index: Self, subscript_right_bracket: Self) -> Self { let syntax = SyntaxVariant::SubscriptExpression(Box::new(SubscriptExpressionChildren { subscript_receiver, subscript_left_bracket, subscript_index, subscript_right_bracket, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_embedded_subscript_expression(_: &C, embedded_subscript_receiver: Self, embedded_subscript_left_bracket: Self, embedded_subscript_index: Self, embedded_subscript_right_bracket: Self) -> Self { let syntax = SyntaxVariant::EmbeddedSubscriptExpression(Box::new(EmbeddedSubscriptExpressionChildren { embedded_subscript_receiver, embedded_subscript_left_bracket, embedded_subscript_index, embedded_subscript_right_bracket, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_awaitable_creation_expression(_: &C, awaitable_attribute_spec: Self, awaitable_async: Self, awaitable_compound_statement: Self) -> Self { let syntax = SyntaxVariant::AwaitableCreationExpression(Box::new(AwaitableCreationExpressionChildren { awaitable_attribute_spec, awaitable_async, awaitable_compound_statement, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_xhp_children_declaration(_: &C, xhp_children_keyword: Self, xhp_children_expression: Self, xhp_children_semicolon: Self) -> Self { let syntax = SyntaxVariant::XHPChildrenDeclaration(Box::new(XHPChildrenDeclarationChildren { xhp_children_keyword, xhp_children_expression, xhp_children_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_xhp_children_parenthesized_list(_: &C, xhp_children_list_left_paren: Self, xhp_children_list_xhp_children: Self, xhp_children_list_right_paren: Self) -> Self { let syntax = SyntaxVariant::XHPChildrenParenthesizedList(Box::new(XHPChildrenParenthesizedListChildren { xhp_children_list_left_paren, xhp_children_list_xhp_children, xhp_children_list_right_paren, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_xhp_category_declaration(_: &C, xhp_category_keyword: Self, xhp_category_categories: Self, xhp_category_semicolon: Self) -> Self { let syntax = SyntaxVariant::XHPCategoryDeclaration(Box::new(XHPCategoryDeclarationChildren { xhp_category_keyword, xhp_category_categories, xhp_category_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_xhp_enum_type(_: &C, xhp_enum_like: Self, xhp_enum_keyword: Self, xhp_enum_left_brace: Self, xhp_enum_values: Self, xhp_enum_right_brace: Self) -> Self { let syntax = SyntaxVariant::XHPEnumType(Box::new(XHPEnumTypeChildren { xhp_enum_like, xhp_enum_keyword, xhp_enum_left_brace, xhp_enum_values, xhp_enum_right_brace, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_xhp_lateinit(_: &C, xhp_lateinit_at: Self, xhp_lateinit_keyword: Self) -> Self { let syntax = SyntaxVariant::XHPLateinit(Box::new(XHPLateinitChildren { xhp_lateinit_at, xhp_lateinit_keyword, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_xhp_required(_: &C, xhp_required_at: Self, xhp_required_keyword: Self) -> Self { let syntax = SyntaxVariant::XHPRequired(Box::new(XHPRequiredChildren { xhp_required_at, xhp_required_keyword, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_xhp_class_attribute_declaration(_: &C, xhp_attribute_keyword: Self, xhp_attribute_attributes: Self, xhp_attribute_semicolon: Self) -> Self { let syntax = SyntaxVariant::XHPClassAttributeDeclaration(Box::new(XHPClassAttributeDeclarationChildren { xhp_attribute_keyword, xhp_attribute_attributes, xhp_attribute_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_xhp_class_attribute(_: &C, xhp_attribute_decl_type: Self, xhp_attribute_decl_name: Self, xhp_attribute_decl_initializer: Self, xhp_attribute_decl_required: Self) -> Self { let syntax = SyntaxVariant::XHPClassAttribute(Box::new(XHPClassAttributeChildren { xhp_attribute_decl_type, xhp_attribute_decl_name, xhp_attribute_decl_initializer, xhp_attribute_decl_required, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_xhp_simple_class_attribute(_: &C, xhp_simple_class_attribute_type: Self) -> Self { let syntax = SyntaxVariant::XHPSimpleClassAttribute(Box::new(XHPSimpleClassAttributeChildren { xhp_simple_class_attribute_type, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_xhp_simple_attribute(_: &C, xhp_simple_attribute_name: Self, xhp_simple_attribute_equal: Self, xhp_simple_attribute_expression: Self) -> Self { let syntax = SyntaxVariant::XHPSimpleAttribute(Box::new(XHPSimpleAttributeChildren { xhp_simple_attribute_name, xhp_simple_attribute_equal, xhp_simple_attribute_expression, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_xhp_spread_attribute(_: &C, xhp_spread_attribute_left_brace: Self, xhp_spread_attribute_spread_operator: Self, xhp_spread_attribute_expression: Self, xhp_spread_attribute_right_brace: Self) -> Self { let syntax = SyntaxVariant::XHPSpreadAttribute(Box::new(XHPSpreadAttributeChildren { xhp_spread_attribute_left_brace, xhp_spread_attribute_spread_operator, xhp_spread_attribute_expression, xhp_spread_attribute_right_brace, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_xhp_open(_: &C, xhp_open_left_angle: Self, xhp_open_name: Self, xhp_open_attributes: Self, xhp_open_right_angle: Self) -> Self { let syntax = SyntaxVariant::XHPOpen(Box::new(XHPOpenChildren { xhp_open_left_angle, xhp_open_name, xhp_open_attributes, xhp_open_right_angle, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_xhp_expression(_: &C, xhp_open: Self, xhp_body: Self, xhp_close: Self) -> Self { let syntax = SyntaxVariant::XHPExpression(Box::new(XHPExpressionChildren { xhp_open, xhp_body, xhp_close, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_xhp_close(_: &C, xhp_close_left_angle: Self, xhp_close_name: Self, xhp_close_right_angle: Self) -> Self { let syntax = SyntaxVariant::XHPClose(Box::new(XHPCloseChildren { xhp_close_left_angle, xhp_close_name, xhp_close_right_angle, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_type_constant(_: &C, type_constant_left_type: Self, type_constant_separator: Self, type_constant_right_type: Self) -> Self { let syntax = SyntaxVariant::TypeConstant(Box::new(TypeConstantChildren { type_constant_left_type, type_constant_separator, type_constant_right_type, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_vector_type_specifier(_: &C, vector_type_keyword: Self, vector_type_left_angle: Self, vector_type_type: Self, vector_type_trailing_comma: Self, vector_type_right_angle: Self) -> Self { let syntax = SyntaxVariant::VectorTypeSpecifier(Box::new(VectorTypeSpecifierChildren { vector_type_keyword, vector_type_left_angle, vector_type_type, vector_type_trailing_comma, vector_type_right_angle, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_keyset_type_specifier(_: &C, keyset_type_keyword: Self, keyset_type_left_angle: Self, keyset_type_type: Self, keyset_type_trailing_comma: Self, keyset_type_right_angle: Self) -> Self { let syntax = SyntaxVariant::KeysetTypeSpecifier(Box::new(KeysetTypeSpecifierChildren { keyset_type_keyword, keyset_type_left_angle, keyset_type_type, keyset_type_trailing_comma, keyset_type_right_angle, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_tuple_type_explicit_specifier(_: &C, tuple_type_keyword: Self, tuple_type_left_angle: Self, tuple_type_types: Self, tuple_type_right_angle: Self) -> Self { let syntax = SyntaxVariant::TupleTypeExplicitSpecifier(Box::new(TupleTypeExplicitSpecifierChildren { tuple_type_keyword, tuple_type_left_angle, tuple_type_types, tuple_type_right_angle, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_varray_type_specifier(_: &C, varray_keyword: Self, varray_left_angle: Self, varray_type: Self, varray_trailing_comma: Self, varray_right_angle: Self) -> Self { let syntax = SyntaxVariant::VarrayTypeSpecifier(Box::new(VarrayTypeSpecifierChildren { varray_keyword, varray_left_angle, varray_type, varray_trailing_comma, varray_right_angle, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_function_ctx_type_specifier(_: &C, function_ctx_type_keyword: Self, function_ctx_type_variable: Self) -> Self { let syntax = SyntaxVariant::FunctionCtxTypeSpecifier(Box::new(FunctionCtxTypeSpecifierChildren { function_ctx_type_keyword, function_ctx_type_variable, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_type_parameter(_: &C, type_attribute_spec: Self, type_reified: Self, type_variance: Self, type_name: Self, type_param_params: Self, type_constraints: Self) -> Self { let syntax = SyntaxVariant::TypeParameter(Box::new(TypeParameterChildren { type_attribute_spec, type_reified, type_variance, type_name, type_param_params, type_constraints, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_type_constraint(_: &C, constraint_keyword: Self, constraint_type: Self) -> Self { let syntax = SyntaxVariant::TypeConstraint(Box::new(TypeConstraintChildren { constraint_keyword, constraint_type, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_context_constraint(_: &C, ctx_constraint_keyword: Self, ctx_constraint_ctx_list: Self) -> Self { let syntax = SyntaxVariant::ContextConstraint(Box::new(ContextConstraintChildren { ctx_constraint_keyword, ctx_constraint_ctx_list, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_darray_type_specifier(_: &C, darray_keyword: Self, darray_left_angle: Self, darray_key: Self, darray_comma: Self, darray_value: Self, darray_trailing_comma: Self, darray_right_angle: Self) -> Self { let syntax = SyntaxVariant::DarrayTypeSpecifier(Box::new(DarrayTypeSpecifierChildren { darray_keyword, darray_left_angle, darray_key, darray_comma, darray_value, darray_trailing_comma, darray_right_angle, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_dictionary_type_specifier(_: &C, dictionary_type_keyword: Self, dictionary_type_left_angle: Self, dictionary_type_members: Self, dictionary_type_right_angle: Self) -> Self { let syntax = SyntaxVariant::DictionaryTypeSpecifier(Box::new(DictionaryTypeSpecifierChildren { dictionary_type_keyword, dictionary_type_left_angle, dictionary_type_members, dictionary_type_right_angle, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_closure_type_specifier(_: &C, closure_outer_left_paren: Self, closure_readonly_keyword: Self, closure_function_keyword: Self, closure_inner_left_paren: Self, closure_parameter_list: Self, closure_inner_right_paren: Self, closure_contexts: Self, closure_colon: Self, closure_readonly_return: Self, closure_return_type: Self, closure_outer_right_paren: Self) -> Self { let syntax = SyntaxVariant::ClosureTypeSpecifier(Box::new(ClosureTypeSpecifierChildren { closure_outer_left_paren, closure_readonly_keyword, closure_function_keyword, closure_inner_left_paren, closure_parameter_list, closure_inner_right_paren, closure_contexts, closure_colon, closure_readonly_return, closure_return_type, closure_outer_right_paren, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_closure_parameter_type_specifier(_: &C, closure_parameter_call_convention: Self, closure_parameter_readonly: Self, closure_parameter_type: Self) -> Self { let syntax = SyntaxVariant::ClosureParameterTypeSpecifier(Box::new(ClosureParameterTypeSpecifierChildren { closure_parameter_call_convention, closure_parameter_readonly, closure_parameter_type, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_type_refinement(_: &C, type_refinement_type: Self, type_refinement_keyword: Self, type_refinement_left_brace: Self, type_refinement_members: Self, type_refinement_right_brace: Self) -> Self { let syntax = SyntaxVariant::TypeRefinement(Box::new(TypeRefinementChildren { type_refinement_type, type_refinement_keyword, type_refinement_left_brace, type_refinement_members, type_refinement_right_brace, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_type_in_refinement(_: &C, type_in_refinement_keyword: Self, type_in_refinement_name: Self, type_in_refinement_type_parameters: Self, type_in_refinement_constraints: Self, type_in_refinement_equal: Self, type_in_refinement_type: Self) -> Self { let syntax = SyntaxVariant::TypeInRefinement(Box::new(TypeInRefinementChildren { type_in_refinement_keyword, type_in_refinement_name, type_in_refinement_type_parameters, type_in_refinement_constraints, type_in_refinement_equal, type_in_refinement_type, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_ctx_in_refinement(_: &C, ctx_in_refinement_keyword: Self, ctx_in_refinement_name: Self, ctx_in_refinement_type_parameters: Self, ctx_in_refinement_constraints: Self, ctx_in_refinement_equal: Self, ctx_in_refinement_ctx_list: Self) -> Self { let syntax = SyntaxVariant::CtxInRefinement(Box::new(CtxInRefinementChildren { ctx_in_refinement_keyword, ctx_in_refinement_name, ctx_in_refinement_type_parameters, ctx_in_refinement_constraints, ctx_in_refinement_equal, ctx_in_refinement_ctx_list, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_classname_type_specifier(_: &C, classname_keyword: Self, classname_left_angle: Self, classname_type: Self, classname_trailing_comma: Self, classname_right_angle: Self) -> Self { let syntax = SyntaxVariant::ClassnameTypeSpecifier(Box::new(ClassnameTypeSpecifierChildren { classname_keyword, classname_left_angle, classname_type, classname_trailing_comma, classname_right_angle, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_field_specifier(_: &C, field_question: Self, field_name: Self, field_arrow: Self, field_type: Self) -> Self { let syntax = SyntaxVariant::FieldSpecifier(Box::new(FieldSpecifierChildren { field_question, field_name, field_arrow, field_type, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_field_initializer(_: &C, field_initializer_name: Self, field_initializer_arrow: Self, field_initializer_value: Self) -> Self { let syntax = SyntaxVariant::FieldInitializer(Box::new(FieldInitializerChildren { field_initializer_name, field_initializer_arrow, field_initializer_value, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_shape_type_specifier(_: &C, shape_type_keyword: Self, shape_type_left_paren: Self, shape_type_fields: Self, shape_type_ellipsis: Self, shape_type_right_paren: Self) -> Self { let syntax = SyntaxVariant::ShapeTypeSpecifier(Box::new(ShapeTypeSpecifierChildren { shape_type_keyword, shape_type_left_paren, shape_type_fields, shape_type_ellipsis, shape_type_right_paren, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_shape_expression(_: &C, shape_expression_keyword: Self, shape_expression_left_paren: Self, shape_expression_fields: Self, shape_expression_right_paren: Self) -> Self { let syntax = SyntaxVariant::ShapeExpression(Box::new(ShapeExpressionChildren { shape_expression_keyword, shape_expression_left_paren, shape_expression_fields, shape_expression_right_paren, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_tuple_expression(_: &C, tuple_expression_keyword: Self, tuple_expression_left_paren: Self, tuple_expression_items: Self, tuple_expression_right_paren: Self) -> Self { let syntax = SyntaxVariant::TupleExpression(Box::new(TupleExpressionChildren { tuple_expression_keyword, tuple_expression_left_paren, tuple_expression_items, tuple_expression_right_paren, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_generic_type_specifier(_: &C, generic_class_type: Self, generic_argument_list: Self) -> Self { let syntax = SyntaxVariant::GenericTypeSpecifier(Box::new(GenericTypeSpecifierChildren { generic_class_type, generic_argument_list, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_nullable_type_specifier(_: &C, nullable_question: Self, nullable_type: Self) -> Self { let syntax = SyntaxVariant::NullableTypeSpecifier(Box::new(NullableTypeSpecifierChildren { nullable_question, nullable_type, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_like_type_specifier(_: &C, like_tilde: Self, like_type: Self) -> Self { let syntax = SyntaxVariant::LikeTypeSpecifier(Box::new(LikeTypeSpecifierChildren { like_tilde, like_type, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_soft_type_specifier(_: &C, soft_at: Self, soft_type: Self) -> Self { let syntax = SyntaxVariant::SoftTypeSpecifier(Box::new(SoftTypeSpecifierChildren { soft_at, soft_type, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_attributized_specifier(_: &C, attributized_specifier_attribute_spec: Self, attributized_specifier_type: Self) -> Self { let syntax = SyntaxVariant::AttributizedSpecifier(Box::new(AttributizedSpecifierChildren { attributized_specifier_attribute_spec, attributized_specifier_type, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_reified_type_argument(_: &C, reified_type_argument_reified: Self, reified_type_argument_type: Self) -> Self { let syntax = SyntaxVariant::ReifiedTypeArgument(Box::new(ReifiedTypeArgumentChildren { reified_type_argument_reified, reified_type_argument_type, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_type_arguments(_: &C, type_arguments_left_angle: Self, type_arguments_types: Self, type_arguments_right_angle: Self) -> Self { let syntax = SyntaxVariant::TypeArguments(Box::new(TypeArgumentsChildren { type_arguments_left_angle, type_arguments_types, type_arguments_right_angle, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_type_parameters(_: &C, type_parameters_left_angle: Self, type_parameters_parameters: Self, type_parameters_right_angle: Self) -> Self { let syntax = SyntaxVariant::TypeParameters(Box::new(TypeParametersChildren { type_parameters_left_angle, type_parameters_parameters, type_parameters_right_angle, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_tuple_type_specifier(_: &C, tuple_left_paren: Self, tuple_types: Self, tuple_right_paren: Self) -> Self { let syntax = SyntaxVariant::TupleTypeSpecifier(Box::new(TupleTypeSpecifierChildren { tuple_left_paren, tuple_types, tuple_right_paren, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_union_type_specifier(_: &C, union_left_paren: Self, union_types: Self, union_right_paren: Self) -> Self { let syntax = SyntaxVariant::UnionTypeSpecifier(Box::new(UnionTypeSpecifierChildren { union_left_paren, union_types, union_right_paren, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_intersection_type_specifier(_: &C, intersection_left_paren: Self, intersection_types: Self, intersection_right_paren: Self) -> Self { let syntax = SyntaxVariant::IntersectionTypeSpecifier(Box::new(IntersectionTypeSpecifierChildren { intersection_left_paren, intersection_types, intersection_right_paren, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_error(_: &C, error_error: Self) -> Self { let syntax = SyntaxVariant::ErrorSyntax(Box::new(ErrorSyntaxChildren { error_error, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_list_item(_: &C, list_item: Self, list_separator: Self) -> Self { let syntax = SyntaxVariant::ListItem(Box::new(ListItemChildren { list_item, list_separator, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_enum_class_label_expression(_: &C, enum_class_label_qualifier: Self, enum_class_label_hash: Self, enum_class_label_expression: Self) -> Self { let syntax = SyntaxVariant::EnumClassLabelExpression(Box::new(EnumClassLabelExpressionChildren { enum_class_label_qualifier, enum_class_label_hash, enum_class_label_expression, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_module_declaration(_: &C, module_declaration_attribute_spec: Self, module_declaration_new_keyword: Self, module_declaration_module_keyword: Self, module_declaration_name: Self, module_declaration_left_brace: Self, module_declaration_exports: Self, module_declaration_imports: Self, module_declaration_right_brace: Self) -> Self { let syntax = SyntaxVariant::ModuleDeclaration(Box::new(ModuleDeclarationChildren { module_declaration_attribute_spec, module_declaration_new_keyword, module_declaration_module_keyword, module_declaration_name, module_declaration_left_brace, module_declaration_exports, module_declaration_imports, module_declaration_right_brace, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_module_exports(_: &C, module_exports_exports_keyword: Self, module_exports_left_brace: Self, module_exports_exports: Self, module_exports_right_brace: Self) -> Self { let syntax = SyntaxVariant::ModuleExports(Box::new(ModuleExportsChildren { module_exports_exports_keyword, module_exports_left_brace, module_exports_exports, module_exports_right_brace, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_module_imports(_: &C, module_imports_imports_keyword: Self, module_imports_left_brace: Self, module_imports_imports: Self, module_imports_right_brace: Self) -> Self { let syntax = SyntaxVariant::ModuleImports(Box::new(ModuleImportsChildren { module_imports_imports_keyword, module_imports_left_brace, module_imports_imports, module_imports_right_brace, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_module_membership_declaration(_: &C, module_membership_declaration_module_keyword: Self, module_membership_declaration_name: Self, module_membership_declaration_semicolon: Self) -> Self { let syntax = SyntaxVariant::ModuleMembershipDeclaration(Box::new(ModuleMembershipDeclarationChildren { module_membership_declaration_module_keyword, module_membership_declaration_name, module_membership_declaration_semicolon, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } fn make_package_expression(_: &C, package_expression_keyword: Self, package_expression_name: Self) -> Self { let syntax = SyntaxVariant::PackageExpression(Box::new(PackageExpressionChildren { package_expression_keyword, package_expression_name, })); let value = V::from_values(syntax.iter_children().map(|child| &child.value)); Self::make(syntax, value) } } impl<T, V> Syntax<T, V> where T: LexableToken, { pub fn fold_over_children_owned<U>( f: &dyn Fn(Self, U) -> U, acc: U, syntax: SyntaxVariant<T, V>, ) -> U { match syntax { SyntaxVariant::Missing => acc, SyntaxVariant::Token (_) => acc, SyntaxVariant::SyntaxList(elems) => { let mut acc = acc; for item in elems { acc = f(item, acc); } acc }, SyntaxVariant::EndOfFile(x) => { let EndOfFileChildren { end_of_file_token } = *x; let acc = f(end_of_file_token, acc); acc }, SyntaxVariant::Script(x) => { let ScriptChildren { script_declarations } = *x; let acc = f(script_declarations, acc); acc }, SyntaxVariant::QualifiedName(x) => { let QualifiedNameChildren { qualified_name_parts } = *x; let acc = f(qualified_name_parts, acc); acc }, SyntaxVariant::ModuleName(x) => { let ModuleNameChildren { module_name_parts } = *x; let acc = f(module_name_parts, acc); acc }, SyntaxVariant::SimpleTypeSpecifier(x) => { let SimpleTypeSpecifierChildren { simple_type_specifier } = *x; let acc = f(simple_type_specifier, acc); acc }, SyntaxVariant::LiteralExpression(x) => { let LiteralExpressionChildren { literal_expression } = *x; let acc = f(literal_expression, acc); acc }, SyntaxVariant::PrefixedStringExpression(x) => { let PrefixedStringExpressionChildren { prefixed_string_name, prefixed_string_str } = *x; let acc = f(prefixed_string_name, acc); let acc = f(prefixed_string_str, acc); acc }, SyntaxVariant::PrefixedCodeExpression(x) => { let PrefixedCodeExpressionChildren { prefixed_code_prefix, prefixed_code_left_backtick, prefixed_code_body, prefixed_code_right_backtick } = *x; let acc = f(prefixed_code_prefix, acc); let acc = f(prefixed_code_left_backtick, acc); let acc = f(prefixed_code_body, acc); let acc = f(prefixed_code_right_backtick, acc); acc }, SyntaxVariant::VariableExpression(x) => { let VariableExpressionChildren { variable_expression } = *x; let acc = f(variable_expression, acc); acc }, SyntaxVariant::PipeVariableExpression(x) => { let PipeVariableExpressionChildren { pipe_variable_expression } = *x; let acc = f(pipe_variable_expression, acc); acc }, SyntaxVariant::FileAttributeSpecification(x) => { let FileAttributeSpecificationChildren { file_attribute_specification_left_double_angle, file_attribute_specification_keyword, file_attribute_specification_colon, file_attribute_specification_attributes, file_attribute_specification_right_double_angle } = *x; let acc = f(file_attribute_specification_left_double_angle, acc); let acc = f(file_attribute_specification_keyword, acc); let acc = f(file_attribute_specification_colon, acc); let acc = f(file_attribute_specification_attributes, acc); let acc = f(file_attribute_specification_right_double_angle, acc); acc }, SyntaxVariant::EnumDeclaration(x) => { let EnumDeclarationChildren { enum_attribute_spec, enum_modifiers, enum_keyword, enum_name, enum_colon, enum_base, enum_type, enum_left_brace, enum_use_clauses, enum_enumerators, enum_right_brace } = *x; let acc = f(enum_attribute_spec, acc); let acc = f(enum_modifiers, acc); let acc = f(enum_keyword, acc); let acc = f(enum_name, acc); let acc = f(enum_colon, acc); let acc = f(enum_base, acc); let acc = f(enum_type, acc); let acc = f(enum_left_brace, acc); let acc = f(enum_use_clauses, acc); let acc = f(enum_enumerators, acc); let acc = f(enum_right_brace, acc); acc }, SyntaxVariant::EnumUse(x) => { let EnumUseChildren { enum_use_keyword, enum_use_names, enum_use_semicolon } = *x; let acc = f(enum_use_keyword, acc); let acc = f(enum_use_names, acc); let acc = f(enum_use_semicolon, acc); acc }, SyntaxVariant::Enumerator(x) => { let EnumeratorChildren { enumerator_name, enumerator_equal, enumerator_value, enumerator_semicolon } = *x; let acc = f(enumerator_name, acc); let acc = f(enumerator_equal, acc); let acc = f(enumerator_value, acc); let acc = f(enumerator_semicolon, acc); acc }, SyntaxVariant::EnumClassDeclaration(x) => { let EnumClassDeclarationChildren { enum_class_attribute_spec, enum_class_modifiers, enum_class_enum_keyword, enum_class_class_keyword, enum_class_name, enum_class_colon, enum_class_base, enum_class_extends, enum_class_extends_list, enum_class_left_brace, enum_class_elements, enum_class_right_brace } = *x; let acc = f(enum_class_attribute_spec, acc); let acc = f(enum_class_modifiers, acc); let acc = f(enum_class_enum_keyword, acc); let acc = f(enum_class_class_keyword, acc); let acc = f(enum_class_name, acc); let acc = f(enum_class_colon, acc); let acc = f(enum_class_base, acc); let acc = f(enum_class_extends, acc); let acc = f(enum_class_extends_list, acc); let acc = f(enum_class_left_brace, acc); let acc = f(enum_class_elements, acc); let acc = f(enum_class_right_brace, acc); acc }, SyntaxVariant::EnumClassEnumerator(x) => { let EnumClassEnumeratorChildren { enum_class_enumerator_modifiers, enum_class_enumerator_type, enum_class_enumerator_name, enum_class_enumerator_initializer, enum_class_enumerator_semicolon } = *x; let acc = f(enum_class_enumerator_modifiers, acc); let acc = f(enum_class_enumerator_type, acc); let acc = f(enum_class_enumerator_name, acc); let acc = f(enum_class_enumerator_initializer, acc); let acc = f(enum_class_enumerator_semicolon, acc); acc }, SyntaxVariant::AliasDeclaration(x) => { let AliasDeclarationChildren { alias_attribute_spec, alias_modifiers, alias_module_kw_opt, alias_keyword, alias_name, alias_generic_parameter, alias_constraint, alias_equal, alias_type, alias_semicolon } = *x; let acc = f(alias_attribute_spec, acc); let acc = f(alias_modifiers, acc); let acc = f(alias_module_kw_opt, acc); let acc = f(alias_keyword, acc); let acc = f(alias_name, acc); let acc = f(alias_generic_parameter, acc); let acc = f(alias_constraint, acc); let acc = f(alias_equal, acc); let acc = f(alias_type, acc); let acc = f(alias_semicolon, acc); acc }, SyntaxVariant::ContextAliasDeclaration(x) => { let ContextAliasDeclarationChildren { ctx_alias_attribute_spec, ctx_alias_keyword, ctx_alias_name, ctx_alias_generic_parameter, ctx_alias_as_constraint, ctx_alias_equal, ctx_alias_context, ctx_alias_semicolon } = *x; let acc = f(ctx_alias_attribute_spec, acc); let acc = f(ctx_alias_keyword, acc); let acc = f(ctx_alias_name, acc); let acc = f(ctx_alias_generic_parameter, acc); let acc = f(ctx_alias_as_constraint, acc); let acc = f(ctx_alias_equal, acc); let acc = f(ctx_alias_context, acc); let acc = f(ctx_alias_semicolon, acc); acc }, SyntaxVariant::CaseTypeDeclaration(x) => { let CaseTypeDeclarationChildren { case_type_attribute_spec, case_type_modifiers, case_type_case_keyword, case_type_type_keyword, case_type_name, case_type_generic_parameter, case_type_as, case_type_bounds, case_type_equal, case_type_variants, case_type_semicolon } = *x; let acc = f(case_type_attribute_spec, acc); let acc = f(case_type_modifiers, acc); let acc = f(case_type_case_keyword, acc); let acc = f(case_type_type_keyword, acc); let acc = f(case_type_name, acc); let acc = f(case_type_generic_parameter, acc); let acc = f(case_type_as, acc); let acc = f(case_type_bounds, acc); let acc = f(case_type_equal, acc); let acc = f(case_type_variants, acc); let acc = f(case_type_semicolon, acc); acc }, SyntaxVariant::CaseTypeVariant(x) => { let CaseTypeVariantChildren { case_type_variant_bar, case_type_variant_type } = *x; let acc = f(case_type_variant_bar, acc); let acc = f(case_type_variant_type, acc); acc }, SyntaxVariant::PropertyDeclaration(x) => { let PropertyDeclarationChildren { property_attribute_spec, property_modifiers, property_type, property_declarators, property_semicolon } = *x; let acc = f(property_attribute_spec, acc); let acc = f(property_modifiers, acc); let acc = f(property_type, acc); let acc = f(property_declarators, acc); let acc = f(property_semicolon, acc); acc }, SyntaxVariant::PropertyDeclarator(x) => { let PropertyDeclaratorChildren { property_name, property_initializer } = *x; let acc = f(property_name, acc); let acc = f(property_initializer, acc); acc }, SyntaxVariant::NamespaceDeclaration(x) => { let NamespaceDeclarationChildren { namespace_header, namespace_body } = *x; let acc = f(namespace_header, acc); let acc = f(namespace_body, acc); acc }, SyntaxVariant::NamespaceDeclarationHeader(x) => { let NamespaceDeclarationHeaderChildren { namespace_keyword, namespace_name } = *x; let acc = f(namespace_keyword, acc); let acc = f(namespace_name, acc); acc }, SyntaxVariant::NamespaceBody(x) => { let NamespaceBodyChildren { namespace_left_brace, namespace_declarations, namespace_right_brace } = *x; let acc = f(namespace_left_brace, acc); let acc = f(namespace_declarations, acc); let acc = f(namespace_right_brace, acc); acc }, SyntaxVariant::NamespaceEmptyBody(x) => { let NamespaceEmptyBodyChildren { namespace_semicolon } = *x; let acc = f(namespace_semicolon, acc); acc }, SyntaxVariant::NamespaceUseDeclaration(x) => { let NamespaceUseDeclarationChildren { namespace_use_keyword, namespace_use_kind, namespace_use_clauses, namespace_use_semicolon } = *x; let acc = f(namespace_use_keyword, acc); let acc = f(namespace_use_kind, acc); let acc = f(namespace_use_clauses, acc); let acc = f(namespace_use_semicolon, acc); acc }, SyntaxVariant::NamespaceGroupUseDeclaration(x) => { let NamespaceGroupUseDeclarationChildren { namespace_group_use_keyword, namespace_group_use_kind, namespace_group_use_prefix, namespace_group_use_left_brace, namespace_group_use_clauses, namespace_group_use_right_brace, namespace_group_use_semicolon } = *x; let acc = f(namespace_group_use_keyword, acc); let acc = f(namespace_group_use_kind, acc); let acc = f(namespace_group_use_prefix, acc); let acc = f(namespace_group_use_left_brace, acc); let acc = f(namespace_group_use_clauses, acc); let acc = f(namespace_group_use_right_brace, acc); let acc = f(namespace_group_use_semicolon, acc); acc }, SyntaxVariant::NamespaceUseClause(x) => { let NamespaceUseClauseChildren { namespace_use_clause_kind, namespace_use_name, namespace_use_as, namespace_use_alias } = *x; let acc = f(namespace_use_clause_kind, acc); let acc = f(namespace_use_name, acc); let acc = f(namespace_use_as, acc); let acc = f(namespace_use_alias, acc); acc }, SyntaxVariant::FunctionDeclaration(x) => { let FunctionDeclarationChildren { function_attribute_spec, function_declaration_header, function_body } = *x; let acc = f(function_attribute_spec, acc); let acc = f(function_declaration_header, acc); let acc = f(function_body, acc); acc }, SyntaxVariant::FunctionDeclarationHeader(x) => { let FunctionDeclarationHeaderChildren { function_modifiers, function_keyword, function_name, function_type_parameter_list, function_left_paren, function_parameter_list, function_right_paren, function_contexts, function_colon, function_readonly_return, function_type, function_where_clause } = *x; let acc = f(function_modifiers, acc); let acc = f(function_keyword, acc); let acc = f(function_name, acc); let acc = f(function_type_parameter_list, acc); let acc = f(function_left_paren, acc); let acc = f(function_parameter_list, acc); let acc = f(function_right_paren, acc); let acc = f(function_contexts, acc); let acc = f(function_colon, acc); let acc = f(function_readonly_return, acc); let acc = f(function_type, acc); let acc = f(function_where_clause, acc); acc }, SyntaxVariant::Contexts(x) => { let ContextsChildren { contexts_left_bracket, contexts_types, contexts_right_bracket } = *x; let acc = f(contexts_left_bracket, acc); let acc = f(contexts_types, acc); let acc = f(contexts_right_bracket, acc); acc }, SyntaxVariant::WhereClause(x) => { let WhereClauseChildren { where_clause_keyword, where_clause_constraints } = *x; let acc = f(where_clause_keyword, acc); let acc = f(where_clause_constraints, acc); acc }, SyntaxVariant::WhereConstraint(x) => { let WhereConstraintChildren { where_constraint_left_type, where_constraint_operator, where_constraint_right_type } = *x; let acc = f(where_constraint_left_type, acc); let acc = f(where_constraint_operator, acc); let acc = f(where_constraint_right_type, acc); acc }, SyntaxVariant::MethodishDeclaration(x) => { let MethodishDeclarationChildren { methodish_attribute, methodish_function_decl_header, methodish_function_body, methodish_semicolon } = *x; let acc = f(methodish_attribute, acc); let acc = f(methodish_function_decl_header, acc); let acc = f(methodish_function_body, acc); let acc = f(methodish_semicolon, acc); acc }, SyntaxVariant::MethodishTraitResolution(x) => { let MethodishTraitResolutionChildren { methodish_trait_attribute, methodish_trait_function_decl_header, methodish_trait_equal, methodish_trait_name, methodish_trait_semicolon } = *x; let acc = f(methodish_trait_attribute, acc); let acc = f(methodish_trait_function_decl_header, acc); let acc = f(methodish_trait_equal, acc); let acc = f(methodish_trait_name, acc); let acc = f(methodish_trait_semicolon, acc); acc }, SyntaxVariant::ClassishDeclaration(x) => { let ClassishDeclarationChildren { classish_attribute, classish_modifiers, classish_xhp, classish_keyword, classish_name, classish_type_parameters, classish_extends_keyword, classish_extends_list, classish_implements_keyword, classish_implements_list, classish_where_clause, classish_body } = *x; let acc = f(classish_attribute, acc); let acc = f(classish_modifiers, acc); let acc = f(classish_xhp, acc); let acc = f(classish_keyword, acc); let acc = f(classish_name, acc); let acc = f(classish_type_parameters, acc); let acc = f(classish_extends_keyword, acc); let acc = f(classish_extends_list, acc); let acc = f(classish_implements_keyword, acc); let acc = f(classish_implements_list, acc); let acc = f(classish_where_clause, acc); let acc = f(classish_body, acc); acc }, SyntaxVariant::ClassishBody(x) => { let ClassishBodyChildren { classish_body_left_brace, classish_body_elements, classish_body_right_brace } = *x; let acc = f(classish_body_left_brace, acc); let acc = f(classish_body_elements, acc); let acc = f(classish_body_right_brace, acc); acc }, SyntaxVariant::TraitUse(x) => { let TraitUseChildren { trait_use_keyword, trait_use_names, trait_use_semicolon } = *x; let acc = f(trait_use_keyword, acc); let acc = f(trait_use_names, acc); let acc = f(trait_use_semicolon, acc); acc }, SyntaxVariant::RequireClause(x) => { let RequireClauseChildren { require_keyword, require_kind, require_name, require_semicolon } = *x; let acc = f(require_keyword, acc); let acc = f(require_kind, acc); let acc = f(require_name, acc); let acc = f(require_semicolon, acc); acc }, SyntaxVariant::ConstDeclaration(x) => { let ConstDeclarationChildren { const_attribute_spec, const_modifiers, const_keyword, const_type_specifier, const_declarators, const_semicolon } = *x; let acc = f(const_attribute_spec, acc); let acc = f(const_modifiers, acc); let acc = f(const_keyword, acc); let acc = f(const_type_specifier, acc); let acc = f(const_declarators, acc); let acc = f(const_semicolon, acc); acc }, SyntaxVariant::ConstantDeclarator(x) => { let ConstantDeclaratorChildren { constant_declarator_name, constant_declarator_initializer } = *x; let acc = f(constant_declarator_name, acc); let acc = f(constant_declarator_initializer, acc); acc }, SyntaxVariant::TypeConstDeclaration(x) => { let TypeConstDeclarationChildren { type_const_attribute_spec, type_const_modifiers, type_const_keyword, type_const_type_keyword, type_const_name, type_const_type_parameters, type_const_type_constraints, type_const_equal, type_const_type_specifier, type_const_semicolon } = *x; let acc = f(type_const_attribute_spec, acc); let acc = f(type_const_modifiers, acc); let acc = f(type_const_keyword, acc); let acc = f(type_const_type_keyword, acc); let acc = f(type_const_name, acc); let acc = f(type_const_type_parameters, acc); let acc = f(type_const_type_constraints, acc); let acc = f(type_const_equal, acc); let acc = f(type_const_type_specifier, acc); let acc = f(type_const_semicolon, acc); acc }, SyntaxVariant::ContextConstDeclaration(x) => { let ContextConstDeclarationChildren { context_const_modifiers, context_const_const_keyword, context_const_ctx_keyword, context_const_name, context_const_type_parameters, context_const_constraint, context_const_equal, context_const_ctx_list, context_const_semicolon } = *x; let acc = f(context_const_modifiers, acc); let acc = f(context_const_const_keyword, acc); let acc = f(context_const_ctx_keyword, acc); let acc = f(context_const_name, acc); let acc = f(context_const_type_parameters, acc); let acc = f(context_const_constraint, acc); let acc = f(context_const_equal, acc); let acc = f(context_const_ctx_list, acc); let acc = f(context_const_semicolon, acc); acc }, SyntaxVariant::DecoratedExpression(x) => { let DecoratedExpressionChildren { decorated_expression_decorator, decorated_expression_expression } = *x; let acc = f(decorated_expression_decorator, acc); let acc = f(decorated_expression_expression, acc); acc }, SyntaxVariant::ParameterDeclaration(x) => { let ParameterDeclarationChildren { parameter_attribute, parameter_visibility, parameter_call_convention, parameter_readonly, parameter_type, parameter_name, parameter_default_value } = *x; let acc = f(parameter_attribute, acc); let acc = f(parameter_visibility, acc); let acc = f(parameter_call_convention, acc); let acc = f(parameter_readonly, acc); let acc = f(parameter_type, acc); let acc = f(parameter_name, acc); let acc = f(parameter_default_value, acc); acc }, SyntaxVariant::VariadicParameter(x) => { let VariadicParameterChildren { variadic_parameter_call_convention, variadic_parameter_type, variadic_parameter_ellipsis } = *x; let acc = f(variadic_parameter_call_convention, acc); let acc = f(variadic_parameter_type, acc); let acc = f(variadic_parameter_ellipsis, acc); acc }, SyntaxVariant::OldAttributeSpecification(x) => { let OldAttributeSpecificationChildren { old_attribute_specification_left_double_angle, old_attribute_specification_attributes, old_attribute_specification_right_double_angle } = *x; let acc = f(old_attribute_specification_left_double_angle, acc); let acc = f(old_attribute_specification_attributes, acc); let acc = f(old_attribute_specification_right_double_angle, acc); acc }, SyntaxVariant::AttributeSpecification(x) => { let AttributeSpecificationChildren { attribute_specification_attributes } = *x; let acc = f(attribute_specification_attributes, acc); acc }, SyntaxVariant::Attribute(x) => { let AttributeChildren { attribute_at, attribute_attribute_name } = *x; let acc = f(attribute_at, acc); let acc = f(attribute_attribute_name, acc); acc }, SyntaxVariant::InclusionExpression(x) => { let InclusionExpressionChildren { inclusion_require, inclusion_filename } = *x; let acc = f(inclusion_require, acc); let acc = f(inclusion_filename, acc); acc }, SyntaxVariant::InclusionDirective(x) => { let InclusionDirectiveChildren { inclusion_expression, inclusion_semicolon } = *x; let acc = f(inclusion_expression, acc); let acc = f(inclusion_semicolon, acc); acc }, SyntaxVariant::CompoundStatement(x) => { let CompoundStatementChildren { compound_left_brace, compound_statements, compound_right_brace } = *x; let acc = f(compound_left_brace, acc); let acc = f(compound_statements, acc); let acc = f(compound_right_brace, acc); acc }, SyntaxVariant::ExpressionStatement(x) => { let ExpressionStatementChildren { expression_statement_expression, expression_statement_semicolon } = *x; let acc = f(expression_statement_expression, acc); let acc = f(expression_statement_semicolon, acc); acc }, SyntaxVariant::MarkupSection(x) => { let MarkupSectionChildren { markup_hashbang, markup_suffix } = *x; let acc = f(markup_hashbang, acc); let acc = f(markup_suffix, acc); acc }, SyntaxVariant::MarkupSuffix(x) => { let MarkupSuffixChildren { markup_suffix_less_than_question, markup_suffix_name } = *x; let acc = f(markup_suffix_less_than_question, acc); let acc = f(markup_suffix_name, acc); acc }, SyntaxVariant::UnsetStatement(x) => { let UnsetStatementChildren { unset_keyword, unset_left_paren, unset_variables, unset_right_paren, unset_semicolon } = *x; let acc = f(unset_keyword, acc); let acc = f(unset_left_paren, acc); let acc = f(unset_variables, acc); let acc = f(unset_right_paren, acc); let acc = f(unset_semicolon, acc); acc }, SyntaxVariant::DeclareLocalStatement(x) => { let DeclareLocalStatementChildren { declare_local_keyword, declare_local_variable, declare_local_colon, declare_local_type, declare_local_initializer, declare_local_semicolon } = *x; let acc = f(declare_local_keyword, acc); let acc = f(declare_local_variable, acc); let acc = f(declare_local_colon, acc); let acc = f(declare_local_type, acc); let acc = f(declare_local_initializer, acc); let acc = f(declare_local_semicolon, acc); acc }, SyntaxVariant::UsingStatementBlockScoped(x) => { let UsingStatementBlockScopedChildren { using_block_await_keyword, using_block_using_keyword, using_block_left_paren, using_block_expressions, using_block_right_paren, using_block_body } = *x; let acc = f(using_block_await_keyword, acc); let acc = f(using_block_using_keyword, acc); let acc = f(using_block_left_paren, acc); let acc = f(using_block_expressions, acc); let acc = f(using_block_right_paren, acc); let acc = f(using_block_body, acc); acc }, SyntaxVariant::UsingStatementFunctionScoped(x) => { let UsingStatementFunctionScopedChildren { using_function_await_keyword, using_function_using_keyword, using_function_expression, using_function_semicolon } = *x; let acc = f(using_function_await_keyword, acc); let acc = f(using_function_using_keyword, acc); let acc = f(using_function_expression, acc); let acc = f(using_function_semicolon, acc); acc }, SyntaxVariant::WhileStatement(x) => { let WhileStatementChildren { while_keyword, while_left_paren, while_condition, while_right_paren, while_body } = *x; let acc = f(while_keyword, acc); let acc = f(while_left_paren, acc); let acc = f(while_condition, acc); let acc = f(while_right_paren, acc); let acc = f(while_body, acc); acc }, SyntaxVariant::IfStatement(x) => { let IfStatementChildren { if_keyword, if_left_paren, if_condition, if_right_paren, if_statement, if_else_clause } = *x; let acc = f(if_keyword, acc); let acc = f(if_left_paren, acc); let acc = f(if_condition, acc); let acc = f(if_right_paren, acc); let acc = f(if_statement, acc); let acc = f(if_else_clause, acc); acc }, SyntaxVariant::ElseClause(x) => { let ElseClauseChildren { else_keyword, else_statement } = *x; let acc = f(else_keyword, acc); let acc = f(else_statement, acc); acc }, SyntaxVariant::TryStatement(x) => { let TryStatementChildren { try_keyword, try_compound_statement, try_catch_clauses, try_finally_clause } = *x; let acc = f(try_keyword, acc); let acc = f(try_compound_statement, acc); let acc = f(try_catch_clauses, acc); let acc = f(try_finally_clause, acc); acc }, SyntaxVariant::CatchClause(x) => { let CatchClauseChildren { catch_keyword, catch_left_paren, catch_type, catch_variable, catch_right_paren, catch_body } = *x; let acc = f(catch_keyword, acc); let acc = f(catch_left_paren, acc); let acc = f(catch_type, acc); let acc = f(catch_variable, acc); let acc = f(catch_right_paren, acc); let acc = f(catch_body, acc); acc }, SyntaxVariant::FinallyClause(x) => { let FinallyClauseChildren { finally_keyword, finally_body } = *x; let acc = f(finally_keyword, acc); let acc = f(finally_body, acc); acc }, SyntaxVariant::DoStatement(x) => { let DoStatementChildren { do_keyword, do_body, do_while_keyword, do_left_paren, do_condition, do_right_paren, do_semicolon } = *x; let acc = f(do_keyword, acc); let acc = f(do_body, acc); let acc = f(do_while_keyword, acc); let acc = f(do_left_paren, acc); let acc = f(do_condition, acc); let acc = f(do_right_paren, acc); let acc = f(do_semicolon, acc); acc }, SyntaxVariant::ForStatement(x) => { let ForStatementChildren { for_keyword, for_left_paren, for_initializer, for_first_semicolon, for_control, for_second_semicolon, for_end_of_loop, for_right_paren, for_body } = *x; let acc = f(for_keyword, acc); let acc = f(for_left_paren, acc); let acc = f(for_initializer, acc); let acc = f(for_first_semicolon, acc); let acc = f(for_control, acc); let acc = f(for_second_semicolon, acc); let acc = f(for_end_of_loop, acc); let acc = f(for_right_paren, acc); let acc = f(for_body, acc); acc }, SyntaxVariant::ForeachStatement(x) => { let ForeachStatementChildren { foreach_keyword, foreach_left_paren, foreach_collection, foreach_await_keyword, foreach_as, foreach_key, foreach_arrow, foreach_value, foreach_right_paren, foreach_body } = *x; let acc = f(foreach_keyword, acc); let acc = f(foreach_left_paren, acc); let acc = f(foreach_collection, acc); let acc = f(foreach_await_keyword, acc); let acc = f(foreach_as, acc); let acc = f(foreach_key, acc); let acc = f(foreach_arrow, acc); let acc = f(foreach_value, acc); let acc = f(foreach_right_paren, acc); let acc = f(foreach_body, acc); acc }, SyntaxVariant::SwitchStatement(x) => { let SwitchStatementChildren { switch_keyword, switch_left_paren, switch_expression, switch_right_paren, switch_left_brace, switch_sections, switch_right_brace } = *x; let acc = f(switch_keyword, acc); let acc = f(switch_left_paren, acc); let acc = f(switch_expression, acc); let acc = f(switch_right_paren, acc); let acc = f(switch_left_brace, acc); let acc = f(switch_sections, acc); let acc = f(switch_right_brace, acc); acc }, SyntaxVariant::SwitchSection(x) => { let SwitchSectionChildren { switch_section_labels, switch_section_statements, switch_section_fallthrough } = *x; let acc = f(switch_section_labels, acc); let acc = f(switch_section_statements, acc); let acc = f(switch_section_fallthrough, acc); acc }, SyntaxVariant::SwitchFallthrough(x) => { let SwitchFallthroughChildren { fallthrough_keyword, fallthrough_semicolon } = *x; let acc = f(fallthrough_keyword, acc); let acc = f(fallthrough_semicolon, acc); acc }, SyntaxVariant::CaseLabel(x) => { let CaseLabelChildren { case_keyword, case_expression, case_colon } = *x; let acc = f(case_keyword, acc); let acc = f(case_expression, acc); let acc = f(case_colon, acc); acc }, SyntaxVariant::DefaultLabel(x) => { let DefaultLabelChildren { default_keyword, default_colon } = *x; let acc = f(default_keyword, acc); let acc = f(default_colon, acc); acc }, SyntaxVariant::MatchStatement(x) => { let MatchStatementChildren { match_statement_keyword, match_statement_left_paren, match_statement_expression, match_statement_right_paren, match_statement_left_brace, match_statement_arms, match_statement_right_brace } = *x; let acc = f(match_statement_keyword, acc); let acc = f(match_statement_left_paren, acc); let acc = f(match_statement_expression, acc); let acc = f(match_statement_right_paren, acc); let acc = f(match_statement_left_brace, acc); let acc = f(match_statement_arms, acc); let acc = f(match_statement_right_brace, acc); acc }, SyntaxVariant::MatchStatementArm(x) => { let MatchStatementArmChildren { match_statement_arm_pattern, match_statement_arm_arrow, match_statement_arm_body } = *x; let acc = f(match_statement_arm_pattern, acc); let acc = f(match_statement_arm_arrow, acc); let acc = f(match_statement_arm_body, acc); acc }, SyntaxVariant::ReturnStatement(x) => { let ReturnStatementChildren { return_keyword, return_expression, return_semicolon } = *x; let acc = f(return_keyword, acc); let acc = f(return_expression, acc); let acc = f(return_semicolon, acc); acc }, SyntaxVariant::YieldBreakStatement(x) => { let YieldBreakStatementChildren { yield_break_keyword, yield_break_break, yield_break_semicolon } = *x; let acc = f(yield_break_keyword, acc); let acc = f(yield_break_break, acc); let acc = f(yield_break_semicolon, acc); acc }, SyntaxVariant::ThrowStatement(x) => { let ThrowStatementChildren { throw_keyword, throw_expression, throw_semicolon } = *x; let acc = f(throw_keyword, acc); let acc = f(throw_expression, acc); let acc = f(throw_semicolon, acc); acc }, SyntaxVariant::BreakStatement(x) => { let BreakStatementChildren { break_keyword, break_semicolon } = *x; let acc = f(break_keyword, acc); let acc = f(break_semicolon, acc); acc }, SyntaxVariant::ContinueStatement(x) => { let ContinueStatementChildren { continue_keyword, continue_semicolon } = *x; let acc = f(continue_keyword, acc); let acc = f(continue_semicolon, acc); acc }, SyntaxVariant::EchoStatement(x) => { let EchoStatementChildren { echo_keyword, echo_expressions, echo_semicolon } = *x; let acc = f(echo_keyword, acc); let acc = f(echo_expressions, acc); let acc = f(echo_semicolon, acc); acc }, SyntaxVariant::ConcurrentStatement(x) => { let ConcurrentStatementChildren { concurrent_keyword, concurrent_statement } = *x; let acc = f(concurrent_keyword, acc); let acc = f(concurrent_statement, acc); acc }, SyntaxVariant::SimpleInitializer(x) => { let SimpleInitializerChildren { simple_initializer_equal, simple_initializer_value } = *x; let acc = f(simple_initializer_equal, acc); let acc = f(simple_initializer_value, acc); acc }, SyntaxVariant::AnonymousClass(x) => { let AnonymousClassChildren { anonymous_class_class_keyword, anonymous_class_left_paren, anonymous_class_argument_list, anonymous_class_right_paren, anonymous_class_extends_keyword, anonymous_class_extends_list, anonymous_class_implements_keyword, anonymous_class_implements_list, anonymous_class_body } = *x; let acc = f(anonymous_class_class_keyword, acc); let acc = f(anonymous_class_left_paren, acc); let acc = f(anonymous_class_argument_list, acc); let acc = f(anonymous_class_right_paren, acc); let acc = f(anonymous_class_extends_keyword, acc); let acc = f(anonymous_class_extends_list, acc); let acc = f(anonymous_class_implements_keyword, acc); let acc = f(anonymous_class_implements_list, acc); let acc = f(anonymous_class_body, acc); acc }, SyntaxVariant::AnonymousFunction(x) => { let AnonymousFunctionChildren { anonymous_attribute_spec, anonymous_async_keyword, anonymous_function_keyword, anonymous_left_paren, anonymous_parameters, anonymous_right_paren, anonymous_ctx_list, anonymous_colon, anonymous_readonly_return, anonymous_type, anonymous_use, anonymous_body } = *x; let acc = f(anonymous_attribute_spec, acc); let acc = f(anonymous_async_keyword, acc); let acc = f(anonymous_function_keyword, acc); let acc = f(anonymous_left_paren, acc); let acc = f(anonymous_parameters, acc); let acc = f(anonymous_right_paren, acc); let acc = f(anonymous_ctx_list, acc); let acc = f(anonymous_colon, acc); let acc = f(anonymous_readonly_return, acc); let acc = f(anonymous_type, acc); let acc = f(anonymous_use, acc); let acc = f(anonymous_body, acc); acc }, SyntaxVariant::AnonymousFunctionUseClause(x) => { let AnonymousFunctionUseClauseChildren { anonymous_use_keyword, anonymous_use_left_paren, anonymous_use_variables, anonymous_use_right_paren } = *x; let acc = f(anonymous_use_keyword, acc); let acc = f(anonymous_use_left_paren, acc); let acc = f(anonymous_use_variables, acc); let acc = f(anonymous_use_right_paren, acc); acc }, SyntaxVariant::VariablePattern(x) => { let VariablePatternChildren { variable_pattern_variable } = *x; let acc = f(variable_pattern_variable, acc); acc }, SyntaxVariant::ConstructorPattern(x) => { let ConstructorPatternChildren { constructor_pattern_constructor, constructor_pattern_left_paren, constructor_pattern_members, constructor_pattern_right_paren } = *x; let acc = f(constructor_pattern_constructor, acc); let acc = f(constructor_pattern_left_paren, acc); let acc = f(constructor_pattern_members, acc); let acc = f(constructor_pattern_right_paren, acc); acc }, SyntaxVariant::RefinementPattern(x) => { let RefinementPatternChildren { refinement_pattern_variable, refinement_pattern_colon, refinement_pattern_specifier } = *x; let acc = f(refinement_pattern_variable, acc); let acc = f(refinement_pattern_colon, acc); let acc = f(refinement_pattern_specifier, acc); acc }, SyntaxVariant::LambdaExpression(x) => { let LambdaExpressionChildren { lambda_attribute_spec, lambda_async, lambda_signature, lambda_arrow, lambda_body } = *x; let acc = f(lambda_attribute_spec, acc); let acc = f(lambda_async, acc); let acc = f(lambda_signature, acc); let acc = f(lambda_arrow, acc); let acc = f(lambda_body, acc); acc }, SyntaxVariant::LambdaSignature(x) => { let LambdaSignatureChildren { lambda_left_paren, lambda_parameters, lambda_right_paren, lambda_contexts, lambda_colon, lambda_readonly_return, lambda_type } = *x; let acc = f(lambda_left_paren, acc); let acc = f(lambda_parameters, acc); let acc = f(lambda_right_paren, acc); let acc = f(lambda_contexts, acc); let acc = f(lambda_colon, acc); let acc = f(lambda_readonly_return, acc); let acc = f(lambda_type, acc); acc }, SyntaxVariant::CastExpression(x) => { let CastExpressionChildren { cast_left_paren, cast_type, cast_right_paren, cast_operand } = *x; let acc = f(cast_left_paren, acc); let acc = f(cast_type, acc); let acc = f(cast_right_paren, acc); let acc = f(cast_operand, acc); acc }, SyntaxVariant::ScopeResolutionExpression(x) => { let ScopeResolutionExpressionChildren { scope_resolution_qualifier, scope_resolution_operator, scope_resolution_name } = *x; let acc = f(scope_resolution_qualifier, acc); let acc = f(scope_resolution_operator, acc); let acc = f(scope_resolution_name, acc); acc }, SyntaxVariant::MemberSelectionExpression(x) => { let MemberSelectionExpressionChildren { member_object, member_operator, member_name } = *x; let acc = f(member_object, acc); let acc = f(member_operator, acc); let acc = f(member_name, acc); acc }, SyntaxVariant::SafeMemberSelectionExpression(x) => { let SafeMemberSelectionExpressionChildren { safe_member_object, safe_member_operator, safe_member_name } = *x; let acc = f(safe_member_object, acc); let acc = f(safe_member_operator, acc); let acc = f(safe_member_name, acc); acc }, SyntaxVariant::EmbeddedMemberSelectionExpression(x) => { let EmbeddedMemberSelectionExpressionChildren { embedded_member_object, embedded_member_operator, embedded_member_name } = *x; let acc = f(embedded_member_object, acc); let acc = f(embedded_member_operator, acc); let acc = f(embedded_member_name, acc); acc }, SyntaxVariant::YieldExpression(x) => { let YieldExpressionChildren { yield_keyword, yield_operand } = *x; let acc = f(yield_keyword, acc); let acc = f(yield_operand, acc); acc }, SyntaxVariant::PrefixUnaryExpression(x) => { let PrefixUnaryExpressionChildren { prefix_unary_operator, prefix_unary_operand } = *x; let acc = f(prefix_unary_operator, acc); let acc = f(prefix_unary_operand, acc); acc }, SyntaxVariant::PostfixUnaryExpression(x) => { let PostfixUnaryExpressionChildren { postfix_unary_operand, postfix_unary_operator } = *x; let acc = f(postfix_unary_operand, acc); let acc = f(postfix_unary_operator, acc); acc }, SyntaxVariant::BinaryExpression(x) => { let BinaryExpressionChildren { binary_left_operand, binary_operator, binary_right_operand } = *x; let acc = f(binary_left_operand, acc); let acc = f(binary_operator, acc); let acc = f(binary_right_operand, acc); acc }, SyntaxVariant::IsExpression(x) => { let IsExpressionChildren { is_left_operand, is_operator, is_right_operand } = *x; let acc = f(is_left_operand, acc); let acc = f(is_operator, acc); let acc = f(is_right_operand, acc); acc }, SyntaxVariant::AsExpression(x) => { let AsExpressionChildren { as_left_operand, as_operator, as_right_operand } = *x; let acc = f(as_left_operand, acc); let acc = f(as_operator, acc); let acc = f(as_right_operand, acc); acc }, SyntaxVariant::NullableAsExpression(x) => { let NullableAsExpressionChildren { nullable_as_left_operand, nullable_as_operator, nullable_as_right_operand } = *x; let acc = f(nullable_as_left_operand, acc); let acc = f(nullable_as_operator, acc); let acc = f(nullable_as_right_operand, acc); acc }, SyntaxVariant::UpcastExpression(x) => { let UpcastExpressionChildren { upcast_left_operand, upcast_operator, upcast_right_operand } = *x; let acc = f(upcast_left_operand, acc); let acc = f(upcast_operator, acc); let acc = f(upcast_right_operand, acc); acc }, SyntaxVariant::ConditionalExpression(x) => { let ConditionalExpressionChildren { conditional_test, conditional_question, conditional_consequence, conditional_colon, conditional_alternative } = *x; let acc = f(conditional_test, acc); let acc = f(conditional_question, acc); let acc = f(conditional_consequence, acc); let acc = f(conditional_colon, acc); let acc = f(conditional_alternative, acc); acc }, SyntaxVariant::EvalExpression(x) => { let EvalExpressionChildren { eval_keyword, eval_left_paren, eval_argument, eval_right_paren } = *x; let acc = f(eval_keyword, acc); let acc = f(eval_left_paren, acc); let acc = f(eval_argument, acc); let acc = f(eval_right_paren, acc); acc }, SyntaxVariant::IssetExpression(x) => { let IssetExpressionChildren { isset_keyword, isset_left_paren, isset_argument_list, isset_right_paren } = *x; let acc = f(isset_keyword, acc); let acc = f(isset_left_paren, acc); let acc = f(isset_argument_list, acc); let acc = f(isset_right_paren, acc); acc }, SyntaxVariant::FunctionCallExpression(x) => { let FunctionCallExpressionChildren { function_call_receiver, function_call_type_args, function_call_left_paren, function_call_argument_list, function_call_right_paren } = *x; let acc = f(function_call_receiver, acc); let acc = f(function_call_type_args, acc); let acc = f(function_call_left_paren, acc); let acc = f(function_call_argument_list, acc); let acc = f(function_call_right_paren, acc); acc }, SyntaxVariant::FunctionPointerExpression(x) => { let FunctionPointerExpressionChildren { function_pointer_receiver, function_pointer_type_args } = *x; let acc = f(function_pointer_receiver, acc); let acc = f(function_pointer_type_args, acc); acc }, SyntaxVariant::ParenthesizedExpression(x) => { let ParenthesizedExpressionChildren { parenthesized_expression_left_paren, parenthesized_expression_expression, parenthesized_expression_right_paren } = *x; let acc = f(parenthesized_expression_left_paren, acc); let acc = f(parenthesized_expression_expression, acc); let acc = f(parenthesized_expression_right_paren, acc); acc }, SyntaxVariant::BracedExpression(x) => { let BracedExpressionChildren { braced_expression_left_brace, braced_expression_expression, braced_expression_right_brace } = *x; let acc = f(braced_expression_left_brace, acc); let acc = f(braced_expression_expression, acc); let acc = f(braced_expression_right_brace, acc); acc }, SyntaxVariant::ETSpliceExpression(x) => { let ETSpliceExpressionChildren { et_splice_expression_dollar, et_splice_expression_left_brace, et_splice_expression_expression, et_splice_expression_right_brace } = *x; let acc = f(et_splice_expression_dollar, acc); let acc = f(et_splice_expression_left_brace, acc); let acc = f(et_splice_expression_expression, acc); let acc = f(et_splice_expression_right_brace, acc); acc }, SyntaxVariant::EmbeddedBracedExpression(x) => { let EmbeddedBracedExpressionChildren { embedded_braced_expression_left_brace, embedded_braced_expression_expression, embedded_braced_expression_right_brace } = *x; let acc = f(embedded_braced_expression_left_brace, acc); let acc = f(embedded_braced_expression_expression, acc); let acc = f(embedded_braced_expression_right_brace, acc); acc }, SyntaxVariant::ListExpression(x) => { let ListExpressionChildren { list_keyword, list_left_paren, list_members, list_right_paren } = *x; let acc = f(list_keyword, acc); let acc = f(list_left_paren, acc); let acc = f(list_members, acc); let acc = f(list_right_paren, acc); acc }, SyntaxVariant::CollectionLiteralExpression(x) => { let CollectionLiteralExpressionChildren { collection_literal_name, collection_literal_left_brace, collection_literal_initializers, collection_literal_right_brace } = *x; let acc = f(collection_literal_name, acc); let acc = f(collection_literal_left_brace, acc); let acc = f(collection_literal_initializers, acc); let acc = f(collection_literal_right_brace, acc); acc }, SyntaxVariant::ObjectCreationExpression(x) => { let ObjectCreationExpressionChildren { object_creation_new_keyword, object_creation_object } = *x; let acc = f(object_creation_new_keyword, acc); let acc = f(object_creation_object, acc); acc }, SyntaxVariant::ConstructorCall(x) => { let ConstructorCallChildren { constructor_call_type, constructor_call_left_paren, constructor_call_argument_list, constructor_call_right_paren } = *x; let acc = f(constructor_call_type, acc); let acc = f(constructor_call_left_paren, acc); let acc = f(constructor_call_argument_list, acc); let acc = f(constructor_call_right_paren, acc); acc }, SyntaxVariant::DarrayIntrinsicExpression(x) => { let DarrayIntrinsicExpressionChildren { darray_intrinsic_keyword, darray_intrinsic_explicit_type, darray_intrinsic_left_bracket, darray_intrinsic_members, darray_intrinsic_right_bracket } = *x; let acc = f(darray_intrinsic_keyword, acc); let acc = f(darray_intrinsic_explicit_type, acc); let acc = f(darray_intrinsic_left_bracket, acc); let acc = f(darray_intrinsic_members, acc); let acc = f(darray_intrinsic_right_bracket, acc); acc }, SyntaxVariant::DictionaryIntrinsicExpression(x) => { let DictionaryIntrinsicExpressionChildren { dictionary_intrinsic_keyword, dictionary_intrinsic_explicit_type, dictionary_intrinsic_left_bracket, dictionary_intrinsic_members, dictionary_intrinsic_right_bracket } = *x; let acc = f(dictionary_intrinsic_keyword, acc); let acc = f(dictionary_intrinsic_explicit_type, acc); let acc = f(dictionary_intrinsic_left_bracket, acc); let acc = f(dictionary_intrinsic_members, acc); let acc = f(dictionary_intrinsic_right_bracket, acc); acc }, SyntaxVariant::KeysetIntrinsicExpression(x) => { let KeysetIntrinsicExpressionChildren { keyset_intrinsic_keyword, keyset_intrinsic_explicit_type, keyset_intrinsic_left_bracket, keyset_intrinsic_members, keyset_intrinsic_right_bracket } = *x; let acc = f(keyset_intrinsic_keyword, acc); let acc = f(keyset_intrinsic_explicit_type, acc); let acc = f(keyset_intrinsic_left_bracket, acc); let acc = f(keyset_intrinsic_members, acc); let acc = f(keyset_intrinsic_right_bracket, acc); acc }, SyntaxVariant::VarrayIntrinsicExpression(x) => { let VarrayIntrinsicExpressionChildren { varray_intrinsic_keyword, varray_intrinsic_explicit_type, varray_intrinsic_left_bracket, varray_intrinsic_members, varray_intrinsic_right_bracket } = *x; let acc = f(varray_intrinsic_keyword, acc); let acc = f(varray_intrinsic_explicit_type, acc); let acc = f(varray_intrinsic_left_bracket, acc); let acc = f(varray_intrinsic_members, acc); let acc = f(varray_intrinsic_right_bracket, acc); acc }, SyntaxVariant::VectorIntrinsicExpression(x) => { let VectorIntrinsicExpressionChildren { vector_intrinsic_keyword, vector_intrinsic_explicit_type, vector_intrinsic_left_bracket, vector_intrinsic_members, vector_intrinsic_right_bracket } = *x; let acc = f(vector_intrinsic_keyword, acc); let acc = f(vector_intrinsic_explicit_type, acc); let acc = f(vector_intrinsic_left_bracket, acc); let acc = f(vector_intrinsic_members, acc); let acc = f(vector_intrinsic_right_bracket, acc); acc }, SyntaxVariant::ElementInitializer(x) => { let ElementInitializerChildren { element_key, element_arrow, element_value } = *x; let acc = f(element_key, acc); let acc = f(element_arrow, acc); let acc = f(element_value, acc); acc }, SyntaxVariant::SubscriptExpression(x) => { let SubscriptExpressionChildren { subscript_receiver, subscript_left_bracket, subscript_index, subscript_right_bracket } = *x; let acc = f(subscript_receiver, acc); let acc = f(subscript_left_bracket, acc); let acc = f(subscript_index, acc); let acc = f(subscript_right_bracket, acc); acc }, SyntaxVariant::EmbeddedSubscriptExpression(x) => { let EmbeddedSubscriptExpressionChildren { embedded_subscript_receiver, embedded_subscript_left_bracket, embedded_subscript_index, embedded_subscript_right_bracket } = *x; let acc = f(embedded_subscript_receiver, acc); let acc = f(embedded_subscript_left_bracket, acc); let acc = f(embedded_subscript_index, acc); let acc = f(embedded_subscript_right_bracket, acc); acc }, SyntaxVariant::AwaitableCreationExpression(x) => { let AwaitableCreationExpressionChildren { awaitable_attribute_spec, awaitable_async, awaitable_compound_statement } = *x; let acc = f(awaitable_attribute_spec, acc); let acc = f(awaitable_async, acc); let acc = f(awaitable_compound_statement, acc); acc }, SyntaxVariant::XHPChildrenDeclaration(x) => { let XHPChildrenDeclarationChildren { xhp_children_keyword, xhp_children_expression, xhp_children_semicolon } = *x; let acc = f(xhp_children_keyword, acc); let acc = f(xhp_children_expression, acc); let acc = f(xhp_children_semicolon, acc); acc }, SyntaxVariant::XHPChildrenParenthesizedList(x) => { let XHPChildrenParenthesizedListChildren { xhp_children_list_left_paren, xhp_children_list_xhp_children, xhp_children_list_right_paren } = *x; let acc = f(xhp_children_list_left_paren, acc); let acc = f(xhp_children_list_xhp_children, acc); let acc = f(xhp_children_list_right_paren, acc); acc }, SyntaxVariant::XHPCategoryDeclaration(x) => { let XHPCategoryDeclarationChildren { xhp_category_keyword, xhp_category_categories, xhp_category_semicolon } = *x; let acc = f(xhp_category_keyword, acc); let acc = f(xhp_category_categories, acc); let acc = f(xhp_category_semicolon, acc); acc }, SyntaxVariant::XHPEnumType(x) => { let XHPEnumTypeChildren { xhp_enum_like, xhp_enum_keyword, xhp_enum_left_brace, xhp_enum_values, xhp_enum_right_brace } = *x; let acc = f(xhp_enum_like, acc); let acc = f(xhp_enum_keyword, acc); let acc = f(xhp_enum_left_brace, acc); let acc = f(xhp_enum_values, acc); let acc = f(xhp_enum_right_brace, acc); acc }, SyntaxVariant::XHPLateinit(x) => { let XHPLateinitChildren { xhp_lateinit_at, xhp_lateinit_keyword } = *x; let acc = f(xhp_lateinit_at, acc); let acc = f(xhp_lateinit_keyword, acc); acc }, SyntaxVariant::XHPRequired(x) => { let XHPRequiredChildren { xhp_required_at, xhp_required_keyword } = *x; let acc = f(xhp_required_at, acc); let acc = f(xhp_required_keyword, acc); acc }, SyntaxVariant::XHPClassAttributeDeclaration(x) => { let XHPClassAttributeDeclarationChildren { xhp_attribute_keyword, xhp_attribute_attributes, xhp_attribute_semicolon } = *x; let acc = f(xhp_attribute_keyword, acc); let acc = f(xhp_attribute_attributes, acc); let acc = f(xhp_attribute_semicolon, acc); acc }, SyntaxVariant::XHPClassAttribute(x) => { let XHPClassAttributeChildren { xhp_attribute_decl_type, xhp_attribute_decl_name, xhp_attribute_decl_initializer, xhp_attribute_decl_required } = *x; let acc = f(xhp_attribute_decl_type, acc); let acc = f(xhp_attribute_decl_name, acc); let acc = f(xhp_attribute_decl_initializer, acc); let acc = f(xhp_attribute_decl_required, acc); acc }, SyntaxVariant::XHPSimpleClassAttribute(x) => { let XHPSimpleClassAttributeChildren { xhp_simple_class_attribute_type } = *x; let acc = f(xhp_simple_class_attribute_type, acc); acc }, SyntaxVariant::XHPSimpleAttribute(x) => { let XHPSimpleAttributeChildren { xhp_simple_attribute_name, xhp_simple_attribute_equal, xhp_simple_attribute_expression } = *x; let acc = f(xhp_simple_attribute_name, acc); let acc = f(xhp_simple_attribute_equal, acc); let acc = f(xhp_simple_attribute_expression, acc); acc }, SyntaxVariant::XHPSpreadAttribute(x) => { let XHPSpreadAttributeChildren { xhp_spread_attribute_left_brace, xhp_spread_attribute_spread_operator, xhp_spread_attribute_expression, xhp_spread_attribute_right_brace } = *x; let acc = f(xhp_spread_attribute_left_brace, acc); let acc = f(xhp_spread_attribute_spread_operator, acc); let acc = f(xhp_spread_attribute_expression, acc); let acc = f(xhp_spread_attribute_right_brace, acc); acc }, SyntaxVariant::XHPOpen(x) => { let XHPOpenChildren { xhp_open_left_angle, xhp_open_name, xhp_open_attributes, xhp_open_right_angle } = *x; let acc = f(xhp_open_left_angle, acc); let acc = f(xhp_open_name, acc); let acc = f(xhp_open_attributes, acc); let acc = f(xhp_open_right_angle, acc); acc }, SyntaxVariant::XHPExpression(x) => { let XHPExpressionChildren { xhp_open, xhp_body, xhp_close } = *x; let acc = f(xhp_open, acc); let acc = f(xhp_body, acc); let acc = f(xhp_close, acc); acc }, SyntaxVariant::XHPClose(x) => { let XHPCloseChildren { xhp_close_left_angle, xhp_close_name, xhp_close_right_angle } = *x; let acc = f(xhp_close_left_angle, acc); let acc = f(xhp_close_name, acc); let acc = f(xhp_close_right_angle, acc); acc }, SyntaxVariant::TypeConstant(x) => { let TypeConstantChildren { type_constant_left_type, type_constant_separator, type_constant_right_type } = *x; let acc = f(type_constant_left_type, acc); let acc = f(type_constant_separator, acc); let acc = f(type_constant_right_type, acc); acc }, SyntaxVariant::VectorTypeSpecifier(x) => { let VectorTypeSpecifierChildren { vector_type_keyword, vector_type_left_angle, vector_type_type, vector_type_trailing_comma, vector_type_right_angle } = *x; let acc = f(vector_type_keyword, acc); let acc = f(vector_type_left_angle, acc); let acc = f(vector_type_type, acc); let acc = f(vector_type_trailing_comma, acc); let acc = f(vector_type_right_angle, acc); acc }, SyntaxVariant::KeysetTypeSpecifier(x) => { let KeysetTypeSpecifierChildren { keyset_type_keyword, keyset_type_left_angle, keyset_type_type, keyset_type_trailing_comma, keyset_type_right_angle } = *x; let acc = f(keyset_type_keyword, acc); let acc = f(keyset_type_left_angle, acc); let acc = f(keyset_type_type, acc); let acc = f(keyset_type_trailing_comma, acc); let acc = f(keyset_type_right_angle, acc); acc }, SyntaxVariant::TupleTypeExplicitSpecifier(x) => { let TupleTypeExplicitSpecifierChildren { tuple_type_keyword, tuple_type_left_angle, tuple_type_types, tuple_type_right_angle } = *x; let acc = f(tuple_type_keyword, acc); let acc = f(tuple_type_left_angle, acc); let acc = f(tuple_type_types, acc); let acc = f(tuple_type_right_angle, acc); acc }, SyntaxVariant::VarrayTypeSpecifier(x) => { let VarrayTypeSpecifierChildren { varray_keyword, varray_left_angle, varray_type, varray_trailing_comma, varray_right_angle } = *x; let acc = f(varray_keyword, acc); let acc = f(varray_left_angle, acc); let acc = f(varray_type, acc); let acc = f(varray_trailing_comma, acc); let acc = f(varray_right_angle, acc); acc }, SyntaxVariant::FunctionCtxTypeSpecifier(x) => { let FunctionCtxTypeSpecifierChildren { function_ctx_type_keyword, function_ctx_type_variable } = *x; let acc = f(function_ctx_type_keyword, acc); let acc = f(function_ctx_type_variable, acc); acc }, SyntaxVariant::TypeParameter(x) => { let TypeParameterChildren { type_attribute_spec, type_reified, type_variance, type_name, type_param_params, type_constraints } = *x; let acc = f(type_attribute_spec, acc); let acc = f(type_reified, acc); let acc = f(type_variance, acc); let acc = f(type_name, acc); let acc = f(type_param_params, acc); let acc = f(type_constraints, acc); acc }, SyntaxVariant::TypeConstraint(x) => { let TypeConstraintChildren { constraint_keyword, constraint_type } = *x; let acc = f(constraint_keyword, acc); let acc = f(constraint_type, acc); acc }, SyntaxVariant::ContextConstraint(x) => { let ContextConstraintChildren { ctx_constraint_keyword, ctx_constraint_ctx_list } = *x; let acc = f(ctx_constraint_keyword, acc); let acc = f(ctx_constraint_ctx_list, acc); acc }, SyntaxVariant::DarrayTypeSpecifier(x) => { let DarrayTypeSpecifierChildren { darray_keyword, darray_left_angle, darray_key, darray_comma, darray_value, darray_trailing_comma, darray_right_angle } = *x; let acc = f(darray_keyword, acc); let acc = f(darray_left_angle, acc); let acc = f(darray_key, acc); let acc = f(darray_comma, acc); let acc = f(darray_value, acc); let acc = f(darray_trailing_comma, acc); let acc = f(darray_right_angle, acc); acc }, SyntaxVariant::DictionaryTypeSpecifier(x) => { let DictionaryTypeSpecifierChildren { dictionary_type_keyword, dictionary_type_left_angle, dictionary_type_members, dictionary_type_right_angle } = *x; let acc = f(dictionary_type_keyword, acc); let acc = f(dictionary_type_left_angle, acc); let acc = f(dictionary_type_members, acc); let acc = f(dictionary_type_right_angle, acc); acc }, SyntaxVariant::ClosureTypeSpecifier(x) => { let ClosureTypeSpecifierChildren { closure_outer_left_paren, closure_readonly_keyword, closure_function_keyword, closure_inner_left_paren, closure_parameter_list, closure_inner_right_paren, closure_contexts, closure_colon, closure_readonly_return, closure_return_type, closure_outer_right_paren } = *x; let acc = f(closure_outer_left_paren, acc); let acc = f(closure_readonly_keyword, acc); let acc = f(closure_function_keyword, acc); let acc = f(closure_inner_left_paren, acc); let acc = f(closure_parameter_list, acc); let acc = f(closure_inner_right_paren, acc); let acc = f(closure_contexts, acc); let acc = f(closure_colon, acc); let acc = f(closure_readonly_return, acc); let acc = f(closure_return_type, acc); let acc = f(closure_outer_right_paren, acc); acc }, SyntaxVariant::ClosureParameterTypeSpecifier(x) => { let ClosureParameterTypeSpecifierChildren { closure_parameter_call_convention, closure_parameter_readonly, closure_parameter_type } = *x; let acc = f(closure_parameter_call_convention, acc); let acc = f(closure_parameter_readonly, acc); let acc = f(closure_parameter_type, acc); acc }, SyntaxVariant::TypeRefinement(x) => { let TypeRefinementChildren { type_refinement_type, type_refinement_keyword, type_refinement_left_brace, type_refinement_members, type_refinement_right_brace } = *x; let acc = f(type_refinement_type, acc); let acc = f(type_refinement_keyword, acc); let acc = f(type_refinement_left_brace, acc); let acc = f(type_refinement_members, acc); let acc = f(type_refinement_right_brace, acc); acc }, SyntaxVariant::TypeInRefinement(x) => { let TypeInRefinementChildren { type_in_refinement_keyword, type_in_refinement_name, type_in_refinement_type_parameters, type_in_refinement_constraints, type_in_refinement_equal, type_in_refinement_type } = *x; let acc = f(type_in_refinement_keyword, acc); let acc = f(type_in_refinement_name, acc); let acc = f(type_in_refinement_type_parameters, acc); let acc = f(type_in_refinement_constraints, acc); let acc = f(type_in_refinement_equal, acc); let acc = f(type_in_refinement_type, acc); acc }, SyntaxVariant::CtxInRefinement(x) => { let CtxInRefinementChildren { ctx_in_refinement_keyword, ctx_in_refinement_name, ctx_in_refinement_type_parameters, ctx_in_refinement_constraints, ctx_in_refinement_equal, ctx_in_refinement_ctx_list } = *x; let acc = f(ctx_in_refinement_keyword, acc); let acc = f(ctx_in_refinement_name, acc); let acc = f(ctx_in_refinement_type_parameters, acc); let acc = f(ctx_in_refinement_constraints, acc); let acc = f(ctx_in_refinement_equal, acc); let acc = f(ctx_in_refinement_ctx_list, acc); acc }, SyntaxVariant::ClassnameTypeSpecifier(x) => { let ClassnameTypeSpecifierChildren { classname_keyword, classname_left_angle, classname_type, classname_trailing_comma, classname_right_angle } = *x; let acc = f(classname_keyword, acc); let acc = f(classname_left_angle, acc); let acc = f(classname_type, acc); let acc = f(classname_trailing_comma, acc); let acc = f(classname_right_angle, acc); acc }, SyntaxVariant::FieldSpecifier(x) => { let FieldSpecifierChildren { field_question, field_name, field_arrow, field_type } = *x; let acc = f(field_question, acc); let acc = f(field_name, acc); let acc = f(field_arrow, acc); let acc = f(field_type, acc); acc }, SyntaxVariant::FieldInitializer(x) => { let FieldInitializerChildren { field_initializer_name, field_initializer_arrow, field_initializer_value } = *x; let acc = f(field_initializer_name, acc); let acc = f(field_initializer_arrow, acc); let acc = f(field_initializer_value, acc); acc }, SyntaxVariant::ShapeTypeSpecifier(x) => { let ShapeTypeSpecifierChildren { shape_type_keyword, shape_type_left_paren, shape_type_fields, shape_type_ellipsis, shape_type_right_paren } = *x; let acc = f(shape_type_keyword, acc); let acc = f(shape_type_left_paren, acc); let acc = f(shape_type_fields, acc); let acc = f(shape_type_ellipsis, acc); let acc = f(shape_type_right_paren, acc); acc }, SyntaxVariant::ShapeExpression(x) => { let ShapeExpressionChildren { shape_expression_keyword, shape_expression_left_paren, shape_expression_fields, shape_expression_right_paren } = *x; let acc = f(shape_expression_keyword, acc); let acc = f(shape_expression_left_paren, acc); let acc = f(shape_expression_fields, acc); let acc = f(shape_expression_right_paren, acc); acc }, SyntaxVariant::TupleExpression(x) => { let TupleExpressionChildren { tuple_expression_keyword, tuple_expression_left_paren, tuple_expression_items, tuple_expression_right_paren } = *x; let acc = f(tuple_expression_keyword, acc); let acc = f(tuple_expression_left_paren, acc); let acc = f(tuple_expression_items, acc); let acc = f(tuple_expression_right_paren, acc); acc }, SyntaxVariant::GenericTypeSpecifier(x) => { let GenericTypeSpecifierChildren { generic_class_type, generic_argument_list } = *x; let acc = f(generic_class_type, acc); let acc = f(generic_argument_list, acc); acc }, SyntaxVariant::NullableTypeSpecifier(x) => { let NullableTypeSpecifierChildren { nullable_question, nullable_type } = *x; let acc = f(nullable_question, acc); let acc = f(nullable_type, acc); acc }, SyntaxVariant::LikeTypeSpecifier(x) => { let LikeTypeSpecifierChildren { like_tilde, like_type } = *x; let acc = f(like_tilde, acc); let acc = f(like_type, acc); acc }, SyntaxVariant::SoftTypeSpecifier(x) => { let SoftTypeSpecifierChildren { soft_at, soft_type } = *x; let acc = f(soft_at, acc); let acc = f(soft_type, acc); acc }, SyntaxVariant::AttributizedSpecifier(x) => { let AttributizedSpecifierChildren { attributized_specifier_attribute_spec, attributized_specifier_type } = *x; let acc = f(attributized_specifier_attribute_spec, acc); let acc = f(attributized_specifier_type, acc); acc }, SyntaxVariant::ReifiedTypeArgument(x) => { let ReifiedTypeArgumentChildren { reified_type_argument_reified, reified_type_argument_type } = *x; let acc = f(reified_type_argument_reified, acc); let acc = f(reified_type_argument_type, acc); acc }, SyntaxVariant::TypeArguments(x) => { let TypeArgumentsChildren { type_arguments_left_angle, type_arguments_types, type_arguments_right_angle } = *x; let acc = f(type_arguments_left_angle, acc); let acc = f(type_arguments_types, acc); let acc = f(type_arguments_right_angle, acc); acc }, SyntaxVariant::TypeParameters(x) => { let TypeParametersChildren { type_parameters_left_angle, type_parameters_parameters, type_parameters_right_angle } = *x; let acc = f(type_parameters_left_angle, acc); let acc = f(type_parameters_parameters, acc); let acc = f(type_parameters_right_angle, acc); acc }, SyntaxVariant::TupleTypeSpecifier(x) => { let TupleTypeSpecifierChildren { tuple_left_paren, tuple_types, tuple_right_paren } = *x; let acc = f(tuple_left_paren, acc); let acc = f(tuple_types, acc); let acc = f(tuple_right_paren, acc); acc }, SyntaxVariant::UnionTypeSpecifier(x) => { let UnionTypeSpecifierChildren { union_left_paren, union_types, union_right_paren } = *x; let acc = f(union_left_paren, acc); let acc = f(union_types, acc); let acc = f(union_right_paren, acc); acc }, SyntaxVariant::IntersectionTypeSpecifier(x) => { let IntersectionTypeSpecifierChildren { intersection_left_paren, intersection_types, intersection_right_paren } = *x; let acc = f(intersection_left_paren, acc); let acc = f(intersection_types, acc); let acc = f(intersection_right_paren, acc); acc }, SyntaxVariant::ErrorSyntax(x) => { let ErrorSyntaxChildren { error_error } = *x; let acc = f(error_error, acc); acc }, SyntaxVariant::ListItem(x) => { let ListItemChildren { list_item, list_separator } = *x; let acc = f(list_item, acc); let acc = f(list_separator, acc); acc }, SyntaxVariant::EnumClassLabelExpression(x) => { let EnumClassLabelExpressionChildren { enum_class_label_qualifier, enum_class_label_hash, enum_class_label_expression } = *x; let acc = f(enum_class_label_qualifier, acc); let acc = f(enum_class_label_hash, acc); let acc = f(enum_class_label_expression, acc); acc }, SyntaxVariant::ModuleDeclaration(x) => { let ModuleDeclarationChildren { module_declaration_attribute_spec, module_declaration_new_keyword, module_declaration_module_keyword, module_declaration_name, module_declaration_left_brace, module_declaration_exports, module_declaration_imports, module_declaration_right_brace } = *x; let acc = f(module_declaration_attribute_spec, acc); let acc = f(module_declaration_new_keyword, acc); let acc = f(module_declaration_module_keyword, acc); let acc = f(module_declaration_name, acc); let acc = f(module_declaration_left_brace, acc); let acc = f(module_declaration_exports, acc); let acc = f(module_declaration_imports, acc); let acc = f(module_declaration_right_brace, acc); acc }, SyntaxVariant::ModuleExports(x) => { let ModuleExportsChildren { module_exports_exports_keyword, module_exports_left_brace, module_exports_exports, module_exports_right_brace } = *x; let acc = f(module_exports_exports_keyword, acc); let acc = f(module_exports_left_brace, acc); let acc = f(module_exports_exports, acc); let acc = f(module_exports_right_brace, acc); acc }, SyntaxVariant::ModuleImports(x) => { let ModuleImportsChildren { module_imports_imports_keyword, module_imports_left_brace, module_imports_imports, module_imports_right_brace } = *x; let acc = f(module_imports_imports_keyword, acc); let acc = f(module_imports_left_brace, acc); let acc = f(module_imports_imports, acc); let acc = f(module_imports_right_brace, acc); acc }, SyntaxVariant::ModuleMembershipDeclaration(x) => { let ModuleMembershipDeclarationChildren { module_membership_declaration_module_keyword, module_membership_declaration_name, module_membership_declaration_semicolon } = *x; let acc = f(module_membership_declaration_module_keyword, acc); let acc = f(module_membership_declaration_name, acc); let acc = f(module_membership_declaration_semicolon, acc); acc }, SyntaxVariant::PackageExpression(x) => { let PackageExpressionChildren { package_expression_keyword, package_expression_name } = *x; let acc = f(package_expression_keyword, acc); let acc = f(package_expression_name, acc); acc }, } } pub fn kind(&self) -> SyntaxKind { match &self.syntax { SyntaxVariant::Missing => SyntaxKind::Missing, SyntaxVariant::Token (t) => SyntaxKind::Token(t.kind()), SyntaxVariant::SyntaxList (_) => SyntaxKind::SyntaxList, SyntaxVariant::EndOfFile {..} => SyntaxKind::EndOfFile, SyntaxVariant::Script {..} => SyntaxKind::Script, SyntaxVariant::QualifiedName {..} => SyntaxKind::QualifiedName, SyntaxVariant::ModuleName {..} => SyntaxKind::ModuleName, SyntaxVariant::SimpleTypeSpecifier {..} => SyntaxKind::SimpleTypeSpecifier, SyntaxVariant::LiteralExpression {..} => SyntaxKind::LiteralExpression, SyntaxVariant::PrefixedStringExpression {..} => SyntaxKind::PrefixedStringExpression, SyntaxVariant::PrefixedCodeExpression {..} => SyntaxKind::PrefixedCodeExpression, SyntaxVariant::VariableExpression {..} => SyntaxKind::VariableExpression, SyntaxVariant::PipeVariableExpression {..} => SyntaxKind::PipeVariableExpression, SyntaxVariant::FileAttributeSpecification {..} => SyntaxKind::FileAttributeSpecification, SyntaxVariant::EnumDeclaration {..} => SyntaxKind::EnumDeclaration, SyntaxVariant::EnumUse {..} => SyntaxKind::EnumUse, SyntaxVariant::Enumerator {..} => SyntaxKind::Enumerator, SyntaxVariant::EnumClassDeclaration {..} => SyntaxKind::EnumClassDeclaration, SyntaxVariant::EnumClassEnumerator {..} => SyntaxKind::EnumClassEnumerator, SyntaxVariant::AliasDeclaration {..} => SyntaxKind::AliasDeclaration, SyntaxVariant::ContextAliasDeclaration {..} => SyntaxKind::ContextAliasDeclaration, SyntaxVariant::CaseTypeDeclaration {..} => SyntaxKind::CaseTypeDeclaration, SyntaxVariant::CaseTypeVariant {..} => SyntaxKind::CaseTypeVariant, SyntaxVariant::PropertyDeclaration {..} => SyntaxKind::PropertyDeclaration, SyntaxVariant::PropertyDeclarator {..} => SyntaxKind::PropertyDeclarator, SyntaxVariant::NamespaceDeclaration {..} => SyntaxKind::NamespaceDeclaration, SyntaxVariant::NamespaceDeclarationHeader {..} => SyntaxKind::NamespaceDeclarationHeader, SyntaxVariant::NamespaceBody {..} => SyntaxKind::NamespaceBody, SyntaxVariant::NamespaceEmptyBody {..} => SyntaxKind::NamespaceEmptyBody, SyntaxVariant::NamespaceUseDeclaration {..} => SyntaxKind::NamespaceUseDeclaration, SyntaxVariant::NamespaceGroupUseDeclaration {..} => SyntaxKind::NamespaceGroupUseDeclaration, SyntaxVariant::NamespaceUseClause {..} => SyntaxKind::NamespaceUseClause, SyntaxVariant::FunctionDeclaration {..} => SyntaxKind::FunctionDeclaration, SyntaxVariant::FunctionDeclarationHeader {..} => SyntaxKind::FunctionDeclarationHeader, SyntaxVariant::Contexts {..} => SyntaxKind::Contexts, SyntaxVariant::WhereClause {..} => SyntaxKind::WhereClause, SyntaxVariant::WhereConstraint {..} => SyntaxKind::WhereConstraint, SyntaxVariant::MethodishDeclaration {..} => SyntaxKind::MethodishDeclaration, SyntaxVariant::MethodishTraitResolution {..} => SyntaxKind::MethodishTraitResolution, SyntaxVariant::ClassishDeclaration {..} => SyntaxKind::ClassishDeclaration, SyntaxVariant::ClassishBody {..} => SyntaxKind::ClassishBody, SyntaxVariant::TraitUse {..} => SyntaxKind::TraitUse, SyntaxVariant::RequireClause {..} => SyntaxKind::RequireClause, SyntaxVariant::ConstDeclaration {..} => SyntaxKind::ConstDeclaration, SyntaxVariant::ConstantDeclarator {..} => SyntaxKind::ConstantDeclarator, SyntaxVariant::TypeConstDeclaration {..} => SyntaxKind::TypeConstDeclaration, SyntaxVariant::ContextConstDeclaration {..} => SyntaxKind::ContextConstDeclaration, SyntaxVariant::DecoratedExpression {..} => SyntaxKind::DecoratedExpression, SyntaxVariant::ParameterDeclaration {..} => SyntaxKind::ParameterDeclaration, SyntaxVariant::VariadicParameter {..} => SyntaxKind::VariadicParameter, SyntaxVariant::OldAttributeSpecification {..} => SyntaxKind::OldAttributeSpecification, SyntaxVariant::AttributeSpecification {..} => SyntaxKind::AttributeSpecification, SyntaxVariant::Attribute {..} => SyntaxKind::Attribute, SyntaxVariant::InclusionExpression {..} => SyntaxKind::InclusionExpression, SyntaxVariant::InclusionDirective {..} => SyntaxKind::InclusionDirective, SyntaxVariant::CompoundStatement {..} => SyntaxKind::CompoundStatement, SyntaxVariant::ExpressionStatement {..} => SyntaxKind::ExpressionStatement, SyntaxVariant::MarkupSection {..} => SyntaxKind::MarkupSection, SyntaxVariant::MarkupSuffix {..} => SyntaxKind::MarkupSuffix, SyntaxVariant::UnsetStatement {..} => SyntaxKind::UnsetStatement, SyntaxVariant::DeclareLocalStatement {..} => SyntaxKind::DeclareLocalStatement, SyntaxVariant::UsingStatementBlockScoped {..} => SyntaxKind::UsingStatementBlockScoped, SyntaxVariant::UsingStatementFunctionScoped {..} => SyntaxKind::UsingStatementFunctionScoped, SyntaxVariant::WhileStatement {..} => SyntaxKind::WhileStatement, SyntaxVariant::IfStatement {..} => SyntaxKind::IfStatement, SyntaxVariant::ElseClause {..} => SyntaxKind::ElseClause, SyntaxVariant::TryStatement {..} => SyntaxKind::TryStatement, SyntaxVariant::CatchClause {..} => SyntaxKind::CatchClause, SyntaxVariant::FinallyClause {..} => SyntaxKind::FinallyClause, SyntaxVariant::DoStatement {..} => SyntaxKind::DoStatement, SyntaxVariant::ForStatement {..} => SyntaxKind::ForStatement, SyntaxVariant::ForeachStatement {..} => SyntaxKind::ForeachStatement, SyntaxVariant::SwitchStatement {..} => SyntaxKind::SwitchStatement, SyntaxVariant::SwitchSection {..} => SyntaxKind::SwitchSection, SyntaxVariant::SwitchFallthrough {..} => SyntaxKind::SwitchFallthrough, SyntaxVariant::CaseLabel {..} => SyntaxKind::CaseLabel, SyntaxVariant::DefaultLabel {..} => SyntaxKind::DefaultLabel, SyntaxVariant::MatchStatement {..} => SyntaxKind::MatchStatement, SyntaxVariant::MatchStatementArm {..} => SyntaxKind::MatchStatementArm, SyntaxVariant::ReturnStatement {..} => SyntaxKind::ReturnStatement, SyntaxVariant::YieldBreakStatement {..} => SyntaxKind::YieldBreakStatement, SyntaxVariant::ThrowStatement {..} => SyntaxKind::ThrowStatement, SyntaxVariant::BreakStatement {..} => SyntaxKind::BreakStatement, SyntaxVariant::ContinueStatement {..} => SyntaxKind::ContinueStatement, SyntaxVariant::EchoStatement {..} => SyntaxKind::EchoStatement, SyntaxVariant::ConcurrentStatement {..} => SyntaxKind::ConcurrentStatement, SyntaxVariant::SimpleInitializer {..} => SyntaxKind::SimpleInitializer, SyntaxVariant::AnonymousClass {..} => SyntaxKind::AnonymousClass, SyntaxVariant::AnonymousFunction {..} => SyntaxKind::AnonymousFunction, SyntaxVariant::AnonymousFunctionUseClause {..} => SyntaxKind::AnonymousFunctionUseClause, SyntaxVariant::VariablePattern {..} => SyntaxKind::VariablePattern, SyntaxVariant::ConstructorPattern {..} => SyntaxKind::ConstructorPattern, SyntaxVariant::RefinementPattern {..} => SyntaxKind::RefinementPattern, SyntaxVariant::LambdaExpression {..} => SyntaxKind::LambdaExpression, SyntaxVariant::LambdaSignature {..} => SyntaxKind::LambdaSignature, SyntaxVariant::CastExpression {..} => SyntaxKind::CastExpression, SyntaxVariant::ScopeResolutionExpression {..} => SyntaxKind::ScopeResolutionExpression, SyntaxVariant::MemberSelectionExpression {..} => SyntaxKind::MemberSelectionExpression, SyntaxVariant::SafeMemberSelectionExpression {..} => SyntaxKind::SafeMemberSelectionExpression, SyntaxVariant::EmbeddedMemberSelectionExpression {..} => SyntaxKind::EmbeddedMemberSelectionExpression, SyntaxVariant::YieldExpression {..} => SyntaxKind::YieldExpression, SyntaxVariant::PrefixUnaryExpression {..} => SyntaxKind::PrefixUnaryExpression, SyntaxVariant::PostfixUnaryExpression {..} => SyntaxKind::PostfixUnaryExpression, SyntaxVariant::BinaryExpression {..} => SyntaxKind::BinaryExpression, SyntaxVariant::IsExpression {..} => SyntaxKind::IsExpression, SyntaxVariant::AsExpression {..} => SyntaxKind::AsExpression, SyntaxVariant::NullableAsExpression {..} => SyntaxKind::NullableAsExpression, SyntaxVariant::UpcastExpression {..} => SyntaxKind::UpcastExpression, SyntaxVariant::ConditionalExpression {..} => SyntaxKind::ConditionalExpression, SyntaxVariant::EvalExpression {..} => SyntaxKind::EvalExpression, SyntaxVariant::IssetExpression {..} => SyntaxKind::IssetExpression, SyntaxVariant::FunctionCallExpression {..} => SyntaxKind::FunctionCallExpression, SyntaxVariant::FunctionPointerExpression {..} => SyntaxKind::FunctionPointerExpression, SyntaxVariant::ParenthesizedExpression {..} => SyntaxKind::ParenthesizedExpression, SyntaxVariant::BracedExpression {..} => SyntaxKind::BracedExpression, SyntaxVariant::ETSpliceExpression {..} => SyntaxKind::ETSpliceExpression, SyntaxVariant::EmbeddedBracedExpression {..} => SyntaxKind::EmbeddedBracedExpression, SyntaxVariant::ListExpression {..} => SyntaxKind::ListExpression, SyntaxVariant::CollectionLiteralExpression {..} => SyntaxKind::CollectionLiteralExpression, SyntaxVariant::ObjectCreationExpression {..} => SyntaxKind::ObjectCreationExpression, SyntaxVariant::ConstructorCall {..} => SyntaxKind::ConstructorCall, SyntaxVariant::DarrayIntrinsicExpression {..} => SyntaxKind::DarrayIntrinsicExpression, SyntaxVariant::DictionaryIntrinsicExpression {..} => SyntaxKind::DictionaryIntrinsicExpression, SyntaxVariant::KeysetIntrinsicExpression {..} => SyntaxKind::KeysetIntrinsicExpression, SyntaxVariant::VarrayIntrinsicExpression {..} => SyntaxKind::VarrayIntrinsicExpression, SyntaxVariant::VectorIntrinsicExpression {..} => SyntaxKind::VectorIntrinsicExpression, SyntaxVariant::ElementInitializer {..} => SyntaxKind::ElementInitializer, SyntaxVariant::SubscriptExpression {..} => SyntaxKind::SubscriptExpression, SyntaxVariant::EmbeddedSubscriptExpression {..} => SyntaxKind::EmbeddedSubscriptExpression, SyntaxVariant::AwaitableCreationExpression {..} => SyntaxKind::AwaitableCreationExpression, SyntaxVariant::XHPChildrenDeclaration {..} => SyntaxKind::XHPChildrenDeclaration, SyntaxVariant::XHPChildrenParenthesizedList {..} => SyntaxKind::XHPChildrenParenthesizedList, SyntaxVariant::XHPCategoryDeclaration {..} => SyntaxKind::XHPCategoryDeclaration, SyntaxVariant::XHPEnumType {..} => SyntaxKind::XHPEnumType, SyntaxVariant::XHPLateinit {..} => SyntaxKind::XHPLateinit, SyntaxVariant::XHPRequired {..} => SyntaxKind::XHPRequired, SyntaxVariant::XHPClassAttributeDeclaration {..} => SyntaxKind::XHPClassAttributeDeclaration, SyntaxVariant::XHPClassAttribute {..} => SyntaxKind::XHPClassAttribute, SyntaxVariant::XHPSimpleClassAttribute {..} => SyntaxKind::XHPSimpleClassAttribute, SyntaxVariant::XHPSimpleAttribute {..} => SyntaxKind::XHPSimpleAttribute, SyntaxVariant::XHPSpreadAttribute {..} => SyntaxKind::XHPSpreadAttribute, SyntaxVariant::XHPOpen {..} => SyntaxKind::XHPOpen, SyntaxVariant::XHPExpression {..} => SyntaxKind::XHPExpression, SyntaxVariant::XHPClose {..} => SyntaxKind::XHPClose, SyntaxVariant::TypeConstant {..} => SyntaxKind::TypeConstant, SyntaxVariant::VectorTypeSpecifier {..} => SyntaxKind::VectorTypeSpecifier, SyntaxVariant::KeysetTypeSpecifier {..} => SyntaxKind::KeysetTypeSpecifier, SyntaxVariant::TupleTypeExplicitSpecifier {..} => SyntaxKind::TupleTypeExplicitSpecifier, SyntaxVariant::VarrayTypeSpecifier {..} => SyntaxKind::VarrayTypeSpecifier, SyntaxVariant::FunctionCtxTypeSpecifier {..} => SyntaxKind::FunctionCtxTypeSpecifier, SyntaxVariant::TypeParameter {..} => SyntaxKind::TypeParameter, SyntaxVariant::TypeConstraint {..} => SyntaxKind::TypeConstraint, SyntaxVariant::ContextConstraint {..} => SyntaxKind::ContextConstraint, SyntaxVariant::DarrayTypeSpecifier {..} => SyntaxKind::DarrayTypeSpecifier, SyntaxVariant::DictionaryTypeSpecifier {..} => SyntaxKind::DictionaryTypeSpecifier, SyntaxVariant::ClosureTypeSpecifier {..} => SyntaxKind::ClosureTypeSpecifier, SyntaxVariant::ClosureParameterTypeSpecifier {..} => SyntaxKind::ClosureParameterTypeSpecifier, SyntaxVariant::TypeRefinement {..} => SyntaxKind::TypeRefinement, SyntaxVariant::TypeInRefinement {..} => SyntaxKind::TypeInRefinement, SyntaxVariant::CtxInRefinement {..} => SyntaxKind::CtxInRefinement, SyntaxVariant::ClassnameTypeSpecifier {..} => SyntaxKind::ClassnameTypeSpecifier, SyntaxVariant::FieldSpecifier {..} => SyntaxKind::FieldSpecifier, SyntaxVariant::FieldInitializer {..} => SyntaxKind::FieldInitializer, SyntaxVariant::ShapeTypeSpecifier {..} => SyntaxKind::ShapeTypeSpecifier, SyntaxVariant::ShapeExpression {..} => SyntaxKind::ShapeExpression, SyntaxVariant::TupleExpression {..} => SyntaxKind::TupleExpression, SyntaxVariant::GenericTypeSpecifier {..} => SyntaxKind::GenericTypeSpecifier, SyntaxVariant::NullableTypeSpecifier {..} => SyntaxKind::NullableTypeSpecifier, SyntaxVariant::LikeTypeSpecifier {..} => SyntaxKind::LikeTypeSpecifier, SyntaxVariant::SoftTypeSpecifier {..} => SyntaxKind::SoftTypeSpecifier, SyntaxVariant::AttributizedSpecifier {..} => SyntaxKind::AttributizedSpecifier, SyntaxVariant::ReifiedTypeArgument {..} => SyntaxKind::ReifiedTypeArgument, SyntaxVariant::TypeArguments {..} => SyntaxKind::TypeArguments, SyntaxVariant::TypeParameters {..} => SyntaxKind::TypeParameters, SyntaxVariant::TupleTypeSpecifier {..} => SyntaxKind::TupleTypeSpecifier, SyntaxVariant::UnionTypeSpecifier {..} => SyntaxKind::UnionTypeSpecifier, SyntaxVariant::IntersectionTypeSpecifier {..} => SyntaxKind::IntersectionTypeSpecifier, SyntaxVariant::ErrorSyntax {..} => SyntaxKind::ErrorSyntax, SyntaxVariant::ListItem {..} => SyntaxKind::ListItem, SyntaxVariant::EnumClassLabelExpression {..} => SyntaxKind::EnumClassLabelExpression, SyntaxVariant::ModuleDeclaration {..} => SyntaxKind::ModuleDeclaration, SyntaxVariant::ModuleExports {..} => SyntaxKind::ModuleExports, SyntaxVariant::ModuleImports {..} => SyntaxKind::ModuleImports, SyntaxVariant::ModuleMembershipDeclaration {..} => SyntaxKind::ModuleMembershipDeclaration, SyntaxVariant::PackageExpression {..} => SyntaxKind::PackageExpression, } } pub fn from_children(kind : SyntaxKind, mut ts : Vec<Self>) -> SyntaxVariant<T, V> { match (kind, ts.len()) { (SyntaxKind::Missing, 0) => SyntaxVariant::Missing, (SyntaxKind::SyntaxList, _) => SyntaxVariant::SyntaxList(ts), (SyntaxKind::EndOfFile, 1) => SyntaxVariant::EndOfFile(Box::new(EndOfFileChildren { end_of_file_token: ts.pop().unwrap(), })), (SyntaxKind::Script, 1) => SyntaxVariant::Script(Box::new(ScriptChildren { script_declarations: ts.pop().unwrap(), })), (SyntaxKind::QualifiedName, 1) => SyntaxVariant::QualifiedName(Box::new(QualifiedNameChildren { qualified_name_parts: ts.pop().unwrap(), })), (SyntaxKind::ModuleName, 1) => SyntaxVariant::ModuleName(Box::new(ModuleNameChildren { module_name_parts: ts.pop().unwrap(), })), (SyntaxKind::SimpleTypeSpecifier, 1) => SyntaxVariant::SimpleTypeSpecifier(Box::new(SimpleTypeSpecifierChildren { simple_type_specifier: ts.pop().unwrap(), })), (SyntaxKind::LiteralExpression, 1) => SyntaxVariant::LiteralExpression(Box::new(LiteralExpressionChildren { literal_expression: ts.pop().unwrap(), })), (SyntaxKind::PrefixedStringExpression, 2) => SyntaxVariant::PrefixedStringExpression(Box::new(PrefixedStringExpressionChildren { prefixed_string_str: ts.pop().unwrap(), prefixed_string_name: ts.pop().unwrap(), })), (SyntaxKind::PrefixedCodeExpression, 4) => SyntaxVariant::PrefixedCodeExpression(Box::new(PrefixedCodeExpressionChildren { prefixed_code_right_backtick: ts.pop().unwrap(), prefixed_code_body: ts.pop().unwrap(), prefixed_code_left_backtick: ts.pop().unwrap(), prefixed_code_prefix: ts.pop().unwrap(), })), (SyntaxKind::VariableExpression, 1) => SyntaxVariant::VariableExpression(Box::new(VariableExpressionChildren { variable_expression: ts.pop().unwrap(), })), (SyntaxKind::PipeVariableExpression, 1) => SyntaxVariant::PipeVariableExpression(Box::new(PipeVariableExpressionChildren { pipe_variable_expression: ts.pop().unwrap(), })), (SyntaxKind::FileAttributeSpecification, 5) => SyntaxVariant::FileAttributeSpecification(Box::new(FileAttributeSpecificationChildren { file_attribute_specification_right_double_angle: ts.pop().unwrap(), file_attribute_specification_attributes: ts.pop().unwrap(), file_attribute_specification_colon: ts.pop().unwrap(), file_attribute_specification_keyword: ts.pop().unwrap(), file_attribute_specification_left_double_angle: ts.pop().unwrap(), })), (SyntaxKind::EnumDeclaration, 11) => SyntaxVariant::EnumDeclaration(Box::new(EnumDeclarationChildren { enum_right_brace: ts.pop().unwrap(), enum_enumerators: ts.pop().unwrap(), enum_use_clauses: ts.pop().unwrap(), enum_left_brace: ts.pop().unwrap(), enum_type: ts.pop().unwrap(), enum_base: ts.pop().unwrap(), enum_colon: ts.pop().unwrap(), enum_name: ts.pop().unwrap(), enum_keyword: ts.pop().unwrap(), enum_modifiers: ts.pop().unwrap(), enum_attribute_spec: ts.pop().unwrap(), })), (SyntaxKind::EnumUse, 3) => SyntaxVariant::EnumUse(Box::new(EnumUseChildren { enum_use_semicolon: ts.pop().unwrap(), enum_use_names: ts.pop().unwrap(), enum_use_keyword: ts.pop().unwrap(), })), (SyntaxKind::Enumerator, 4) => SyntaxVariant::Enumerator(Box::new(EnumeratorChildren { enumerator_semicolon: ts.pop().unwrap(), enumerator_value: ts.pop().unwrap(), enumerator_equal: ts.pop().unwrap(), enumerator_name: ts.pop().unwrap(), })), (SyntaxKind::EnumClassDeclaration, 12) => SyntaxVariant::EnumClassDeclaration(Box::new(EnumClassDeclarationChildren { enum_class_right_brace: ts.pop().unwrap(), enum_class_elements: ts.pop().unwrap(), enum_class_left_brace: ts.pop().unwrap(), enum_class_extends_list: ts.pop().unwrap(), enum_class_extends: ts.pop().unwrap(), enum_class_base: ts.pop().unwrap(), enum_class_colon: ts.pop().unwrap(), enum_class_name: ts.pop().unwrap(), enum_class_class_keyword: ts.pop().unwrap(), enum_class_enum_keyword: ts.pop().unwrap(), enum_class_modifiers: ts.pop().unwrap(), enum_class_attribute_spec: ts.pop().unwrap(), })), (SyntaxKind::EnumClassEnumerator, 5) => SyntaxVariant::EnumClassEnumerator(Box::new(EnumClassEnumeratorChildren { enum_class_enumerator_semicolon: ts.pop().unwrap(), enum_class_enumerator_initializer: ts.pop().unwrap(), enum_class_enumerator_name: ts.pop().unwrap(), enum_class_enumerator_type: ts.pop().unwrap(), enum_class_enumerator_modifiers: ts.pop().unwrap(), })), (SyntaxKind::AliasDeclaration, 10) => SyntaxVariant::AliasDeclaration(Box::new(AliasDeclarationChildren { alias_semicolon: ts.pop().unwrap(), alias_type: ts.pop().unwrap(), alias_equal: ts.pop().unwrap(), alias_constraint: ts.pop().unwrap(), alias_generic_parameter: ts.pop().unwrap(), alias_name: ts.pop().unwrap(), alias_keyword: ts.pop().unwrap(), alias_module_kw_opt: ts.pop().unwrap(), alias_modifiers: ts.pop().unwrap(), alias_attribute_spec: ts.pop().unwrap(), })), (SyntaxKind::ContextAliasDeclaration, 8) => SyntaxVariant::ContextAliasDeclaration(Box::new(ContextAliasDeclarationChildren { ctx_alias_semicolon: ts.pop().unwrap(), ctx_alias_context: ts.pop().unwrap(), ctx_alias_equal: ts.pop().unwrap(), ctx_alias_as_constraint: ts.pop().unwrap(), ctx_alias_generic_parameter: ts.pop().unwrap(), ctx_alias_name: ts.pop().unwrap(), ctx_alias_keyword: ts.pop().unwrap(), ctx_alias_attribute_spec: ts.pop().unwrap(), })), (SyntaxKind::CaseTypeDeclaration, 11) => SyntaxVariant::CaseTypeDeclaration(Box::new(CaseTypeDeclarationChildren { case_type_semicolon: ts.pop().unwrap(), case_type_variants: ts.pop().unwrap(), case_type_equal: ts.pop().unwrap(), case_type_bounds: ts.pop().unwrap(), case_type_as: ts.pop().unwrap(), case_type_generic_parameter: ts.pop().unwrap(), case_type_name: ts.pop().unwrap(), case_type_type_keyword: ts.pop().unwrap(), case_type_case_keyword: ts.pop().unwrap(), case_type_modifiers: ts.pop().unwrap(), case_type_attribute_spec: ts.pop().unwrap(), })), (SyntaxKind::CaseTypeVariant, 2) => SyntaxVariant::CaseTypeVariant(Box::new(CaseTypeVariantChildren { case_type_variant_type: ts.pop().unwrap(), case_type_variant_bar: ts.pop().unwrap(), })), (SyntaxKind::PropertyDeclaration, 5) => SyntaxVariant::PropertyDeclaration(Box::new(PropertyDeclarationChildren { property_semicolon: ts.pop().unwrap(), property_declarators: ts.pop().unwrap(), property_type: ts.pop().unwrap(), property_modifiers: ts.pop().unwrap(), property_attribute_spec: ts.pop().unwrap(), })), (SyntaxKind::PropertyDeclarator, 2) => SyntaxVariant::PropertyDeclarator(Box::new(PropertyDeclaratorChildren { property_initializer: ts.pop().unwrap(), property_name: ts.pop().unwrap(), })), (SyntaxKind::NamespaceDeclaration, 2) => SyntaxVariant::NamespaceDeclaration(Box::new(NamespaceDeclarationChildren { namespace_body: ts.pop().unwrap(), namespace_header: ts.pop().unwrap(), })), (SyntaxKind::NamespaceDeclarationHeader, 2) => SyntaxVariant::NamespaceDeclarationHeader(Box::new(NamespaceDeclarationHeaderChildren { namespace_name: ts.pop().unwrap(), namespace_keyword: ts.pop().unwrap(), })), (SyntaxKind::NamespaceBody, 3) => SyntaxVariant::NamespaceBody(Box::new(NamespaceBodyChildren { namespace_right_brace: ts.pop().unwrap(), namespace_declarations: ts.pop().unwrap(), namespace_left_brace: ts.pop().unwrap(), })), (SyntaxKind::NamespaceEmptyBody, 1) => SyntaxVariant::NamespaceEmptyBody(Box::new(NamespaceEmptyBodyChildren { namespace_semicolon: ts.pop().unwrap(), })), (SyntaxKind::NamespaceUseDeclaration, 4) => SyntaxVariant::NamespaceUseDeclaration(Box::new(NamespaceUseDeclarationChildren { namespace_use_semicolon: ts.pop().unwrap(), namespace_use_clauses: ts.pop().unwrap(), namespace_use_kind: ts.pop().unwrap(), namespace_use_keyword: ts.pop().unwrap(), })), (SyntaxKind::NamespaceGroupUseDeclaration, 7) => SyntaxVariant::NamespaceGroupUseDeclaration(Box::new(NamespaceGroupUseDeclarationChildren { namespace_group_use_semicolon: ts.pop().unwrap(), namespace_group_use_right_brace: ts.pop().unwrap(), namespace_group_use_clauses: ts.pop().unwrap(), namespace_group_use_left_brace: ts.pop().unwrap(), namespace_group_use_prefix: ts.pop().unwrap(), namespace_group_use_kind: ts.pop().unwrap(), namespace_group_use_keyword: ts.pop().unwrap(), })), (SyntaxKind::NamespaceUseClause, 4) => SyntaxVariant::NamespaceUseClause(Box::new(NamespaceUseClauseChildren { namespace_use_alias: ts.pop().unwrap(), namespace_use_as: ts.pop().unwrap(), namespace_use_name: ts.pop().unwrap(), namespace_use_clause_kind: ts.pop().unwrap(), })), (SyntaxKind::FunctionDeclaration, 3) => SyntaxVariant::FunctionDeclaration(Box::new(FunctionDeclarationChildren { function_body: ts.pop().unwrap(), function_declaration_header: ts.pop().unwrap(), function_attribute_spec: ts.pop().unwrap(), })), (SyntaxKind::FunctionDeclarationHeader, 12) => SyntaxVariant::FunctionDeclarationHeader(Box::new(FunctionDeclarationHeaderChildren { function_where_clause: ts.pop().unwrap(), function_type: ts.pop().unwrap(), function_readonly_return: ts.pop().unwrap(), function_colon: ts.pop().unwrap(), function_contexts: ts.pop().unwrap(), function_right_paren: ts.pop().unwrap(), function_parameter_list: ts.pop().unwrap(), function_left_paren: ts.pop().unwrap(), function_type_parameter_list: ts.pop().unwrap(), function_name: ts.pop().unwrap(), function_keyword: ts.pop().unwrap(), function_modifiers: ts.pop().unwrap(), })), (SyntaxKind::Contexts, 3) => SyntaxVariant::Contexts(Box::new(ContextsChildren { contexts_right_bracket: ts.pop().unwrap(), contexts_types: ts.pop().unwrap(), contexts_left_bracket: ts.pop().unwrap(), })), (SyntaxKind::WhereClause, 2) => SyntaxVariant::WhereClause(Box::new(WhereClauseChildren { where_clause_constraints: ts.pop().unwrap(), where_clause_keyword: ts.pop().unwrap(), })), (SyntaxKind::WhereConstraint, 3) => SyntaxVariant::WhereConstraint(Box::new(WhereConstraintChildren { where_constraint_right_type: ts.pop().unwrap(), where_constraint_operator: ts.pop().unwrap(), where_constraint_left_type: ts.pop().unwrap(), })), (SyntaxKind::MethodishDeclaration, 4) => SyntaxVariant::MethodishDeclaration(Box::new(MethodishDeclarationChildren { methodish_semicolon: ts.pop().unwrap(), methodish_function_body: ts.pop().unwrap(), methodish_function_decl_header: ts.pop().unwrap(), methodish_attribute: ts.pop().unwrap(), })), (SyntaxKind::MethodishTraitResolution, 5) => SyntaxVariant::MethodishTraitResolution(Box::new(MethodishTraitResolutionChildren { methodish_trait_semicolon: ts.pop().unwrap(), methodish_trait_name: ts.pop().unwrap(), methodish_trait_equal: ts.pop().unwrap(), methodish_trait_function_decl_header: ts.pop().unwrap(), methodish_trait_attribute: ts.pop().unwrap(), })), (SyntaxKind::ClassishDeclaration, 12) => SyntaxVariant::ClassishDeclaration(Box::new(ClassishDeclarationChildren { classish_body: ts.pop().unwrap(), classish_where_clause: ts.pop().unwrap(), classish_implements_list: ts.pop().unwrap(), classish_implements_keyword: ts.pop().unwrap(), classish_extends_list: ts.pop().unwrap(), classish_extends_keyword: ts.pop().unwrap(), classish_type_parameters: ts.pop().unwrap(), classish_name: ts.pop().unwrap(), classish_keyword: ts.pop().unwrap(), classish_xhp: ts.pop().unwrap(), classish_modifiers: ts.pop().unwrap(), classish_attribute: ts.pop().unwrap(), })), (SyntaxKind::ClassishBody, 3) => SyntaxVariant::ClassishBody(Box::new(ClassishBodyChildren { classish_body_right_brace: ts.pop().unwrap(), classish_body_elements: ts.pop().unwrap(), classish_body_left_brace: ts.pop().unwrap(), })), (SyntaxKind::TraitUse, 3) => SyntaxVariant::TraitUse(Box::new(TraitUseChildren { trait_use_semicolon: ts.pop().unwrap(), trait_use_names: ts.pop().unwrap(), trait_use_keyword: ts.pop().unwrap(), })), (SyntaxKind::RequireClause, 4) => SyntaxVariant::RequireClause(Box::new(RequireClauseChildren { require_semicolon: ts.pop().unwrap(), require_name: ts.pop().unwrap(), require_kind: ts.pop().unwrap(), require_keyword: ts.pop().unwrap(), })), (SyntaxKind::ConstDeclaration, 6) => SyntaxVariant::ConstDeclaration(Box::new(ConstDeclarationChildren { const_semicolon: ts.pop().unwrap(), const_declarators: ts.pop().unwrap(), const_type_specifier: ts.pop().unwrap(), const_keyword: ts.pop().unwrap(), const_modifiers: ts.pop().unwrap(), const_attribute_spec: ts.pop().unwrap(), })), (SyntaxKind::ConstantDeclarator, 2) => SyntaxVariant::ConstantDeclarator(Box::new(ConstantDeclaratorChildren { constant_declarator_initializer: ts.pop().unwrap(), constant_declarator_name: ts.pop().unwrap(), })), (SyntaxKind::TypeConstDeclaration, 10) => SyntaxVariant::TypeConstDeclaration(Box::new(TypeConstDeclarationChildren { type_const_semicolon: ts.pop().unwrap(), type_const_type_specifier: ts.pop().unwrap(), type_const_equal: ts.pop().unwrap(), type_const_type_constraints: ts.pop().unwrap(), type_const_type_parameters: ts.pop().unwrap(), type_const_name: ts.pop().unwrap(), type_const_type_keyword: ts.pop().unwrap(), type_const_keyword: ts.pop().unwrap(), type_const_modifiers: ts.pop().unwrap(), type_const_attribute_spec: ts.pop().unwrap(), })), (SyntaxKind::ContextConstDeclaration, 9) => SyntaxVariant::ContextConstDeclaration(Box::new(ContextConstDeclarationChildren { context_const_semicolon: ts.pop().unwrap(), context_const_ctx_list: ts.pop().unwrap(), context_const_equal: ts.pop().unwrap(), context_const_constraint: ts.pop().unwrap(), context_const_type_parameters: ts.pop().unwrap(), context_const_name: ts.pop().unwrap(), context_const_ctx_keyword: ts.pop().unwrap(), context_const_const_keyword: ts.pop().unwrap(), context_const_modifiers: ts.pop().unwrap(), })), (SyntaxKind::DecoratedExpression, 2) => SyntaxVariant::DecoratedExpression(Box::new(DecoratedExpressionChildren { decorated_expression_expression: ts.pop().unwrap(), decorated_expression_decorator: ts.pop().unwrap(), })), (SyntaxKind::ParameterDeclaration, 7) => SyntaxVariant::ParameterDeclaration(Box::new(ParameterDeclarationChildren { parameter_default_value: ts.pop().unwrap(), parameter_name: ts.pop().unwrap(), parameter_type: ts.pop().unwrap(), parameter_readonly: ts.pop().unwrap(), parameter_call_convention: ts.pop().unwrap(), parameter_visibility: ts.pop().unwrap(), parameter_attribute: ts.pop().unwrap(), })), (SyntaxKind::VariadicParameter, 3) => SyntaxVariant::VariadicParameter(Box::new(VariadicParameterChildren { variadic_parameter_ellipsis: ts.pop().unwrap(), variadic_parameter_type: ts.pop().unwrap(), variadic_parameter_call_convention: ts.pop().unwrap(), })), (SyntaxKind::OldAttributeSpecification, 3) => SyntaxVariant::OldAttributeSpecification(Box::new(OldAttributeSpecificationChildren { old_attribute_specification_right_double_angle: ts.pop().unwrap(), old_attribute_specification_attributes: ts.pop().unwrap(), old_attribute_specification_left_double_angle: ts.pop().unwrap(), })), (SyntaxKind::AttributeSpecification, 1) => SyntaxVariant::AttributeSpecification(Box::new(AttributeSpecificationChildren { attribute_specification_attributes: ts.pop().unwrap(), })), (SyntaxKind::Attribute, 2) => SyntaxVariant::Attribute(Box::new(AttributeChildren { attribute_attribute_name: ts.pop().unwrap(), attribute_at: ts.pop().unwrap(), })), (SyntaxKind::InclusionExpression, 2) => SyntaxVariant::InclusionExpression(Box::new(InclusionExpressionChildren { inclusion_filename: ts.pop().unwrap(), inclusion_require: ts.pop().unwrap(), })), (SyntaxKind::InclusionDirective, 2) => SyntaxVariant::InclusionDirective(Box::new(InclusionDirectiveChildren { inclusion_semicolon: ts.pop().unwrap(), inclusion_expression: ts.pop().unwrap(), })), (SyntaxKind::CompoundStatement, 3) => SyntaxVariant::CompoundStatement(Box::new(CompoundStatementChildren { compound_right_brace: ts.pop().unwrap(), compound_statements: ts.pop().unwrap(), compound_left_brace: ts.pop().unwrap(), })), (SyntaxKind::ExpressionStatement, 2) => SyntaxVariant::ExpressionStatement(Box::new(ExpressionStatementChildren { expression_statement_semicolon: ts.pop().unwrap(), expression_statement_expression: ts.pop().unwrap(), })), (SyntaxKind::MarkupSection, 2) => SyntaxVariant::MarkupSection(Box::new(MarkupSectionChildren { markup_suffix: ts.pop().unwrap(), markup_hashbang: ts.pop().unwrap(), })), (SyntaxKind::MarkupSuffix, 2) => SyntaxVariant::MarkupSuffix(Box::new(MarkupSuffixChildren { markup_suffix_name: ts.pop().unwrap(), markup_suffix_less_than_question: ts.pop().unwrap(), })), (SyntaxKind::UnsetStatement, 5) => SyntaxVariant::UnsetStatement(Box::new(UnsetStatementChildren { unset_semicolon: ts.pop().unwrap(), unset_right_paren: ts.pop().unwrap(), unset_variables: ts.pop().unwrap(), unset_left_paren: ts.pop().unwrap(), unset_keyword: ts.pop().unwrap(), })), (SyntaxKind::DeclareLocalStatement, 6) => SyntaxVariant::DeclareLocalStatement(Box::new(DeclareLocalStatementChildren { declare_local_semicolon: ts.pop().unwrap(), declare_local_initializer: ts.pop().unwrap(), declare_local_type: ts.pop().unwrap(), declare_local_colon: ts.pop().unwrap(), declare_local_variable: ts.pop().unwrap(), declare_local_keyword: ts.pop().unwrap(), })), (SyntaxKind::UsingStatementBlockScoped, 6) => SyntaxVariant::UsingStatementBlockScoped(Box::new(UsingStatementBlockScopedChildren { using_block_body: ts.pop().unwrap(), using_block_right_paren: ts.pop().unwrap(), using_block_expressions: ts.pop().unwrap(), using_block_left_paren: ts.pop().unwrap(), using_block_using_keyword: ts.pop().unwrap(), using_block_await_keyword: ts.pop().unwrap(), })), (SyntaxKind::UsingStatementFunctionScoped, 4) => SyntaxVariant::UsingStatementFunctionScoped(Box::new(UsingStatementFunctionScopedChildren { using_function_semicolon: ts.pop().unwrap(), using_function_expression: ts.pop().unwrap(), using_function_using_keyword: ts.pop().unwrap(), using_function_await_keyword: ts.pop().unwrap(), })), (SyntaxKind::WhileStatement, 5) => SyntaxVariant::WhileStatement(Box::new(WhileStatementChildren { while_body: ts.pop().unwrap(), while_right_paren: ts.pop().unwrap(), while_condition: ts.pop().unwrap(), while_left_paren: ts.pop().unwrap(), while_keyword: ts.pop().unwrap(), })), (SyntaxKind::IfStatement, 6) => SyntaxVariant::IfStatement(Box::new(IfStatementChildren { if_else_clause: ts.pop().unwrap(), if_statement: ts.pop().unwrap(), if_right_paren: ts.pop().unwrap(), if_condition: ts.pop().unwrap(), if_left_paren: ts.pop().unwrap(), if_keyword: ts.pop().unwrap(), })), (SyntaxKind::ElseClause, 2) => SyntaxVariant::ElseClause(Box::new(ElseClauseChildren { else_statement: ts.pop().unwrap(), else_keyword: ts.pop().unwrap(), })), (SyntaxKind::TryStatement, 4) => SyntaxVariant::TryStatement(Box::new(TryStatementChildren { try_finally_clause: ts.pop().unwrap(), try_catch_clauses: ts.pop().unwrap(), try_compound_statement: ts.pop().unwrap(), try_keyword: ts.pop().unwrap(), })), (SyntaxKind::CatchClause, 6) => SyntaxVariant::CatchClause(Box::new(CatchClauseChildren { catch_body: ts.pop().unwrap(), catch_right_paren: ts.pop().unwrap(), catch_variable: ts.pop().unwrap(), catch_type: ts.pop().unwrap(), catch_left_paren: ts.pop().unwrap(), catch_keyword: ts.pop().unwrap(), })), (SyntaxKind::FinallyClause, 2) => SyntaxVariant::FinallyClause(Box::new(FinallyClauseChildren { finally_body: ts.pop().unwrap(), finally_keyword: ts.pop().unwrap(), })), (SyntaxKind::DoStatement, 7) => SyntaxVariant::DoStatement(Box::new(DoStatementChildren { do_semicolon: ts.pop().unwrap(), do_right_paren: ts.pop().unwrap(), do_condition: ts.pop().unwrap(), do_left_paren: ts.pop().unwrap(), do_while_keyword: ts.pop().unwrap(), do_body: ts.pop().unwrap(), do_keyword: ts.pop().unwrap(), })), (SyntaxKind::ForStatement, 9) => SyntaxVariant::ForStatement(Box::new(ForStatementChildren { for_body: ts.pop().unwrap(), for_right_paren: ts.pop().unwrap(), for_end_of_loop: ts.pop().unwrap(), for_second_semicolon: ts.pop().unwrap(), for_control: ts.pop().unwrap(), for_first_semicolon: ts.pop().unwrap(), for_initializer: ts.pop().unwrap(), for_left_paren: ts.pop().unwrap(), for_keyword: ts.pop().unwrap(), })), (SyntaxKind::ForeachStatement, 10) => SyntaxVariant::ForeachStatement(Box::new(ForeachStatementChildren { foreach_body: ts.pop().unwrap(), foreach_right_paren: ts.pop().unwrap(), foreach_value: ts.pop().unwrap(), foreach_arrow: ts.pop().unwrap(), foreach_key: ts.pop().unwrap(), foreach_as: ts.pop().unwrap(), foreach_await_keyword: ts.pop().unwrap(), foreach_collection: ts.pop().unwrap(), foreach_left_paren: ts.pop().unwrap(), foreach_keyword: ts.pop().unwrap(), })), (SyntaxKind::SwitchStatement, 7) => SyntaxVariant::SwitchStatement(Box::new(SwitchStatementChildren { switch_right_brace: ts.pop().unwrap(), switch_sections: ts.pop().unwrap(), switch_left_brace: ts.pop().unwrap(), switch_right_paren: ts.pop().unwrap(), switch_expression: ts.pop().unwrap(), switch_left_paren: ts.pop().unwrap(), switch_keyword: ts.pop().unwrap(), })), (SyntaxKind::SwitchSection, 3) => SyntaxVariant::SwitchSection(Box::new(SwitchSectionChildren { switch_section_fallthrough: ts.pop().unwrap(), switch_section_statements: ts.pop().unwrap(), switch_section_labels: ts.pop().unwrap(), })), (SyntaxKind::SwitchFallthrough, 2) => SyntaxVariant::SwitchFallthrough(Box::new(SwitchFallthroughChildren { fallthrough_semicolon: ts.pop().unwrap(), fallthrough_keyword: ts.pop().unwrap(), })), (SyntaxKind::CaseLabel, 3) => SyntaxVariant::CaseLabel(Box::new(CaseLabelChildren { case_colon: ts.pop().unwrap(), case_expression: ts.pop().unwrap(), case_keyword: ts.pop().unwrap(), })), (SyntaxKind::DefaultLabel, 2) => SyntaxVariant::DefaultLabel(Box::new(DefaultLabelChildren { default_colon: ts.pop().unwrap(), default_keyword: ts.pop().unwrap(), })), (SyntaxKind::MatchStatement, 7) => SyntaxVariant::MatchStatement(Box::new(MatchStatementChildren { match_statement_right_brace: ts.pop().unwrap(), match_statement_arms: ts.pop().unwrap(), match_statement_left_brace: ts.pop().unwrap(), match_statement_right_paren: ts.pop().unwrap(), match_statement_expression: ts.pop().unwrap(), match_statement_left_paren: ts.pop().unwrap(), match_statement_keyword: ts.pop().unwrap(), })), (SyntaxKind::MatchStatementArm, 3) => SyntaxVariant::MatchStatementArm(Box::new(MatchStatementArmChildren { match_statement_arm_body: ts.pop().unwrap(), match_statement_arm_arrow: ts.pop().unwrap(), match_statement_arm_pattern: ts.pop().unwrap(), })), (SyntaxKind::ReturnStatement, 3) => SyntaxVariant::ReturnStatement(Box::new(ReturnStatementChildren { return_semicolon: ts.pop().unwrap(), return_expression: ts.pop().unwrap(), return_keyword: ts.pop().unwrap(), })), (SyntaxKind::YieldBreakStatement, 3) => SyntaxVariant::YieldBreakStatement(Box::new(YieldBreakStatementChildren { yield_break_semicolon: ts.pop().unwrap(), yield_break_break: ts.pop().unwrap(), yield_break_keyword: ts.pop().unwrap(), })), (SyntaxKind::ThrowStatement, 3) => SyntaxVariant::ThrowStatement(Box::new(ThrowStatementChildren { throw_semicolon: ts.pop().unwrap(), throw_expression: ts.pop().unwrap(), throw_keyword: ts.pop().unwrap(), })), (SyntaxKind::BreakStatement, 2) => SyntaxVariant::BreakStatement(Box::new(BreakStatementChildren { break_semicolon: ts.pop().unwrap(), break_keyword: ts.pop().unwrap(), })), (SyntaxKind::ContinueStatement, 2) => SyntaxVariant::ContinueStatement(Box::new(ContinueStatementChildren { continue_semicolon: ts.pop().unwrap(), continue_keyword: ts.pop().unwrap(), })), (SyntaxKind::EchoStatement, 3) => SyntaxVariant::EchoStatement(Box::new(EchoStatementChildren { echo_semicolon: ts.pop().unwrap(), echo_expressions: ts.pop().unwrap(), echo_keyword: ts.pop().unwrap(), })), (SyntaxKind::ConcurrentStatement, 2) => SyntaxVariant::ConcurrentStatement(Box::new(ConcurrentStatementChildren { concurrent_statement: ts.pop().unwrap(), concurrent_keyword: ts.pop().unwrap(), })), (SyntaxKind::SimpleInitializer, 2) => SyntaxVariant::SimpleInitializer(Box::new(SimpleInitializerChildren { simple_initializer_value: ts.pop().unwrap(), simple_initializer_equal: ts.pop().unwrap(), })), (SyntaxKind::AnonymousClass, 9) => SyntaxVariant::AnonymousClass(Box::new(AnonymousClassChildren { anonymous_class_body: ts.pop().unwrap(), anonymous_class_implements_list: ts.pop().unwrap(), anonymous_class_implements_keyword: ts.pop().unwrap(), anonymous_class_extends_list: ts.pop().unwrap(), anonymous_class_extends_keyword: ts.pop().unwrap(), anonymous_class_right_paren: ts.pop().unwrap(), anonymous_class_argument_list: ts.pop().unwrap(), anonymous_class_left_paren: ts.pop().unwrap(), anonymous_class_class_keyword: ts.pop().unwrap(), })), (SyntaxKind::AnonymousFunction, 12) => SyntaxVariant::AnonymousFunction(Box::new(AnonymousFunctionChildren { anonymous_body: ts.pop().unwrap(), anonymous_use: ts.pop().unwrap(), anonymous_type: ts.pop().unwrap(), anonymous_readonly_return: ts.pop().unwrap(), anonymous_colon: ts.pop().unwrap(), anonymous_ctx_list: ts.pop().unwrap(), anonymous_right_paren: ts.pop().unwrap(), anonymous_parameters: ts.pop().unwrap(), anonymous_left_paren: ts.pop().unwrap(), anonymous_function_keyword: ts.pop().unwrap(), anonymous_async_keyword: ts.pop().unwrap(), anonymous_attribute_spec: ts.pop().unwrap(), })), (SyntaxKind::AnonymousFunctionUseClause, 4) => SyntaxVariant::AnonymousFunctionUseClause(Box::new(AnonymousFunctionUseClauseChildren { anonymous_use_right_paren: ts.pop().unwrap(), anonymous_use_variables: ts.pop().unwrap(), anonymous_use_left_paren: ts.pop().unwrap(), anonymous_use_keyword: ts.pop().unwrap(), })), (SyntaxKind::VariablePattern, 1) => SyntaxVariant::VariablePattern(Box::new(VariablePatternChildren { variable_pattern_variable: ts.pop().unwrap(), })), (SyntaxKind::ConstructorPattern, 4) => SyntaxVariant::ConstructorPattern(Box::new(ConstructorPatternChildren { constructor_pattern_right_paren: ts.pop().unwrap(), constructor_pattern_members: ts.pop().unwrap(), constructor_pattern_left_paren: ts.pop().unwrap(), constructor_pattern_constructor: ts.pop().unwrap(), })), (SyntaxKind::RefinementPattern, 3) => SyntaxVariant::RefinementPattern(Box::new(RefinementPatternChildren { refinement_pattern_specifier: ts.pop().unwrap(), refinement_pattern_colon: ts.pop().unwrap(), refinement_pattern_variable: ts.pop().unwrap(), })), (SyntaxKind::LambdaExpression, 5) => SyntaxVariant::LambdaExpression(Box::new(LambdaExpressionChildren { lambda_body: ts.pop().unwrap(), lambda_arrow: ts.pop().unwrap(), lambda_signature: ts.pop().unwrap(), lambda_async: ts.pop().unwrap(), lambda_attribute_spec: ts.pop().unwrap(), })), (SyntaxKind::LambdaSignature, 7) => SyntaxVariant::LambdaSignature(Box::new(LambdaSignatureChildren { lambda_type: ts.pop().unwrap(), lambda_readonly_return: ts.pop().unwrap(), lambda_colon: ts.pop().unwrap(), lambda_contexts: ts.pop().unwrap(), lambda_right_paren: ts.pop().unwrap(), lambda_parameters: ts.pop().unwrap(), lambda_left_paren: ts.pop().unwrap(), })), (SyntaxKind::CastExpression, 4) => SyntaxVariant::CastExpression(Box::new(CastExpressionChildren { cast_operand: ts.pop().unwrap(), cast_right_paren: ts.pop().unwrap(), cast_type: ts.pop().unwrap(), cast_left_paren: ts.pop().unwrap(), })), (SyntaxKind::ScopeResolutionExpression, 3) => SyntaxVariant::ScopeResolutionExpression(Box::new(ScopeResolutionExpressionChildren { scope_resolution_name: ts.pop().unwrap(), scope_resolution_operator: ts.pop().unwrap(), scope_resolution_qualifier: ts.pop().unwrap(), })), (SyntaxKind::MemberSelectionExpression, 3) => SyntaxVariant::MemberSelectionExpression(Box::new(MemberSelectionExpressionChildren { member_name: ts.pop().unwrap(), member_operator: ts.pop().unwrap(), member_object: ts.pop().unwrap(), })), (SyntaxKind::SafeMemberSelectionExpression, 3) => SyntaxVariant::SafeMemberSelectionExpression(Box::new(SafeMemberSelectionExpressionChildren { safe_member_name: ts.pop().unwrap(), safe_member_operator: ts.pop().unwrap(), safe_member_object: ts.pop().unwrap(), })), (SyntaxKind::EmbeddedMemberSelectionExpression, 3) => SyntaxVariant::EmbeddedMemberSelectionExpression(Box::new(EmbeddedMemberSelectionExpressionChildren { embedded_member_name: ts.pop().unwrap(), embedded_member_operator: ts.pop().unwrap(), embedded_member_object: ts.pop().unwrap(), })), (SyntaxKind::YieldExpression, 2) => SyntaxVariant::YieldExpression(Box::new(YieldExpressionChildren { yield_operand: ts.pop().unwrap(), yield_keyword: ts.pop().unwrap(), })), (SyntaxKind::PrefixUnaryExpression, 2) => SyntaxVariant::PrefixUnaryExpression(Box::new(PrefixUnaryExpressionChildren { prefix_unary_operand: ts.pop().unwrap(), prefix_unary_operator: ts.pop().unwrap(), })), (SyntaxKind::PostfixUnaryExpression, 2) => SyntaxVariant::PostfixUnaryExpression(Box::new(PostfixUnaryExpressionChildren { postfix_unary_operator: ts.pop().unwrap(), postfix_unary_operand: ts.pop().unwrap(), })), (SyntaxKind::BinaryExpression, 3) => SyntaxVariant::BinaryExpression(Box::new(BinaryExpressionChildren { binary_right_operand: ts.pop().unwrap(), binary_operator: ts.pop().unwrap(), binary_left_operand: ts.pop().unwrap(), })), (SyntaxKind::IsExpression, 3) => SyntaxVariant::IsExpression(Box::new(IsExpressionChildren { is_right_operand: ts.pop().unwrap(), is_operator: ts.pop().unwrap(), is_left_operand: ts.pop().unwrap(), })), (SyntaxKind::AsExpression, 3) => SyntaxVariant::AsExpression(Box::new(AsExpressionChildren { as_right_operand: ts.pop().unwrap(), as_operator: ts.pop().unwrap(), as_left_operand: ts.pop().unwrap(), })), (SyntaxKind::NullableAsExpression, 3) => SyntaxVariant::NullableAsExpression(Box::new(NullableAsExpressionChildren { nullable_as_right_operand: ts.pop().unwrap(), nullable_as_operator: ts.pop().unwrap(), nullable_as_left_operand: ts.pop().unwrap(), })), (SyntaxKind::UpcastExpression, 3) => SyntaxVariant::UpcastExpression(Box::new(UpcastExpressionChildren { upcast_right_operand: ts.pop().unwrap(), upcast_operator: ts.pop().unwrap(), upcast_left_operand: ts.pop().unwrap(), })), (SyntaxKind::ConditionalExpression, 5) => SyntaxVariant::ConditionalExpression(Box::new(ConditionalExpressionChildren { conditional_alternative: ts.pop().unwrap(), conditional_colon: ts.pop().unwrap(), conditional_consequence: ts.pop().unwrap(), conditional_question: ts.pop().unwrap(), conditional_test: ts.pop().unwrap(), })), (SyntaxKind::EvalExpression, 4) => SyntaxVariant::EvalExpression(Box::new(EvalExpressionChildren { eval_right_paren: ts.pop().unwrap(), eval_argument: ts.pop().unwrap(), eval_left_paren: ts.pop().unwrap(), eval_keyword: ts.pop().unwrap(), })), (SyntaxKind::IssetExpression, 4) => SyntaxVariant::IssetExpression(Box::new(IssetExpressionChildren { isset_right_paren: ts.pop().unwrap(), isset_argument_list: ts.pop().unwrap(), isset_left_paren: ts.pop().unwrap(), isset_keyword: ts.pop().unwrap(), })), (SyntaxKind::FunctionCallExpression, 5) => SyntaxVariant::FunctionCallExpression(Box::new(FunctionCallExpressionChildren { function_call_right_paren: ts.pop().unwrap(), function_call_argument_list: ts.pop().unwrap(), function_call_left_paren: ts.pop().unwrap(), function_call_type_args: ts.pop().unwrap(), function_call_receiver: ts.pop().unwrap(), })), (SyntaxKind::FunctionPointerExpression, 2) => SyntaxVariant::FunctionPointerExpression(Box::new(FunctionPointerExpressionChildren { function_pointer_type_args: ts.pop().unwrap(), function_pointer_receiver: ts.pop().unwrap(), })), (SyntaxKind::ParenthesizedExpression, 3) => SyntaxVariant::ParenthesizedExpression(Box::new(ParenthesizedExpressionChildren { parenthesized_expression_right_paren: ts.pop().unwrap(), parenthesized_expression_expression: ts.pop().unwrap(), parenthesized_expression_left_paren: ts.pop().unwrap(), })), (SyntaxKind::BracedExpression, 3) => SyntaxVariant::BracedExpression(Box::new(BracedExpressionChildren { braced_expression_right_brace: ts.pop().unwrap(), braced_expression_expression: ts.pop().unwrap(), braced_expression_left_brace: ts.pop().unwrap(), })), (SyntaxKind::ETSpliceExpression, 4) => SyntaxVariant::ETSpliceExpression(Box::new(ETSpliceExpressionChildren { et_splice_expression_right_brace: ts.pop().unwrap(), et_splice_expression_expression: ts.pop().unwrap(), et_splice_expression_left_brace: ts.pop().unwrap(), et_splice_expression_dollar: ts.pop().unwrap(), })), (SyntaxKind::EmbeddedBracedExpression, 3) => SyntaxVariant::EmbeddedBracedExpression(Box::new(EmbeddedBracedExpressionChildren { embedded_braced_expression_right_brace: ts.pop().unwrap(), embedded_braced_expression_expression: ts.pop().unwrap(), embedded_braced_expression_left_brace: ts.pop().unwrap(), })), (SyntaxKind::ListExpression, 4) => SyntaxVariant::ListExpression(Box::new(ListExpressionChildren { list_right_paren: ts.pop().unwrap(), list_members: ts.pop().unwrap(), list_left_paren: ts.pop().unwrap(), list_keyword: ts.pop().unwrap(), })), (SyntaxKind::CollectionLiteralExpression, 4) => SyntaxVariant::CollectionLiteralExpression(Box::new(CollectionLiteralExpressionChildren { collection_literal_right_brace: ts.pop().unwrap(), collection_literal_initializers: ts.pop().unwrap(), collection_literal_left_brace: ts.pop().unwrap(), collection_literal_name: ts.pop().unwrap(), })), (SyntaxKind::ObjectCreationExpression, 2) => SyntaxVariant::ObjectCreationExpression(Box::new(ObjectCreationExpressionChildren { object_creation_object: ts.pop().unwrap(), object_creation_new_keyword: ts.pop().unwrap(), })), (SyntaxKind::ConstructorCall, 4) => SyntaxVariant::ConstructorCall(Box::new(ConstructorCallChildren { constructor_call_right_paren: ts.pop().unwrap(), constructor_call_argument_list: ts.pop().unwrap(), constructor_call_left_paren: ts.pop().unwrap(), constructor_call_type: ts.pop().unwrap(), })), (SyntaxKind::DarrayIntrinsicExpression, 5) => SyntaxVariant::DarrayIntrinsicExpression(Box::new(DarrayIntrinsicExpressionChildren { darray_intrinsic_right_bracket: ts.pop().unwrap(), darray_intrinsic_members: ts.pop().unwrap(), darray_intrinsic_left_bracket: ts.pop().unwrap(), darray_intrinsic_explicit_type: ts.pop().unwrap(), darray_intrinsic_keyword: ts.pop().unwrap(), })), (SyntaxKind::DictionaryIntrinsicExpression, 5) => SyntaxVariant::DictionaryIntrinsicExpression(Box::new(DictionaryIntrinsicExpressionChildren { dictionary_intrinsic_right_bracket: ts.pop().unwrap(), dictionary_intrinsic_members: ts.pop().unwrap(), dictionary_intrinsic_left_bracket: ts.pop().unwrap(), dictionary_intrinsic_explicit_type: ts.pop().unwrap(), dictionary_intrinsic_keyword: ts.pop().unwrap(), })), (SyntaxKind::KeysetIntrinsicExpression, 5) => SyntaxVariant::KeysetIntrinsicExpression(Box::new(KeysetIntrinsicExpressionChildren { keyset_intrinsic_right_bracket: ts.pop().unwrap(), keyset_intrinsic_members: ts.pop().unwrap(), keyset_intrinsic_left_bracket: ts.pop().unwrap(), keyset_intrinsic_explicit_type: ts.pop().unwrap(), keyset_intrinsic_keyword: ts.pop().unwrap(), })), (SyntaxKind::VarrayIntrinsicExpression, 5) => SyntaxVariant::VarrayIntrinsicExpression(Box::new(VarrayIntrinsicExpressionChildren { varray_intrinsic_right_bracket: ts.pop().unwrap(), varray_intrinsic_members: ts.pop().unwrap(), varray_intrinsic_left_bracket: ts.pop().unwrap(), varray_intrinsic_explicit_type: ts.pop().unwrap(), varray_intrinsic_keyword: ts.pop().unwrap(), })), (SyntaxKind::VectorIntrinsicExpression, 5) => SyntaxVariant::VectorIntrinsicExpression(Box::new(VectorIntrinsicExpressionChildren { vector_intrinsic_right_bracket: ts.pop().unwrap(), vector_intrinsic_members: ts.pop().unwrap(), vector_intrinsic_left_bracket: ts.pop().unwrap(), vector_intrinsic_explicit_type: ts.pop().unwrap(), vector_intrinsic_keyword: ts.pop().unwrap(), })), (SyntaxKind::ElementInitializer, 3) => SyntaxVariant::ElementInitializer(Box::new(ElementInitializerChildren { element_value: ts.pop().unwrap(), element_arrow: ts.pop().unwrap(), element_key: ts.pop().unwrap(), })), (SyntaxKind::SubscriptExpression, 4) => SyntaxVariant::SubscriptExpression(Box::new(SubscriptExpressionChildren { subscript_right_bracket: ts.pop().unwrap(), subscript_index: ts.pop().unwrap(), subscript_left_bracket: ts.pop().unwrap(), subscript_receiver: ts.pop().unwrap(), })), (SyntaxKind::EmbeddedSubscriptExpression, 4) => SyntaxVariant::EmbeddedSubscriptExpression(Box::new(EmbeddedSubscriptExpressionChildren { embedded_subscript_right_bracket: ts.pop().unwrap(), embedded_subscript_index: ts.pop().unwrap(), embedded_subscript_left_bracket: ts.pop().unwrap(), embedded_subscript_receiver: ts.pop().unwrap(), })), (SyntaxKind::AwaitableCreationExpression, 3) => SyntaxVariant::AwaitableCreationExpression(Box::new(AwaitableCreationExpressionChildren { awaitable_compound_statement: ts.pop().unwrap(), awaitable_async: ts.pop().unwrap(), awaitable_attribute_spec: ts.pop().unwrap(), })), (SyntaxKind::XHPChildrenDeclaration, 3) => SyntaxVariant::XHPChildrenDeclaration(Box::new(XHPChildrenDeclarationChildren { xhp_children_semicolon: ts.pop().unwrap(), xhp_children_expression: ts.pop().unwrap(), xhp_children_keyword: ts.pop().unwrap(), })), (SyntaxKind::XHPChildrenParenthesizedList, 3) => SyntaxVariant::XHPChildrenParenthesizedList(Box::new(XHPChildrenParenthesizedListChildren { xhp_children_list_right_paren: ts.pop().unwrap(), xhp_children_list_xhp_children: ts.pop().unwrap(), xhp_children_list_left_paren: ts.pop().unwrap(), })), (SyntaxKind::XHPCategoryDeclaration, 3) => SyntaxVariant::XHPCategoryDeclaration(Box::new(XHPCategoryDeclarationChildren { xhp_category_semicolon: ts.pop().unwrap(), xhp_category_categories: ts.pop().unwrap(), xhp_category_keyword: ts.pop().unwrap(), })), (SyntaxKind::XHPEnumType, 5) => SyntaxVariant::XHPEnumType(Box::new(XHPEnumTypeChildren { xhp_enum_right_brace: ts.pop().unwrap(), xhp_enum_values: ts.pop().unwrap(), xhp_enum_left_brace: ts.pop().unwrap(), xhp_enum_keyword: ts.pop().unwrap(), xhp_enum_like: ts.pop().unwrap(), })), (SyntaxKind::XHPLateinit, 2) => SyntaxVariant::XHPLateinit(Box::new(XHPLateinitChildren { xhp_lateinit_keyword: ts.pop().unwrap(), xhp_lateinit_at: ts.pop().unwrap(), })), (SyntaxKind::XHPRequired, 2) => SyntaxVariant::XHPRequired(Box::new(XHPRequiredChildren { xhp_required_keyword: ts.pop().unwrap(), xhp_required_at: ts.pop().unwrap(), })), (SyntaxKind::XHPClassAttributeDeclaration, 3) => SyntaxVariant::XHPClassAttributeDeclaration(Box::new(XHPClassAttributeDeclarationChildren { xhp_attribute_semicolon: ts.pop().unwrap(), xhp_attribute_attributes: ts.pop().unwrap(), xhp_attribute_keyword: ts.pop().unwrap(), })), (SyntaxKind::XHPClassAttribute, 4) => SyntaxVariant::XHPClassAttribute(Box::new(XHPClassAttributeChildren { xhp_attribute_decl_required: ts.pop().unwrap(), xhp_attribute_decl_initializer: ts.pop().unwrap(), xhp_attribute_decl_name: ts.pop().unwrap(), xhp_attribute_decl_type: ts.pop().unwrap(), })), (SyntaxKind::XHPSimpleClassAttribute, 1) => SyntaxVariant::XHPSimpleClassAttribute(Box::new(XHPSimpleClassAttributeChildren { xhp_simple_class_attribute_type: ts.pop().unwrap(), })), (SyntaxKind::XHPSimpleAttribute, 3) => SyntaxVariant::XHPSimpleAttribute(Box::new(XHPSimpleAttributeChildren { xhp_simple_attribute_expression: ts.pop().unwrap(), xhp_simple_attribute_equal: ts.pop().unwrap(), xhp_simple_attribute_name: ts.pop().unwrap(), })), (SyntaxKind::XHPSpreadAttribute, 4) => SyntaxVariant::XHPSpreadAttribute(Box::new(XHPSpreadAttributeChildren { xhp_spread_attribute_right_brace: ts.pop().unwrap(), xhp_spread_attribute_expression: ts.pop().unwrap(), xhp_spread_attribute_spread_operator: ts.pop().unwrap(), xhp_spread_attribute_left_brace: ts.pop().unwrap(), })), (SyntaxKind::XHPOpen, 4) => SyntaxVariant::XHPOpen(Box::new(XHPOpenChildren { xhp_open_right_angle: ts.pop().unwrap(), xhp_open_attributes: ts.pop().unwrap(), xhp_open_name: ts.pop().unwrap(), xhp_open_left_angle: ts.pop().unwrap(), })), (SyntaxKind::XHPExpression, 3) => SyntaxVariant::XHPExpression(Box::new(XHPExpressionChildren { xhp_close: ts.pop().unwrap(), xhp_body: ts.pop().unwrap(), xhp_open: ts.pop().unwrap(), })), (SyntaxKind::XHPClose, 3) => SyntaxVariant::XHPClose(Box::new(XHPCloseChildren { xhp_close_right_angle: ts.pop().unwrap(), xhp_close_name: ts.pop().unwrap(), xhp_close_left_angle: ts.pop().unwrap(), })), (SyntaxKind::TypeConstant, 3) => SyntaxVariant::TypeConstant(Box::new(TypeConstantChildren { type_constant_right_type: ts.pop().unwrap(), type_constant_separator: ts.pop().unwrap(), type_constant_left_type: ts.pop().unwrap(), })), (SyntaxKind::VectorTypeSpecifier, 5) => SyntaxVariant::VectorTypeSpecifier(Box::new(VectorTypeSpecifierChildren { vector_type_right_angle: ts.pop().unwrap(), vector_type_trailing_comma: ts.pop().unwrap(), vector_type_type: ts.pop().unwrap(), vector_type_left_angle: ts.pop().unwrap(), vector_type_keyword: ts.pop().unwrap(), })), (SyntaxKind::KeysetTypeSpecifier, 5) => SyntaxVariant::KeysetTypeSpecifier(Box::new(KeysetTypeSpecifierChildren { keyset_type_right_angle: ts.pop().unwrap(), keyset_type_trailing_comma: ts.pop().unwrap(), keyset_type_type: ts.pop().unwrap(), keyset_type_left_angle: ts.pop().unwrap(), keyset_type_keyword: ts.pop().unwrap(), })), (SyntaxKind::TupleTypeExplicitSpecifier, 4) => SyntaxVariant::TupleTypeExplicitSpecifier(Box::new(TupleTypeExplicitSpecifierChildren { tuple_type_right_angle: ts.pop().unwrap(), tuple_type_types: ts.pop().unwrap(), tuple_type_left_angle: ts.pop().unwrap(), tuple_type_keyword: ts.pop().unwrap(), })), (SyntaxKind::VarrayTypeSpecifier, 5) => SyntaxVariant::VarrayTypeSpecifier(Box::new(VarrayTypeSpecifierChildren { varray_right_angle: ts.pop().unwrap(), varray_trailing_comma: ts.pop().unwrap(), varray_type: ts.pop().unwrap(), varray_left_angle: ts.pop().unwrap(), varray_keyword: ts.pop().unwrap(), })), (SyntaxKind::FunctionCtxTypeSpecifier, 2) => SyntaxVariant::FunctionCtxTypeSpecifier(Box::new(FunctionCtxTypeSpecifierChildren { function_ctx_type_variable: ts.pop().unwrap(), function_ctx_type_keyword: ts.pop().unwrap(), })), (SyntaxKind::TypeParameter, 6) => SyntaxVariant::TypeParameter(Box::new(TypeParameterChildren { type_constraints: ts.pop().unwrap(), type_param_params: ts.pop().unwrap(), type_name: ts.pop().unwrap(), type_variance: ts.pop().unwrap(), type_reified: ts.pop().unwrap(), type_attribute_spec: ts.pop().unwrap(), })), (SyntaxKind::TypeConstraint, 2) => SyntaxVariant::TypeConstraint(Box::new(TypeConstraintChildren { constraint_type: ts.pop().unwrap(), constraint_keyword: ts.pop().unwrap(), })), (SyntaxKind::ContextConstraint, 2) => SyntaxVariant::ContextConstraint(Box::new(ContextConstraintChildren { ctx_constraint_ctx_list: ts.pop().unwrap(), ctx_constraint_keyword: ts.pop().unwrap(), })), (SyntaxKind::DarrayTypeSpecifier, 7) => SyntaxVariant::DarrayTypeSpecifier(Box::new(DarrayTypeSpecifierChildren { darray_right_angle: ts.pop().unwrap(), darray_trailing_comma: ts.pop().unwrap(), darray_value: ts.pop().unwrap(), darray_comma: ts.pop().unwrap(), darray_key: ts.pop().unwrap(), darray_left_angle: ts.pop().unwrap(), darray_keyword: ts.pop().unwrap(), })), (SyntaxKind::DictionaryTypeSpecifier, 4) => SyntaxVariant::DictionaryTypeSpecifier(Box::new(DictionaryTypeSpecifierChildren { dictionary_type_right_angle: ts.pop().unwrap(), dictionary_type_members: ts.pop().unwrap(), dictionary_type_left_angle: ts.pop().unwrap(), dictionary_type_keyword: ts.pop().unwrap(), })), (SyntaxKind::ClosureTypeSpecifier, 11) => SyntaxVariant::ClosureTypeSpecifier(Box::new(ClosureTypeSpecifierChildren { closure_outer_right_paren: ts.pop().unwrap(), closure_return_type: ts.pop().unwrap(), closure_readonly_return: ts.pop().unwrap(), closure_colon: ts.pop().unwrap(), closure_contexts: ts.pop().unwrap(), closure_inner_right_paren: ts.pop().unwrap(), closure_parameter_list: ts.pop().unwrap(), closure_inner_left_paren: ts.pop().unwrap(), closure_function_keyword: ts.pop().unwrap(), closure_readonly_keyword: ts.pop().unwrap(), closure_outer_left_paren: ts.pop().unwrap(), })), (SyntaxKind::ClosureParameterTypeSpecifier, 3) => SyntaxVariant::ClosureParameterTypeSpecifier(Box::new(ClosureParameterTypeSpecifierChildren { closure_parameter_type: ts.pop().unwrap(), closure_parameter_readonly: ts.pop().unwrap(), closure_parameter_call_convention: ts.pop().unwrap(), })), (SyntaxKind::TypeRefinement, 5) => SyntaxVariant::TypeRefinement(Box::new(TypeRefinementChildren { type_refinement_right_brace: ts.pop().unwrap(), type_refinement_members: ts.pop().unwrap(), type_refinement_left_brace: ts.pop().unwrap(), type_refinement_keyword: ts.pop().unwrap(), type_refinement_type: ts.pop().unwrap(), })), (SyntaxKind::TypeInRefinement, 6) => SyntaxVariant::TypeInRefinement(Box::new(TypeInRefinementChildren { type_in_refinement_type: ts.pop().unwrap(), type_in_refinement_equal: ts.pop().unwrap(), type_in_refinement_constraints: ts.pop().unwrap(), type_in_refinement_type_parameters: ts.pop().unwrap(), type_in_refinement_name: ts.pop().unwrap(), type_in_refinement_keyword: ts.pop().unwrap(), })), (SyntaxKind::CtxInRefinement, 6) => SyntaxVariant::CtxInRefinement(Box::new(CtxInRefinementChildren { ctx_in_refinement_ctx_list: ts.pop().unwrap(), ctx_in_refinement_equal: ts.pop().unwrap(), ctx_in_refinement_constraints: ts.pop().unwrap(), ctx_in_refinement_type_parameters: ts.pop().unwrap(), ctx_in_refinement_name: ts.pop().unwrap(), ctx_in_refinement_keyword: ts.pop().unwrap(), })), (SyntaxKind::ClassnameTypeSpecifier, 5) => SyntaxVariant::ClassnameTypeSpecifier(Box::new(ClassnameTypeSpecifierChildren { classname_right_angle: ts.pop().unwrap(), classname_trailing_comma: ts.pop().unwrap(), classname_type: ts.pop().unwrap(), classname_left_angle: ts.pop().unwrap(), classname_keyword: ts.pop().unwrap(), })), (SyntaxKind::FieldSpecifier, 4) => SyntaxVariant::FieldSpecifier(Box::new(FieldSpecifierChildren { field_type: ts.pop().unwrap(), field_arrow: ts.pop().unwrap(), field_name: ts.pop().unwrap(), field_question: ts.pop().unwrap(), })), (SyntaxKind::FieldInitializer, 3) => SyntaxVariant::FieldInitializer(Box::new(FieldInitializerChildren { field_initializer_value: ts.pop().unwrap(), field_initializer_arrow: ts.pop().unwrap(), field_initializer_name: ts.pop().unwrap(), })), (SyntaxKind::ShapeTypeSpecifier, 5) => SyntaxVariant::ShapeTypeSpecifier(Box::new(ShapeTypeSpecifierChildren { shape_type_right_paren: ts.pop().unwrap(), shape_type_ellipsis: ts.pop().unwrap(), shape_type_fields: ts.pop().unwrap(), shape_type_left_paren: ts.pop().unwrap(), shape_type_keyword: ts.pop().unwrap(), })), (SyntaxKind::ShapeExpression, 4) => SyntaxVariant::ShapeExpression(Box::new(ShapeExpressionChildren { shape_expression_right_paren: ts.pop().unwrap(), shape_expression_fields: ts.pop().unwrap(), shape_expression_left_paren: ts.pop().unwrap(), shape_expression_keyword: ts.pop().unwrap(), })), (SyntaxKind::TupleExpression, 4) => SyntaxVariant::TupleExpression(Box::new(TupleExpressionChildren { tuple_expression_right_paren: ts.pop().unwrap(), tuple_expression_items: ts.pop().unwrap(), tuple_expression_left_paren: ts.pop().unwrap(), tuple_expression_keyword: ts.pop().unwrap(), })), (SyntaxKind::GenericTypeSpecifier, 2) => SyntaxVariant::GenericTypeSpecifier(Box::new(GenericTypeSpecifierChildren { generic_argument_list: ts.pop().unwrap(), generic_class_type: ts.pop().unwrap(), })), (SyntaxKind::NullableTypeSpecifier, 2) => SyntaxVariant::NullableTypeSpecifier(Box::new(NullableTypeSpecifierChildren { nullable_type: ts.pop().unwrap(), nullable_question: ts.pop().unwrap(), })), (SyntaxKind::LikeTypeSpecifier, 2) => SyntaxVariant::LikeTypeSpecifier(Box::new(LikeTypeSpecifierChildren { like_type: ts.pop().unwrap(), like_tilde: ts.pop().unwrap(), })), (SyntaxKind::SoftTypeSpecifier, 2) => SyntaxVariant::SoftTypeSpecifier(Box::new(SoftTypeSpecifierChildren { soft_type: ts.pop().unwrap(), soft_at: ts.pop().unwrap(), })), (SyntaxKind::AttributizedSpecifier, 2) => SyntaxVariant::AttributizedSpecifier(Box::new(AttributizedSpecifierChildren { attributized_specifier_type: ts.pop().unwrap(), attributized_specifier_attribute_spec: ts.pop().unwrap(), })), (SyntaxKind::ReifiedTypeArgument, 2) => SyntaxVariant::ReifiedTypeArgument(Box::new(ReifiedTypeArgumentChildren { reified_type_argument_type: ts.pop().unwrap(), reified_type_argument_reified: ts.pop().unwrap(), })), (SyntaxKind::TypeArguments, 3) => SyntaxVariant::TypeArguments(Box::new(TypeArgumentsChildren { type_arguments_right_angle: ts.pop().unwrap(), type_arguments_types: ts.pop().unwrap(), type_arguments_left_angle: ts.pop().unwrap(), })), (SyntaxKind::TypeParameters, 3) => SyntaxVariant::TypeParameters(Box::new(TypeParametersChildren { type_parameters_right_angle: ts.pop().unwrap(), type_parameters_parameters: ts.pop().unwrap(), type_parameters_left_angle: ts.pop().unwrap(), })), (SyntaxKind::TupleTypeSpecifier, 3) => SyntaxVariant::TupleTypeSpecifier(Box::new(TupleTypeSpecifierChildren { tuple_right_paren: ts.pop().unwrap(), tuple_types: ts.pop().unwrap(), tuple_left_paren: ts.pop().unwrap(), })), (SyntaxKind::UnionTypeSpecifier, 3) => SyntaxVariant::UnionTypeSpecifier(Box::new(UnionTypeSpecifierChildren { union_right_paren: ts.pop().unwrap(), union_types: ts.pop().unwrap(), union_left_paren: ts.pop().unwrap(), })), (SyntaxKind::IntersectionTypeSpecifier, 3) => SyntaxVariant::IntersectionTypeSpecifier(Box::new(IntersectionTypeSpecifierChildren { intersection_right_paren: ts.pop().unwrap(), intersection_types: ts.pop().unwrap(), intersection_left_paren: ts.pop().unwrap(), })), (SyntaxKind::ErrorSyntax, 1) => SyntaxVariant::ErrorSyntax(Box::new(ErrorSyntaxChildren { error_error: ts.pop().unwrap(), })), (SyntaxKind::ListItem, 2) => SyntaxVariant::ListItem(Box::new(ListItemChildren { list_separator: ts.pop().unwrap(), list_item: ts.pop().unwrap(), })), (SyntaxKind::EnumClassLabelExpression, 3) => SyntaxVariant::EnumClassLabelExpression(Box::new(EnumClassLabelExpressionChildren { enum_class_label_expression: ts.pop().unwrap(), enum_class_label_hash: ts.pop().unwrap(), enum_class_label_qualifier: ts.pop().unwrap(), })), (SyntaxKind::ModuleDeclaration, 8) => SyntaxVariant::ModuleDeclaration(Box::new(ModuleDeclarationChildren { module_declaration_right_brace: ts.pop().unwrap(), module_declaration_imports: ts.pop().unwrap(), module_declaration_exports: ts.pop().unwrap(), module_declaration_left_brace: ts.pop().unwrap(), module_declaration_name: ts.pop().unwrap(), module_declaration_module_keyword: ts.pop().unwrap(), module_declaration_new_keyword: ts.pop().unwrap(), module_declaration_attribute_spec: ts.pop().unwrap(), })), (SyntaxKind::ModuleExports, 4) => SyntaxVariant::ModuleExports(Box::new(ModuleExportsChildren { module_exports_right_brace: ts.pop().unwrap(), module_exports_exports: ts.pop().unwrap(), module_exports_left_brace: ts.pop().unwrap(), module_exports_exports_keyword: ts.pop().unwrap(), })), (SyntaxKind::ModuleImports, 4) => SyntaxVariant::ModuleImports(Box::new(ModuleImportsChildren { module_imports_right_brace: ts.pop().unwrap(), module_imports_imports: ts.pop().unwrap(), module_imports_left_brace: ts.pop().unwrap(), module_imports_imports_keyword: ts.pop().unwrap(), })), (SyntaxKind::ModuleMembershipDeclaration, 3) => SyntaxVariant::ModuleMembershipDeclaration(Box::new(ModuleMembershipDeclarationChildren { module_membership_declaration_semicolon: ts.pop().unwrap(), module_membership_declaration_name: ts.pop().unwrap(), module_membership_declaration_module_keyword: ts.pop().unwrap(), })), (SyntaxKind::PackageExpression, 2) => SyntaxVariant::PackageExpression(Box::new(PackageExpressionChildren { package_expression_name: ts.pop().unwrap(), package_expression_keyword: ts.pop().unwrap(), })), _ => panic!("from_children called with wrong number of children"), } } pub fn children(&self) -> &[Self] { match &self.syntax { SyntaxVariant::Missing => &[], SyntaxVariant::Token(..) => &[], SyntaxVariant::SyntaxList(l) => l.as_slice(), SyntaxVariant::EndOfFile(x) => unsafe { std::slice::from_raw_parts(&x.end_of_file_token, 1) }, SyntaxVariant::Script(x) => unsafe { std::slice::from_raw_parts(&x.script_declarations, 1) }, SyntaxVariant::QualifiedName(x) => unsafe { std::slice::from_raw_parts(&x.qualified_name_parts, 1) }, SyntaxVariant::ModuleName(x) => unsafe { std::slice::from_raw_parts(&x.module_name_parts, 1) }, SyntaxVariant::SimpleTypeSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.simple_type_specifier, 1) }, SyntaxVariant::LiteralExpression(x) => unsafe { std::slice::from_raw_parts(&x.literal_expression, 1) }, SyntaxVariant::PrefixedStringExpression(x) => unsafe { std::slice::from_raw_parts(&x.prefixed_string_name, 2) }, SyntaxVariant::PrefixedCodeExpression(x) => unsafe { std::slice::from_raw_parts(&x.prefixed_code_prefix, 4) }, SyntaxVariant::VariableExpression(x) => unsafe { std::slice::from_raw_parts(&x.variable_expression, 1) }, SyntaxVariant::PipeVariableExpression(x) => unsafe { std::slice::from_raw_parts(&x.pipe_variable_expression, 1) }, SyntaxVariant::FileAttributeSpecification(x) => unsafe { std::slice::from_raw_parts(&x.file_attribute_specification_left_double_angle, 5) }, SyntaxVariant::EnumDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.enum_attribute_spec, 11) }, SyntaxVariant::EnumUse(x) => unsafe { std::slice::from_raw_parts(&x.enum_use_keyword, 3) }, SyntaxVariant::Enumerator(x) => unsafe { std::slice::from_raw_parts(&x.enumerator_name, 4) }, SyntaxVariant::EnumClassDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.enum_class_attribute_spec, 12) }, SyntaxVariant::EnumClassEnumerator(x) => unsafe { std::slice::from_raw_parts(&x.enum_class_enumerator_modifiers, 5) }, SyntaxVariant::AliasDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.alias_attribute_spec, 10) }, SyntaxVariant::ContextAliasDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.ctx_alias_attribute_spec, 8) }, SyntaxVariant::CaseTypeDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.case_type_attribute_spec, 11) }, SyntaxVariant::CaseTypeVariant(x) => unsafe { std::slice::from_raw_parts(&x.case_type_variant_bar, 2) }, SyntaxVariant::PropertyDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.property_attribute_spec, 5) }, SyntaxVariant::PropertyDeclarator(x) => unsafe { std::slice::from_raw_parts(&x.property_name, 2) }, SyntaxVariant::NamespaceDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.namespace_header, 2) }, SyntaxVariant::NamespaceDeclarationHeader(x) => unsafe { std::slice::from_raw_parts(&x.namespace_keyword, 2) }, SyntaxVariant::NamespaceBody(x) => unsafe { std::slice::from_raw_parts(&x.namespace_left_brace, 3) }, SyntaxVariant::NamespaceEmptyBody(x) => unsafe { std::slice::from_raw_parts(&x.namespace_semicolon, 1) }, SyntaxVariant::NamespaceUseDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.namespace_use_keyword, 4) }, SyntaxVariant::NamespaceGroupUseDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.namespace_group_use_keyword, 7) }, SyntaxVariant::NamespaceUseClause(x) => unsafe { std::slice::from_raw_parts(&x.namespace_use_clause_kind, 4) }, SyntaxVariant::FunctionDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.function_attribute_spec, 3) }, SyntaxVariant::FunctionDeclarationHeader(x) => unsafe { std::slice::from_raw_parts(&x.function_modifiers, 12) }, SyntaxVariant::Contexts(x) => unsafe { std::slice::from_raw_parts(&x.contexts_left_bracket, 3) }, SyntaxVariant::WhereClause(x) => unsafe { std::slice::from_raw_parts(&x.where_clause_keyword, 2) }, SyntaxVariant::WhereConstraint(x) => unsafe { std::slice::from_raw_parts(&x.where_constraint_left_type, 3) }, SyntaxVariant::MethodishDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.methodish_attribute, 4) }, SyntaxVariant::MethodishTraitResolution(x) => unsafe { std::slice::from_raw_parts(&x.methodish_trait_attribute, 5) }, SyntaxVariant::ClassishDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.classish_attribute, 12) }, SyntaxVariant::ClassishBody(x) => unsafe { std::slice::from_raw_parts(&x.classish_body_left_brace, 3) }, SyntaxVariant::TraitUse(x) => unsafe { std::slice::from_raw_parts(&x.trait_use_keyword, 3) }, SyntaxVariant::RequireClause(x) => unsafe { std::slice::from_raw_parts(&x.require_keyword, 4) }, SyntaxVariant::ConstDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.const_attribute_spec, 6) }, SyntaxVariant::ConstantDeclarator(x) => unsafe { std::slice::from_raw_parts(&x.constant_declarator_name, 2) }, SyntaxVariant::TypeConstDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.type_const_attribute_spec, 10) }, SyntaxVariant::ContextConstDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.context_const_modifiers, 9) }, SyntaxVariant::DecoratedExpression(x) => unsafe { std::slice::from_raw_parts(&x.decorated_expression_decorator, 2) }, SyntaxVariant::ParameterDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.parameter_attribute, 7) }, SyntaxVariant::VariadicParameter(x) => unsafe { std::slice::from_raw_parts(&x.variadic_parameter_call_convention, 3) }, SyntaxVariant::OldAttributeSpecification(x) => unsafe { std::slice::from_raw_parts(&x.old_attribute_specification_left_double_angle, 3) }, SyntaxVariant::AttributeSpecification(x) => unsafe { std::slice::from_raw_parts(&x.attribute_specification_attributes, 1) }, SyntaxVariant::Attribute(x) => unsafe { std::slice::from_raw_parts(&x.attribute_at, 2) }, SyntaxVariant::InclusionExpression(x) => unsafe { std::slice::from_raw_parts(&x.inclusion_require, 2) }, SyntaxVariant::InclusionDirective(x) => unsafe { std::slice::from_raw_parts(&x.inclusion_expression, 2) }, SyntaxVariant::CompoundStatement(x) => unsafe { std::slice::from_raw_parts(&x.compound_left_brace, 3) }, SyntaxVariant::ExpressionStatement(x) => unsafe { std::slice::from_raw_parts(&x.expression_statement_expression, 2) }, SyntaxVariant::MarkupSection(x) => unsafe { std::slice::from_raw_parts(&x.markup_hashbang, 2) }, SyntaxVariant::MarkupSuffix(x) => unsafe { std::slice::from_raw_parts(&x.markup_suffix_less_than_question, 2) }, SyntaxVariant::UnsetStatement(x) => unsafe { std::slice::from_raw_parts(&x.unset_keyword, 5) }, SyntaxVariant::DeclareLocalStatement(x) => unsafe { std::slice::from_raw_parts(&x.declare_local_keyword, 6) }, SyntaxVariant::UsingStatementBlockScoped(x) => unsafe { std::slice::from_raw_parts(&x.using_block_await_keyword, 6) }, SyntaxVariant::UsingStatementFunctionScoped(x) => unsafe { std::slice::from_raw_parts(&x.using_function_await_keyword, 4) }, SyntaxVariant::WhileStatement(x) => unsafe { std::slice::from_raw_parts(&x.while_keyword, 5) }, SyntaxVariant::IfStatement(x) => unsafe { std::slice::from_raw_parts(&x.if_keyword, 6) }, SyntaxVariant::ElseClause(x) => unsafe { std::slice::from_raw_parts(&x.else_keyword, 2) }, SyntaxVariant::TryStatement(x) => unsafe { std::slice::from_raw_parts(&x.try_keyword, 4) }, SyntaxVariant::CatchClause(x) => unsafe { std::slice::from_raw_parts(&x.catch_keyword, 6) }, SyntaxVariant::FinallyClause(x) => unsafe { std::slice::from_raw_parts(&x.finally_keyword, 2) }, SyntaxVariant::DoStatement(x) => unsafe { std::slice::from_raw_parts(&x.do_keyword, 7) }, SyntaxVariant::ForStatement(x) => unsafe { std::slice::from_raw_parts(&x.for_keyword, 9) }, SyntaxVariant::ForeachStatement(x) => unsafe { std::slice::from_raw_parts(&x.foreach_keyword, 10) }, SyntaxVariant::SwitchStatement(x) => unsafe { std::slice::from_raw_parts(&x.switch_keyword, 7) }, SyntaxVariant::SwitchSection(x) => unsafe { std::slice::from_raw_parts(&x.switch_section_labels, 3) }, SyntaxVariant::SwitchFallthrough(x) => unsafe { std::slice::from_raw_parts(&x.fallthrough_keyword, 2) }, SyntaxVariant::CaseLabel(x) => unsafe { std::slice::from_raw_parts(&x.case_keyword, 3) }, SyntaxVariant::DefaultLabel(x) => unsafe { std::slice::from_raw_parts(&x.default_keyword, 2) }, SyntaxVariant::MatchStatement(x) => unsafe { std::slice::from_raw_parts(&x.match_statement_keyword, 7) }, SyntaxVariant::MatchStatementArm(x) => unsafe { std::slice::from_raw_parts(&x.match_statement_arm_pattern, 3) }, SyntaxVariant::ReturnStatement(x) => unsafe { std::slice::from_raw_parts(&x.return_keyword, 3) }, SyntaxVariant::YieldBreakStatement(x) => unsafe { std::slice::from_raw_parts(&x.yield_break_keyword, 3) }, SyntaxVariant::ThrowStatement(x) => unsafe { std::slice::from_raw_parts(&x.throw_keyword, 3) }, SyntaxVariant::BreakStatement(x) => unsafe { std::slice::from_raw_parts(&x.break_keyword, 2) }, SyntaxVariant::ContinueStatement(x) => unsafe { std::slice::from_raw_parts(&x.continue_keyword, 2) }, SyntaxVariant::EchoStatement(x) => unsafe { std::slice::from_raw_parts(&x.echo_keyword, 3) }, SyntaxVariant::ConcurrentStatement(x) => unsafe { std::slice::from_raw_parts(&x.concurrent_keyword, 2) }, SyntaxVariant::SimpleInitializer(x) => unsafe { std::slice::from_raw_parts(&x.simple_initializer_equal, 2) }, SyntaxVariant::AnonymousClass(x) => unsafe { std::slice::from_raw_parts(&x.anonymous_class_class_keyword, 9) }, SyntaxVariant::AnonymousFunction(x) => unsafe { std::slice::from_raw_parts(&x.anonymous_attribute_spec, 12) }, SyntaxVariant::AnonymousFunctionUseClause(x) => unsafe { std::slice::from_raw_parts(&x.anonymous_use_keyword, 4) }, SyntaxVariant::VariablePattern(x) => unsafe { std::slice::from_raw_parts(&x.variable_pattern_variable, 1) }, SyntaxVariant::ConstructorPattern(x) => unsafe { std::slice::from_raw_parts(&x.constructor_pattern_constructor, 4) }, SyntaxVariant::RefinementPattern(x) => unsafe { std::slice::from_raw_parts(&x.refinement_pattern_variable, 3) }, SyntaxVariant::LambdaExpression(x) => unsafe { std::slice::from_raw_parts(&x.lambda_attribute_spec, 5) }, SyntaxVariant::LambdaSignature(x) => unsafe { std::slice::from_raw_parts(&x.lambda_left_paren, 7) }, SyntaxVariant::CastExpression(x) => unsafe { std::slice::from_raw_parts(&x.cast_left_paren, 4) }, SyntaxVariant::ScopeResolutionExpression(x) => unsafe { std::slice::from_raw_parts(&x.scope_resolution_qualifier, 3) }, SyntaxVariant::MemberSelectionExpression(x) => unsafe { std::slice::from_raw_parts(&x.member_object, 3) }, SyntaxVariant::SafeMemberSelectionExpression(x) => unsafe { std::slice::from_raw_parts(&x.safe_member_object, 3) }, SyntaxVariant::EmbeddedMemberSelectionExpression(x) => unsafe { std::slice::from_raw_parts(&x.embedded_member_object, 3) }, SyntaxVariant::YieldExpression(x) => unsafe { std::slice::from_raw_parts(&x.yield_keyword, 2) }, SyntaxVariant::PrefixUnaryExpression(x) => unsafe { std::slice::from_raw_parts(&x.prefix_unary_operator, 2) }, SyntaxVariant::PostfixUnaryExpression(x) => unsafe { std::slice::from_raw_parts(&x.postfix_unary_operand, 2) }, SyntaxVariant::BinaryExpression(x) => unsafe { std::slice::from_raw_parts(&x.binary_left_operand, 3) }, SyntaxVariant::IsExpression(x) => unsafe { std::slice::from_raw_parts(&x.is_left_operand, 3) }, SyntaxVariant::AsExpression(x) => unsafe { std::slice::from_raw_parts(&x.as_left_operand, 3) }, SyntaxVariant::NullableAsExpression(x) => unsafe { std::slice::from_raw_parts(&x.nullable_as_left_operand, 3) }, SyntaxVariant::UpcastExpression(x) => unsafe { std::slice::from_raw_parts(&x.upcast_left_operand, 3) }, SyntaxVariant::ConditionalExpression(x) => unsafe { std::slice::from_raw_parts(&x.conditional_test, 5) }, SyntaxVariant::EvalExpression(x) => unsafe { std::slice::from_raw_parts(&x.eval_keyword, 4) }, SyntaxVariant::IssetExpression(x) => unsafe { std::slice::from_raw_parts(&x.isset_keyword, 4) }, SyntaxVariant::FunctionCallExpression(x) => unsafe { std::slice::from_raw_parts(&x.function_call_receiver, 5) }, SyntaxVariant::FunctionPointerExpression(x) => unsafe { std::slice::from_raw_parts(&x.function_pointer_receiver, 2) }, SyntaxVariant::ParenthesizedExpression(x) => unsafe { std::slice::from_raw_parts(&x.parenthesized_expression_left_paren, 3) }, SyntaxVariant::BracedExpression(x) => unsafe { std::slice::from_raw_parts(&x.braced_expression_left_brace, 3) }, SyntaxVariant::ETSpliceExpression(x) => unsafe { std::slice::from_raw_parts(&x.et_splice_expression_dollar, 4) }, SyntaxVariant::EmbeddedBracedExpression(x) => unsafe { std::slice::from_raw_parts(&x.embedded_braced_expression_left_brace, 3) }, SyntaxVariant::ListExpression(x) => unsafe { std::slice::from_raw_parts(&x.list_keyword, 4) }, SyntaxVariant::CollectionLiteralExpression(x) => unsafe { std::slice::from_raw_parts(&x.collection_literal_name, 4) }, SyntaxVariant::ObjectCreationExpression(x) => unsafe { std::slice::from_raw_parts(&x.object_creation_new_keyword, 2) }, SyntaxVariant::ConstructorCall(x) => unsafe { std::slice::from_raw_parts(&x.constructor_call_type, 4) }, SyntaxVariant::DarrayIntrinsicExpression(x) => unsafe { std::slice::from_raw_parts(&x.darray_intrinsic_keyword, 5) }, SyntaxVariant::DictionaryIntrinsicExpression(x) => unsafe { std::slice::from_raw_parts(&x.dictionary_intrinsic_keyword, 5) }, SyntaxVariant::KeysetIntrinsicExpression(x) => unsafe { std::slice::from_raw_parts(&x.keyset_intrinsic_keyword, 5) }, SyntaxVariant::VarrayIntrinsicExpression(x) => unsafe { std::slice::from_raw_parts(&x.varray_intrinsic_keyword, 5) }, SyntaxVariant::VectorIntrinsicExpression(x) => unsafe { std::slice::from_raw_parts(&x.vector_intrinsic_keyword, 5) }, SyntaxVariant::ElementInitializer(x) => unsafe { std::slice::from_raw_parts(&x.element_key, 3) }, SyntaxVariant::SubscriptExpression(x) => unsafe { std::slice::from_raw_parts(&x.subscript_receiver, 4) }, SyntaxVariant::EmbeddedSubscriptExpression(x) => unsafe { std::slice::from_raw_parts(&x.embedded_subscript_receiver, 4) }, SyntaxVariant::AwaitableCreationExpression(x) => unsafe { std::slice::from_raw_parts(&x.awaitable_attribute_spec, 3) }, SyntaxVariant::XHPChildrenDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.xhp_children_keyword, 3) }, SyntaxVariant::XHPChildrenParenthesizedList(x) => unsafe { std::slice::from_raw_parts(&x.xhp_children_list_left_paren, 3) }, SyntaxVariant::XHPCategoryDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.xhp_category_keyword, 3) }, SyntaxVariant::XHPEnumType(x) => unsafe { std::slice::from_raw_parts(&x.xhp_enum_like, 5) }, SyntaxVariant::XHPLateinit(x) => unsafe { std::slice::from_raw_parts(&x.xhp_lateinit_at, 2) }, SyntaxVariant::XHPRequired(x) => unsafe { std::slice::from_raw_parts(&x.xhp_required_at, 2) }, SyntaxVariant::XHPClassAttributeDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.xhp_attribute_keyword, 3) }, SyntaxVariant::XHPClassAttribute(x) => unsafe { std::slice::from_raw_parts(&x.xhp_attribute_decl_type, 4) }, SyntaxVariant::XHPSimpleClassAttribute(x) => unsafe { std::slice::from_raw_parts(&x.xhp_simple_class_attribute_type, 1) }, SyntaxVariant::XHPSimpleAttribute(x) => unsafe { std::slice::from_raw_parts(&x.xhp_simple_attribute_name, 3) }, SyntaxVariant::XHPSpreadAttribute(x) => unsafe { std::slice::from_raw_parts(&x.xhp_spread_attribute_left_brace, 4) }, SyntaxVariant::XHPOpen(x) => unsafe { std::slice::from_raw_parts(&x.xhp_open_left_angle, 4) }, SyntaxVariant::XHPExpression(x) => unsafe { std::slice::from_raw_parts(&x.xhp_open, 3) }, SyntaxVariant::XHPClose(x) => unsafe { std::slice::from_raw_parts(&x.xhp_close_left_angle, 3) }, SyntaxVariant::TypeConstant(x) => unsafe { std::slice::from_raw_parts(&x.type_constant_left_type, 3) }, SyntaxVariant::VectorTypeSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.vector_type_keyword, 5) }, SyntaxVariant::KeysetTypeSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.keyset_type_keyword, 5) }, SyntaxVariant::TupleTypeExplicitSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.tuple_type_keyword, 4) }, SyntaxVariant::VarrayTypeSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.varray_keyword, 5) }, SyntaxVariant::FunctionCtxTypeSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.function_ctx_type_keyword, 2) }, SyntaxVariant::TypeParameter(x) => unsafe { std::slice::from_raw_parts(&x.type_attribute_spec, 6) }, SyntaxVariant::TypeConstraint(x) => unsafe { std::slice::from_raw_parts(&x.constraint_keyword, 2) }, SyntaxVariant::ContextConstraint(x) => unsafe { std::slice::from_raw_parts(&x.ctx_constraint_keyword, 2) }, SyntaxVariant::DarrayTypeSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.darray_keyword, 7) }, SyntaxVariant::DictionaryTypeSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.dictionary_type_keyword, 4) }, SyntaxVariant::ClosureTypeSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.closure_outer_left_paren, 11) }, SyntaxVariant::ClosureParameterTypeSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.closure_parameter_call_convention, 3) }, SyntaxVariant::TypeRefinement(x) => unsafe { std::slice::from_raw_parts(&x.type_refinement_type, 5) }, SyntaxVariant::TypeInRefinement(x) => unsafe { std::slice::from_raw_parts(&x.type_in_refinement_keyword, 6) }, SyntaxVariant::CtxInRefinement(x) => unsafe { std::slice::from_raw_parts(&x.ctx_in_refinement_keyword, 6) }, SyntaxVariant::ClassnameTypeSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.classname_keyword, 5) }, SyntaxVariant::FieldSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.field_question, 4) }, SyntaxVariant::FieldInitializer(x) => unsafe { std::slice::from_raw_parts(&x.field_initializer_name, 3) }, SyntaxVariant::ShapeTypeSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.shape_type_keyword, 5) }, SyntaxVariant::ShapeExpression(x) => unsafe { std::slice::from_raw_parts(&x.shape_expression_keyword, 4) }, SyntaxVariant::TupleExpression(x) => unsafe { std::slice::from_raw_parts(&x.tuple_expression_keyword, 4) }, SyntaxVariant::GenericTypeSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.generic_class_type, 2) }, SyntaxVariant::NullableTypeSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.nullable_question, 2) }, SyntaxVariant::LikeTypeSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.like_tilde, 2) }, SyntaxVariant::SoftTypeSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.soft_at, 2) }, SyntaxVariant::AttributizedSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.attributized_specifier_attribute_spec, 2) }, SyntaxVariant::ReifiedTypeArgument(x) => unsafe { std::slice::from_raw_parts(&x.reified_type_argument_reified, 2) }, SyntaxVariant::TypeArguments(x) => unsafe { std::slice::from_raw_parts(&x.type_arguments_left_angle, 3) }, SyntaxVariant::TypeParameters(x) => unsafe { std::slice::from_raw_parts(&x.type_parameters_left_angle, 3) }, SyntaxVariant::TupleTypeSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.tuple_left_paren, 3) }, SyntaxVariant::UnionTypeSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.union_left_paren, 3) }, SyntaxVariant::IntersectionTypeSpecifier(x) => unsafe { std::slice::from_raw_parts(&x.intersection_left_paren, 3) }, SyntaxVariant::ErrorSyntax(x) => unsafe { std::slice::from_raw_parts(&x.error_error, 1) }, SyntaxVariant::ListItem(x) => unsafe { std::slice::from_raw_parts(&x.list_item, 2) }, SyntaxVariant::EnumClassLabelExpression(x) => unsafe { std::slice::from_raw_parts(&x.enum_class_label_qualifier, 3) }, SyntaxVariant::ModuleDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.module_declaration_attribute_spec, 8) }, SyntaxVariant::ModuleExports(x) => unsafe { std::slice::from_raw_parts(&x.module_exports_exports_keyword, 4) }, SyntaxVariant::ModuleImports(x) => unsafe { std::slice::from_raw_parts(&x.module_imports_imports_keyword, 4) }, SyntaxVariant::ModuleMembershipDeclaration(x) => unsafe { std::slice::from_raw_parts(&x.module_membership_declaration_module_keyword, 3) }, SyntaxVariant::PackageExpression(x) => unsafe { std::slice::from_raw_parts(&x.package_expression_keyword, 2) }, } } pub fn children_mut(&mut self) -> &mut [Self] { match &mut self.syntax { SyntaxVariant::Missing => &mut [], SyntaxVariant::Token(..) => &mut [], SyntaxVariant::SyntaxList(l) => l.as_mut_slice(), SyntaxVariant::EndOfFile(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.end_of_file_token, 1) }, SyntaxVariant::Script(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.script_declarations, 1) }, SyntaxVariant::QualifiedName(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.qualified_name_parts, 1) }, SyntaxVariant::ModuleName(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.module_name_parts, 1) }, SyntaxVariant::SimpleTypeSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.simple_type_specifier, 1) }, SyntaxVariant::LiteralExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.literal_expression, 1) }, SyntaxVariant::PrefixedStringExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.prefixed_string_name, 2) }, SyntaxVariant::PrefixedCodeExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.prefixed_code_prefix, 4) }, SyntaxVariant::VariableExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.variable_expression, 1) }, SyntaxVariant::PipeVariableExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.pipe_variable_expression, 1) }, SyntaxVariant::FileAttributeSpecification(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.file_attribute_specification_left_double_angle, 5) }, SyntaxVariant::EnumDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.enum_attribute_spec, 11) }, SyntaxVariant::EnumUse(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.enum_use_keyword, 3) }, SyntaxVariant::Enumerator(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.enumerator_name, 4) }, SyntaxVariant::EnumClassDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.enum_class_attribute_spec, 12) }, SyntaxVariant::EnumClassEnumerator(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.enum_class_enumerator_modifiers, 5) }, SyntaxVariant::AliasDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.alias_attribute_spec, 10) }, SyntaxVariant::ContextAliasDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.ctx_alias_attribute_spec, 8) }, SyntaxVariant::CaseTypeDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.case_type_attribute_spec, 11) }, SyntaxVariant::CaseTypeVariant(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.case_type_variant_bar, 2) }, SyntaxVariant::PropertyDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.property_attribute_spec, 5) }, SyntaxVariant::PropertyDeclarator(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.property_name, 2) }, SyntaxVariant::NamespaceDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.namespace_header, 2) }, SyntaxVariant::NamespaceDeclarationHeader(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.namespace_keyword, 2) }, SyntaxVariant::NamespaceBody(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.namespace_left_brace, 3) }, SyntaxVariant::NamespaceEmptyBody(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.namespace_semicolon, 1) }, SyntaxVariant::NamespaceUseDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.namespace_use_keyword, 4) }, SyntaxVariant::NamespaceGroupUseDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.namespace_group_use_keyword, 7) }, SyntaxVariant::NamespaceUseClause(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.namespace_use_clause_kind, 4) }, SyntaxVariant::FunctionDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.function_attribute_spec, 3) }, SyntaxVariant::FunctionDeclarationHeader(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.function_modifiers, 12) }, SyntaxVariant::Contexts(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.contexts_left_bracket, 3) }, SyntaxVariant::WhereClause(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.where_clause_keyword, 2) }, SyntaxVariant::WhereConstraint(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.where_constraint_left_type, 3) }, SyntaxVariant::MethodishDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.methodish_attribute, 4) }, SyntaxVariant::MethodishTraitResolution(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.methodish_trait_attribute, 5) }, SyntaxVariant::ClassishDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.classish_attribute, 12) }, SyntaxVariant::ClassishBody(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.classish_body_left_brace, 3) }, SyntaxVariant::TraitUse(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.trait_use_keyword, 3) }, SyntaxVariant::RequireClause(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.require_keyword, 4) }, SyntaxVariant::ConstDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.const_attribute_spec, 6) }, SyntaxVariant::ConstantDeclarator(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.constant_declarator_name, 2) }, SyntaxVariant::TypeConstDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.type_const_attribute_spec, 10) }, SyntaxVariant::ContextConstDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.context_const_modifiers, 9) }, SyntaxVariant::DecoratedExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.decorated_expression_decorator, 2) }, SyntaxVariant::ParameterDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.parameter_attribute, 7) }, SyntaxVariant::VariadicParameter(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.variadic_parameter_call_convention, 3) }, SyntaxVariant::OldAttributeSpecification(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.old_attribute_specification_left_double_angle, 3) }, SyntaxVariant::AttributeSpecification(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.attribute_specification_attributes, 1) }, SyntaxVariant::Attribute(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.attribute_at, 2) }, SyntaxVariant::InclusionExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.inclusion_require, 2) }, SyntaxVariant::InclusionDirective(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.inclusion_expression, 2) }, SyntaxVariant::CompoundStatement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.compound_left_brace, 3) }, SyntaxVariant::ExpressionStatement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.expression_statement_expression, 2) }, SyntaxVariant::MarkupSection(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.markup_hashbang, 2) }, SyntaxVariant::MarkupSuffix(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.markup_suffix_less_than_question, 2) }, SyntaxVariant::UnsetStatement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.unset_keyword, 5) }, SyntaxVariant::DeclareLocalStatement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.declare_local_keyword, 6) }, SyntaxVariant::UsingStatementBlockScoped(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.using_block_await_keyword, 6) }, SyntaxVariant::UsingStatementFunctionScoped(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.using_function_await_keyword, 4) }, SyntaxVariant::WhileStatement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.while_keyword, 5) }, SyntaxVariant::IfStatement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.if_keyword, 6) }, SyntaxVariant::ElseClause(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.else_keyword, 2) }, SyntaxVariant::TryStatement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.try_keyword, 4) }, SyntaxVariant::CatchClause(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.catch_keyword, 6) }, SyntaxVariant::FinallyClause(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.finally_keyword, 2) }, SyntaxVariant::DoStatement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.do_keyword, 7) }, SyntaxVariant::ForStatement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.for_keyword, 9) }, SyntaxVariant::ForeachStatement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.foreach_keyword, 10) }, SyntaxVariant::SwitchStatement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.switch_keyword, 7) }, SyntaxVariant::SwitchSection(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.switch_section_labels, 3) }, SyntaxVariant::SwitchFallthrough(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.fallthrough_keyword, 2) }, SyntaxVariant::CaseLabel(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.case_keyword, 3) }, SyntaxVariant::DefaultLabel(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.default_keyword, 2) }, SyntaxVariant::MatchStatement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.match_statement_keyword, 7) }, SyntaxVariant::MatchStatementArm(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.match_statement_arm_pattern, 3) }, SyntaxVariant::ReturnStatement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.return_keyword, 3) }, SyntaxVariant::YieldBreakStatement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.yield_break_keyword, 3) }, SyntaxVariant::ThrowStatement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.throw_keyword, 3) }, SyntaxVariant::BreakStatement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.break_keyword, 2) }, SyntaxVariant::ContinueStatement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.continue_keyword, 2) }, SyntaxVariant::EchoStatement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.echo_keyword, 3) }, SyntaxVariant::ConcurrentStatement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.concurrent_keyword, 2) }, SyntaxVariant::SimpleInitializer(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.simple_initializer_equal, 2) }, SyntaxVariant::AnonymousClass(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.anonymous_class_class_keyword, 9) }, SyntaxVariant::AnonymousFunction(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.anonymous_attribute_spec, 12) }, SyntaxVariant::AnonymousFunctionUseClause(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.anonymous_use_keyword, 4) }, SyntaxVariant::VariablePattern(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.variable_pattern_variable, 1) }, SyntaxVariant::ConstructorPattern(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.constructor_pattern_constructor, 4) }, SyntaxVariant::RefinementPattern(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.refinement_pattern_variable, 3) }, SyntaxVariant::LambdaExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.lambda_attribute_spec, 5) }, SyntaxVariant::LambdaSignature(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.lambda_left_paren, 7) }, SyntaxVariant::CastExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.cast_left_paren, 4) }, SyntaxVariant::ScopeResolutionExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.scope_resolution_qualifier, 3) }, SyntaxVariant::MemberSelectionExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.member_object, 3) }, SyntaxVariant::SafeMemberSelectionExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.safe_member_object, 3) }, SyntaxVariant::EmbeddedMemberSelectionExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.embedded_member_object, 3) }, SyntaxVariant::YieldExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.yield_keyword, 2) }, SyntaxVariant::PrefixUnaryExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.prefix_unary_operator, 2) }, SyntaxVariant::PostfixUnaryExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.postfix_unary_operand, 2) }, SyntaxVariant::BinaryExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.binary_left_operand, 3) }, SyntaxVariant::IsExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.is_left_operand, 3) }, SyntaxVariant::AsExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.as_left_operand, 3) }, SyntaxVariant::NullableAsExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.nullable_as_left_operand, 3) }, SyntaxVariant::UpcastExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.upcast_left_operand, 3) }, SyntaxVariant::ConditionalExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.conditional_test, 5) }, SyntaxVariant::EvalExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.eval_keyword, 4) }, SyntaxVariant::IssetExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.isset_keyword, 4) }, SyntaxVariant::FunctionCallExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.function_call_receiver, 5) }, SyntaxVariant::FunctionPointerExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.function_pointer_receiver, 2) }, SyntaxVariant::ParenthesizedExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.parenthesized_expression_left_paren, 3) }, SyntaxVariant::BracedExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.braced_expression_left_brace, 3) }, SyntaxVariant::ETSpliceExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.et_splice_expression_dollar, 4) }, SyntaxVariant::EmbeddedBracedExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.embedded_braced_expression_left_brace, 3) }, SyntaxVariant::ListExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.list_keyword, 4) }, SyntaxVariant::CollectionLiteralExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.collection_literal_name, 4) }, SyntaxVariant::ObjectCreationExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.object_creation_new_keyword, 2) }, SyntaxVariant::ConstructorCall(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.constructor_call_type, 4) }, SyntaxVariant::DarrayIntrinsicExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.darray_intrinsic_keyword, 5) }, SyntaxVariant::DictionaryIntrinsicExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.dictionary_intrinsic_keyword, 5) }, SyntaxVariant::KeysetIntrinsicExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.keyset_intrinsic_keyword, 5) }, SyntaxVariant::VarrayIntrinsicExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.varray_intrinsic_keyword, 5) }, SyntaxVariant::VectorIntrinsicExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.vector_intrinsic_keyword, 5) }, SyntaxVariant::ElementInitializer(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.element_key, 3) }, SyntaxVariant::SubscriptExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.subscript_receiver, 4) }, SyntaxVariant::EmbeddedSubscriptExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.embedded_subscript_receiver, 4) }, SyntaxVariant::AwaitableCreationExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.awaitable_attribute_spec, 3) }, SyntaxVariant::XHPChildrenDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.xhp_children_keyword, 3) }, SyntaxVariant::XHPChildrenParenthesizedList(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.xhp_children_list_left_paren, 3) }, SyntaxVariant::XHPCategoryDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.xhp_category_keyword, 3) }, SyntaxVariant::XHPEnumType(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.xhp_enum_like, 5) }, SyntaxVariant::XHPLateinit(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.xhp_lateinit_at, 2) }, SyntaxVariant::XHPRequired(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.xhp_required_at, 2) }, SyntaxVariant::XHPClassAttributeDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.xhp_attribute_keyword, 3) }, SyntaxVariant::XHPClassAttribute(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.xhp_attribute_decl_type, 4) }, SyntaxVariant::XHPSimpleClassAttribute(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.xhp_simple_class_attribute_type, 1) }, SyntaxVariant::XHPSimpleAttribute(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.xhp_simple_attribute_name, 3) }, SyntaxVariant::XHPSpreadAttribute(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.xhp_spread_attribute_left_brace, 4) }, SyntaxVariant::XHPOpen(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.xhp_open_left_angle, 4) }, SyntaxVariant::XHPExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.xhp_open, 3) }, SyntaxVariant::XHPClose(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.xhp_close_left_angle, 3) }, SyntaxVariant::TypeConstant(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.type_constant_left_type, 3) }, SyntaxVariant::VectorTypeSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.vector_type_keyword, 5) }, SyntaxVariant::KeysetTypeSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.keyset_type_keyword, 5) }, SyntaxVariant::TupleTypeExplicitSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.tuple_type_keyword, 4) }, SyntaxVariant::VarrayTypeSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.varray_keyword, 5) }, SyntaxVariant::FunctionCtxTypeSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.function_ctx_type_keyword, 2) }, SyntaxVariant::TypeParameter(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.type_attribute_spec, 6) }, SyntaxVariant::TypeConstraint(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.constraint_keyword, 2) }, SyntaxVariant::ContextConstraint(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.ctx_constraint_keyword, 2) }, SyntaxVariant::DarrayTypeSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.darray_keyword, 7) }, SyntaxVariant::DictionaryTypeSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.dictionary_type_keyword, 4) }, SyntaxVariant::ClosureTypeSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.closure_outer_left_paren, 11) }, SyntaxVariant::ClosureParameterTypeSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.closure_parameter_call_convention, 3) }, SyntaxVariant::TypeRefinement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.type_refinement_type, 5) }, SyntaxVariant::TypeInRefinement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.type_in_refinement_keyword, 6) }, SyntaxVariant::CtxInRefinement(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.ctx_in_refinement_keyword, 6) }, SyntaxVariant::ClassnameTypeSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.classname_keyword, 5) }, SyntaxVariant::FieldSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.field_question, 4) }, SyntaxVariant::FieldInitializer(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.field_initializer_name, 3) }, SyntaxVariant::ShapeTypeSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.shape_type_keyword, 5) }, SyntaxVariant::ShapeExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.shape_expression_keyword, 4) }, SyntaxVariant::TupleExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.tuple_expression_keyword, 4) }, SyntaxVariant::GenericTypeSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.generic_class_type, 2) }, SyntaxVariant::NullableTypeSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.nullable_question, 2) }, SyntaxVariant::LikeTypeSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.like_tilde, 2) }, SyntaxVariant::SoftTypeSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.soft_at, 2) }, SyntaxVariant::AttributizedSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.attributized_specifier_attribute_spec, 2) }, SyntaxVariant::ReifiedTypeArgument(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.reified_type_argument_reified, 2) }, SyntaxVariant::TypeArguments(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.type_arguments_left_angle, 3) }, SyntaxVariant::TypeParameters(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.type_parameters_left_angle, 3) }, SyntaxVariant::TupleTypeSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.tuple_left_paren, 3) }, SyntaxVariant::UnionTypeSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.union_left_paren, 3) }, SyntaxVariant::IntersectionTypeSpecifier(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.intersection_left_paren, 3) }, SyntaxVariant::ErrorSyntax(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.error_error, 1) }, SyntaxVariant::ListItem(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.list_item, 2) }, SyntaxVariant::EnumClassLabelExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.enum_class_label_qualifier, 3) }, SyntaxVariant::ModuleDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.module_declaration_attribute_spec, 8) }, SyntaxVariant::ModuleExports(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.module_exports_exports_keyword, 4) }, SyntaxVariant::ModuleImports(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.module_imports_imports_keyword, 4) }, SyntaxVariant::ModuleMembershipDeclaration(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.module_membership_declaration_module_keyword, 3) }, SyntaxVariant::PackageExpression(x) => unsafe { std::slice::from_raw_parts_mut(&mut x.package_expression_keyword, 2) }, } } } #[derive(Debug, Clone)] #[repr(C)] pub struct EndOfFileChildren<T, V> { pub end_of_file_token: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ScriptChildren<T, V> { pub script_declarations: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct QualifiedNameChildren<T, V> { pub qualified_name_parts: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ModuleNameChildren<T, V> { pub module_name_parts: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct SimpleTypeSpecifierChildren<T, V> { pub simple_type_specifier: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct LiteralExpressionChildren<T, V> { pub literal_expression: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct PrefixedStringExpressionChildren<T, V> { pub prefixed_string_name: Syntax<T, V>, pub prefixed_string_str: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct PrefixedCodeExpressionChildren<T, V> { pub prefixed_code_prefix: Syntax<T, V>, pub prefixed_code_left_backtick: Syntax<T, V>, pub prefixed_code_body: Syntax<T, V>, pub prefixed_code_right_backtick: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct VariableExpressionChildren<T, V> { pub variable_expression: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct PipeVariableExpressionChildren<T, V> { pub pipe_variable_expression: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct FileAttributeSpecificationChildren<T, V> { pub file_attribute_specification_left_double_angle: Syntax<T, V>, pub file_attribute_specification_keyword: Syntax<T, V>, pub file_attribute_specification_colon: Syntax<T, V>, pub file_attribute_specification_attributes: Syntax<T, V>, pub file_attribute_specification_right_double_angle: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct EnumDeclarationChildren<T, V> { pub enum_attribute_spec: Syntax<T, V>, pub enum_modifiers: Syntax<T, V>, pub enum_keyword: Syntax<T, V>, pub enum_name: Syntax<T, V>, pub enum_colon: Syntax<T, V>, pub enum_base: Syntax<T, V>, pub enum_type: Syntax<T, V>, pub enum_left_brace: Syntax<T, V>, pub enum_use_clauses: Syntax<T, V>, pub enum_enumerators: Syntax<T, V>, pub enum_right_brace: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct EnumUseChildren<T, V> { pub enum_use_keyword: Syntax<T, V>, pub enum_use_names: Syntax<T, V>, pub enum_use_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct EnumeratorChildren<T, V> { pub enumerator_name: Syntax<T, V>, pub enumerator_equal: Syntax<T, V>, pub enumerator_value: Syntax<T, V>, pub enumerator_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct EnumClassDeclarationChildren<T, V> { pub enum_class_attribute_spec: Syntax<T, V>, pub enum_class_modifiers: Syntax<T, V>, pub enum_class_enum_keyword: Syntax<T, V>, pub enum_class_class_keyword: Syntax<T, V>, pub enum_class_name: Syntax<T, V>, pub enum_class_colon: Syntax<T, V>, pub enum_class_base: Syntax<T, V>, pub enum_class_extends: Syntax<T, V>, pub enum_class_extends_list: Syntax<T, V>, pub enum_class_left_brace: Syntax<T, V>, pub enum_class_elements: Syntax<T, V>, pub enum_class_right_brace: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct EnumClassEnumeratorChildren<T, V> { pub enum_class_enumerator_modifiers: Syntax<T, V>, pub enum_class_enumerator_type: Syntax<T, V>, pub enum_class_enumerator_name: Syntax<T, V>, pub enum_class_enumerator_initializer: Syntax<T, V>, pub enum_class_enumerator_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct AliasDeclarationChildren<T, V> { pub alias_attribute_spec: Syntax<T, V>, pub alias_modifiers: Syntax<T, V>, pub alias_module_kw_opt: Syntax<T, V>, pub alias_keyword: Syntax<T, V>, pub alias_name: Syntax<T, V>, pub alias_generic_parameter: Syntax<T, V>, pub alias_constraint: Syntax<T, V>, pub alias_equal: Syntax<T, V>, pub alias_type: Syntax<T, V>, pub alias_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ContextAliasDeclarationChildren<T, V> { pub ctx_alias_attribute_spec: Syntax<T, V>, pub ctx_alias_keyword: Syntax<T, V>, pub ctx_alias_name: Syntax<T, V>, pub ctx_alias_generic_parameter: Syntax<T, V>, pub ctx_alias_as_constraint: Syntax<T, V>, pub ctx_alias_equal: Syntax<T, V>, pub ctx_alias_context: Syntax<T, V>, pub ctx_alias_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct CaseTypeDeclarationChildren<T, V> { pub case_type_attribute_spec: Syntax<T, V>, pub case_type_modifiers: Syntax<T, V>, pub case_type_case_keyword: Syntax<T, V>, pub case_type_type_keyword: Syntax<T, V>, pub case_type_name: Syntax<T, V>, pub case_type_generic_parameter: Syntax<T, V>, pub case_type_as: Syntax<T, V>, pub case_type_bounds: Syntax<T, V>, pub case_type_equal: Syntax<T, V>, pub case_type_variants: Syntax<T, V>, pub case_type_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct CaseTypeVariantChildren<T, V> { pub case_type_variant_bar: Syntax<T, V>, pub case_type_variant_type: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct PropertyDeclarationChildren<T, V> { pub property_attribute_spec: Syntax<T, V>, pub property_modifiers: Syntax<T, V>, pub property_type: Syntax<T, V>, pub property_declarators: Syntax<T, V>, pub property_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct PropertyDeclaratorChildren<T, V> { pub property_name: Syntax<T, V>, pub property_initializer: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct NamespaceDeclarationChildren<T, V> { pub namespace_header: Syntax<T, V>, pub namespace_body: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct NamespaceDeclarationHeaderChildren<T, V> { pub namespace_keyword: Syntax<T, V>, pub namespace_name: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct NamespaceBodyChildren<T, V> { pub namespace_left_brace: Syntax<T, V>, pub namespace_declarations: Syntax<T, V>, pub namespace_right_brace: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct NamespaceEmptyBodyChildren<T, V> { pub namespace_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct NamespaceUseDeclarationChildren<T, V> { pub namespace_use_keyword: Syntax<T, V>, pub namespace_use_kind: Syntax<T, V>, pub namespace_use_clauses: Syntax<T, V>, pub namespace_use_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct NamespaceGroupUseDeclarationChildren<T, V> { pub namespace_group_use_keyword: Syntax<T, V>, pub namespace_group_use_kind: Syntax<T, V>, pub namespace_group_use_prefix: Syntax<T, V>, pub namespace_group_use_left_brace: Syntax<T, V>, pub namespace_group_use_clauses: Syntax<T, V>, pub namespace_group_use_right_brace: Syntax<T, V>, pub namespace_group_use_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct NamespaceUseClauseChildren<T, V> { pub namespace_use_clause_kind: Syntax<T, V>, pub namespace_use_name: Syntax<T, V>, pub namespace_use_as: Syntax<T, V>, pub namespace_use_alias: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct FunctionDeclarationChildren<T, V> { pub function_attribute_spec: Syntax<T, V>, pub function_declaration_header: Syntax<T, V>, pub function_body: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct FunctionDeclarationHeaderChildren<T, V> { pub function_modifiers: Syntax<T, V>, pub function_keyword: Syntax<T, V>, pub function_name: Syntax<T, V>, pub function_type_parameter_list: Syntax<T, V>, pub function_left_paren: Syntax<T, V>, pub function_parameter_list: Syntax<T, V>, pub function_right_paren: Syntax<T, V>, pub function_contexts: Syntax<T, V>, pub function_colon: Syntax<T, V>, pub function_readonly_return: Syntax<T, V>, pub function_type: Syntax<T, V>, pub function_where_clause: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ContextsChildren<T, V> { pub contexts_left_bracket: Syntax<T, V>, pub contexts_types: Syntax<T, V>, pub contexts_right_bracket: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct WhereClauseChildren<T, V> { pub where_clause_keyword: Syntax<T, V>, pub where_clause_constraints: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct WhereConstraintChildren<T, V> { pub where_constraint_left_type: Syntax<T, V>, pub where_constraint_operator: Syntax<T, V>, pub where_constraint_right_type: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct MethodishDeclarationChildren<T, V> { pub methodish_attribute: Syntax<T, V>, pub methodish_function_decl_header: Syntax<T, V>, pub methodish_function_body: Syntax<T, V>, pub methodish_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct MethodishTraitResolutionChildren<T, V> { pub methodish_trait_attribute: Syntax<T, V>, pub methodish_trait_function_decl_header: Syntax<T, V>, pub methodish_trait_equal: Syntax<T, V>, pub methodish_trait_name: Syntax<T, V>, pub methodish_trait_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ClassishDeclarationChildren<T, V> { pub classish_attribute: Syntax<T, V>, pub classish_modifiers: Syntax<T, V>, pub classish_xhp: Syntax<T, V>, pub classish_keyword: Syntax<T, V>, pub classish_name: Syntax<T, V>, pub classish_type_parameters: Syntax<T, V>, pub classish_extends_keyword: Syntax<T, V>, pub classish_extends_list: Syntax<T, V>, pub classish_implements_keyword: Syntax<T, V>, pub classish_implements_list: Syntax<T, V>, pub classish_where_clause: Syntax<T, V>, pub classish_body: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ClassishBodyChildren<T, V> { pub classish_body_left_brace: Syntax<T, V>, pub classish_body_elements: Syntax<T, V>, pub classish_body_right_brace: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct TraitUseChildren<T, V> { pub trait_use_keyword: Syntax<T, V>, pub trait_use_names: Syntax<T, V>, pub trait_use_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct RequireClauseChildren<T, V> { pub require_keyword: Syntax<T, V>, pub require_kind: Syntax<T, V>, pub require_name: Syntax<T, V>, pub require_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ConstDeclarationChildren<T, V> { pub const_attribute_spec: Syntax<T, V>, pub const_modifiers: Syntax<T, V>, pub const_keyword: Syntax<T, V>, pub const_type_specifier: Syntax<T, V>, pub const_declarators: Syntax<T, V>, pub const_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ConstantDeclaratorChildren<T, V> { pub constant_declarator_name: Syntax<T, V>, pub constant_declarator_initializer: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct TypeConstDeclarationChildren<T, V> { pub type_const_attribute_spec: Syntax<T, V>, pub type_const_modifiers: Syntax<T, V>, pub type_const_keyword: Syntax<T, V>, pub type_const_type_keyword: Syntax<T, V>, pub type_const_name: Syntax<T, V>, pub type_const_type_parameters: Syntax<T, V>, pub type_const_type_constraints: Syntax<T, V>, pub type_const_equal: Syntax<T, V>, pub type_const_type_specifier: Syntax<T, V>, pub type_const_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ContextConstDeclarationChildren<T, V> { pub context_const_modifiers: Syntax<T, V>, pub context_const_const_keyword: Syntax<T, V>, pub context_const_ctx_keyword: Syntax<T, V>, pub context_const_name: Syntax<T, V>, pub context_const_type_parameters: Syntax<T, V>, pub context_const_constraint: Syntax<T, V>, pub context_const_equal: Syntax<T, V>, pub context_const_ctx_list: Syntax<T, V>, pub context_const_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct DecoratedExpressionChildren<T, V> { pub decorated_expression_decorator: Syntax<T, V>, pub decorated_expression_expression: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ParameterDeclarationChildren<T, V> { pub parameter_attribute: Syntax<T, V>, pub parameter_visibility: Syntax<T, V>, pub parameter_call_convention: Syntax<T, V>, pub parameter_readonly: Syntax<T, V>, pub parameter_type: Syntax<T, V>, pub parameter_name: Syntax<T, V>, pub parameter_default_value: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct VariadicParameterChildren<T, V> { pub variadic_parameter_call_convention: Syntax<T, V>, pub variadic_parameter_type: Syntax<T, V>, pub variadic_parameter_ellipsis: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct OldAttributeSpecificationChildren<T, V> { pub old_attribute_specification_left_double_angle: Syntax<T, V>, pub old_attribute_specification_attributes: Syntax<T, V>, pub old_attribute_specification_right_double_angle: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct AttributeSpecificationChildren<T, V> { pub attribute_specification_attributes: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct AttributeChildren<T, V> { pub attribute_at: Syntax<T, V>, pub attribute_attribute_name: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct InclusionExpressionChildren<T, V> { pub inclusion_require: Syntax<T, V>, pub inclusion_filename: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct InclusionDirectiveChildren<T, V> { pub inclusion_expression: Syntax<T, V>, pub inclusion_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct CompoundStatementChildren<T, V> { pub compound_left_brace: Syntax<T, V>, pub compound_statements: Syntax<T, V>, pub compound_right_brace: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ExpressionStatementChildren<T, V> { pub expression_statement_expression: Syntax<T, V>, pub expression_statement_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct MarkupSectionChildren<T, V> { pub markup_hashbang: Syntax<T, V>, pub markup_suffix: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct MarkupSuffixChildren<T, V> { pub markup_suffix_less_than_question: Syntax<T, V>, pub markup_suffix_name: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct UnsetStatementChildren<T, V> { pub unset_keyword: Syntax<T, V>, pub unset_left_paren: Syntax<T, V>, pub unset_variables: Syntax<T, V>, pub unset_right_paren: Syntax<T, V>, pub unset_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct DeclareLocalStatementChildren<T, V> { pub declare_local_keyword: Syntax<T, V>, pub declare_local_variable: Syntax<T, V>, pub declare_local_colon: Syntax<T, V>, pub declare_local_type: Syntax<T, V>, pub declare_local_initializer: Syntax<T, V>, pub declare_local_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct UsingStatementBlockScopedChildren<T, V> { pub using_block_await_keyword: Syntax<T, V>, pub using_block_using_keyword: Syntax<T, V>, pub using_block_left_paren: Syntax<T, V>, pub using_block_expressions: Syntax<T, V>, pub using_block_right_paren: Syntax<T, V>, pub using_block_body: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct UsingStatementFunctionScopedChildren<T, V> { pub using_function_await_keyword: Syntax<T, V>, pub using_function_using_keyword: Syntax<T, V>, pub using_function_expression: Syntax<T, V>, pub using_function_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct WhileStatementChildren<T, V> { pub while_keyword: Syntax<T, V>, pub while_left_paren: Syntax<T, V>, pub while_condition: Syntax<T, V>, pub while_right_paren: Syntax<T, V>, pub while_body: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct IfStatementChildren<T, V> { pub if_keyword: Syntax<T, V>, pub if_left_paren: Syntax<T, V>, pub if_condition: Syntax<T, V>, pub if_right_paren: Syntax<T, V>, pub if_statement: Syntax<T, V>, pub if_else_clause: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ElseClauseChildren<T, V> { pub else_keyword: Syntax<T, V>, pub else_statement: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct TryStatementChildren<T, V> { pub try_keyword: Syntax<T, V>, pub try_compound_statement: Syntax<T, V>, pub try_catch_clauses: Syntax<T, V>, pub try_finally_clause: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct CatchClauseChildren<T, V> { pub catch_keyword: Syntax<T, V>, pub catch_left_paren: Syntax<T, V>, pub catch_type: Syntax<T, V>, pub catch_variable: Syntax<T, V>, pub catch_right_paren: Syntax<T, V>, pub catch_body: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct FinallyClauseChildren<T, V> { pub finally_keyword: Syntax<T, V>, pub finally_body: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct DoStatementChildren<T, V> { pub do_keyword: Syntax<T, V>, pub do_body: Syntax<T, V>, pub do_while_keyword: Syntax<T, V>, pub do_left_paren: Syntax<T, V>, pub do_condition: Syntax<T, V>, pub do_right_paren: Syntax<T, V>, pub do_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ForStatementChildren<T, V> { pub for_keyword: Syntax<T, V>, pub for_left_paren: Syntax<T, V>, pub for_initializer: Syntax<T, V>, pub for_first_semicolon: Syntax<T, V>, pub for_control: Syntax<T, V>, pub for_second_semicolon: Syntax<T, V>, pub for_end_of_loop: Syntax<T, V>, pub for_right_paren: Syntax<T, V>, pub for_body: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ForeachStatementChildren<T, V> { pub foreach_keyword: Syntax<T, V>, pub foreach_left_paren: Syntax<T, V>, pub foreach_collection: Syntax<T, V>, pub foreach_await_keyword: Syntax<T, V>, pub foreach_as: Syntax<T, V>, pub foreach_key: Syntax<T, V>, pub foreach_arrow: Syntax<T, V>, pub foreach_value: Syntax<T, V>, pub foreach_right_paren: Syntax<T, V>, pub foreach_body: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct SwitchStatementChildren<T, V> { pub switch_keyword: Syntax<T, V>, pub switch_left_paren: Syntax<T, V>, pub switch_expression: Syntax<T, V>, pub switch_right_paren: Syntax<T, V>, pub switch_left_brace: Syntax<T, V>, pub switch_sections: Syntax<T, V>, pub switch_right_brace: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct SwitchSectionChildren<T, V> { pub switch_section_labels: Syntax<T, V>, pub switch_section_statements: Syntax<T, V>, pub switch_section_fallthrough: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct SwitchFallthroughChildren<T, V> { pub fallthrough_keyword: Syntax<T, V>, pub fallthrough_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct CaseLabelChildren<T, V> { pub case_keyword: Syntax<T, V>, pub case_expression: Syntax<T, V>, pub case_colon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct DefaultLabelChildren<T, V> { pub default_keyword: Syntax<T, V>, pub default_colon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct MatchStatementChildren<T, V> { pub match_statement_keyword: Syntax<T, V>, pub match_statement_left_paren: Syntax<T, V>, pub match_statement_expression: Syntax<T, V>, pub match_statement_right_paren: Syntax<T, V>, pub match_statement_left_brace: Syntax<T, V>, pub match_statement_arms: Syntax<T, V>, pub match_statement_right_brace: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct MatchStatementArmChildren<T, V> { pub match_statement_arm_pattern: Syntax<T, V>, pub match_statement_arm_arrow: Syntax<T, V>, pub match_statement_arm_body: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ReturnStatementChildren<T, V> { pub return_keyword: Syntax<T, V>, pub return_expression: Syntax<T, V>, pub return_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct YieldBreakStatementChildren<T, V> { pub yield_break_keyword: Syntax<T, V>, pub yield_break_break: Syntax<T, V>, pub yield_break_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ThrowStatementChildren<T, V> { pub throw_keyword: Syntax<T, V>, pub throw_expression: Syntax<T, V>, pub throw_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct BreakStatementChildren<T, V> { pub break_keyword: Syntax<T, V>, pub break_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ContinueStatementChildren<T, V> { pub continue_keyword: Syntax<T, V>, pub continue_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct EchoStatementChildren<T, V> { pub echo_keyword: Syntax<T, V>, pub echo_expressions: Syntax<T, V>, pub echo_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ConcurrentStatementChildren<T, V> { pub concurrent_keyword: Syntax<T, V>, pub concurrent_statement: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct SimpleInitializerChildren<T, V> { pub simple_initializer_equal: Syntax<T, V>, pub simple_initializer_value: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct AnonymousClassChildren<T, V> { pub anonymous_class_class_keyword: Syntax<T, V>, pub anonymous_class_left_paren: Syntax<T, V>, pub anonymous_class_argument_list: Syntax<T, V>, pub anonymous_class_right_paren: Syntax<T, V>, pub anonymous_class_extends_keyword: Syntax<T, V>, pub anonymous_class_extends_list: Syntax<T, V>, pub anonymous_class_implements_keyword: Syntax<T, V>, pub anonymous_class_implements_list: Syntax<T, V>, pub anonymous_class_body: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct AnonymousFunctionChildren<T, V> { pub anonymous_attribute_spec: Syntax<T, V>, pub anonymous_async_keyword: Syntax<T, V>, pub anonymous_function_keyword: Syntax<T, V>, pub anonymous_left_paren: Syntax<T, V>, pub anonymous_parameters: Syntax<T, V>, pub anonymous_right_paren: Syntax<T, V>, pub anonymous_ctx_list: Syntax<T, V>, pub anonymous_colon: Syntax<T, V>, pub anonymous_readonly_return: Syntax<T, V>, pub anonymous_type: Syntax<T, V>, pub anonymous_use: Syntax<T, V>, pub anonymous_body: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct AnonymousFunctionUseClauseChildren<T, V> { pub anonymous_use_keyword: Syntax<T, V>, pub anonymous_use_left_paren: Syntax<T, V>, pub anonymous_use_variables: Syntax<T, V>, pub anonymous_use_right_paren: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct VariablePatternChildren<T, V> { pub variable_pattern_variable: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ConstructorPatternChildren<T, V> { pub constructor_pattern_constructor: Syntax<T, V>, pub constructor_pattern_left_paren: Syntax<T, V>, pub constructor_pattern_members: Syntax<T, V>, pub constructor_pattern_right_paren: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct RefinementPatternChildren<T, V> { pub refinement_pattern_variable: Syntax<T, V>, pub refinement_pattern_colon: Syntax<T, V>, pub refinement_pattern_specifier: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct LambdaExpressionChildren<T, V> { pub lambda_attribute_spec: Syntax<T, V>, pub lambda_async: Syntax<T, V>, pub lambda_signature: Syntax<T, V>, pub lambda_arrow: Syntax<T, V>, pub lambda_body: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct LambdaSignatureChildren<T, V> { pub lambda_left_paren: Syntax<T, V>, pub lambda_parameters: Syntax<T, V>, pub lambda_right_paren: Syntax<T, V>, pub lambda_contexts: Syntax<T, V>, pub lambda_colon: Syntax<T, V>, pub lambda_readonly_return: Syntax<T, V>, pub lambda_type: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct CastExpressionChildren<T, V> { pub cast_left_paren: Syntax<T, V>, pub cast_type: Syntax<T, V>, pub cast_right_paren: Syntax<T, V>, pub cast_operand: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ScopeResolutionExpressionChildren<T, V> { pub scope_resolution_qualifier: Syntax<T, V>, pub scope_resolution_operator: Syntax<T, V>, pub scope_resolution_name: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct MemberSelectionExpressionChildren<T, V> { pub member_object: Syntax<T, V>, pub member_operator: Syntax<T, V>, pub member_name: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct SafeMemberSelectionExpressionChildren<T, V> { pub safe_member_object: Syntax<T, V>, pub safe_member_operator: Syntax<T, V>, pub safe_member_name: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct EmbeddedMemberSelectionExpressionChildren<T, V> { pub embedded_member_object: Syntax<T, V>, pub embedded_member_operator: Syntax<T, V>, pub embedded_member_name: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct YieldExpressionChildren<T, V> { pub yield_keyword: Syntax<T, V>, pub yield_operand: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct PrefixUnaryExpressionChildren<T, V> { pub prefix_unary_operator: Syntax<T, V>, pub prefix_unary_operand: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct PostfixUnaryExpressionChildren<T, V> { pub postfix_unary_operand: Syntax<T, V>, pub postfix_unary_operator: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct BinaryExpressionChildren<T, V> { pub binary_left_operand: Syntax<T, V>, pub binary_operator: Syntax<T, V>, pub binary_right_operand: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct IsExpressionChildren<T, V> { pub is_left_operand: Syntax<T, V>, pub is_operator: Syntax<T, V>, pub is_right_operand: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct AsExpressionChildren<T, V> { pub as_left_operand: Syntax<T, V>, pub as_operator: Syntax<T, V>, pub as_right_operand: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct NullableAsExpressionChildren<T, V> { pub nullable_as_left_operand: Syntax<T, V>, pub nullable_as_operator: Syntax<T, V>, pub nullable_as_right_operand: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct UpcastExpressionChildren<T, V> { pub upcast_left_operand: Syntax<T, V>, pub upcast_operator: Syntax<T, V>, pub upcast_right_operand: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ConditionalExpressionChildren<T, V> { pub conditional_test: Syntax<T, V>, pub conditional_question: Syntax<T, V>, pub conditional_consequence: Syntax<T, V>, pub conditional_colon: Syntax<T, V>, pub conditional_alternative: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct EvalExpressionChildren<T, V> { pub eval_keyword: Syntax<T, V>, pub eval_left_paren: Syntax<T, V>, pub eval_argument: Syntax<T, V>, pub eval_right_paren: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct IssetExpressionChildren<T, V> { pub isset_keyword: Syntax<T, V>, pub isset_left_paren: Syntax<T, V>, pub isset_argument_list: Syntax<T, V>, pub isset_right_paren: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct FunctionCallExpressionChildren<T, V> { pub function_call_receiver: Syntax<T, V>, pub function_call_type_args: Syntax<T, V>, pub function_call_left_paren: Syntax<T, V>, pub function_call_argument_list: Syntax<T, V>, pub function_call_right_paren: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct FunctionPointerExpressionChildren<T, V> { pub function_pointer_receiver: Syntax<T, V>, pub function_pointer_type_args: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ParenthesizedExpressionChildren<T, V> { pub parenthesized_expression_left_paren: Syntax<T, V>, pub parenthesized_expression_expression: Syntax<T, V>, pub parenthesized_expression_right_paren: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct BracedExpressionChildren<T, V> { pub braced_expression_left_brace: Syntax<T, V>, pub braced_expression_expression: Syntax<T, V>, pub braced_expression_right_brace: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ETSpliceExpressionChildren<T, V> { pub et_splice_expression_dollar: Syntax<T, V>, pub et_splice_expression_left_brace: Syntax<T, V>, pub et_splice_expression_expression: Syntax<T, V>, pub et_splice_expression_right_brace: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct EmbeddedBracedExpressionChildren<T, V> { pub embedded_braced_expression_left_brace: Syntax<T, V>, pub embedded_braced_expression_expression: Syntax<T, V>, pub embedded_braced_expression_right_brace: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ListExpressionChildren<T, V> { pub list_keyword: Syntax<T, V>, pub list_left_paren: Syntax<T, V>, pub list_members: Syntax<T, V>, pub list_right_paren: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct CollectionLiteralExpressionChildren<T, V> { pub collection_literal_name: Syntax<T, V>, pub collection_literal_left_brace: Syntax<T, V>, pub collection_literal_initializers: Syntax<T, V>, pub collection_literal_right_brace: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ObjectCreationExpressionChildren<T, V> { pub object_creation_new_keyword: Syntax<T, V>, pub object_creation_object: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ConstructorCallChildren<T, V> { pub constructor_call_type: Syntax<T, V>, pub constructor_call_left_paren: Syntax<T, V>, pub constructor_call_argument_list: Syntax<T, V>, pub constructor_call_right_paren: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct DarrayIntrinsicExpressionChildren<T, V> { pub darray_intrinsic_keyword: Syntax<T, V>, pub darray_intrinsic_explicit_type: Syntax<T, V>, pub darray_intrinsic_left_bracket: Syntax<T, V>, pub darray_intrinsic_members: Syntax<T, V>, pub darray_intrinsic_right_bracket: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct DictionaryIntrinsicExpressionChildren<T, V> { pub dictionary_intrinsic_keyword: Syntax<T, V>, pub dictionary_intrinsic_explicit_type: Syntax<T, V>, pub dictionary_intrinsic_left_bracket: Syntax<T, V>, pub dictionary_intrinsic_members: Syntax<T, V>, pub dictionary_intrinsic_right_bracket: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct KeysetIntrinsicExpressionChildren<T, V> { pub keyset_intrinsic_keyword: Syntax<T, V>, pub keyset_intrinsic_explicit_type: Syntax<T, V>, pub keyset_intrinsic_left_bracket: Syntax<T, V>, pub keyset_intrinsic_members: Syntax<T, V>, pub keyset_intrinsic_right_bracket: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct VarrayIntrinsicExpressionChildren<T, V> { pub varray_intrinsic_keyword: Syntax<T, V>, pub varray_intrinsic_explicit_type: Syntax<T, V>, pub varray_intrinsic_left_bracket: Syntax<T, V>, pub varray_intrinsic_members: Syntax<T, V>, pub varray_intrinsic_right_bracket: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct VectorIntrinsicExpressionChildren<T, V> { pub vector_intrinsic_keyword: Syntax<T, V>, pub vector_intrinsic_explicit_type: Syntax<T, V>, pub vector_intrinsic_left_bracket: Syntax<T, V>, pub vector_intrinsic_members: Syntax<T, V>, pub vector_intrinsic_right_bracket: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ElementInitializerChildren<T, V> { pub element_key: Syntax<T, V>, pub element_arrow: Syntax<T, V>, pub element_value: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct SubscriptExpressionChildren<T, V> { pub subscript_receiver: Syntax<T, V>, pub subscript_left_bracket: Syntax<T, V>, pub subscript_index: Syntax<T, V>, pub subscript_right_bracket: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct EmbeddedSubscriptExpressionChildren<T, V> { pub embedded_subscript_receiver: Syntax<T, V>, pub embedded_subscript_left_bracket: Syntax<T, V>, pub embedded_subscript_index: Syntax<T, V>, pub embedded_subscript_right_bracket: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct AwaitableCreationExpressionChildren<T, V> { pub awaitable_attribute_spec: Syntax<T, V>, pub awaitable_async: Syntax<T, V>, pub awaitable_compound_statement: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct XHPChildrenDeclarationChildren<T, V> { pub xhp_children_keyword: Syntax<T, V>, pub xhp_children_expression: Syntax<T, V>, pub xhp_children_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct XHPChildrenParenthesizedListChildren<T, V> { pub xhp_children_list_left_paren: Syntax<T, V>, pub xhp_children_list_xhp_children: Syntax<T, V>, pub xhp_children_list_right_paren: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct XHPCategoryDeclarationChildren<T, V> { pub xhp_category_keyword: Syntax<T, V>, pub xhp_category_categories: Syntax<T, V>, pub xhp_category_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct XHPEnumTypeChildren<T, V> { pub xhp_enum_like: Syntax<T, V>, pub xhp_enum_keyword: Syntax<T, V>, pub xhp_enum_left_brace: Syntax<T, V>, pub xhp_enum_values: Syntax<T, V>, pub xhp_enum_right_brace: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct XHPLateinitChildren<T, V> { pub xhp_lateinit_at: Syntax<T, V>, pub xhp_lateinit_keyword: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct XHPRequiredChildren<T, V> { pub xhp_required_at: Syntax<T, V>, pub xhp_required_keyword: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct XHPClassAttributeDeclarationChildren<T, V> { pub xhp_attribute_keyword: Syntax<T, V>, pub xhp_attribute_attributes: Syntax<T, V>, pub xhp_attribute_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct XHPClassAttributeChildren<T, V> { pub xhp_attribute_decl_type: Syntax<T, V>, pub xhp_attribute_decl_name: Syntax<T, V>, pub xhp_attribute_decl_initializer: Syntax<T, V>, pub xhp_attribute_decl_required: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct XHPSimpleClassAttributeChildren<T, V> { pub xhp_simple_class_attribute_type: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct XHPSimpleAttributeChildren<T, V> { pub xhp_simple_attribute_name: Syntax<T, V>, pub xhp_simple_attribute_equal: Syntax<T, V>, pub xhp_simple_attribute_expression: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct XHPSpreadAttributeChildren<T, V> { pub xhp_spread_attribute_left_brace: Syntax<T, V>, pub xhp_spread_attribute_spread_operator: Syntax<T, V>, pub xhp_spread_attribute_expression: Syntax<T, V>, pub xhp_spread_attribute_right_brace: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct XHPOpenChildren<T, V> { pub xhp_open_left_angle: Syntax<T, V>, pub xhp_open_name: Syntax<T, V>, pub xhp_open_attributes: Syntax<T, V>, pub xhp_open_right_angle: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct XHPExpressionChildren<T, V> { pub xhp_open: Syntax<T, V>, pub xhp_body: Syntax<T, V>, pub xhp_close: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct XHPCloseChildren<T, V> { pub xhp_close_left_angle: Syntax<T, V>, pub xhp_close_name: Syntax<T, V>, pub xhp_close_right_angle: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct TypeConstantChildren<T, V> { pub type_constant_left_type: Syntax<T, V>, pub type_constant_separator: Syntax<T, V>, pub type_constant_right_type: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct VectorTypeSpecifierChildren<T, V> { pub vector_type_keyword: Syntax<T, V>, pub vector_type_left_angle: Syntax<T, V>, pub vector_type_type: Syntax<T, V>, pub vector_type_trailing_comma: Syntax<T, V>, pub vector_type_right_angle: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct KeysetTypeSpecifierChildren<T, V> { pub keyset_type_keyword: Syntax<T, V>, pub keyset_type_left_angle: Syntax<T, V>, pub keyset_type_type: Syntax<T, V>, pub keyset_type_trailing_comma: Syntax<T, V>, pub keyset_type_right_angle: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct TupleTypeExplicitSpecifierChildren<T, V> { pub tuple_type_keyword: Syntax<T, V>, pub tuple_type_left_angle: Syntax<T, V>, pub tuple_type_types: Syntax<T, V>, pub tuple_type_right_angle: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct VarrayTypeSpecifierChildren<T, V> { pub varray_keyword: Syntax<T, V>, pub varray_left_angle: Syntax<T, V>, pub varray_type: Syntax<T, V>, pub varray_trailing_comma: Syntax<T, V>, pub varray_right_angle: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct FunctionCtxTypeSpecifierChildren<T, V> { pub function_ctx_type_keyword: Syntax<T, V>, pub function_ctx_type_variable: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct TypeParameterChildren<T, V> { pub type_attribute_spec: Syntax<T, V>, pub type_reified: Syntax<T, V>, pub type_variance: Syntax<T, V>, pub type_name: Syntax<T, V>, pub type_param_params: Syntax<T, V>, pub type_constraints: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct TypeConstraintChildren<T, V> { pub constraint_keyword: Syntax<T, V>, pub constraint_type: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ContextConstraintChildren<T, V> { pub ctx_constraint_keyword: Syntax<T, V>, pub ctx_constraint_ctx_list: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct DarrayTypeSpecifierChildren<T, V> { pub darray_keyword: Syntax<T, V>, pub darray_left_angle: Syntax<T, V>, pub darray_key: Syntax<T, V>, pub darray_comma: Syntax<T, V>, pub darray_value: Syntax<T, V>, pub darray_trailing_comma: Syntax<T, V>, pub darray_right_angle: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct DictionaryTypeSpecifierChildren<T, V> { pub dictionary_type_keyword: Syntax<T, V>, pub dictionary_type_left_angle: Syntax<T, V>, pub dictionary_type_members: Syntax<T, V>, pub dictionary_type_right_angle: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ClosureTypeSpecifierChildren<T, V> { pub closure_outer_left_paren: Syntax<T, V>, pub closure_readonly_keyword: Syntax<T, V>, pub closure_function_keyword: Syntax<T, V>, pub closure_inner_left_paren: Syntax<T, V>, pub closure_parameter_list: Syntax<T, V>, pub closure_inner_right_paren: Syntax<T, V>, pub closure_contexts: Syntax<T, V>, pub closure_colon: Syntax<T, V>, pub closure_readonly_return: Syntax<T, V>, pub closure_return_type: Syntax<T, V>, pub closure_outer_right_paren: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ClosureParameterTypeSpecifierChildren<T, V> { pub closure_parameter_call_convention: Syntax<T, V>, pub closure_parameter_readonly: Syntax<T, V>, pub closure_parameter_type: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct TypeRefinementChildren<T, V> { pub type_refinement_type: Syntax<T, V>, pub type_refinement_keyword: Syntax<T, V>, pub type_refinement_left_brace: Syntax<T, V>, pub type_refinement_members: Syntax<T, V>, pub type_refinement_right_brace: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct TypeInRefinementChildren<T, V> { pub type_in_refinement_keyword: Syntax<T, V>, pub type_in_refinement_name: Syntax<T, V>, pub type_in_refinement_type_parameters: Syntax<T, V>, pub type_in_refinement_constraints: Syntax<T, V>, pub type_in_refinement_equal: Syntax<T, V>, pub type_in_refinement_type: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct CtxInRefinementChildren<T, V> { pub ctx_in_refinement_keyword: Syntax<T, V>, pub ctx_in_refinement_name: Syntax<T, V>, pub ctx_in_refinement_type_parameters: Syntax<T, V>, pub ctx_in_refinement_constraints: Syntax<T, V>, pub ctx_in_refinement_equal: Syntax<T, V>, pub ctx_in_refinement_ctx_list: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ClassnameTypeSpecifierChildren<T, V> { pub classname_keyword: Syntax<T, V>, pub classname_left_angle: Syntax<T, V>, pub classname_type: Syntax<T, V>, pub classname_trailing_comma: Syntax<T, V>, pub classname_right_angle: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct FieldSpecifierChildren<T, V> { pub field_question: Syntax<T, V>, pub field_name: Syntax<T, V>, pub field_arrow: Syntax<T, V>, pub field_type: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct FieldInitializerChildren<T, V> { pub field_initializer_name: Syntax<T, V>, pub field_initializer_arrow: Syntax<T, V>, pub field_initializer_value: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ShapeTypeSpecifierChildren<T, V> { pub shape_type_keyword: Syntax<T, V>, pub shape_type_left_paren: Syntax<T, V>, pub shape_type_fields: Syntax<T, V>, pub shape_type_ellipsis: Syntax<T, V>, pub shape_type_right_paren: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ShapeExpressionChildren<T, V> { pub shape_expression_keyword: Syntax<T, V>, pub shape_expression_left_paren: Syntax<T, V>, pub shape_expression_fields: Syntax<T, V>, pub shape_expression_right_paren: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct TupleExpressionChildren<T, V> { pub tuple_expression_keyword: Syntax<T, V>, pub tuple_expression_left_paren: Syntax<T, V>, pub tuple_expression_items: Syntax<T, V>, pub tuple_expression_right_paren: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct GenericTypeSpecifierChildren<T, V> { pub generic_class_type: Syntax<T, V>, pub generic_argument_list: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct NullableTypeSpecifierChildren<T, V> { pub nullable_question: Syntax<T, V>, pub nullable_type: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct LikeTypeSpecifierChildren<T, V> { pub like_tilde: Syntax<T, V>, pub like_type: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct SoftTypeSpecifierChildren<T, V> { pub soft_at: Syntax<T, V>, pub soft_type: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct AttributizedSpecifierChildren<T, V> { pub attributized_specifier_attribute_spec: Syntax<T, V>, pub attributized_specifier_type: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ReifiedTypeArgumentChildren<T, V> { pub reified_type_argument_reified: Syntax<T, V>, pub reified_type_argument_type: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct TypeArgumentsChildren<T, V> { pub type_arguments_left_angle: Syntax<T, V>, pub type_arguments_types: Syntax<T, V>, pub type_arguments_right_angle: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct TypeParametersChildren<T, V> { pub type_parameters_left_angle: Syntax<T, V>, pub type_parameters_parameters: Syntax<T, V>, pub type_parameters_right_angle: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct TupleTypeSpecifierChildren<T, V> { pub tuple_left_paren: Syntax<T, V>, pub tuple_types: Syntax<T, V>, pub tuple_right_paren: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct UnionTypeSpecifierChildren<T, V> { pub union_left_paren: Syntax<T, V>, pub union_types: Syntax<T, V>, pub union_right_paren: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct IntersectionTypeSpecifierChildren<T, V> { pub intersection_left_paren: Syntax<T, V>, pub intersection_types: Syntax<T, V>, pub intersection_right_paren: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ErrorSyntaxChildren<T, V> { pub error_error: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ListItemChildren<T, V> { pub list_item: Syntax<T, V>, pub list_separator: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct EnumClassLabelExpressionChildren<T, V> { pub enum_class_label_qualifier: Syntax<T, V>, pub enum_class_label_hash: Syntax<T, V>, pub enum_class_label_expression: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ModuleDeclarationChildren<T, V> { pub module_declaration_attribute_spec: Syntax<T, V>, pub module_declaration_new_keyword: Syntax<T, V>, pub module_declaration_module_keyword: Syntax<T, V>, pub module_declaration_name: Syntax<T, V>, pub module_declaration_left_brace: Syntax<T, V>, pub module_declaration_exports: Syntax<T, V>, pub module_declaration_imports: Syntax<T, V>, pub module_declaration_right_brace: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ModuleExportsChildren<T, V> { pub module_exports_exports_keyword: Syntax<T, V>, pub module_exports_left_brace: Syntax<T, V>, pub module_exports_exports: Syntax<T, V>, pub module_exports_right_brace: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ModuleImportsChildren<T, V> { pub module_imports_imports_keyword: Syntax<T, V>, pub module_imports_left_brace: Syntax<T, V>, pub module_imports_imports: Syntax<T, V>, pub module_imports_right_brace: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct ModuleMembershipDeclarationChildren<T, V> { pub module_membership_declaration_module_keyword: Syntax<T, V>, pub module_membership_declaration_name: Syntax<T, V>, pub module_membership_declaration_semicolon: Syntax<T, V>, } #[derive(Debug, Clone)] #[repr(C)] pub struct PackageExpressionChildren<T, V> { pub package_expression_keyword: Syntax<T, V>, pub package_expression_name: Syntax<T, V>, } #[derive(Debug, Clone)] pub enum SyntaxVariant<T, V> { Token(Box<T>), Missing, SyntaxList(Vec<Syntax<T, V>>), EndOfFile(Box<EndOfFileChildren<T, V>>), Script(Box<ScriptChildren<T, V>>), QualifiedName(Box<QualifiedNameChildren<T, V>>), ModuleName(Box<ModuleNameChildren<T, V>>), SimpleTypeSpecifier(Box<SimpleTypeSpecifierChildren<T, V>>), LiteralExpression(Box<LiteralExpressionChildren<T, V>>), PrefixedStringExpression(Box<PrefixedStringExpressionChildren<T, V>>), PrefixedCodeExpression(Box<PrefixedCodeExpressionChildren<T, V>>), VariableExpression(Box<VariableExpressionChildren<T, V>>), PipeVariableExpression(Box<PipeVariableExpressionChildren<T, V>>), FileAttributeSpecification(Box<FileAttributeSpecificationChildren<T, V>>), EnumDeclaration(Box<EnumDeclarationChildren<T, V>>), EnumUse(Box<EnumUseChildren<T, V>>), Enumerator(Box<EnumeratorChildren<T, V>>), EnumClassDeclaration(Box<EnumClassDeclarationChildren<T, V>>), EnumClassEnumerator(Box<EnumClassEnumeratorChildren<T, V>>), AliasDeclaration(Box<AliasDeclarationChildren<T, V>>), ContextAliasDeclaration(Box<ContextAliasDeclarationChildren<T, V>>), CaseTypeDeclaration(Box<CaseTypeDeclarationChildren<T, V>>), CaseTypeVariant(Box<CaseTypeVariantChildren<T, V>>), PropertyDeclaration(Box<PropertyDeclarationChildren<T, V>>), PropertyDeclarator(Box<PropertyDeclaratorChildren<T, V>>), NamespaceDeclaration(Box<NamespaceDeclarationChildren<T, V>>), NamespaceDeclarationHeader(Box<NamespaceDeclarationHeaderChildren<T, V>>), NamespaceBody(Box<NamespaceBodyChildren<T, V>>), NamespaceEmptyBody(Box<NamespaceEmptyBodyChildren<T, V>>), NamespaceUseDeclaration(Box<NamespaceUseDeclarationChildren<T, V>>), NamespaceGroupUseDeclaration(Box<NamespaceGroupUseDeclarationChildren<T, V>>), NamespaceUseClause(Box<NamespaceUseClauseChildren<T, V>>), FunctionDeclaration(Box<FunctionDeclarationChildren<T, V>>), FunctionDeclarationHeader(Box<FunctionDeclarationHeaderChildren<T, V>>), Contexts(Box<ContextsChildren<T, V>>), WhereClause(Box<WhereClauseChildren<T, V>>), WhereConstraint(Box<WhereConstraintChildren<T, V>>), MethodishDeclaration(Box<MethodishDeclarationChildren<T, V>>), MethodishTraitResolution(Box<MethodishTraitResolutionChildren<T, V>>), ClassishDeclaration(Box<ClassishDeclarationChildren<T, V>>), ClassishBody(Box<ClassishBodyChildren<T, V>>), TraitUse(Box<TraitUseChildren<T, V>>), RequireClause(Box<RequireClauseChildren<T, V>>), ConstDeclaration(Box<ConstDeclarationChildren<T, V>>), ConstantDeclarator(Box<ConstantDeclaratorChildren<T, V>>), TypeConstDeclaration(Box<TypeConstDeclarationChildren<T, V>>), ContextConstDeclaration(Box<ContextConstDeclarationChildren<T, V>>), DecoratedExpression(Box<DecoratedExpressionChildren<T, V>>), ParameterDeclaration(Box<ParameterDeclarationChildren<T, V>>), VariadicParameter(Box<VariadicParameterChildren<T, V>>), OldAttributeSpecification(Box<OldAttributeSpecificationChildren<T, V>>), AttributeSpecification(Box<AttributeSpecificationChildren<T, V>>), Attribute(Box<AttributeChildren<T, V>>), InclusionExpression(Box<InclusionExpressionChildren<T, V>>), InclusionDirective(Box<InclusionDirectiveChildren<T, V>>), CompoundStatement(Box<CompoundStatementChildren<T, V>>), ExpressionStatement(Box<ExpressionStatementChildren<T, V>>), MarkupSection(Box<MarkupSectionChildren<T, V>>), MarkupSuffix(Box<MarkupSuffixChildren<T, V>>), UnsetStatement(Box<UnsetStatementChildren<T, V>>), DeclareLocalStatement(Box<DeclareLocalStatementChildren<T, V>>), UsingStatementBlockScoped(Box<UsingStatementBlockScopedChildren<T, V>>), UsingStatementFunctionScoped(Box<UsingStatementFunctionScopedChildren<T, V>>), WhileStatement(Box<WhileStatementChildren<T, V>>), IfStatement(Box<IfStatementChildren<T, V>>), ElseClause(Box<ElseClauseChildren<T, V>>), TryStatement(Box<TryStatementChildren<T, V>>), CatchClause(Box<CatchClauseChildren<T, V>>), FinallyClause(Box<FinallyClauseChildren<T, V>>), DoStatement(Box<DoStatementChildren<T, V>>), ForStatement(Box<ForStatementChildren<T, V>>), ForeachStatement(Box<ForeachStatementChildren<T, V>>), SwitchStatement(Box<SwitchStatementChildren<T, V>>), SwitchSection(Box<SwitchSectionChildren<T, V>>), SwitchFallthrough(Box<SwitchFallthroughChildren<T, V>>), CaseLabel(Box<CaseLabelChildren<T, V>>), DefaultLabel(Box<DefaultLabelChildren<T, V>>), MatchStatement(Box<MatchStatementChildren<T, V>>), MatchStatementArm(Box<MatchStatementArmChildren<T, V>>), ReturnStatement(Box<ReturnStatementChildren<T, V>>), YieldBreakStatement(Box<YieldBreakStatementChildren<T, V>>), ThrowStatement(Box<ThrowStatementChildren<T, V>>), BreakStatement(Box<BreakStatementChildren<T, V>>), ContinueStatement(Box<ContinueStatementChildren<T, V>>), EchoStatement(Box<EchoStatementChildren<T, V>>), ConcurrentStatement(Box<ConcurrentStatementChildren<T, V>>), SimpleInitializer(Box<SimpleInitializerChildren<T, V>>), AnonymousClass(Box<AnonymousClassChildren<T, V>>), AnonymousFunction(Box<AnonymousFunctionChildren<T, V>>), AnonymousFunctionUseClause(Box<AnonymousFunctionUseClauseChildren<T, V>>), VariablePattern(Box<VariablePatternChildren<T, V>>), ConstructorPattern(Box<ConstructorPatternChildren<T, V>>), RefinementPattern(Box<RefinementPatternChildren<T, V>>), LambdaExpression(Box<LambdaExpressionChildren<T, V>>), LambdaSignature(Box<LambdaSignatureChildren<T, V>>), CastExpression(Box<CastExpressionChildren<T, V>>), ScopeResolutionExpression(Box<ScopeResolutionExpressionChildren<T, V>>), MemberSelectionExpression(Box<MemberSelectionExpressionChildren<T, V>>), SafeMemberSelectionExpression(Box<SafeMemberSelectionExpressionChildren<T, V>>), EmbeddedMemberSelectionExpression(Box<EmbeddedMemberSelectionExpressionChildren<T, V>>), YieldExpression(Box<YieldExpressionChildren<T, V>>), PrefixUnaryExpression(Box<PrefixUnaryExpressionChildren<T, V>>), PostfixUnaryExpression(Box<PostfixUnaryExpressionChildren<T, V>>), BinaryExpression(Box<BinaryExpressionChildren<T, V>>), IsExpression(Box<IsExpressionChildren<T, V>>), AsExpression(Box<AsExpressionChildren<T, V>>), NullableAsExpression(Box<NullableAsExpressionChildren<T, V>>), UpcastExpression(Box<UpcastExpressionChildren<T, V>>), ConditionalExpression(Box<ConditionalExpressionChildren<T, V>>), EvalExpression(Box<EvalExpressionChildren<T, V>>), IssetExpression(Box<IssetExpressionChildren<T, V>>), FunctionCallExpression(Box<FunctionCallExpressionChildren<T, V>>), FunctionPointerExpression(Box<FunctionPointerExpressionChildren<T, V>>), ParenthesizedExpression(Box<ParenthesizedExpressionChildren<T, V>>), BracedExpression(Box<BracedExpressionChildren<T, V>>), ETSpliceExpression(Box<ETSpliceExpressionChildren<T, V>>), EmbeddedBracedExpression(Box<EmbeddedBracedExpressionChildren<T, V>>), ListExpression(Box<ListExpressionChildren<T, V>>), CollectionLiteralExpression(Box<CollectionLiteralExpressionChildren<T, V>>), ObjectCreationExpression(Box<ObjectCreationExpressionChildren<T, V>>), ConstructorCall(Box<ConstructorCallChildren<T, V>>), DarrayIntrinsicExpression(Box<DarrayIntrinsicExpressionChildren<T, V>>), DictionaryIntrinsicExpression(Box<DictionaryIntrinsicExpressionChildren<T, V>>), KeysetIntrinsicExpression(Box<KeysetIntrinsicExpressionChildren<T, V>>), VarrayIntrinsicExpression(Box<VarrayIntrinsicExpressionChildren<T, V>>), VectorIntrinsicExpression(Box<VectorIntrinsicExpressionChildren<T, V>>), ElementInitializer(Box<ElementInitializerChildren<T, V>>), SubscriptExpression(Box<SubscriptExpressionChildren<T, V>>), EmbeddedSubscriptExpression(Box<EmbeddedSubscriptExpressionChildren<T, V>>), AwaitableCreationExpression(Box<AwaitableCreationExpressionChildren<T, V>>), XHPChildrenDeclaration(Box<XHPChildrenDeclarationChildren<T, V>>), XHPChildrenParenthesizedList(Box<XHPChildrenParenthesizedListChildren<T, V>>), XHPCategoryDeclaration(Box<XHPCategoryDeclarationChildren<T, V>>), XHPEnumType(Box<XHPEnumTypeChildren<T, V>>), XHPLateinit(Box<XHPLateinitChildren<T, V>>), XHPRequired(Box<XHPRequiredChildren<T, V>>), XHPClassAttributeDeclaration(Box<XHPClassAttributeDeclarationChildren<T, V>>), XHPClassAttribute(Box<XHPClassAttributeChildren<T, V>>), XHPSimpleClassAttribute(Box<XHPSimpleClassAttributeChildren<T, V>>), XHPSimpleAttribute(Box<XHPSimpleAttributeChildren<T, V>>), XHPSpreadAttribute(Box<XHPSpreadAttributeChildren<T, V>>), XHPOpen(Box<XHPOpenChildren<T, V>>), XHPExpression(Box<XHPExpressionChildren<T, V>>), XHPClose(Box<XHPCloseChildren<T, V>>), TypeConstant(Box<TypeConstantChildren<T, V>>), VectorTypeSpecifier(Box<VectorTypeSpecifierChildren<T, V>>), KeysetTypeSpecifier(Box<KeysetTypeSpecifierChildren<T, V>>), TupleTypeExplicitSpecifier(Box<TupleTypeExplicitSpecifierChildren<T, V>>), VarrayTypeSpecifier(Box<VarrayTypeSpecifierChildren<T, V>>), FunctionCtxTypeSpecifier(Box<FunctionCtxTypeSpecifierChildren<T, V>>), TypeParameter(Box<TypeParameterChildren<T, V>>), TypeConstraint(Box<TypeConstraintChildren<T, V>>), ContextConstraint(Box<ContextConstraintChildren<T, V>>), DarrayTypeSpecifier(Box<DarrayTypeSpecifierChildren<T, V>>), DictionaryTypeSpecifier(Box<DictionaryTypeSpecifierChildren<T, V>>), ClosureTypeSpecifier(Box<ClosureTypeSpecifierChildren<T, V>>), ClosureParameterTypeSpecifier(Box<ClosureParameterTypeSpecifierChildren<T, V>>), TypeRefinement(Box<TypeRefinementChildren<T, V>>), TypeInRefinement(Box<TypeInRefinementChildren<T, V>>), CtxInRefinement(Box<CtxInRefinementChildren<T, V>>), ClassnameTypeSpecifier(Box<ClassnameTypeSpecifierChildren<T, V>>), FieldSpecifier(Box<FieldSpecifierChildren<T, V>>), FieldInitializer(Box<FieldInitializerChildren<T, V>>), ShapeTypeSpecifier(Box<ShapeTypeSpecifierChildren<T, V>>), ShapeExpression(Box<ShapeExpressionChildren<T, V>>), TupleExpression(Box<TupleExpressionChildren<T, V>>), GenericTypeSpecifier(Box<GenericTypeSpecifierChildren<T, V>>), NullableTypeSpecifier(Box<NullableTypeSpecifierChildren<T, V>>), LikeTypeSpecifier(Box<LikeTypeSpecifierChildren<T, V>>), SoftTypeSpecifier(Box<SoftTypeSpecifierChildren<T, V>>), AttributizedSpecifier(Box<AttributizedSpecifierChildren<T, V>>), ReifiedTypeArgument(Box<ReifiedTypeArgumentChildren<T, V>>), TypeArguments(Box<TypeArgumentsChildren<T, V>>), TypeParameters(Box<TypeParametersChildren<T, V>>), TupleTypeSpecifier(Box<TupleTypeSpecifierChildren<T, V>>), UnionTypeSpecifier(Box<UnionTypeSpecifierChildren<T, V>>), IntersectionTypeSpecifier(Box<IntersectionTypeSpecifierChildren<T, V>>), ErrorSyntax(Box<ErrorSyntaxChildren<T, V>>), ListItem(Box<ListItemChildren<T, V>>), EnumClassLabelExpression(Box<EnumClassLabelExpressionChildren<T, V>>), ModuleDeclaration(Box<ModuleDeclarationChildren<T, V>>), ModuleExports(Box<ModuleExportsChildren<T, V>>), ModuleImports(Box<ModuleImportsChildren<T, V>>), ModuleMembershipDeclaration(Box<ModuleMembershipDeclarationChildren<T, V>>), PackageExpression(Box<PackageExpressionChildren<T, V>>), } impl<'a, T, V> SyntaxChildrenIterator<'a, T, V> { pub fn next_impl(&mut self, direction : bool) -> Option<&'a Syntax<T, V>> { use SyntaxVariant::*; let get_index = |len| { let back_index_plus_1 = len - self.index_back; if back_index_plus_1 <= self.index { return None } if direction { Some (self.index) } else { Some (back_index_plus_1 - 1) } }; let res = match &self.syntax { Missing => None, Token (_) => None, SyntaxList(elems) => { get_index(elems.len()).and_then(|x| elems.get(x)) }, EndOfFile(x) => { get_index(1).and_then(|index| { match index { 0 => Some(&x.end_of_file_token), _ => None, } }) }, Script(x) => { get_index(1).and_then(|index| { match index { 0 => Some(&x.script_declarations), _ => None, } }) }, QualifiedName(x) => { get_index(1).and_then(|index| { match index { 0 => Some(&x.qualified_name_parts), _ => None, } }) }, ModuleName(x) => { get_index(1).and_then(|index| { match index { 0 => Some(&x.module_name_parts), _ => None, } }) }, SimpleTypeSpecifier(x) => { get_index(1).and_then(|index| { match index { 0 => Some(&x.simple_type_specifier), _ => None, } }) }, LiteralExpression(x) => { get_index(1).and_then(|index| { match index { 0 => Some(&x.literal_expression), _ => None, } }) }, PrefixedStringExpression(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.prefixed_string_name), 1 => Some(&x.prefixed_string_str), _ => None, } }) }, PrefixedCodeExpression(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.prefixed_code_prefix), 1 => Some(&x.prefixed_code_left_backtick), 2 => Some(&x.prefixed_code_body), 3 => Some(&x.prefixed_code_right_backtick), _ => None, } }) }, VariableExpression(x) => { get_index(1).and_then(|index| { match index { 0 => Some(&x.variable_expression), _ => None, } }) }, PipeVariableExpression(x) => { get_index(1).and_then(|index| { match index { 0 => Some(&x.pipe_variable_expression), _ => None, } }) }, FileAttributeSpecification(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.file_attribute_specification_left_double_angle), 1 => Some(&x.file_attribute_specification_keyword), 2 => Some(&x.file_attribute_specification_colon), 3 => Some(&x.file_attribute_specification_attributes), 4 => Some(&x.file_attribute_specification_right_double_angle), _ => None, } }) }, EnumDeclaration(x) => { get_index(11).and_then(|index| { match index { 0 => Some(&x.enum_attribute_spec), 1 => Some(&x.enum_modifiers), 2 => Some(&x.enum_keyword), 3 => Some(&x.enum_name), 4 => Some(&x.enum_colon), 5 => Some(&x.enum_base), 6 => Some(&x.enum_type), 7 => Some(&x.enum_left_brace), 8 => Some(&x.enum_use_clauses), 9 => Some(&x.enum_enumerators), 10 => Some(&x.enum_right_brace), _ => None, } }) }, EnumUse(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.enum_use_keyword), 1 => Some(&x.enum_use_names), 2 => Some(&x.enum_use_semicolon), _ => None, } }) }, Enumerator(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.enumerator_name), 1 => Some(&x.enumerator_equal), 2 => Some(&x.enumerator_value), 3 => Some(&x.enumerator_semicolon), _ => None, } }) }, EnumClassDeclaration(x) => { get_index(12).and_then(|index| { match index { 0 => Some(&x.enum_class_attribute_spec), 1 => Some(&x.enum_class_modifiers), 2 => Some(&x.enum_class_enum_keyword), 3 => Some(&x.enum_class_class_keyword), 4 => Some(&x.enum_class_name), 5 => Some(&x.enum_class_colon), 6 => Some(&x.enum_class_base), 7 => Some(&x.enum_class_extends), 8 => Some(&x.enum_class_extends_list), 9 => Some(&x.enum_class_left_brace), 10 => Some(&x.enum_class_elements), 11 => Some(&x.enum_class_right_brace), _ => None, } }) }, EnumClassEnumerator(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.enum_class_enumerator_modifiers), 1 => Some(&x.enum_class_enumerator_type), 2 => Some(&x.enum_class_enumerator_name), 3 => Some(&x.enum_class_enumerator_initializer), 4 => Some(&x.enum_class_enumerator_semicolon), _ => None, } }) }, AliasDeclaration(x) => { get_index(10).and_then(|index| { match index { 0 => Some(&x.alias_attribute_spec), 1 => Some(&x.alias_modifiers), 2 => Some(&x.alias_module_kw_opt), 3 => Some(&x.alias_keyword), 4 => Some(&x.alias_name), 5 => Some(&x.alias_generic_parameter), 6 => Some(&x.alias_constraint), 7 => Some(&x.alias_equal), 8 => Some(&x.alias_type), 9 => Some(&x.alias_semicolon), _ => None, } }) }, ContextAliasDeclaration(x) => { get_index(8).and_then(|index| { match index { 0 => Some(&x.ctx_alias_attribute_spec), 1 => Some(&x.ctx_alias_keyword), 2 => Some(&x.ctx_alias_name), 3 => Some(&x.ctx_alias_generic_parameter), 4 => Some(&x.ctx_alias_as_constraint), 5 => Some(&x.ctx_alias_equal), 6 => Some(&x.ctx_alias_context), 7 => Some(&x.ctx_alias_semicolon), _ => None, } }) }, CaseTypeDeclaration(x) => { get_index(11).and_then(|index| { match index { 0 => Some(&x.case_type_attribute_spec), 1 => Some(&x.case_type_modifiers), 2 => Some(&x.case_type_case_keyword), 3 => Some(&x.case_type_type_keyword), 4 => Some(&x.case_type_name), 5 => Some(&x.case_type_generic_parameter), 6 => Some(&x.case_type_as), 7 => Some(&x.case_type_bounds), 8 => Some(&x.case_type_equal), 9 => Some(&x.case_type_variants), 10 => Some(&x.case_type_semicolon), _ => None, } }) }, CaseTypeVariant(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.case_type_variant_bar), 1 => Some(&x.case_type_variant_type), _ => None, } }) }, PropertyDeclaration(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.property_attribute_spec), 1 => Some(&x.property_modifiers), 2 => Some(&x.property_type), 3 => Some(&x.property_declarators), 4 => Some(&x.property_semicolon), _ => None, } }) }, PropertyDeclarator(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.property_name), 1 => Some(&x.property_initializer), _ => None, } }) }, NamespaceDeclaration(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.namespace_header), 1 => Some(&x.namespace_body), _ => None, } }) }, NamespaceDeclarationHeader(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.namespace_keyword), 1 => Some(&x.namespace_name), _ => None, } }) }, NamespaceBody(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.namespace_left_brace), 1 => Some(&x.namespace_declarations), 2 => Some(&x.namespace_right_brace), _ => None, } }) }, NamespaceEmptyBody(x) => { get_index(1).and_then(|index| { match index { 0 => Some(&x.namespace_semicolon), _ => None, } }) }, NamespaceUseDeclaration(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.namespace_use_keyword), 1 => Some(&x.namespace_use_kind), 2 => Some(&x.namespace_use_clauses), 3 => Some(&x.namespace_use_semicolon), _ => None, } }) }, NamespaceGroupUseDeclaration(x) => { get_index(7).and_then(|index| { match index { 0 => Some(&x.namespace_group_use_keyword), 1 => Some(&x.namespace_group_use_kind), 2 => Some(&x.namespace_group_use_prefix), 3 => Some(&x.namespace_group_use_left_brace), 4 => Some(&x.namespace_group_use_clauses), 5 => Some(&x.namespace_group_use_right_brace), 6 => Some(&x.namespace_group_use_semicolon), _ => None, } }) }, NamespaceUseClause(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.namespace_use_clause_kind), 1 => Some(&x.namespace_use_name), 2 => Some(&x.namespace_use_as), 3 => Some(&x.namespace_use_alias), _ => None, } }) }, FunctionDeclaration(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.function_attribute_spec), 1 => Some(&x.function_declaration_header), 2 => Some(&x.function_body), _ => None, } }) }, FunctionDeclarationHeader(x) => { get_index(12).and_then(|index| { match index { 0 => Some(&x.function_modifiers), 1 => Some(&x.function_keyword), 2 => Some(&x.function_name), 3 => Some(&x.function_type_parameter_list), 4 => Some(&x.function_left_paren), 5 => Some(&x.function_parameter_list), 6 => Some(&x.function_right_paren), 7 => Some(&x.function_contexts), 8 => Some(&x.function_colon), 9 => Some(&x.function_readonly_return), 10 => Some(&x.function_type), 11 => Some(&x.function_where_clause), _ => None, } }) }, Contexts(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.contexts_left_bracket), 1 => Some(&x.contexts_types), 2 => Some(&x.contexts_right_bracket), _ => None, } }) }, WhereClause(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.where_clause_keyword), 1 => Some(&x.where_clause_constraints), _ => None, } }) }, WhereConstraint(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.where_constraint_left_type), 1 => Some(&x.where_constraint_operator), 2 => Some(&x.where_constraint_right_type), _ => None, } }) }, MethodishDeclaration(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.methodish_attribute), 1 => Some(&x.methodish_function_decl_header), 2 => Some(&x.methodish_function_body), 3 => Some(&x.methodish_semicolon), _ => None, } }) }, MethodishTraitResolution(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.methodish_trait_attribute), 1 => Some(&x.methodish_trait_function_decl_header), 2 => Some(&x.methodish_trait_equal), 3 => Some(&x.methodish_trait_name), 4 => Some(&x.methodish_trait_semicolon), _ => None, } }) }, ClassishDeclaration(x) => { get_index(12).and_then(|index| { match index { 0 => Some(&x.classish_attribute), 1 => Some(&x.classish_modifiers), 2 => Some(&x.classish_xhp), 3 => Some(&x.classish_keyword), 4 => Some(&x.classish_name), 5 => Some(&x.classish_type_parameters), 6 => Some(&x.classish_extends_keyword), 7 => Some(&x.classish_extends_list), 8 => Some(&x.classish_implements_keyword), 9 => Some(&x.classish_implements_list), 10 => Some(&x.classish_where_clause), 11 => Some(&x.classish_body), _ => None, } }) }, ClassishBody(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.classish_body_left_brace), 1 => Some(&x.classish_body_elements), 2 => Some(&x.classish_body_right_brace), _ => None, } }) }, TraitUse(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.trait_use_keyword), 1 => Some(&x.trait_use_names), 2 => Some(&x.trait_use_semicolon), _ => None, } }) }, RequireClause(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.require_keyword), 1 => Some(&x.require_kind), 2 => Some(&x.require_name), 3 => Some(&x.require_semicolon), _ => None, } }) }, ConstDeclaration(x) => { get_index(6).and_then(|index| { match index { 0 => Some(&x.const_attribute_spec), 1 => Some(&x.const_modifiers), 2 => Some(&x.const_keyword), 3 => Some(&x.const_type_specifier), 4 => Some(&x.const_declarators), 5 => Some(&x.const_semicolon), _ => None, } }) }, ConstantDeclarator(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.constant_declarator_name), 1 => Some(&x.constant_declarator_initializer), _ => None, } }) }, TypeConstDeclaration(x) => { get_index(10).and_then(|index| { match index { 0 => Some(&x.type_const_attribute_spec), 1 => Some(&x.type_const_modifiers), 2 => Some(&x.type_const_keyword), 3 => Some(&x.type_const_type_keyword), 4 => Some(&x.type_const_name), 5 => Some(&x.type_const_type_parameters), 6 => Some(&x.type_const_type_constraints), 7 => Some(&x.type_const_equal), 8 => Some(&x.type_const_type_specifier), 9 => Some(&x.type_const_semicolon), _ => None, } }) }, ContextConstDeclaration(x) => { get_index(9).and_then(|index| { match index { 0 => Some(&x.context_const_modifiers), 1 => Some(&x.context_const_const_keyword), 2 => Some(&x.context_const_ctx_keyword), 3 => Some(&x.context_const_name), 4 => Some(&x.context_const_type_parameters), 5 => Some(&x.context_const_constraint), 6 => Some(&x.context_const_equal), 7 => Some(&x.context_const_ctx_list), 8 => Some(&x.context_const_semicolon), _ => None, } }) }, DecoratedExpression(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.decorated_expression_decorator), 1 => Some(&x.decorated_expression_expression), _ => None, } }) }, ParameterDeclaration(x) => { get_index(7).and_then(|index| { match index { 0 => Some(&x.parameter_attribute), 1 => Some(&x.parameter_visibility), 2 => Some(&x.parameter_call_convention), 3 => Some(&x.parameter_readonly), 4 => Some(&x.parameter_type), 5 => Some(&x.parameter_name), 6 => Some(&x.parameter_default_value), _ => None, } }) }, VariadicParameter(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.variadic_parameter_call_convention), 1 => Some(&x.variadic_parameter_type), 2 => Some(&x.variadic_parameter_ellipsis), _ => None, } }) }, OldAttributeSpecification(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.old_attribute_specification_left_double_angle), 1 => Some(&x.old_attribute_specification_attributes), 2 => Some(&x.old_attribute_specification_right_double_angle), _ => None, } }) }, AttributeSpecification(x) => { get_index(1).and_then(|index| { match index { 0 => Some(&x.attribute_specification_attributes), _ => None, } }) }, Attribute(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.attribute_at), 1 => Some(&x.attribute_attribute_name), _ => None, } }) }, InclusionExpression(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.inclusion_require), 1 => Some(&x.inclusion_filename), _ => None, } }) }, InclusionDirective(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.inclusion_expression), 1 => Some(&x.inclusion_semicolon), _ => None, } }) }, CompoundStatement(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.compound_left_brace), 1 => Some(&x.compound_statements), 2 => Some(&x.compound_right_brace), _ => None, } }) }, ExpressionStatement(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.expression_statement_expression), 1 => Some(&x.expression_statement_semicolon), _ => None, } }) }, MarkupSection(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.markup_hashbang), 1 => Some(&x.markup_suffix), _ => None, } }) }, MarkupSuffix(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.markup_suffix_less_than_question), 1 => Some(&x.markup_suffix_name), _ => None, } }) }, UnsetStatement(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.unset_keyword), 1 => Some(&x.unset_left_paren), 2 => Some(&x.unset_variables), 3 => Some(&x.unset_right_paren), 4 => Some(&x.unset_semicolon), _ => None, } }) }, DeclareLocalStatement(x) => { get_index(6).and_then(|index| { match index { 0 => Some(&x.declare_local_keyword), 1 => Some(&x.declare_local_variable), 2 => Some(&x.declare_local_colon), 3 => Some(&x.declare_local_type), 4 => Some(&x.declare_local_initializer), 5 => Some(&x.declare_local_semicolon), _ => None, } }) }, UsingStatementBlockScoped(x) => { get_index(6).and_then(|index| { match index { 0 => Some(&x.using_block_await_keyword), 1 => Some(&x.using_block_using_keyword), 2 => Some(&x.using_block_left_paren), 3 => Some(&x.using_block_expressions), 4 => Some(&x.using_block_right_paren), 5 => Some(&x.using_block_body), _ => None, } }) }, UsingStatementFunctionScoped(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.using_function_await_keyword), 1 => Some(&x.using_function_using_keyword), 2 => Some(&x.using_function_expression), 3 => Some(&x.using_function_semicolon), _ => None, } }) }, WhileStatement(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.while_keyword), 1 => Some(&x.while_left_paren), 2 => Some(&x.while_condition), 3 => Some(&x.while_right_paren), 4 => Some(&x.while_body), _ => None, } }) }, IfStatement(x) => { get_index(6).and_then(|index| { match index { 0 => Some(&x.if_keyword), 1 => Some(&x.if_left_paren), 2 => Some(&x.if_condition), 3 => Some(&x.if_right_paren), 4 => Some(&x.if_statement), 5 => Some(&x.if_else_clause), _ => None, } }) }, ElseClause(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.else_keyword), 1 => Some(&x.else_statement), _ => None, } }) }, TryStatement(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.try_keyword), 1 => Some(&x.try_compound_statement), 2 => Some(&x.try_catch_clauses), 3 => Some(&x.try_finally_clause), _ => None, } }) }, CatchClause(x) => { get_index(6).and_then(|index| { match index { 0 => Some(&x.catch_keyword), 1 => Some(&x.catch_left_paren), 2 => Some(&x.catch_type), 3 => Some(&x.catch_variable), 4 => Some(&x.catch_right_paren), 5 => Some(&x.catch_body), _ => None, } }) }, FinallyClause(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.finally_keyword), 1 => Some(&x.finally_body), _ => None, } }) }, DoStatement(x) => { get_index(7).and_then(|index| { match index { 0 => Some(&x.do_keyword), 1 => Some(&x.do_body), 2 => Some(&x.do_while_keyword), 3 => Some(&x.do_left_paren), 4 => Some(&x.do_condition), 5 => Some(&x.do_right_paren), 6 => Some(&x.do_semicolon), _ => None, } }) }, ForStatement(x) => { get_index(9).and_then(|index| { match index { 0 => Some(&x.for_keyword), 1 => Some(&x.for_left_paren), 2 => Some(&x.for_initializer), 3 => Some(&x.for_first_semicolon), 4 => Some(&x.for_control), 5 => Some(&x.for_second_semicolon), 6 => Some(&x.for_end_of_loop), 7 => Some(&x.for_right_paren), 8 => Some(&x.for_body), _ => None, } }) }, ForeachStatement(x) => { get_index(10).and_then(|index| { match index { 0 => Some(&x.foreach_keyword), 1 => Some(&x.foreach_left_paren), 2 => Some(&x.foreach_collection), 3 => Some(&x.foreach_await_keyword), 4 => Some(&x.foreach_as), 5 => Some(&x.foreach_key), 6 => Some(&x.foreach_arrow), 7 => Some(&x.foreach_value), 8 => Some(&x.foreach_right_paren), 9 => Some(&x.foreach_body), _ => None, } }) }, SwitchStatement(x) => { get_index(7).and_then(|index| { match index { 0 => Some(&x.switch_keyword), 1 => Some(&x.switch_left_paren), 2 => Some(&x.switch_expression), 3 => Some(&x.switch_right_paren), 4 => Some(&x.switch_left_brace), 5 => Some(&x.switch_sections), 6 => Some(&x.switch_right_brace), _ => None, } }) }, SwitchSection(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.switch_section_labels), 1 => Some(&x.switch_section_statements), 2 => Some(&x.switch_section_fallthrough), _ => None, } }) }, SwitchFallthrough(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.fallthrough_keyword), 1 => Some(&x.fallthrough_semicolon), _ => None, } }) }, CaseLabel(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.case_keyword), 1 => Some(&x.case_expression), 2 => Some(&x.case_colon), _ => None, } }) }, DefaultLabel(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.default_keyword), 1 => Some(&x.default_colon), _ => None, } }) }, MatchStatement(x) => { get_index(7).and_then(|index| { match index { 0 => Some(&x.match_statement_keyword), 1 => Some(&x.match_statement_left_paren), 2 => Some(&x.match_statement_expression), 3 => Some(&x.match_statement_right_paren), 4 => Some(&x.match_statement_left_brace), 5 => Some(&x.match_statement_arms), 6 => Some(&x.match_statement_right_brace), _ => None, } }) }, MatchStatementArm(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.match_statement_arm_pattern), 1 => Some(&x.match_statement_arm_arrow), 2 => Some(&x.match_statement_arm_body), _ => None, } }) }, ReturnStatement(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.return_keyword), 1 => Some(&x.return_expression), 2 => Some(&x.return_semicolon), _ => None, } }) }, YieldBreakStatement(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.yield_break_keyword), 1 => Some(&x.yield_break_break), 2 => Some(&x.yield_break_semicolon), _ => None, } }) }, ThrowStatement(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.throw_keyword), 1 => Some(&x.throw_expression), 2 => Some(&x.throw_semicolon), _ => None, } }) }, BreakStatement(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.break_keyword), 1 => Some(&x.break_semicolon), _ => None, } }) }, ContinueStatement(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.continue_keyword), 1 => Some(&x.continue_semicolon), _ => None, } }) }, EchoStatement(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.echo_keyword), 1 => Some(&x.echo_expressions), 2 => Some(&x.echo_semicolon), _ => None, } }) }, ConcurrentStatement(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.concurrent_keyword), 1 => Some(&x.concurrent_statement), _ => None, } }) }, SimpleInitializer(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.simple_initializer_equal), 1 => Some(&x.simple_initializer_value), _ => None, } }) }, AnonymousClass(x) => { get_index(9).and_then(|index| { match index { 0 => Some(&x.anonymous_class_class_keyword), 1 => Some(&x.anonymous_class_left_paren), 2 => Some(&x.anonymous_class_argument_list), 3 => Some(&x.anonymous_class_right_paren), 4 => Some(&x.anonymous_class_extends_keyword), 5 => Some(&x.anonymous_class_extends_list), 6 => Some(&x.anonymous_class_implements_keyword), 7 => Some(&x.anonymous_class_implements_list), 8 => Some(&x.anonymous_class_body), _ => None, } }) }, AnonymousFunction(x) => { get_index(12).and_then(|index| { match index { 0 => Some(&x.anonymous_attribute_spec), 1 => Some(&x.anonymous_async_keyword), 2 => Some(&x.anonymous_function_keyword), 3 => Some(&x.anonymous_left_paren), 4 => Some(&x.anonymous_parameters), 5 => Some(&x.anonymous_right_paren), 6 => Some(&x.anonymous_ctx_list), 7 => Some(&x.anonymous_colon), 8 => Some(&x.anonymous_readonly_return), 9 => Some(&x.anonymous_type), 10 => Some(&x.anonymous_use), 11 => Some(&x.anonymous_body), _ => None, } }) }, AnonymousFunctionUseClause(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.anonymous_use_keyword), 1 => Some(&x.anonymous_use_left_paren), 2 => Some(&x.anonymous_use_variables), 3 => Some(&x.anonymous_use_right_paren), _ => None, } }) }, VariablePattern(x) => { get_index(1).and_then(|index| { match index { 0 => Some(&x.variable_pattern_variable), _ => None, } }) }, ConstructorPattern(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.constructor_pattern_constructor), 1 => Some(&x.constructor_pattern_left_paren), 2 => Some(&x.constructor_pattern_members), 3 => Some(&x.constructor_pattern_right_paren), _ => None, } }) }, RefinementPattern(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.refinement_pattern_variable), 1 => Some(&x.refinement_pattern_colon), 2 => Some(&x.refinement_pattern_specifier), _ => None, } }) }, LambdaExpression(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.lambda_attribute_spec), 1 => Some(&x.lambda_async), 2 => Some(&x.lambda_signature), 3 => Some(&x.lambda_arrow), 4 => Some(&x.lambda_body), _ => None, } }) }, LambdaSignature(x) => { get_index(7).and_then(|index| { match index { 0 => Some(&x.lambda_left_paren), 1 => Some(&x.lambda_parameters), 2 => Some(&x.lambda_right_paren), 3 => Some(&x.lambda_contexts), 4 => Some(&x.lambda_colon), 5 => Some(&x.lambda_readonly_return), 6 => Some(&x.lambda_type), _ => None, } }) }, CastExpression(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.cast_left_paren), 1 => Some(&x.cast_type), 2 => Some(&x.cast_right_paren), 3 => Some(&x.cast_operand), _ => None, } }) }, ScopeResolutionExpression(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.scope_resolution_qualifier), 1 => Some(&x.scope_resolution_operator), 2 => Some(&x.scope_resolution_name), _ => None, } }) }, MemberSelectionExpression(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.member_object), 1 => Some(&x.member_operator), 2 => Some(&x.member_name), _ => None, } }) }, SafeMemberSelectionExpression(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.safe_member_object), 1 => Some(&x.safe_member_operator), 2 => Some(&x.safe_member_name), _ => None, } }) }, EmbeddedMemberSelectionExpression(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.embedded_member_object), 1 => Some(&x.embedded_member_operator), 2 => Some(&x.embedded_member_name), _ => None, } }) }, YieldExpression(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.yield_keyword), 1 => Some(&x.yield_operand), _ => None, } }) }, PrefixUnaryExpression(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.prefix_unary_operator), 1 => Some(&x.prefix_unary_operand), _ => None, } }) }, PostfixUnaryExpression(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.postfix_unary_operand), 1 => Some(&x.postfix_unary_operator), _ => None, } }) }, BinaryExpression(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.binary_left_operand), 1 => Some(&x.binary_operator), 2 => Some(&x.binary_right_operand), _ => None, } }) }, IsExpression(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.is_left_operand), 1 => Some(&x.is_operator), 2 => Some(&x.is_right_operand), _ => None, } }) }, AsExpression(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.as_left_operand), 1 => Some(&x.as_operator), 2 => Some(&x.as_right_operand), _ => None, } }) }, NullableAsExpression(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.nullable_as_left_operand), 1 => Some(&x.nullable_as_operator), 2 => Some(&x.nullable_as_right_operand), _ => None, } }) }, UpcastExpression(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.upcast_left_operand), 1 => Some(&x.upcast_operator), 2 => Some(&x.upcast_right_operand), _ => None, } }) }, ConditionalExpression(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.conditional_test), 1 => Some(&x.conditional_question), 2 => Some(&x.conditional_consequence), 3 => Some(&x.conditional_colon), 4 => Some(&x.conditional_alternative), _ => None, } }) }, EvalExpression(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.eval_keyword), 1 => Some(&x.eval_left_paren), 2 => Some(&x.eval_argument), 3 => Some(&x.eval_right_paren), _ => None, } }) }, IssetExpression(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.isset_keyword), 1 => Some(&x.isset_left_paren), 2 => Some(&x.isset_argument_list), 3 => Some(&x.isset_right_paren), _ => None, } }) }, FunctionCallExpression(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.function_call_receiver), 1 => Some(&x.function_call_type_args), 2 => Some(&x.function_call_left_paren), 3 => Some(&x.function_call_argument_list), 4 => Some(&x.function_call_right_paren), _ => None, } }) }, FunctionPointerExpression(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.function_pointer_receiver), 1 => Some(&x.function_pointer_type_args), _ => None, } }) }, ParenthesizedExpression(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.parenthesized_expression_left_paren), 1 => Some(&x.parenthesized_expression_expression), 2 => Some(&x.parenthesized_expression_right_paren), _ => None, } }) }, BracedExpression(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.braced_expression_left_brace), 1 => Some(&x.braced_expression_expression), 2 => Some(&x.braced_expression_right_brace), _ => None, } }) }, ETSpliceExpression(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.et_splice_expression_dollar), 1 => Some(&x.et_splice_expression_left_brace), 2 => Some(&x.et_splice_expression_expression), 3 => Some(&x.et_splice_expression_right_brace), _ => None, } }) }, EmbeddedBracedExpression(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.embedded_braced_expression_left_brace), 1 => Some(&x.embedded_braced_expression_expression), 2 => Some(&x.embedded_braced_expression_right_brace), _ => None, } }) }, ListExpression(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.list_keyword), 1 => Some(&x.list_left_paren), 2 => Some(&x.list_members), 3 => Some(&x.list_right_paren), _ => None, } }) }, CollectionLiteralExpression(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.collection_literal_name), 1 => Some(&x.collection_literal_left_brace), 2 => Some(&x.collection_literal_initializers), 3 => Some(&x.collection_literal_right_brace), _ => None, } }) }, ObjectCreationExpression(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.object_creation_new_keyword), 1 => Some(&x.object_creation_object), _ => None, } }) }, ConstructorCall(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.constructor_call_type), 1 => Some(&x.constructor_call_left_paren), 2 => Some(&x.constructor_call_argument_list), 3 => Some(&x.constructor_call_right_paren), _ => None, } }) }, DarrayIntrinsicExpression(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.darray_intrinsic_keyword), 1 => Some(&x.darray_intrinsic_explicit_type), 2 => Some(&x.darray_intrinsic_left_bracket), 3 => Some(&x.darray_intrinsic_members), 4 => Some(&x.darray_intrinsic_right_bracket), _ => None, } }) }, DictionaryIntrinsicExpression(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.dictionary_intrinsic_keyword), 1 => Some(&x.dictionary_intrinsic_explicit_type), 2 => Some(&x.dictionary_intrinsic_left_bracket), 3 => Some(&x.dictionary_intrinsic_members), 4 => Some(&x.dictionary_intrinsic_right_bracket), _ => None, } }) }, KeysetIntrinsicExpression(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.keyset_intrinsic_keyword), 1 => Some(&x.keyset_intrinsic_explicit_type), 2 => Some(&x.keyset_intrinsic_left_bracket), 3 => Some(&x.keyset_intrinsic_members), 4 => Some(&x.keyset_intrinsic_right_bracket), _ => None, } }) }, VarrayIntrinsicExpression(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.varray_intrinsic_keyword), 1 => Some(&x.varray_intrinsic_explicit_type), 2 => Some(&x.varray_intrinsic_left_bracket), 3 => Some(&x.varray_intrinsic_members), 4 => Some(&x.varray_intrinsic_right_bracket), _ => None, } }) }, VectorIntrinsicExpression(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.vector_intrinsic_keyword), 1 => Some(&x.vector_intrinsic_explicit_type), 2 => Some(&x.vector_intrinsic_left_bracket), 3 => Some(&x.vector_intrinsic_members), 4 => Some(&x.vector_intrinsic_right_bracket), _ => None, } }) }, ElementInitializer(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.element_key), 1 => Some(&x.element_arrow), 2 => Some(&x.element_value), _ => None, } }) }, SubscriptExpression(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.subscript_receiver), 1 => Some(&x.subscript_left_bracket), 2 => Some(&x.subscript_index), 3 => Some(&x.subscript_right_bracket), _ => None, } }) }, EmbeddedSubscriptExpression(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.embedded_subscript_receiver), 1 => Some(&x.embedded_subscript_left_bracket), 2 => Some(&x.embedded_subscript_index), 3 => Some(&x.embedded_subscript_right_bracket), _ => None, } }) }, AwaitableCreationExpression(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.awaitable_attribute_spec), 1 => Some(&x.awaitable_async), 2 => Some(&x.awaitable_compound_statement), _ => None, } }) }, XHPChildrenDeclaration(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.xhp_children_keyword), 1 => Some(&x.xhp_children_expression), 2 => Some(&x.xhp_children_semicolon), _ => None, } }) }, XHPChildrenParenthesizedList(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.xhp_children_list_left_paren), 1 => Some(&x.xhp_children_list_xhp_children), 2 => Some(&x.xhp_children_list_right_paren), _ => None, } }) }, XHPCategoryDeclaration(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.xhp_category_keyword), 1 => Some(&x.xhp_category_categories), 2 => Some(&x.xhp_category_semicolon), _ => None, } }) }, XHPEnumType(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.xhp_enum_like), 1 => Some(&x.xhp_enum_keyword), 2 => Some(&x.xhp_enum_left_brace), 3 => Some(&x.xhp_enum_values), 4 => Some(&x.xhp_enum_right_brace), _ => None, } }) }, XHPLateinit(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.xhp_lateinit_at), 1 => Some(&x.xhp_lateinit_keyword), _ => None, } }) }, XHPRequired(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.xhp_required_at), 1 => Some(&x.xhp_required_keyword), _ => None, } }) }, XHPClassAttributeDeclaration(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.xhp_attribute_keyword), 1 => Some(&x.xhp_attribute_attributes), 2 => Some(&x.xhp_attribute_semicolon), _ => None, } }) }, XHPClassAttribute(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.xhp_attribute_decl_type), 1 => Some(&x.xhp_attribute_decl_name), 2 => Some(&x.xhp_attribute_decl_initializer), 3 => Some(&x.xhp_attribute_decl_required), _ => None, } }) }, XHPSimpleClassAttribute(x) => { get_index(1).and_then(|index| { match index { 0 => Some(&x.xhp_simple_class_attribute_type), _ => None, } }) }, XHPSimpleAttribute(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.xhp_simple_attribute_name), 1 => Some(&x.xhp_simple_attribute_equal), 2 => Some(&x.xhp_simple_attribute_expression), _ => None, } }) }, XHPSpreadAttribute(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.xhp_spread_attribute_left_brace), 1 => Some(&x.xhp_spread_attribute_spread_operator), 2 => Some(&x.xhp_spread_attribute_expression), 3 => Some(&x.xhp_spread_attribute_right_brace), _ => None, } }) }, XHPOpen(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.xhp_open_left_angle), 1 => Some(&x.xhp_open_name), 2 => Some(&x.xhp_open_attributes), 3 => Some(&x.xhp_open_right_angle), _ => None, } }) }, XHPExpression(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.xhp_open), 1 => Some(&x.xhp_body), 2 => Some(&x.xhp_close), _ => None, } }) }, XHPClose(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.xhp_close_left_angle), 1 => Some(&x.xhp_close_name), 2 => Some(&x.xhp_close_right_angle), _ => None, } }) }, TypeConstant(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.type_constant_left_type), 1 => Some(&x.type_constant_separator), 2 => Some(&x.type_constant_right_type), _ => None, } }) }, VectorTypeSpecifier(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.vector_type_keyword), 1 => Some(&x.vector_type_left_angle), 2 => Some(&x.vector_type_type), 3 => Some(&x.vector_type_trailing_comma), 4 => Some(&x.vector_type_right_angle), _ => None, } }) }, KeysetTypeSpecifier(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.keyset_type_keyword), 1 => Some(&x.keyset_type_left_angle), 2 => Some(&x.keyset_type_type), 3 => Some(&x.keyset_type_trailing_comma), 4 => Some(&x.keyset_type_right_angle), _ => None, } }) }, TupleTypeExplicitSpecifier(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.tuple_type_keyword), 1 => Some(&x.tuple_type_left_angle), 2 => Some(&x.tuple_type_types), 3 => Some(&x.tuple_type_right_angle), _ => None, } }) }, VarrayTypeSpecifier(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.varray_keyword), 1 => Some(&x.varray_left_angle), 2 => Some(&x.varray_type), 3 => Some(&x.varray_trailing_comma), 4 => Some(&x.varray_right_angle), _ => None, } }) }, FunctionCtxTypeSpecifier(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.function_ctx_type_keyword), 1 => Some(&x.function_ctx_type_variable), _ => None, } }) }, TypeParameter(x) => { get_index(6).and_then(|index| { match index { 0 => Some(&x.type_attribute_spec), 1 => Some(&x.type_reified), 2 => Some(&x.type_variance), 3 => Some(&x.type_name), 4 => Some(&x.type_param_params), 5 => Some(&x.type_constraints), _ => None, } }) }, TypeConstraint(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.constraint_keyword), 1 => Some(&x.constraint_type), _ => None, } }) }, ContextConstraint(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.ctx_constraint_keyword), 1 => Some(&x.ctx_constraint_ctx_list), _ => None, } }) }, DarrayTypeSpecifier(x) => { get_index(7).and_then(|index| { match index { 0 => Some(&x.darray_keyword), 1 => Some(&x.darray_left_angle), 2 => Some(&x.darray_key), 3 => Some(&x.darray_comma), 4 => Some(&x.darray_value), 5 => Some(&x.darray_trailing_comma), 6 => Some(&x.darray_right_angle), _ => None, } }) }, DictionaryTypeSpecifier(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.dictionary_type_keyword), 1 => Some(&x.dictionary_type_left_angle), 2 => Some(&x.dictionary_type_members), 3 => Some(&x.dictionary_type_right_angle), _ => None, } }) }, ClosureTypeSpecifier(x) => { get_index(11).and_then(|index| { match index { 0 => Some(&x.closure_outer_left_paren), 1 => Some(&x.closure_readonly_keyword), 2 => Some(&x.closure_function_keyword), 3 => Some(&x.closure_inner_left_paren), 4 => Some(&x.closure_parameter_list), 5 => Some(&x.closure_inner_right_paren), 6 => Some(&x.closure_contexts), 7 => Some(&x.closure_colon), 8 => Some(&x.closure_readonly_return), 9 => Some(&x.closure_return_type), 10 => Some(&x.closure_outer_right_paren), _ => None, } }) }, ClosureParameterTypeSpecifier(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.closure_parameter_call_convention), 1 => Some(&x.closure_parameter_readonly), 2 => Some(&x.closure_parameter_type), _ => None, } }) }, TypeRefinement(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.type_refinement_type), 1 => Some(&x.type_refinement_keyword), 2 => Some(&x.type_refinement_left_brace), 3 => Some(&x.type_refinement_members), 4 => Some(&x.type_refinement_right_brace), _ => None, } }) }, TypeInRefinement(x) => { get_index(6).and_then(|index| { match index { 0 => Some(&x.type_in_refinement_keyword), 1 => Some(&x.type_in_refinement_name), 2 => Some(&x.type_in_refinement_type_parameters), 3 => Some(&x.type_in_refinement_constraints), 4 => Some(&x.type_in_refinement_equal), 5 => Some(&x.type_in_refinement_type), _ => None, } }) }, CtxInRefinement(x) => { get_index(6).and_then(|index| { match index { 0 => Some(&x.ctx_in_refinement_keyword), 1 => Some(&x.ctx_in_refinement_name), 2 => Some(&x.ctx_in_refinement_type_parameters), 3 => Some(&x.ctx_in_refinement_constraints), 4 => Some(&x.ctx_in_refinement_equal), 5 => Some(&x.ctx_in_refinement_ctx_list), _ => None, } }) }, ClassnameTypeSpecifier(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.classname_keyword), 1 => Some(&x.classname_left_angle), 2 => Some(&x.classname_type), 3 => Some(&x.classname_trailing_comma), 4 => Some(&x.classname_right_angle), _ => None, } }) }, FieldSpecifier(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.field_question), 1 => Some(&x.field_name), 2 => Some(&x.field_arrow), 3 => Some(&x.field_type), _ => None, } }) }, FieldInitializer(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.field_initializer_name), 1 => Some(&x.field_initializer_arrow), 2 => Some(&x.field_initializer_value), _ => None, } }) }, ShapeTypeSpecifier(x) => { get_index(5).and_then(|index| { match index { 0 => Some(&x.shape_type_keyword), 1 => Some(&x.shape_type_left_paren), 2 => Some(&x.shape_type_fields), 3 => Some(&x.shape_type_ellipsis), 4 => Some(&x.shape_type_right_paren), _ => None, } }) }, ShapeExpression(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.shape_expression_keyword), 1 => Some(&x.shape_expression_left_paren), 2 => Some(&x.shape_expression_fields), 3 => Some(&x.shape_expression_right_paren), _ => None, } }) }, TupleExpression(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.tuple_expression_keyword), 1 => Some(&x.tuple_expression_left_paren), 2 => Some(&x.tuple_expression_items), 3 => Some(&x.tuple_expression_right_paren), _ => None, } }) }, GenericTypeSpecifier(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.generic_class_type), 1 => Some(&x.generic_argument_list), _ => None, } }) }, NullableTypeSpecifier(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.nullable_question), 1 => Some(&x.nullable_type), _ => None, } }) }, LikeTypeSpecifier(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.like_tilde), 1 => Some(&x.like_type), _ => None, } }) }, SoftTypeSpecifier(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.soft_at), 1 => Some(&x.soft_type), _ => None, } }) }, AttributizedSpecifier(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.attributized_specifier_attribute_spec), 1 => Some(&x.attributized_specifier_type), _ => None, } }) }, ReifiedTypeArgument(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.reified_type_argument_reified), 1 => Some(&x.reified_type_argument_type), _ => None, } }) }, TypeArguments(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.type_arguments_left_angle), 1 => Some(&x.type_arguments_types), 2 => Some(&x.type_arguments_right_angle), _ => None, } }) }, TypeParameters(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.type_parameters_left_angle), 1 => Some(&x.type_parameters_parameters), 2 => Some(&x.type_parameters_right_angle), _ => None, } }) }, TupleTypeSpecifier(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.tuple_left_paren), 1 => Some(&x.tuple_types), 2 => Some(&x.tuple_right_paren), _ => None, } }) }, UnionTypeSpecifier(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.union_left_paren), 1 => Some(&x.union_types), 2 => Some(&x.union_right_paren), _ => None, } }) }, IntersectionTypeSpecifier(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.intersection_left_paren), 1 => Some(&x.intersection_types), 2 => Some(&x.intersection_right_paren), _ => None, } }) }, ErrorSyntax(x) => { get_index(1).and_then(|index| { match index { 0 => Some(&x.error_error), _ => None, } }) }, ListItem(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.list_item), 1 => Some(&x.list_separator), _ => None, } }) }, EnumClassLabelExpression(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.enum_class_label_qualifier), 1 => Some(&x.enum_class_label_hash), 2 => Some(&x.enum_class_label_expression), _ => None, } }) }, ModuleDeclaration(x) => { get_index(8).and_then(|index| { match index { 0 => Some(&x.module_declaration_attribute_spec), 1 => Some(&x.module_declaration_new_keyword), 2 => Some(&x.module_declaration_module_keyword), 3 => Some(&x.module_declaration_name), 4 => Some(&x.module_declaration_left_brace), 5 => Some(&x.module_declaration_exports), 6 => Some(&x.module_declaration_imports), 7 => Some(&x.module_declaration_right_brace), _ => None, } }) }, ModuleExports(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.module_exports_exports_keyword), 1 => Some(&x.module_exports_left_brace), 2 => Some(&x.module_exports_exports), 3 => Some(&x.module_exports_right_brace), _ => None, } }) }, ModuleImports(x) => { get_index(4).and_then(|index| { match index { 0 => Some(&x.module_imports_imports_keyword), 1 => Some(&x.module_imports_left_brace), 2 => Some(&x.module_imports_imports), 3 => Some(&x.module_imports_right_brace), _ => None, } }) }, ModuleMembershipDeclaration(x) => { get_index(3).and_then(|index| { match index { 0 => Some(&x.module_membership_declaration_module_keyword), 1 => Some(&x.module_membership_declaration_name), 2 => Some(&x.module_membership_declaration_semicolon), _ => None, } }) }, PackageExpression(x) => { get_index(2).and_then(|index| { match index { 0 => Some(&x.package_expression_keyword), 1 => Some(&x.package_expression_name), _ => None, } }) }, }; if res.is_some() { if direction { self.index = self.index + 1 } else { self.index_back = self.index_back + 1 } } res } }
Rust
hhvm/hphp/hack/src/parser/syntax_kind.rs
/** * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. An additional * directory. * ** * * THIS FILE IS @generated; DO NOT EDIT IT * To regenerate this file, run * * buck run //hphp/hack/src:generate_full_fidelity * ** * */ use ocamlrep::{FromOcamlRep, ToOcamlRep}; use crate::token_kind::TokenKind; #[derive(Debug, Copy, Clone, FromOcamlRep, ToOcamlRep, PartialEq)] pub enum SyntaxKind { Missing, Token(TokenKind), SyntaxList, EndOfFile, Script, QualifiedName, ModuleName, SimpleTypeSpecifier, LiteralExpression, PrefixedStringExpression, PrefixedCodeExpression, VariableExpression, PipeVariableExpression, FileAttributeSpecification, EnumDeclaration, EnumUse, Enumerator, EnumClassDeclaration, EnumClassEnumerator, AliasDeclaration, ContextAliasDeclaration, CaseTypeDeclaration, CaseTypeVariant, PropertyDeclaration, PropertyDeclarator, NamespaceDeclaration, NamespaceDeclarationHeader, NamespaceBody, NamespaceEmptyBody, NamespaceUseDeclaration, NamespaceGroupUseDeclaration, NamespaceUseClause, FunctionDeclaration, FunctionDeclarationHeader, Contexts, WhereClause, WhereConstraint, MethodishDeclaration, MethodishTraitResolution, ClassishDeclaration, ClassishBody, TraitUse, RequireClause, ConstDeclaration, ConstantDeclarator, TypeConstDeclaration, ContextConstDeclaration, DecoratedExpression, ParameterDeclaration, VariadicParameter, OldAttributeSpecification, AttributeSpecification, Attribute, InclusionExpression, InclusionDirective, CompoundStatement, ExpressionStatement, MarkupSection, MarkupSuffix, UnsetStatement, DeclareLocalStatement, UsingStatementBlockScoped, UsingStatementFunctionScoped, WhileStatement, IfStatement, ElseClause, TryStatement, CatchClause, FinallyClause, DoStatement, ForStatement, ForeachStatement, SwitchStatement, SwitchSection, SwitchFallthrough, CaseLabel, DefaultLabel, MatchStatement, MatchStatementArm, ReturnStatement, YieldBreakStatement, ThrowStatement, BreakStatement, ContinueStatement, EchoStatement, ConcurrentStatement, SimpleInitializer, AnonymousClass, AnonymousFunction, AnonymousFunctionUseClause, VariablePattern, ConstructorPattern, RefinementPattern, LambdaExpression, LambdaSignature, CastExpression, ScopeResolutionExpression, MemberSelectionExpression, SafeMemberSelectionExpression, EmbeddedMemberSelectionExpression, YieldExpression, PrefixUnaryExpression, PostfixUnaryExpression, BinaryExpression, IsExpression, AsExpression, NullableAsExpression, UpcastExpression, ConditionalExpression, EvalExpression, IssetExpression, FunctionCallExpression, FunctionPointerExpression, ParenthesizedExpression, BracedExpression, ETSpliceExpression, EmbeddedBracedExpression, ListExpression, CollectionLiteralExpression, ObjectCreationExpression, ConstructorCall, DarrayIntrinsicExpression, DictionaryIntrinsicExpression, KeysetIntrinsicExpression, VarrayIntrinsicExpression, VectorIntrinsicExpression, ElementInitializer, SubscriptExpression, EmbeddedSubscriptExpression, AwaitableCreationExpression, XHPChildrenDeclaration, XHPChildrenParenthesizedList, XHPCategoryDeclaration, XHPEnumType, XHPLateinit, XHPRequired, XHPClassAttributeDeclaration, XHPClassAttribute, XHPSimpleClassAttribute, XHPSimpleAttribute, XHPSpreadAttribute, XHPOpen, XHPExpression, XHPClose, TypeConstant, VectorTypeSpecifier, KeysetTypeSpecifier, TupleTypeExplicitSpecifier, VarrayTypeSpecifier, FunctionCtxTypeSpecifier, TypeParameter, TypeConstraint, ContextConstraint, DarrayTypeSpecifier, DictionaryTypeSpecifier, ClosureTypeSpecifier, ClosureParameterTypeSpecifier, TypeRefinement, TypeInRefinement, CtxInRefinement, ClassnameTypeSpecifier, FieldSpecifier, FieldInitializer, ShapeTypeSpecifier, ShapeExpression, TupleExpression, GenericTypeSpecifier, NullableTypeSpecifier, LikeTypeSpecifier, SoftTypeSpecifier, AttributizedSpecifier, ReifiedTypeArgument, TypeArguments, TypeParameters, TupleTypeSpecifier, UnionTypeSpecifier, IntersectionTypeSpecifier, ErrorSyntax, ListItem, EnumClassLabelExpression, ModuleDeclaration, ModuleExports, ModuleImports, ModuleMembershipDeclaration, PackageExpression, } impl SyntaxKind { pub fn to_string(&self) -> &str { match self { SyntaxKind::SyntaxList => "list", SyntaxKind::Missing => "missing", SyntaxKind::Token(_) => "token", SyntaxKind::EndOfFile => "end_of_file", SyntaxKind::Script => "script", SyntaxKind::QualifiedName => "qualified_name", SyntaxKind::ModuleName => "module_name", SyntaxKind::SimpleTypeSpecifier => "simple_type_specifier", SyntaxKind::LiteralExpression => "literal", SyntaxKind::PrefixedStringExpression => "prefixed_string", SyntaxKind::PrefixedCodeExpression => "prefixed_code", SyntaxKind::VariableExpression => "variable", SyntaxKind::PipeVariableExpression => "pipe_variable", SyntaxKind::FileAttributeSpecification => "file_attribute_specification", SyntaxKind::EnumDeclaration => "enum_declaration", SyntaxKind::EnumUse => "enum_use", SyntaxKind::Enumerator => "enumerator", SyntaxKind::EnumClassDeclaration => "enum_class_declaration", SyntaxKind::EnumClassEnumerator => "enum_class_enumerator", SyntaxKind::AliasDeclaration => "alias_declaration", SyntaxKind::ContextAliasDeclaration => "context_alias_declaration", SyntaxKind::CaseTypeDeclaration => "case_type_declaration", SyntaxKind::CaseTypeVariant => "case_type_variant", SyntaxKind::PropertyDeclaration => "property_declaration", SyntaxKind::PropertyDeclarator => "property_declarator", SyntaxKind::NamespaceDeclaration => "namespace_declaration", SyntaxKind::NamespaceDeclarationHeader => "namespace_declaration_header", SyntaxKind::NamespaceBody => "namespace_body", SyntaxKind::NamespaceEmptyBody => "namespace_empty_body", SyntaxKind::NamespaceUseDeclaration => "namespace_use_declaration", SyntaxKind::NamespaceGroupUseDeclaration => "namespace_group_use_declaration", SyntaxKind::NamespaceUseClause => "namespace_use_clause", SyntaxKind::FunctionDeclaration => "function_declaration", SyntaxKind::FunctionDeclarationHeader => "function_declaration_header", SyntaxKind::Contexts => "contexts", SyntaxKind::WhereClause => "where_clause", SyntaxKind::WhereConstraint => "where_constraint", SyntaxKind::MethodishDeclaration => "methodish_declaration", SyntaxKind::MethodishTraitResolution => "methodish_trait_resolution", SyntaxKind::ClassishDeclaration => "classish_declaration", SyntaxKind::ClassishBody => "classish_body", SyntaxKind::TraitUse => "trait_use", SyntaxKind::RequireClause => "require_clause", SyntaxKind::ConstDeclaration => "const_declaration", SyntaxKind::ConstantDeclarator => "constant_declarator", SyntaxKind::TypeConstDeclaration => "type_const_declaration", SyntaxKind::ContextConstDeclaration => "context_const_declaration", SyntaxKind::DecoratedExpression => "decorated_expression", SyntaxKind::ParameterDeclaration => "parameter_declaration", SyntaxKind::VariadicParameter => "variadic_parameter", SyntaxKind::OldAttributeSpecification => "old_attribute_specification", SyntaxKind::AttributeSpecification => "attribute_specification", SyntaxKind::Attribute => "attribute", SyntaxKind::InclusionExpression => "inclusion_expression", SyntaxKind::InclusionDirective => "inclusion_directive", SyntaxKind::CompoundStatement => "compound_statement", SyntaxKind::ExpressionStatement => "expression_statement", SyntaxKind::MarkupSection => "markup_section", SyntaxKind::MarkupSuffix => "markup_suffix", SyntaxKind::UnsetStatement => "unset_statement", SyntaxKind::DeclareLocalStatement => "declare_local_statement", SyntaxKind::UsingStatementBlockScoped => "using_statement_block_scoped", SyntaxKind::UsingStatementFunctionScoped => "using_statement_function_scoped", SyntaxKind::WhileStatement => "while_statement", SyntaxKind::IfStatement => "if_statement", SyntaxKind::ElseClause => "else_clause", SyntaxKind::TryStatement => "try_statement", SyntaxKind::CatchClause => "catch_clause", SyntaxKind::FinallyClause => "finally_clause", SyntaxKind::DoStatement => "do_statement", SyntaxKind::ForStatement => "for_statement", SyntaxKind::ForeachStatement => "foreach_statement", SyntaxKind::SwitchStatement => "switch_statement", SyntaxKind::SwitchSection => "switch_section", SyntaxKind::SwitchFallthrough => "switch_fallthrough", SyntaxKind::CaseLabel => "case_label", SyntaxKind::DefaultLabel => "default_label", SyntaxKind::MatchStatement => "match_statement", SyntaxKind::MatchStatementArm => "match_statement_arm", SyntaxKind::ReturnStatement => "return_statement", SyntaxKind::YieldBreakStatement => "yield_break_statement", SyntaxKind::ThrowStatement => "throw_statement", SyntaxKind::BreakStatement => "break_statement", SyntaxKind::ContinueStatement => "continue_statement", SyntaxKind::EchoStatement => "echo_statement", SyntaxKind::ConcurrentStatement => "concurrent_statement", SyntaxKind::SimpleInitializer => "simple_initializer", SyntaxKind::AnonymousClass => "anonymous_class", SyntaxKind::AnonymousFunction => "anonymous_function", SyntaxKind::AnonymousFunctionUseClause => "anonymous_function_use_clause", SyntaxKind::VariablePattern => "variable_pattern", SyntaxKind::ConstructorPattern => "constructor_pattern", SyntaxKind::RefinementPattern => "refinement_pattern", SyntaxKind::LambdaExpression => "lambda_expression", SyntaxKind::LambdaSignature => "lambda_signature", SyntaxKind::CastExpression => "cast_expression", SyntaxKind::ScopeResolutionExpression => "scope_resolution_expression", SyntaxKind::MemberSelectionExpression => "member_selection_expression", SyntaxKind::SafeMemberSelectionExpression => "safe_member_selection_expression", SyntaxKind::EmbeddedMemberSelectionExpression => "embedded_member_selection_expression", SyntaxKind::YieldExpression => "yield_expression", SyntaxKind::PrefixUnaryExpression => "prefix_unary_expression", SyntaxKind::PostfixUnaryExpression => "postfix_unary_expression", SyntaxKind::BinaryExpression => "binary_expression", SyntaxKind::IsExpression => "is_expression", SyntaxKind::AsExpression => "as_expression", SyntaxKind::NullableAsExpression => "nullable_as_expression", SyntaxKind::UpcastExpression => "upcast_expression", SyntaxKind::ConditionalExpression => "conditional_expression", SyntaxKind::EvalExpression => "eval_expression", SyntaxKind::IssetExpression => "isset_expression", SyntaxKind::FunctionCallExpression => "function_call_expression", SyntaxKind::FunctionPointerExpression => "function_pointer_expression", SyntaxKind::ParenthesizedExpression => "parenthesized_expression", SyntaxKind::BracedExpression => "braced_expression", SyntaxKind::ETSpliceExpression => "et_splice_expression", SyntaxKind::EmbeddedBracedExpression => "embedded_braced_expression", SyntaxKind::ListExpression => "list_expression", SyntaxKind::CollectionLiteralExpression => "collection_literal_expression", SyntaxKind::ObjectCreationExpression => "object_creation_expression", SyntaxKind::ConstructorCall => "constructor_call", SyntaxKind::DarrayIntrinsicExpression => "darray_intrinsic_expression", SyntaxKind::DictionaryIntrinsicExpression => "dictionary_intrinsic_expression", SyntaxKind::KeysetIntrinsicExpression => "keyset_intrinsic_expression", SyntaxKind::VarrayIntrinsicExpression => "varray_intrinsic_expression", SyntaxKind::VectorIntrinsicExpression => "vector_intrinsic_expression", SyntaxKind::ElementInitializer => "element_initializer", SyntaxKind::SubscriptExpression => "subscript_expression", SyntaxKind::EmbeddedSubscriptExpression => "embedded_subscript_expression", SyntaxKind::AwaitableCreationExpression => "awaitable_creation_expression", SyntaxKind::XHPChildrenDeclaration => "xhp_children_declaration", SyntaxKind::XHPChildrenParenthesizedList => "xhp_children_parenthesized_list", SyntaxKind::XHPCategoryDeclaration => "xhp_category_declaration", SyntaxKind::XHPEnumType => "xhp_enum_type", SyntaxKind::XHPLateinit => "xhp_lateinit", SyntaxKind::XHPRequired => "xhp_required", SyntaxKind::XHPClassAttributeDeclaration => "xhp_class_attribute_declaration", SyntaxKind::XHPClassAttribute => "xhp_class_attribute", SyntaxKind::XHPSimpleClassAttribute => "xhp_simple_class_attribute", SyntaxKind::XHPSimpleAttribute => "xhp_simple_attribute", SyntaxKind::XHPSpreadAttribute => "xhp_spread_attribute", SyntaxKind::XHPOpen => "xhp_open", SyntaxKind::XHPExpression => "xhp_expression", SyntaxKind::XHPClose => "xhp_close", SyntaxKind::TypeConstant => "type_constant", SyntaxKind::VectorTypeSpecifier => "vector_type_specifier", SyntaxKind::KeysetTypeSpecifier => "keyset_type_specifier", SyntaxKind::TupleTypeExplicitSpecifier => "tuple_type_explicit_specifier", SyntaxKind::VarrayTypeSpecifier => "varray_type_specifier", SyntaxKind::FunctionCtxTypeSpecifier => "function_ctx_type_specifier", SyntaxKind::TypeParameter => "type_parameter", SyntaxKind::TypeConstraint => "type_constraint", SyntaxKind::ContextConstraint => "context_constraint", SyntaxKind::DarrayTypeSpecifier => "darray_type_specifier", SyntaxKind::DictionaryTypeSpecifier => "dictionary_type_specifier", SyntaxKind::ClosureTypeSpecifier => "closure_type_specifier", SyntaxKind::ClosureParameterTypeSpecifier => "closure_parameter_type_specifier", SyntaxKind::TypeRefinement => "type_refinement", SyntaxKind::TypeInRefinement => "type_in_refinement", SyntaxKind::CtxInRefinement => "ctx_in_refinement", SyntaxKind::ClassnameTypeSpecifier => "classname_type_specifier", SyntaxKind::FieldSpecifier => "field_specifier", SyntaxKind::FieldInitializer => "field_initializer", SyntaxKind::ShapeTypeSpecifier => "shape_type_specifier", SyntaxKind::ShapeExpression => "shape_expression", SyntaxKind::TupleExpression => "tuple_expression", SyntaxKind::GenericTypeSpecifier => "generic_type_specifier", SyntaxKind::NullableTypeSpecifier => "nullable_type_specifier", SyntaxKind::LikeTypeSpecifier => "like_type_specifier", SyntaxKind::SoftTypeSpecifier => "soft_type_specifier", SyntaxKind::AttributizedSpecifier => "attributized_specifier", SyntaxKind::ReifiedTypeArgument => "reified_type_argument", SyntaxKind::TypeArguments => "type_arguments", SyntaxKind::TypeParameters => "type_parameters", SyntaxKind::TupleTypeSpecifier => "tuple_type_specifier", SyntaxKind::UnionTypeSpecifier => "union_type_specifier", SyntaxKind::IntersectionTypeSpecifier => "intersection_type_specifier", SyntaxKind::ErrorSyntax => "error", SyntaxKind::ListItem => "list_item", SyntaxKind::EnumClassLabelExpression => "enum_class_label", SyntaxKind::ModuleDeclaration => "module_declaration", SyntaxKind::ModuleExports => "module_exports", SyntaxKind::ModuleImports => "module_imports", SyntaxKind::ModuleMembershipDeclaration => "module_membership_declaration", SyntaxKind::PackageExpression => "package_expression", } } pub fn ocaml_tag(self) -> u8 { match self { SyntaxKind::Missing => 0, SyntaxKind::Token(_) => 0, SyntaxKind::SyntaxList => 1, SyntaxKind::EndOfFile => 2, SyntaxKind::Script => 3, SyntaxKind::QualifiedName => 4, SyntaxKind::ModuleName => 5, SyntaxKind::SimpleTypeSpecifier => 6, SyntaxKind::LiteralExpression => 7, SyntaxKind::PrefixedStringExpression => 8, SyntaxKind::PrefixedCodeExpression => 9, SyntaxKind::VariableExpression => 10, SyntaxKind::PipeVariableExpression => 11, SyntaxKind::FileAttributeSpecification => 12, SyntaxKind::EnumDeclaration => 13, SyntaxKind::EnumUse => 14, SyntaxKind::Enumerator => 15, SyntaxKind::EnumClassDeclaration => 16, SyntaxKind::EnumClassEnumerator => 17, SyntaxKind::AliasDeclaration => 18, SyntaxKind::ContextAliasDeclaration => 19, SyntaxKind::CaseTypeDeclaration => 20, SyntaxKind::CaseTypeVariant => 21, SyntaxKind::PropertyDeclaration => 22, SyntaxKind::PropertyDeclarator => 23, SyntaxKind::NamespaceDeclaration => 24, SyntaxKind::NamespaceDeclarationHeader => 25, SyntaxKind::NamespaceBody => 26, SyntaxKind::NamespaceEmptyBody => 27, SyntaxKind::NamespaceUseDeclaration => 28, SyntaxKind::NamespaceGroupUseDeclaration => 29, SyntaxKind::NamespaceUseClause => 30, SyntaxKind::FunctionDeclaration => 31, SyntaxKind::FunctionDeclarationHeader => 32, SyntaxKind::Contexts => 33, SyntaxKind::WhereClause => 34, SyntaxKind::WhereConstraint => 35, SyntaxKind::MethodishDeclaration => 36, SyntaxKind::MethodishTraitResolution => 37, SyntaxKind::ClassishDeclaration => 38, SyntaxKind::ClassishBody => 39, SyntaxKind::TraitUse => 40, SyntaxKind::RequireClause => 41, SyntaxKind::ConstDeclaration => 42, SyntaxKind::ConstantDeclarator => 43, SyntaxKind::TypeConstDeclaration => 44, SyntaxKind::ContextConstDeclaration => 45, SyntaxKind::DecoratedExpression => 46, SyntaxKind::ParameterDeclaration => 47, SyntaxKind::VariadicParameter => 48, SyntaxKind::OldAttributeSpecification => 49, SyntaxKind::AttributeSpecification => 50, SyntaxKind::Attribute => 51, SyntaxKind::InclusionExpression => 52, SyntaxKind::InclusionDirective => 53, SyntaxKind::CompoundStatement => 54, SyntaxKind::ExpressionStatement => 55, SyntaxKind::MarkupSection => 56, SyntaxKind::MarkupSuffix => 57, SyntaxKind::UnsetStatement => 58, SyntaxKind::DeclareLocalStatement => 59, SyntaxKind::UsingStatementBlockScoped => 60, SyntaxKind::UsingStatementFunctionScoped => 61, SyntaxKind::WhileStatement => 62, SyntaxKind::IfStatement => 63, SyntaxKind::ElseClause => 64, SyntaxKind::TryStatement => 65, SyntaxKind::CatchClause => 66, SyntaxKind::FinallyClause => 67, SyntaxKind::DoStatement => 68, SyntaxKind::ForStatement => 69, SyntaxKind::ForeachStatement => 70, SyntaxKind::SwitchStatement => 71, SyntaxKind::SwitchSection => 72, SyntaxKind::SwitchFallthrough => 73, SyntaxKind::CaseLabel => 74, SyntaxKind::DefaultLabel => 75, SyntaxKind::MatchStatement => 76, SyntaxKind::MatchStatementArm => 77, SyntaxKind::ReturnStatement => 78, SyntaxKind::YieldBreakStatement => 79, SyntaxKind::ThrowStatement => 80, SyntaxKind::BreakStatement => 81, SyntaxKind::ContinueStatement => 82, SyntaxKind::EchoStatement => 83, SyntaxKind::ConcurrentStatement => 84, SyntaxKind::SimpleInitializer => 85, SyntaxKind::AnonymousClass => 86, SyntaxKind::AnonymousFunction => 87, SyntaxKind::AnonymousFunctionUseClause => 88, SyntaxKind::VariablePattern => 89, SyntaxKind::ConstructorPattern => 90, SyntaxKind::RefinementPattern => 91, SyntaxKind::LambdaExpression => 92, SyntaxKind::LambdaSignature => 93, SyntaxKind::CastExpression => 94, SyntaxKind::ScopeResolutionExpression => 95, SyntaxKind::MemberSelectionExpression => 96, SyntaxKind::SafeMemberSelectionExpression => 97, SyntaxKind::EmbeddedMemberSelectionExpression => 98, SyntaxKind::YieldExpression => 99, SyntaxKind::PrefixUnaryExpression => 100, SyntaxKind::PostfixUnaryExpression => 101, SyntaxKind::BinaryExpression => 102, SyntaxKind::IsExpression => 103, SyntaxKind::AsExpression => 104, SyntaxKind::NullableAsExpression => 105, SyntaxKind::UpcastExpression => 106, SyntaxKind::ConditionalExpression => 107, SyntaxKind::EvalExpression => 108, SyntaxKind::IssetExpression => 109, SyntaxKind::FunctionCallExpression => 110, SyntaxKind::FunctionPointerExpression => 111, SyntaxKind::ParenthesizedExpression => 112, SyntaxKind::BracedExpression => 113, SyntaxKind::ETSpliceExpression => 114, SyntaxKind::EmbeddedBracedExpression => 115, SyntaxKind::ListExpression => 116, SyntaxKind::CollectionLiteralExpression => 117, SyntaxKind::ObjectCreationExpression => 118, SyntaxKind::ConstructorCall => 119, SyntaxKind::DarrayIntrinsicExpression => 120, SyntaxKind::DictionaryIntrinsicExpression => 121, SyntaxKind::KeysetIntrinsicExpression => 122, SyntaxKind::VarrayIntrinsicExpression => 123, SyntaxKind::VectorIntrinsicExpression => 124, SyntaxKind::ElementInitializer => 125, SyntaxKind::SubscriptExpression => 126, SyntaxKind::EmbeddedSubscriptExpression => 127, SyntaxKind::AwaitableCreationExpression => 128, SyntaxKind::XHPChildrenDeclaration => 129, SyntaxKind::XHPChildrenParenthesizedList => 130, SyntaxKind::XHPCategoryDeclaration => 131, SyntaxKind::XHPEnumType => 132, SyntaxKind::XHPLateinit => 133, SyntaxKind::XHPRequired => 134, SyntaxKind::XHPClassAttributeDeclaration => 135, SyntaxKind::XHPClassAttribute => 136, SyntaxKind::XHPSimpleClassAttribute => 137, SyntaxKind::XHPSimpleAttribute => 138, SyntaxKind::XHPSpreadAttribute => 139, SyntaxKind::XHPOpen => 140, SyntaxKind::XHPExpression => 141, SyntaxKind::XHPClose => 142, SyntaxKind::TypeConstant => 143, SyntaxKind::VectorTypeSpecifier => 144, SyntaxKind::KeysetTypeSpecifier => 145, SyntaxKind::TupleTypeExplicitSpecifier => 146, SyntaxKind::VarrayTypeSpecifier => 147, SyntaxKind::FunctionCtxTypeSpecifier => 148, SyntaxKind::TypeParameter => 149, SyntaxKind::TypeConstraint => 150, SyntaxKind::ContextConstraint => 151, SyntaxKind::DarrayTypeSpecifier => 152, SyntaxKind::DictionaryTypeSpecifier => 153, SyntaxKind::ClosureTypeSpecifier => 154, SyntaxKind::ClosureParameterTypeSpecifier => 155, SyntaxKind::TypeRefinement => 156, SyntaxKind::TypeInRefinement => 157, SyntaxKind::CtxInRefinement => 158, SyntaxKind::ClassnameTypeSpecifier => 159, SyntaxKind::FieldSpecifier => 160, SyntaxKind::FieldInitializer => 161, SyntaxKind::ShapeTypeSpecifier => 162, SyntaxKind::ShapeExpression => 163, SyntaxKind::TupleExpression => 164, SyntaxKind::GenericTypeSpecifier => 165, SyntaxKind::NullableTypeSpecifier => 166, SyntaxKind::LikeTypeSpecifier => 167, SyntaxKind::SoftTypeSpecifier => 168, SyntaxKind::AttributizedSpecifier => 169, SyntaxKind::ReifiedTypeArgument => 170, SyntaxKind::TypeArguments => 171, SyntaxKind::TypeParameters => 172, SyntaxKind::TupleTypeSpecifier => 173, SyntaxKind::UnionTypeSpecifier => 174, SyntaxKind::IntersectionTypeSpecifier => 175, SyntaxKind::ErrorSyntax => 176, SyntaxKind::ListItem => 177, SyntaxKind::EnumClassLabelExpression => 178, SyntaxKind::ModuleDeclaration => 179, SyntaxKind::ModuleExports => 180, SyntaxKind::ModuleImports => 181, SyntaxKind::ModuleMembershipDeclaration => 182, SyntaxKind::PackageExpression => 183, } } }
OCaml
hhvm/hphp/hack/src/parser/syntax_sig.ml
(* * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. An additional * directory. * ** * * THIS FILE IS @generated; DO NOT EDIT IT * To regenerate this file, run * * buck run //hphp/hack/src:generate_full_fidelity * ** * * This module contains a signature which can be used to describe the public * surface area of a constructable syntax tree. *) module TriviaKind = Full_fidelity_trivia_kind module TokenKind = Full_fidelity_token_kind module type Syntax_S = sig module Token : Lexable_token_sig.LexableToken_S type value [@@deriving show, eq, sexp_of] type t = { syntax: syntax; value: value; } [@@deriving show, eq, sexp_of] and syntax = | Token of Token.t | Missing | SyntaxList of t list | EndOfFile of { end_of_file_token: t } | Script of { script_declarations: t } | QualifiedName of { qualified_name_parts: t } | ModuleName of { module_name_parts: t } | SimpleTypeSpecifier of { simple_type_specifier: t } | LiteralExpression of { literal_expression: t } | PrefixedStringExpression of { prefixed_string_name: t; prefixed_string_str: t; } | PrefixedCodeExpression of { prefixed_code_prefix: t; prefixed_code_left_backtick: t; prefixed_code_body: t; prefixed_code_right_backtick: t; } | VariableExpression of { variable_expression: t } | PipeVariableExpression of { pipe_variable_expression: t } | FileAttributeSpecification of { file_attribute_specification_left_double_angle: t; file_attribute_specification_keyword: t; file_attribute_specification_colon: t; file_attribute_specification_attributes: t; file_attribute_specification_right_double_angle: t; } | EnumDeclaration of { enum_attribute_spec: t; enum_modifiers: t; enum_keyword: t; enum_name: t; enum_colon: t; enum_base: t; enum_type: t; enum_left_brace: t; enum_use_clauses: t; enum_enumerators: t; enum_right_brace: t; } | EnumUse of { enum_use_keyword: t; enum_use_names: t; enum_use_semicolon: t; } | Enumerator of { enumerator_name: t; enumerator_equal: t; enumerator_value: t; enumerator_semicolon: t; } | EnumClassDeclaration of { enum_class_attribute_spec: t; enum_class_modifiers: t; enum_class_enum_keyword: t; enum_class_class_keyword: t; enum_class_name: t; enum_class_colon: t; enum_class_base: t; enum_class_extends: t; enum_class_extends_list: t; enum_class_left_brace: t; enum_class_elements: t; enum_class_right_brace: t; } | EnumClassEnumerator of { enum_class_enumerator_modifiers: t; enum_class_enumerator_type: t; enum_class_enumerator_name: t; enum_class_enumerator_initializer: t; enum_class_enumerator_semicolon: t; } | AliasDeclaration of { alias_attribute_spec: t; alias_modifiers: t; alias_module_kw_opt: t; alias_keyword: t; alias_name: t; alias_generic_parameter: t; alias_constraint: t; alias_equal: t; alias_type: t; alias_semicolon: t; } | ContextAliasDeclaration of { ctx_alias_attribute_spec: t; ctx_alias_keyword: t; ctx_alias_name: t; ctx_alias_generic_parameter: t; ctx_alias_as_constraint: t; ctx_alias_equal: t; ctx_alias_context: t; ctx_alias_semicolon: t; } | CaseTypeDeclaration of { case_type_attribute_spec: t; case_type_modifiers: t; case_type_case_keyword: t; case_type_type_keyword: t; case_type_name: t; case_type_generic_parameter: t; case_type_as: t; case_type_bounds: t; case_type_equal: t; case_type_variants: t; case_type_semicolon: t; } | CaseTypeVariant of { case_type_variant_bar: t; case_type_variant_type: t; } | PropertyDeclaration of { property_attribute_spec: t; property_modifiers: t; property_type: t; property_declarators: t; property_semicolon: t; } | PropertyDeclarator of { property_name: t; property_initializer: t; } | NamespaceDeclaration of { namespace_header: t; namespace_body: t; } | NamespaceDeclarationHeader of { namespace_keyword: t; namespace_name: t; } | NamespaceBody of { namespace_left_brace: t; namespace_declarations: t; namespace_right_brace: t; } | NamespaceEmptyBody of { namespace_semicolon: t } | NamespaceUseDeclaration of { namespace_use_keyword: t; namespace_use_kind: t; namespace_use_clauses: t; namespace_use_semicolon: t; } | NamespaceGroupUseDeclaration of { namespace_group_use_keyword: t; namespace_group_use_kind: t; namespace_group_use_prefix: t; namespace_group_use_left_brace: t; namespace_group_use_clauses: t; namespace_group_use_right_brace: t; namespace_group_use_semicolon: t; } | NamespaceUseClause of { namespace_use_clause_kind: t; namespace_use_name: t; namespace_use_as: t; namespace_use_alias: t; } | FunctionDeclaration of { function_attribute_spec: t; function_declaration_header: t; function_body: t; } | FunctionDeclarationHeader of { function_modifiers: t; function_keyword: t; function_name: t; function_type_parameter_list: t; function_left_paren: t; function_parameter_list: t; function_right_paren: t; function_contexts: t; function_colon: t; function_readonly_return: t; function_type: t; function_where_clause: t; } | Contexts of { contexts_left_bracket: t; contexts_types: t; contexts_right_bracket: t; } | WhereClause of { where_clause_keyword: t; where_clause_constraints: t; } | WhereConstraint of { where_constraint_left_type: t; where_constraint_operator: t; where_constraint_right_type: t; } | MethodishDeclaration of { methodish_attribute: t; methodish_function_decl_header: t; methodish_function_body: t; methodish_semicolon: t; } | MethodishTraitResolution of { methodish_trait_attribute: t; methodish_trait_function_decl_header: t; methodish_trait_equal: t; methodish_trait_name: t; methodish_trait_semicolon: t; } | ClassishDeclaration of { classish_attribute: t; classish_modifiers: t; classish_xhp: t; classish_keyword: t; classish_name: t; classish_type_parameters: t; classish_extends_keyword: t; classish_extends_list: t; classish_implements_keyword: t; classish_implements_list: t; classish_where_clause: t; classish_body: t; } | ClassishBody of { classish_body_left_brace: t; classish_body_elements: t; classish_body_right_brace: t; } | TraitUse of { trait_use_keyword: t; trait_use_names: t; trait_use_semicolon: t; } | RequireClause of { require_keyword: t; require_kind: t; require_name: t; require_semicolon: t; } | ConstDeclaration of { const_attribute_spec: t; const_modifiers: t; const_keyword: t; const_type_specifier: t; const_declarators: t; const_semicolon: t; } | ConstantDeclarator of { constant_declarator_name: t; constant_declarator_initializer: t; } | TypeConstDeclaration of { type_const_attribute_spec: t; type_const_modifiers: t; type_const_keyword: t; type_const_type_keyword: t; type_const_name: t; type_const_type_parameters: t; type_const_type_constraints: t; type_const_equal: t; type_const_type_specifier: t; type_const_semicolon: t; } | ContextConstDeclaration of { context_const_modifiers: t; context_const_const_keyword: t; context_const_ctx_keyword: t; context_const_name: t; context_const_type_parameters: t; context_const_constraint: t; context_const_equal: t; context_const_ctx_list: t; context_const_semicolon: t; } | DecoratedExpression of { decorated_expression_decorator: t; decorated_expression_expression: t; } | ParameterDeclaration of { parameter_attribute: t; parameter_visibility: t; parameter_call_convention: t; parameter_readonly: t; parameter_type: t; parameter_name: t; parameter_default_value: t; } | VariadicParameter of { variadic_parameter_call_convention: t; variadic_parameter_type: t; variadic_parameter_ellipsis: t; } | OldAttributeSpecification of { old_attribute_specification_left_double_angle: t; old_attribute_specification_attributes: t; old_attribute_specification_right_double_angle: t; } | AttributeSpecification of { attribute_specification_attributes: t } | Attribute of { attribute_at: t; attribute_attribute_name: t; } | InclusionExpression of { inclusion_require: t; inclusion_filename: t; } | InclusionDirective of { inclusion_expression: t; inclusion_semicolon: t; } | CompoundStatement of { compound_left_brace: t; compound_statements: t; compound_right_brace: t; } | ExpressionStatement of { expression_statement_expression: t; expression_statement_semicolon: t; } | MarkupSection of { markup_hashbang: t; markup_suffix: t; } | MarkupSuffix of { markup_suffix_less_than_question: t; markup_suffix_name: t; } | UnsetStatement of { unset_keyword: t; unset_left_paren: t; unset_variables: t; unset_right_paren: t; unset_semicolon: t; } | DeclareLocalStatement of { declare_local_keyword: t; declare_local_variable: t; declare_local_colon: t; declare_local_type: t; declare_local_initializer: t; declare_local_semicolon: t; } | UsingStatementBlockScoped of { using_block_await_keyword: t; using_block_using_keyword: t; using_block_left_paren: t; using_block_expressions: t; using_block_right_paren: t; using_block_body: t; } | UsingStatementFunctionScoped of { using_function_await_keyword: t; using_function_using_keyword: t; using_function_expression: t; using_function_semicolon: t; } | WhileStatement of { while_keyword: t; while_left_paren: t; while_condition: t; while_right_paren: t; while_body: t; } | IfStatement of { if_keyword: t; if_left_paren: t; if_condition: t; if_right_paren: t; if_statement: t; if_else_clause: t; } | ElseClause of { else_keyword: t; else_statement: t; } | TryStatement of { try_keyword: t; try_compound_statement: t; try_catch_clauses: t; try_finally_clause: t; } | CatchClause of { catch_keyword: t; catch_left_paren: t; catch_type: t; catch_variable: t; catch_right_paren: t; catch_body: t; } | FinallyClause of { finally_keyword: t; finally_body: t; } | DoStatement of { do_keyword: t; do_body: t; do_while_keyword: t; do_left_paren: t; do_condition: t; do_right_paren: t; do_semicolon: t; } | ForStatement of { for_keyword: t; for_left_paren: t; for_initializer: t; for_first_semicolon: t; for_control: t; for_second_semicolon: t; for_end_of_loop: t; for_right_paren: t; for_body: t; } | ForeachStatement of { foreach_keyword: t; foreach_left_paren: t; foreach_collection: t; foreach_await_keyword: t; foreach_as: t; foreach_key: t; foreach_arrow: t; foreach_value: t; foreach_right_paren: t; foreach_body: t; } | SwitchStatement of { switch_keyword: t; switch_left_paren: t; switch_expression: t; switch_right_paren: t; switch_left_brace: t; switch_sections: t; switch_right_brace: t; } | SwitchSection of { switch_section_labels: t; switch_section_statements: t; switch_section_fallthrough: t; } | SwitchFallthrough of { fallthrough_keyword: t; fallthrough_semicolon: t; } | CaseLabel of { case_keyword: t; case_expression: t; case_colon: t; } | DefaultLabel of { default_keyword: t; default_colon: t; } | MatchStatement of { match_statement_keyword: t; match_statement_left_paren: t; match_statement_expression: t; match_statement_right_paren: t; match_statement_left_brace: t; match_statement_arms: t; match_statement_right_brace: t; } | MatchStatementArm of { match_statement_arm_pattern: t; match_statement_arm_arrow: t; match_statement_arm_body: t; } | ReturnStatement of { return_keyword: t; return_expression: t; return_semicolon: t; } | YieldBreakStatement of { yield_break_keyword: t; yield_break_break: t; yield_break_semicolon: t; } | ThrowStatement of { throw_keyword: t; throw_expression: t; throw_semicolon: t; } | BreakStatement of { break_keyword: t; break_semicolon: t; } | ContinueStatement of { continue_keyword: t; continue_semicolon: t; } | EchoStatement of { echo_keyword: t; echo_expressions: t; echo_semicolon: t; } | ConcurrentStatement of { concurrent_keyword: t; concurrent_statement: t; } | SimpleInitializer of { simple_initializer_equal: t; simple_initializer_value: t; } | AnonymousClass of { anonymous_class_class_keyword: t; anonymous_class_left_paren: t; anonymous_class_argument_list: t; anonymous_class_right_paren: t; anonymous_class_extends_keyword: t; anonymous_class_extends_list: t; anonymous_class_implements_keyword: t; anonymous_class_implements_list: t; anonymous_class_body: t; } | AnonymousFunction of { anonymous_attribute_spec: t; anonymous_async_keyword: t; anonymous_function_keyword: t; anonymous_left_paren: t; anonymous_parameters: t; anonymous_right_paren: t; anonymous_ctx_list: t; anonymous_colon: t; anonymous_readonly_return: t; anonymous_type: t; anonymous_use: t; anonymous_body: t; } | AnonymousFunctionUseClause of { anonymous_use_keyword: t; anonymous_use_left_paren: t; anonymous_use_variables: t; anonymous_use_right_paren: t; } | VariablePattern of { variable_pattern_variable: t } | ConstructorPattern of { constructor_pattern_constructor: t; constructor_pattern_left_paren: t; constructor_pattern_members: t; constructor_pattern_right_paren: t; } | RefinementPattern of { refinement_pattern_variable: t; refinement_pattern_colon: t; refinement_pattern_specifier: t; } | LambdaExpression of { lambda_attribute_spec: t; lambda_async: t; lambda_signature: t; lambda_arrow: t; lambda_body: t; } | LambdaSignature of { lambda_left_paren: t; lambda_parameters: t; lambda_right_paren: t; lambda_contexts: t; lambda_colon: t; lambda_readonly_return: t; lambda_type: t; } | CastExpression of { cast_left_paren: t; cast_type: t; cast_right_paren: t; cast_operand: t; } | ScopeResolutionExpression of { scope_resolution_qualifier: t; scope_resolution_operator: t; scope_resolution_name: t; } | MemberSelectionExpression of { member_object: t; member_operator: t; member_name: t; } | SafeMemberSelectionExpression of { safe_member_object: t; safe_member_operator: t; safe_member_name: t; } | EmbeddedMemberSelectionExpression of { embedded_member_object: t; embedded_member_operator: t; embedded_member_name: t; } | YieldExpression of { yield_keyword: t; yield_operand: t; } | PrefixUnaryExpression of { prefix_unary_operator: t; prefix_unary_operand: t; } | PostfixUnaryExpression of { postfix_unary_operand: t; postfix_unary_operator: t; } | BinaryExpression of { binary_left_operand: t; binary_operator: t; binary_right_operand: t; } | IsExpression of { is_left_operand: t; is_operator: t; is_right_operand: t; } | AsExpression of { as_left_operand: t; as_operator: t; as_right_operand: t; } | NullableAsExpression of { nullable_as_left_operand: t; nullable_as_operator: t; nullable_as_right_operand: t; } | UpcastExpression of { upcast_left_operand: t; upcast_operator: t; upcast_right_operand: t; } | ConditionalExpression of { conditional_test: t; conditional_question: t; conditional_consequence: t; conditional_colon: t; conditional_alternative: t; } | EvalExpression of { eval_keyword: t; eval_left_paren: t; eval_argument: t; eval_right_paren: t; } | IssetExpression of { isset_keyword: t; isset_left_paren: t; isset_argument_list: t; isset_right_paren: t; } | FunctionCallExpression of { function_call_receiver: t; function_call_type_args: t; function_call_left_paren: t; function_call_argument_list: t; function_call_right_paren: t; } | FunctionPointerExpression of { function_pointer_receiver: t; function_pointer_type_args: t; } | ParenthesizedExpression of { parenthesized_expression_left_paren: t; parenthesized_expression_expression: t; parenthesized_expression_right_paren: t; } | BracedExpression of { braced_expression_left_brace: t; braced_expression_expression: t; braced_expression_right_brace: t; } | ETSpliceExpression of { et_splice_expression_dollar: t; et_splice_expression_left_brace: t; et_splice_expression_expression: t; et_splice_expression_right_brace: t; } | EmbeddedBracedExpression of { embedded_braced_expression_left_brace: t; embedded_braced_expression_expression: t; embedded_braced_expression_right_brace: t; } | ListExpression of { list_keyword: t; list_left_paren: t; list_members: t; list_right_paren: t; } | CollectionLiteralExpression of { collection_literal_name: t; collection_literal_left_brace: t; collection_literal_initializers: t; collection_literal_right_brace: t; } | ObjectCreationExpression of { object_creation_new_keyword: t; object_creation_object: t; } | ConstructorCall of { constructor_call_type: t; constructor_call_left_paren: t; constructor_call_argument_list: t; constructor_call_right_paren: t; } | DarrayIntrinsicExpression of { darray_intrinsic_keyword: t; darray_intrinsic_explicit_type: t; darray_intrinsic_left_bracket: t; darray_intrinsic_members: t; darray_intrinsic_right_bracket: t; } | DictionaryIntrinsicExpression of { dictionary_intrinsic_keyword: t; dictionary_intrinsic_explicit_type: t; dictionary_intrinsic_left_bracket: t; dictionary_intrinsic_members: t; dictionary_intrinsic_right_bracket: t; } | KeysetIntrinsicExpression of { keyset_intrinsic_keyword: t; keyset_intrinsic_explicit_type: t; keyset_intrinsic_left_bracket: t; keyset_intrinsic_members: t; keyset_intrinsic_right_bracket: t; } | VarrayIntrinsicExpression of { varray_intrinsic_keyword: t; varray_intrinsic_explicit_type: t; varray_intrinsic_left_bracket: t; varray_intrinsic_members: t; varray_intrinsic_right_bracket: t; } | VectorIntrinsicExpression of { vector_intrinsic_keyword: t; vector_intrinsic_explicit_type: t; vector_intrinsic_left_bracket: t; vector_intrinsic_members: t; vector_intrinsic_right_bracket: t; } | ElementInitializer of { element_key: t; element_arrow: t; element_value: t; } | SubscriptExpression of { subscript_receiver: t; subscript_left_bracket: t; subscript_index: t; subscript_right_bracket: t; } | EmbeddedSubscriptExpression of { embedded_subscript_receiver: t; embedded_subscript_left_bracket: t; embedded_subscript_index: t; embedded_subscript_right_bracket: t; } | AwaitableCreationExpression of { awaitable_attribute_spec: t; awaitable_async: t; awaitable_compound_statement: t; } | XHPChildrenDeclaration of { xhp_children_keyword: t; xhp_children_expression: t; xhp_children_semicolon: t; } | XHPChildrenParenthesizedList of { xhp_children_list_left_paren: t; xhp_children_list_xhp_children: t; xhp_children_list_right_paren: t; } | XHPCategoryDeclaration of { xhp_category_keyword: t; xhp_category_categories: t; xhp_category_semicolon: t; } | XHPEnumType of { xhp_enum_like: t; xhp_enum_keyword: t; xhp_enum_left_brace: t; xhp_enum_values: t; xhp_enum_right_brace: t; } | XHPLateinit of { xhp_lateinit_at: t; xhp_lateinit_keyword: t; } | XHPRequired of { xhp_required_at: t; xhp_required_keyword: t; } | XHPClassAttributeDeclaration of { xhp_attribute_keyword: t; xhp_attribute_attributes: t; xhp_attribute_semicolon: t; } | XHPClassAttribute of { xhp_attribute_decl_type: t; xhp_attribute_decl_name: t; xhp_attribute_decl_initializer: t; xhp_attribute_decl_required: t; } | XHPSimpleClassAttribute of { xhp_simple_class_attribute_type: t } | XHPSimpleAttribute of { xhp_simple_attribute_name: t; xhp_simple_attribute_equal: t; xhp_simple_attribute_expression: t; } | XHPSpreadAttribute of { xhp_spread_attribute_left_brace: t; xhp_spread_attribute_spread_operator: t; xhp_spread_attribute_expression: t; xhp_spread_attribute_right_brace: t; } | XHPOpen of { xhp_open_left_angle: t; xhp_open_name: t; xhp_open_attributes: t; xhp_open_right_angle: t; } | XHPExpression of { xhp_open: t; xhp_body: t; xhp_close: t; } | XHPClose of { xhp_close_left_angle: t; xhp_close_name: t; xhp_close_right_angle: t; } | TypeConstant of { type_constant_left_type: t; type_constant_separator: t; type_constant_right_type: t; } | VectorTypeSpecifier of { vector_type_keyword: t; vector_type_left_angle: t; vector_type_type: t; vector_type_trailing_comma: t; vector_type_right_angle: t; } | KeysetTypeSpecifier of { keyset_type_keyword: t; keyset_type_left_angle: t; keyset_type_type: t; keyset_type_trailing_comma: t; keyset_type_right_angle: t; } | TupleTypeExplicitSpecifier of { tuple_type_keyword: t; tuple_type_left_angle: t; tuple_type_types: t; tuple_type_right_angle: t; } | VarrayTypeSpecifier of { varray_keyword: t; varray_left_angle: t; varray_type: t; varray_trailing_comma: t; varray_right_angle: t; } | FunctionCtxTypeSpecifier of { function_ctx_type_keyword: t; function_ctx_type_variable: t; } | TypeParameter of { type_attribute_spec: t; type_reified: t; type_variance: t; type_name: t; type_param_params: t; type_constraints: t; } | TypeConstraint of { constraint_keyword: t; constraint_type: t; } | ContextConstraint of { ctx_constraint_keyword: t; ctx_constraint_ctx_list: t; } | DarrayTypeSpecifier of { darray_keyword: t; darray_left_angle: t; darray_key: t; darray_comma: t; darray_value: t; darray_trailing_comma: t; darray_right_angle: t; } | DictionaryTypeSpecifier of { dictionary_type_keyword: t; dictionary_type_left_angle: t; dictionary_type_members: t; dictionary_type_right_angle: t; } | ClosureTypeSpecifier of { closure_outer_left_paren: t; closure_readonly_keyword: t; closure_function_keyword: t; closure_inner_left_paren: t; closure_parameter_list: t; closure_inner_right_paren: t; closure_contexts: t; closure_colon: t; closure_readonly_return: t; closure_return_type: t; closure_outer_right_paren: t; } | ClosureParameterTypeSpecifier of { closure_parameter_call_convention: t; closure_parameter_readonly: t; closure_parameter_type: t; } | TypeRefinement of { type_refinement_type: t; type_refinement_keyword: t; type_refinement_left_brace: t; type_refinement_members: t; type_refinement_right_brace: t; } | TypeInRefinement of { type_in_refinement_keyword: t; type_in_refinement_name: t; type_in_refinement_type_parameters: t; type_in_refinement_constraints: t; type_in_refinement_equal: t; type_in_refinement_type: t; } | CtxInRefinement of { ctx_in_refinement_keyword: t; ctx_in_refinement_name: t; ctx_in_refinement_type_parameters: t; ctx_in_refinement_constraints: t; ctx_in_refinement_equal: t; ctx_in_refinement_ctx_list: t; } | ClassnameTypeSpecifier of { classname_keyword: t; classname_left_angle: t; classname_type: t; classname_trailing_comma: t; classname_right_angle: t; } | FieldSpecifier of { field_question: t; field_name: t; field_arrow: t; field_type: t; } | FieldInitializer of { field_initializer_name: t; field_initializer_arrow: t; field_initializer_value: t; } | ShapeTypeSpecifier of { shape_type_keyword: t; shape_type_left_paren: t; shape_type_fields: t; shape_type_ellipsis: t; shape_type_right_paren: t; } | ShapeExpression of { shape_expression_keyword: t; shape_expression_left_paren: t; shape_expression_fields: t; shape_expression_right_paren: t; } | TupleExpression of { tuple_expression_keyword: t; tuple_expression_left_paren: t; tuple_expression_items: t; tuple_expression_right_paren: t; } | GenericTypeSpecifier of { generic_class_type: t; generic_argument_list: t; } | NullableTypeSpecifier of { nullable_question: t; nullable_type: t; } | LikeTypeSpecifier of { like_tilde: t; like_type: t; } | SoftTypeSpecifier of { soft_at: t; soft_type: t; } | AttributizedSpecifier of { attributized_specifier_attribute_spec: t; attributized_specifier_type: t; } | ReifiedTypeArgument of { reified_type_argument_reified: t; reified_type_argument_type: t; } | TypeArguments of { type_arguments_left_angle: t; type_arguments_types: t; type_arguments_right_angle: t; } | TypeParameters of { type_parameters_left_angle: t; type_parameters_parameters: t; type_parameters_right_angle: t; } | TupleTypeSpecifier of { tuple_left_paren: t; tuple_types: t; tuple_right_paren: t; } | UnionTypeSpecifier of { union_left_paren: t; union_types: t; union_right_paren: t; } | IntersectionTypeSpecifier of { intersection_left_paren: t; intersection_types: t; intersection_right_paren: t; } | ErrorSyntax of { error_error: t } | ListItem of { list_item: t; list_separator: t; } | EnumClassLabelExpression of { enum_class_label_qualifier: t; enum_class_label_hash: t; enum_class_label_expression: t; } | ModuleDeclaration of { module_declaration_attribute_spec: t; module_declaration_new_keyword: t; module_declaration_module_keyword: t; module_declaration_name: t; module_declaration_left_brace: t; module_declaration_exports: t; module_declaration_imports: t; module_declaration_right_brace: t; } | ModuleExports of { module_exports_exports_keyword: t; module_exports_left_brace: t; module_exports_exports: t; module_exports_right_brace: t; } | ModuleImports of { module_imports_imports_keyword: t; module_imports_left_brace: t; module_imports_imports: t; module_imports_right_brace: t; } | ModuleMembershipDeclaration of { module_membership_declaration_module_keyword: t; module_membership_declaration_name: t; module_membership_declaration_semicolon: t; } | PackageExpression of { package_expression_keyword: t; package_expression_name: t; } [@@deriving sexp_of] val rust_parse : Full_fidelity_source_text.t -> Full_fidelity_parser_env.t -> unit * t * Full_fidelity_syntax_error.t list * Rust_pointer.t option val rust_parser_errors : Full_fidelity_source_text.t -> Rust_pointer.t -> ParserOptions.ffi_t -> Full_fidelity_syntax_error.t list val has_leading_trivia : TriviaKind.t -> Token.t -> bool val to_json : ?with_value:bool -> ?ignore_missing:bool -> t -> Hh_json.json val extract_text : t -> string option val is_in_body : t -> int -> bool val syntax_node_to_list : t -> t list val width : t -> int val full_width : t -> int val trailing_width : t -> int val leading_width : t -> int val leading_token : t -> Token.t option val children : t -> t list val syntax : t -> syntax val kind : t -> Full_fidelity_syntax_kind.t val value : t -> value val make_token : Token.t -> t val get_token : t -> Token.t option val all_tokens : t -> Token.t list val make_missing : Full_fidelity_source_text.t -> int -> t val make_list : Full_fidelity_source_text.t -> int -> t list -> t val is_namespace_prefix : t -> bool val syntax_list_fold : init:'a -> f:('a -> t -> 'a) -> t -> 'a val make_end_of_file : t -> t val make_script : t -> t val make_qualified_name : t -> t val make_module_name : t -> t val make_simple_type_specifier : t -> t val make_literal_expression : t -> t val make_prefixed_string_expression : t -> t -> t val make_prefixed_code_expression : t -> t -> t -> t -> t val make_variable_expression : t -> t val make_pipe_variable_expression : t -> t val make_file_attribute_specification : t -> t -> t -> t -> t -> t val make_enum_declaration : t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t val make_enum_use : t -> t -> t -> t val make_enumerator : t -> t -> t -> t -> t val make_enum_class_declaration : t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t val make_enum_class_enumerator : t -> t -> t -> t -> t -> t val make_alias_declaration : t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t val make_context_alias_declaration : t -> t -> t -> t -> t -> t -> t -> t -> t val make_case_type_declaration : t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t val make_case_type_variant : t -> t -> t val make_property_declaration : t -> t -> t -> t -> t -> t val make_property_declarator : t -> t -> t val make_namespace_declaration : t -> t -> t val make_namespace_declaration_header : t -> t -> t val make_namespace_body : t -> t -> t -> t val make_namespace_empty_body : t -> t val make_namespace_use_declaration : t -> t -> t -> t -> t val make_namespace_group_use_declaration : t -> t -> t -> t -> t -> t -> t -> t val make_namespace_use_clause : t -> t -> t -> t -> t val make_function_declaration : t -> t -> t -> t val make_function_declaration_header : t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t val make_contexts : t -> t -> t -> t val make_where_clause : t -> t -> t val make_where_constraint : t -> t -> t -> t val make_methodish_declaration : t -> t -> t -> t -> t val make_methodish_trait_resolution : t -> t -> t -> t -> t -> t val make_classish_declaration : t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t val make_classish_body : t -> t -> t -> t val make_trait_use : t -> t -> t -> t val make_require_clause : t -> t -> t -> t -> t val make_const_declaration : t -> t -> t -> t -> t -> t -> t val make_constant_declarator : t -> t -> t val make_type_const_declaration : t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t val make_context_const_declaration : t -> t -> t -> t -> t -> t -> t -> t -> t -> t val make_decorated_expression : t -> t -> t val make_parameter_declaration : t -> t -> t -> t -> t -> t -> t -> t val make_variadic_parameter : t -> t -> t -> t val make_old_attribute_specification : t -> t -> t -> t val make_attribute_specification : t -> t val make_attribute : t -> t -> t val make_inclusion_expression : t -> t -> t val make_inclusion_directive : t -> t -> t val make_compound_statement : t -> t -> t -> t val make_expression_statement : t -> t -> t val make_markup_section : t -> t -> t val make_markup_suffix : t -> t -> t val make_unset_statement : t -> t -> t -> t -> t -> t val make_declare_local_statement : t -> t -> t -> t -> t -> t -> t val make_using_statement_block_scoped : t -> t -> t -> t -> t -> t -> t val make_using_statement_function_scoped : t -> t -> t -> t -> t val make_while_statement : t -> t -> t -> t -> t -> t val make_if_statement : t -> t -> t -> t -> t -> t -> t val make_else_clause : t -> t -> t val make_try_statement : t -> t -> t -> t -> t val make_catch_clause : t -> t -> t -> t -> t -> t -> t val make_finally_clause : t -> t -> t val make_do_statement : t -> t -> t -> t -> t -> t -> t -> t val make_for_statement : t -> t -> t -> t -> t -> t -> t -> t -> t -> t val make_foreach_statement : t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t val make_switch_statement : t -> t -> t -> t -> t -> t -> t -> t val make_switch_section : t -> t -> t -> t val make_switch_fallthrough : t -> t -> t val make_case_label : t -> t -> t -> t val make_default_label : t -> t -> t val make_match_statement : t -> t -> t -> t -> t -> t -> t -> t val make_match_statement_arm : t -> t -> t -> t val make_return_statement : t -> t -> t -> t val make_yield_break_statement : t -> t -> t -> t val make_throw_statement : t -> t -> t -> t val make_break_statement : t -> t -> t val make_continue_statement : t -> t -> t val make_echo_statement : t -> t -> t -> t val make_concurrent_statement : t -> t -> t val make_simple_initializer : t -> t -> t val make_anonymous_class : t -> t -> t -> t -> t -> t -> t -> t -> t -> t val make_anonymous_function : t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t val make_anonymous_function_use_clause : t -> t -> t -> t -> t val make_variable_pattern : t -> t val make_constructor_pattern : t -> t -> t -> t -> t val make_refinement_pattern : t -> t -> t -> t val make_lambda_expression : t -> t -> t -> t -> t -> t val make_lambda_signature : t -> t -> t -> t -> t -> t -> t -> t val make_cast_expression : t -> t -> t -> t -> t val make_scope_resolution_expression : t -> t -> t -> t val make_member_selection_expression : t -> t -> t -> t val make_safe_member_selection_expression : t -> t -> t -> t val make_embedded_member_selection_expression : t -> t -> t -> t val make_yield_expression : t -> t -> t val make_prefix_unary_expression : t -> t -> t val make_postfix_unary_expression : t -> t -> t val make_binary_expression : t -> t -> t -> t val make_is_expression : t -> t -> t -> t val make_as_expression : t -> t -> t -> t val make_nullable_as_expression : t -> t -> t -> t val make_upcast_expression : t -> t -> t -> t val make_conditional_expression : t -> t -> t -> t -> t -> t val make_eval_expression : t -> t -> t -> t -> t val make_isset_expression : t -> t -> t -> t -> t val make_function_call_expression : t -> t -> t -> t -> t -> t val make_function_pointer_expression : t -> t -> t val make_parenthesized_expression : t -> t -> t -> t val make_braced_expression : t -> t -> t -> t val make_et_splice_expression : t -> t -> t -> t -> t val make_embedded_braced_expression : t -> t -> t -> t val make_list_expression : t -> t -> t -> t -> t val make_collection_literal_expression : t -> t -> t -> t -> t val make_object_creation_expression : t -> t -> t val make_constructor_call : t -> t -> t -> t -> t val make_darray_intrinsic_expression : t -> t -> t -> t -> t -> t val make_dictionary_intrinsic_expression : t -> t -> t -> t -> t -> t val make_keyset_intrinsic_expression : t -> t -> t -> t -> t -> t val make_varray_intrinsic_expression : t -> t -> t -> t -> t -> t val make_vector_intrinsic_expression : t -> t -> t -> t -> t -> t val make_element_initializer : t -> t -> t -> t val make_subscript_expression : t -> t -> t -> t -> t val make_embedded_subscript_expression : t -> t -> t -> t -> t val make_awaitable_creation_expression : t -> t -> t -> t val make_xhp_children_declaration : t -> t -> t -> t val make_xhp_children_parenthesized_list : t -> t -> t -> t val make_xhp_category_declaration : t -> t -> t -> t val make_xhp_enum_type : t -> t -> t -> t -> t -> t val make_xhp_lateinit : t -> t -> t val make_xhp_required : t -> t -> t val make_xhp_class_attribute_declaration : t -> t -> t -> t val make_xhp_class_attribute : t -> t -> t -> t -> t val make_xhp_simple_class_attribute : t -> t val make_xhp_simple_attribute : t -> t -> t -> t val make_xhp_spread_attribute : t -> t -> t -> t -> t val make_xhp_open : t -> t -> t -> t -> t val make_xhp_expression : t -> t -> t -> t val make_xhp_close : t -> t -> t -> t val make_type_constant : t -> t -> t -> t val make_vector_type_specifier : t -> t -> t -> t -> t -> t val make_keyset_type_specifier : t -> t -> t -> t -> t -> t val make_tuple_type_explicit_specifier : t -> t -> t -> t -> t val make_varray_type_specifier : t -> t -> t -> t -> t -> t val make_function_ctx_type_specifier : t -> t -> t val make_type_parameter : t -> t -> t -> t -> t -> t -> t val make_type_constraint : t -> t -> t val make_context_constraint : t -> t -> t val make_darray_type_specifier : t -> t -> t -> t -> t -> t -> t -> t val make_dictionary_type_specifier : t -> t -> t -> t -> t val make_closure_type_specifier : t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t -> t val make_closure_parameter_type_specifier : t -> t -> t -> t val make_type_refinement : t -> t -> t -> t -> t -> t val make_type_in_refinement : t -> t -> t -> t -> t -> t -> t val make_ctx_in_refinement : t -> t -> t -> t -> t -> t -> t val make_classname_type_specifier : t -> t -> t -> t -> t -> t val make_field_specifier : t -> t -> t -> t -> t val make_field_initializer : t -> t -> t -> t val make_shape_type_specifier : t -> t -> t -> t -> t -> t val make_shape_expression : t -> t -> t -> t -> t val make_tuple_expression : t -> t -> t -> t -> t val make_generic_type_specifier : t -> t -> t val make_nullable_type_specifier : t -> t -> t val make_like_type_specifier : t -> t -> t val make_soft_type_specifier : t -> t -> t val make_attributized_specifier : t -> t -> t val make_reified_type_argument : t -> t -> t val make_type_arguments : t -> t -> t -> t val make_type_parameters : t -> t -> t -> t val make_tuple_type_specifier : t -> t -> t -> t val make_union_type_specifier : t -> t -> t -> t val make_intersection_type_specifier : t -> t -> t -> t val make_error : t -> t val make_list_item : t -> t -> t val make_enum_class_label_expression : t -> t -> t -> t val make_module_declaration : t -> t -> t -> t -> t -> t -> t -> t -> t val make_module_exports : t -> t -> t -> t -> t val make_module_imports : t -> t -> t -> t -> t val make_module_membership_declaration : t -> t -> t -> t val make_package_expression : t -> t -> t val position : Relative_path.t -> t -> Pos.t option val offset : t -> int option val is_missing : t -> bool val is_list : t -> bool val is_end_of_file : t -> bool val is_script : t -> bool val is_qualified_name : t -> bool val is_module_name : t -> bool val is_simple_type_specifier : t -> bool val is_literal_expression : t -> bool val is_prefixed_string_expression : t -> bool val is_prefixed_code_expression : t -> bool val is_variable_expression : t -> bool val is_pipe_variable_expression : t -> bool val is_file_attribute_specification : t -> bool val is_enum_declaration : t -> bool val is_enum_use : t -> bool val is_enumerator : t -> bool val is_enum_class_declaration : t -> bool val is_enum_class_enumerator : t -> bool val is_alias_declaration : t -> bool val is_context_alias_declaration : t -> bool val is_case_type_declaration : t -> bool val is_case_type_variant : t -> bool val is_property_declaration : t -> bool val is_property_declarator : t -> bool val is_namespace_declaration : t -> bool val is_namespace_declaration_header : t -> bool val is_namespace_body : t -> bool val is_namespace_empty_body : t -> bool val is_namespace_use_declaration : t -> bool val is_namespace_group_use_declaration : t -> bool val is_namespace_use_clause : t -> bool val is_function_declaration : t -> bool val is_function_declaration_header : t -> bool val is_contexts : t -> bool val is_where_clause : t -> bool val is_where_constraint : t -> bool val is_methodish_declaration : t -> bool val is_methodish_trait_resolution : t -> bool val is_classish_declaration : t -> bool val is_classish_body : t -> bool val is_trait_use : t -> bool val is_require_clause : t -> bool val is_const_declaration : t -> bool val is_constant_declarator : t -> bool val is_type_const_declaration : t -> bool val is_context_const_declaration : t -> bool val is_decorated_expression : t -> bool val is_parameter_declaration : t -> bool val is_variadic_parameter : t -> bool val is_old_attribute_specification : t -> bool val is_attribute_specification : t -> bool val is_attribute : t -> bool val is_inclusion_expression : t -> bool val is_inclusion_directive : t -> bool val is_compound_statement : t -> bool val is_expression_statement : t -> bool val is_markup_section : t -> bool val is_markup_suffix : t -> bool val is_unset_statement : t -> bool val is_declare_local_statement : t -> bool val is_using_statement_block_scoped : t -> bool val is_using_statement_function_scoped : t -> bool val is_while_statement : t -> bool val is_if_statement : t -> bool val is_else_clause : t -> bool val is_try_statement : t -> bool val is_catch_clause : t -> bool val is_finally_clause : t -> bool val is_do_statement : t -> bool val is_for_statement : t -> bool val is_foreach_statement : t -> bool val is_switch_statement : t -> bool val is_switch_section : t -> bool val is_switch_fallthrough : t -> bool val is_case_label : t -> bool val is_default_label : t -> bool val is_match_statement : t -> bool val is_match_statement_arm : t -> bool val is_return_statement : t -> bool val is_yield_break_statement : t -> bool val is_throw_statement : t -> bool val is_break_statement : t -> bool val is_continue_statement : t -> bool val is_echo_statement : t -> bool val is_concurrent_statement : t -> bool val is_simple_initializer : t -> bool val is_anonymous_class : t -> bool val is_anonymous_function : t -> bool val is_anonymous_function_use_clause : t -> bool val is_variable_pattern : t -> bool val is_constructor_pattern : t -> bool val is_refinement_pattern : t -> bool val is_lambda_expression : t -> bool val is_lambda_signature : t -> bool val is_cast_expression : t -> bool val is_scope_resolution_expression : t -> bool val is_member_selection_expression : t -> bool val is_safe_member_selection_expression : t -> bool val is_embedded_member_selection_expression : t -> bool val is_yield_expression : t -> bool val is_prefix_unary_expression : t -> bool val is_postfix_unary_expression : t -> bool val is_binary_expression : t -> bool val is_is_expression : t -> bool val is_as_expression : t -> bool val is_nullable_as_expression : t -> bool val is_upcast_expression : t -> bool val is_conditional_expression : t -> bool val is_eval_expression : t -> bool val is_isset_expression : t -> bool val is_function_call_expression : t -> bool val is_function_pointer_expression : t -> bool val is_parenthesized_expression : t -> bool val is_braced_expression : t -> bool val is_et_splice_expression : t -> bool val is_embedded_braced_expression : t -> bool val is_list_expression : t -> bool val is_collection_literal_expression : t -> bool val is_object_creation_expression : t -> bool val is_constructor_call : t -> bool val is_darray_intrinsic_expression : t -> bool val is_dictionary_intrinsic_expression : t -> bool val is_keyset_intrinsic_expression : t -> bool val is_varray_intrinsic_expression : t -> bool val is_vector_intrinsic_expression : t -> bool val is_element_initializer : t -> bool val is_subscript_expression : t -> bool val is_embedded_subscript_expression : t -> bool val is_awaitable_creation_expression : t -> bool val is_xhp_children_declaration : t -> bool val is_xhp_children_parenthesized_list : t -> bool val is_xhp_category_declaration : t -> bool val is_xhp_enum_type : t -> bool val is_xhp_lateinit : t -> bool val is_xhp_required : t -> bool val is_xhp_class_attribute_declaration : t -> bool val is_xhp_class_attribute : t -> bool val is_xhp_simple_class_attribute : t -> bool val is_xhp_simple_attribute : t -> bool val is_xhp_spread_attribute : t -> bool val is_xhp_open : t -> bool val is_xhp_expression : t -> bool val is_xhp_close : t -> bool val is_type_constant : t -> bool val is_vector_type_specifier : t -> bool val is_keyset_type_specifier : t -> bool val is_tuple_type_explicit_specifier : t -> bool val is_varray_type_specifier : t -> bool val is_function_ctx_type_specifier : t -> bool val is_type_parameter : t -> bool val is_type_constraint : t -> bool val is_context_constraint : t -> bool val is_darray_type_specifier : t -> bool val is_dictionary_type_specifier : t -> bool val is_closure_type_specifier : t -> bool val is_closure_parameter_type_specifier : t -> bool val is_type_refinement : t -> bool val is_type_in_refinement : t -> bool val is_ctx_in_refinement : t -> bool val is_classname_type_specifier : t -> bool val is_field_specifier : t -> bool val is_field_initializer : t -> bool val is_shape_type_specifier : t -> bool val is_shape_expression : t -> bool val is_tuple_expression : t -> bool val is_generic_type_specifier : t -> bool val is_nullable_type_specifier : t -> bool val is_like_type_specifier : t -> bool val is_soft_type_specifier : t -> bool val is_attributized_specifier : t -> bool val is_reified_type_argument : t -> bool val is_type_arguments : t -> bool val is_type_parameters : t -> bool val is_tuple_type_specifier : t -> bool val is_union_type_specifier : t -> bool val is_intersection_type_specifier : t -> bool val is_error : t -> bool val is_list_item : t -> bool val is_enum_class_label_expression : t -> bool val is_module_declaration : t -> bool val is_module_exports : t -> bool val is_module_imports : t -> bool val is_module_membership_declaration : t -> bool val is_package_expression : t -> bool val is_specific_token : TokenKind.t -> t -> bool val is_loop_statement : t -> bool val is_external : t -> bool val is_name : t -> bool val is_construct : t -> bool val is_static : t -> bool val is_private : t -> bool val is_public : t -> bool val is_protected : t -> bool val is_abstract : t -> bool val is_final : t -> bool val is_async : t -> bool val is_void : t -> bool val is_left_brace : t -> bool val is_ellipsis : t -> bool val is_comma : t -> bool val is_ampersand : t -> bool val is_inout : t -> bool end
Rust
hhvm/hphp/hack/src/parser/syntax_smart_constructors.rs
// Copyright (c) Facebook, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. mod syntax_smart_constructors_generated; use parser_core_types::syntax_by_ref::arena_state::State as ArenaState; use smart_constructors::NoState; pub use crate::syntax_smart_constructors_generated::*; pub trait StateType<R>: Clone { fn next(&mut self, inputs: &[&R]); } impl<R> StateType<R> for NoState { fn next(&mut self, _inputs: &[&R]) {} } impl<R> StateType<R> for ArenaState<'_> { fn next(&mut self, _inputs: &[&R]) {} }
Rust
hhvm/hphp/hack/src/parser/syntax_smart_constructors_generated.rs
/** * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. An additional * directory. * ** * * THIS FILE IS @generated; DO NOT EDIT IT * To regenerate this file, run * * buck run //hphp/hack/src:generate_full_fidelity * ** * */ use parser_core_types::{ syntax::*, token_factory::TokenFactory, }; use smart_constructors::{NoState, SmartConstructors}; use crate::StateType; pub trait SyntaxSmartConstructors<S: SyntaxType<St>, TF: TokenFactory<Token = S::Token>, St = NoState>: SmartConstructors<State = St, Output=S, Factory = TF> where St: StateType<S>, { fn make_missing(&mut self, offset: usize) -> Self::Output { let r = Self::Output::make_missing(self.state_mut(), offset); self.state_mut().next(&[]); r } fn make_token(&mut self, arg: <Self::Factory as TokenFactory>::Token) -> Self::Output { let r = Self::Output::make_token(self.state_mut(), arg); self.state_mut().next(&[]); r } fn make_list(&mut self, items: Vec<Self::Output>, offset: usize) -> Self::Output { if items.is_empty() { <Self as SyntaxSmartConstructors<S, TF, St>>::make_missing(self, offset) } else { let item_refs: Vec<_> = items.iter().collect(); self.state_mut().next(&item_refs); Self::Output::make_list(self.state_mut(), items, offset) } } fn make_end_of_file(&mut self, arg0 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0]); Self::Output::make_end_of_file(self.state_mut(), arg0) } fn make_script(&mut self, arg0 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0]); Self::Output::make_script(self.state_mut(), arg0) } fn make_qualified_name(&mut self, arg0 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0]); Self::Output::make_qualified_name(self.state_mut(), arg0) } fn make_module_name(&mut self, arg0 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0]); Self::Output::make_module_name(self.state_mut(), arg0) } fn make_simple_type_specifier(&mut self, arg0 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0]); Self::Output::make_simple_type_specifier(self.state_mut(), arg0) } fn make_literal_expression(&mut self, arg0 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0]); Self::Output::make_literal_expression(self.state_mut(), arg0) } fn make_prefixed_string_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_prefixed_string_expression(self.state_mut(), arg0, arg1) } fn make_prefixed_code_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_prefixed_code_expression(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_variable_expression(&mut self, arg0 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0]); Self::Output::make_variable_expression(self.state_mut(), arg0) } fn make_pipe_variable_expression(&mut self, arg0 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0]); Self::Output::make_pipe_variable_expression(self.state_mut(), arg0) } fn make_file_attribute_specification(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_file_attribute_specification(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_enum_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output, arg9 : Self::Output, arg10 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8, &arg9, &arg10]); Self::Output::make_enum_declaration(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) } fn make_enum_use(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_enum_use(self.state_mut(), arg0, arg1, arg2) } fn make_enumerator(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_enumerator(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_enum_class_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output, arg9 : Self::Output, arg10 : Self::Output, arg11 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8, &arg9, &arg10, &arg11]); Self::Output::make_enum_class_declaration(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) } fn make_enum_class_enumerator(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_enum_class_enumerator(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_alias_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output, arg9 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8, &arg9]); Self::Output::make_alias_declaration(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) } fn make_context_alias_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7]); Self::Output::make_context_alias_declaration(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) } fn make_case_type_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output, arg9 : Self::Output, arg10 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8, &arg9, &arg10]); Self::Output::make_case_type_declaration(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) } fn make_case_type_variant(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_case_type_variant(self.state_mut(), arg0, arg1) } fn make_property_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_property_declaration(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_property_declarator(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_property_declarator(self.state_mut(), arg0, arg1) } fn make_namespace_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_namespace_declaration(self.state_mut(), arg0, arg1) } fn make_namespace_declaration_header(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_namespace_declaration_header(self.state_mut(), arg0, arg1) } fn make_namespace_body(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_namespace_body(self.state_mut(), arg0, arg1, arg2) } fn make_namespace_empty_body(&mut self, arg0 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0]); Self::Output::make_namespace_empty_body(self.state_mut(), arg0) } fn make_namespace_use_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_namespace_use_declaration(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_namespace_group_use_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6]); Self::Output::make_namespace_group_use_declaration(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6) } fn make_namespace_use_clause(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_namespace_use_clause(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_function_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_function_declaration(self.state_mut(), arg0, arg1, arg2) } fn make_function_declaration_header(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output, arg9 : Self::Output, arg10 : Self::Output, arg11 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8, &arg9, &arg10, &arg11]); Self::Output::make_function_declaration_header(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) } fn make_contexts(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_contexts(self.state_mut(), arg0, arg1, arg2) } fn make_where_clause(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_where_clause(self.state_mut(), arg0, arg1) } fn make_where_constraint(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_where_constraint(self.state_mut(), arg0, arg1, arg2) } fn make_methodish_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_methodish_declaration(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_methodish_trait_resolution(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_methodish_trait_resolution(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_classish_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output, arg9 : Self::Output, arg10 : Self::Output, arg11 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8, &arg9, &arg10, &arg11]); Self::Output::make_classish_declaration(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) } fn make_classish_body(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_classish_body(self.state_mut(), arg0, arg1, arg2) } fn make_trait_use(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_trait_use(self.state_mut(), arg0, arg1, arg2) } fn make_require_clause(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_require_clause(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_const_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5]); Self::Output::make_const_declaration(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5) } fn make_constant_declarator(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_constant_declarator(self.state_mut(), arg0, arg1) } fn make_type_const_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output, arg9 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8, &arg9]); Self::Output::make_type_const_declaration(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) } fn make_context_const_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8]); Self::Output::make_context_const_declaration(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) } fn make_decorated_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_decorated_expression(self.state_mut(), arg0, arg1) } fn make_parameter_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6]); Self::Output::make_parameter_declaration(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6) } fn make_variadic_parameter(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_variadic_parameter(self.state_mut(), arg0, arg1, arg2) } fn make_old_attribute_specification(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_old_attribute_specification(self.state_mut(), arg0, arg1, arg2) } fn make_attribute_specification(&mut self, arg0 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0]); Self::Output::make_attribute_specification(self.state_mut(), arg0) } fn make_attribute(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_attribute(self.state_mut(), arg0, arg1) } fn make_inclusion_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_inclusion_expression(self.state_mut(), arg0, arg1) } fn make_inclusion_directive(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_inclusion_directive(self.state_mut(), arg0, arg1) } fn make_compound_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_compound_statement(self.state_mut(), arg0, arg1, arg2) } fn make_expression_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_expression_statement(self.state_mut(), arg0, arg1) } fn make_markup_section(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_markup_section(self.state_mut(), arg0, arg1) } fn make_markup_suffix(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_markup_suffix(self.state_mut(), arg0, arg1) } fn make_unset_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_unset_statement(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_declare_local_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5]); Self::Output::make_declare_local_statement(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5) } fn make_using_statement_block_scoped(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5]); Self::Output::make_using_statement_block_scoped(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5) } fn make_using_statement_function_scoped(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_using_statement_function_scoped(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_while_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_while_statement(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_if_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5]); Self::Output::make_if_statement(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5) } fn make_else_clause(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_else_clause(self.state_mut(), arg0, arg1) } fn make_try_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_try_statement(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_catch_clause(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5]); Self::Output::make_catch_clause(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5) } fn make_finally_clause(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_finally_clause(self.state_mut(), arg0, arg1) } fn make_do_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6]); Self::Output::make_do_statement(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6) } fn make_for_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8]); Self::Output::make_for_statement(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) } fn make_foreach_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output, arg9 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8, &arg9]); Self::Output::make_foreach_statement(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) } fn make_switch_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6]); Self::Output::make_switch_statement(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6) } fn make_switch_section(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_switch_section(self.state_mut(), arg0, arg1, arg2) } fn make_switch_fallthrough(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_switch_fallthrough(self.state_mut(), arg0, arg1) } fn make_case_label(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_case_label(self.state_mut(), arg0, arg1, arg2) } fn make_default_label(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_default_label(self.state_mut(), arg0, arg1) } fn make_match_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6]); Self::Output::make_match_statement(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6) } fn make_match_statement_arm(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_match_statement_arm(self.state_mut(), arg0, arg1, arg2) } fn make_return_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_return_statement(self.state_mut(), arg0, arg1, arg2) } fn make_yield_break_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_yield_break_statement(self.state_mut(), arg0, arg1, arg2) } fn make_throw_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_throw_statement(self.state_mut(), arg0, arg1, arg2) } fn make_break_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_break_statement(self.state_mut(), arg0, arg1) } fn make_continue_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_continue_statement(self.state_mut(), arg0, arg1) } fn make_echo_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_echo_statement(self.state_mut(), arg0, arg1, arg2) } fn make_concurrent_statement(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_concurrent_statement(self.state_mut(), arg0, arg1) } fn make_simple_initializer(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_simple_initializer(self.state_mut(), arg0, arg1) } fn make_anonymous_class(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8]); Self::Output::make_anonymous_class(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) } fn make_anonymous_function(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output, arg9 : Self::Output, arg10 : Self::Output, arg11 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8, &arg9, &arg10, &arg11]); Self::Output::make_anonymous_function(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) } fn make_anonymous_function_use_clause(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_anonymous_function_use_clause(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_variable_pattern(&mut self, arg0 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0]); Self::Output::make_variable_pattern(self.state_mut(), arg0) } fn make_constructor_pattern(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_constructor_pattern(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_refinement_pattern(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_refinement_pattern(self.state_mut(), arg0, arg1, arg2) } fn make_lambda_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_lambda_expression(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_lambda_signature(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6]); Self::Output::make_lambda_signature(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6) } fn make_cast_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_cast_expression(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_scope_resolution_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_scope_resolution_expression(self.state_mut(), arg0, arg1, arg2) } fn make_member_selection_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_member_selection_expression(self.state_mut(), arg0, arg1, arg2) } fn make_safe_member_selection_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_safe_member_selection_expression(self.state_mut(), arg0, arg1, arg2) } fn make_embedded_member_selection_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_embedded_member_selection_expression(self.state_mut(), arg0, arg1, arg2) } fn make_yield_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_yield_expression(self.state_mut(), arg0, arg1) } fn make_prefix_unary_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_prefix_unary_expression(self.state_mut(), arg0, arg1) } fn make_postfix_unary_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_postfix_unary_expression(self.state_mut(), arg0, arg1) } fn make_binary_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_binary_expression(self.state_mut(), arg0, arg1, arg2) } fn make_is_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_is_expression(self.state_mut(), arg0, arg1, arg2) } fn make_as_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_as_expression(self.state_mut(), arg0, arg1, arg2) } fn make_nullable_as_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_nullable_as_expression(self.state_mut(), arg0, arg1, arg2) } fn make_upcast_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_upcast_expression(self.state_mut(), arg0, arg1, arg2) } fn make_conditional_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_conditional_expression(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_eval_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_eval_expression(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_isset_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_isset_expression(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_function_call_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_function_call_expression(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_function_pointer_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_function_pointer_expression(self.state_mut(), arg0, arg1) } fn make_parenthesized_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_parenthesized_expression(self.state_mut(), arg0, arg1, arg2) } fn make_braced_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_braced_expression(self.state_mut(), arg0, arg1, arg2) } fn make_et_splice_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_et_splice_expression(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_embedded_braced_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_embedded_braced_expression(self.state_mut(), arg0, arg1, arg2) } fn make_list_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_list_expression(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_collection_literal_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_collection_literal_expression(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_object_creation_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_object_creation_expression(self.state_mut(), arg0, arg1) } fn make_constructor_call(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_constructor_call(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_darray_intrinsic_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_darray_intrinsic_expression(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_dictionary_intrinsic_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_dictionary_intrinsic_expression(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_keyset_intrinsic_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_keyset_intrinsic_expression(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_varray_intrinsic_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_varray_intrinsic_expression(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_vector_intrinsic_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_vector_intrinsic_expression(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_element_initializer(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_element_initializer(self.state_mut(), arg0, arg1, arg2) } fn make_subscript_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_subscript_expression(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_embedded_subscript_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_embedded_subscript_expression(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_awaitable_creation_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_awaitable_creation_expression(self.state_mut(), arg0, arg1, arg2) } fn make_xhp_children_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_xhp_children_declaration(self.state_mut(), arg0, arg1, arg2) } fn make_xhp_children_parenthesized_list(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_xhp_children_parenthesized_list(self.state_mut(), arg0, arg1, arg2) } fn make_xhp_category_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_xhp_category_declaration(self.state_mut(), arg0, arg1, arg2) } fn make_xhp_enum_type(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_xhp_enum_type(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_xhp_lateinit(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_xhp_lateinit(self.state_mut(), arg0, arg1) } fn make_xhp_required(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_xhp_required(self.state_mut(), arg0, arg1) } fn make_xhp_class_attribute_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_xhp_class_attribute_declaration(self.state_mut(), arg0, arg1, arg2) } fn make_xhp_class_attribute(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_xhp_class_attribute(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_xhp_simple_class_attribute(&mut self, arg0 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0]); Self::Output::make_xhp_simple_class_attribute(self.state_mut(), arg0) } fn make_xhp_simple_attribute(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_xhp_simple_attribute(self.state_mut(), arg0, arg1, arg2) } fn make_xhp_spread_attribute(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_xhp_spread_attribute(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_xhp_open(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_xhp_open(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_xhp_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_xhp_expression(self.state_mut(), arg0, arg1, arg2) } fn make_xhp_close(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_xhp_close(self.state_mut(), arg0, arg1, arg2) } fn make_type_constant(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_type_constant(self.state_mut(), arg0, arg1, arg2) } fn make_vector_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_vector_type_specifier(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_keyset_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_keyset_type_specifier(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_tuple_type_explicit_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_tuple_type_explicit_specifier(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_varray_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_varray_type_specifier(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_function_ctx_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_function_ctx_type_specifier(self.state_mut(), arg0, arg1) } fn make_type_parameter(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5]); Self::Output::make_type_parameter(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5) } fn make_type_constraint(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_type_constraint(self.state_mut(), arg0, arg1) } fn make_context_constraint(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_context_constraint(self.state_mut(), arg0, arg1) } fn make_darray_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6]); Self::Output::make_darray_type_specifier(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6) } fn make_dictionary_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_dictionary_type_specifier(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_closure_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output, arg8 : Self::Output, arg9 : Self::Output, arg10 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8, &arg9, &arg10]); Self::Output::make_closure_type_specifier(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) } fn make_closure_parameter_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_closure_parameter_type_specifier(self.state_mut(), arg0, arg1, arg2) } fn make_type_refinement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_type_refinement(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_type_in_refinement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5]); Self::Output::make_type_in_refinement(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5) } fn make_ctx_in_refinement(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5]); Self::Output::make_ctx_in_refinement(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5) } fn make_classname_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_classname_type_specifier(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_field_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_field_specifier(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_field_initializer(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_field_initializer(self.state_mut(), arg0, arg1, arg2) } fn make_shape_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4]); Self::Output::make_shape_type_specifier(self.state_mut(), arg0, arg1, arg2, arg3, arg4) } fn make_shape_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_shape_expression(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_tuple_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_tuple_expression(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_generic_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_generic_type_specifier(self.state_mut(), arg0, arg1) } fn make_nullable_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_nullable_type_specifier(self.state_mut(), arg0, arg1) } fn make_like_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_like_type_specifier(self.state_mut(), arg0, arg1) } fn make_soft_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_soft_type_specifier(self.state_mut(), arg0, arg1) } fn make_attributized_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_attributized_specifier(self.state_mut(), arg0, arg1) } fn make_reified_type_argument(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_reified_type_argument(self.state_mut(), arg0, arg1) } fn make_type_arguments(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_type_arguments(self.state_mut(), arg0, arg1, arg2) } fn make_type_parameters(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_type_parameters(self.state_mut(), arg0, arg1, arg2) } fn make_tuple_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_tuple_type_specifier(self.state_mut(), arg0, arg1, arg2) } fn make_union_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_union_type_specifier(self.state_mut(), arg0, arg1, arg2) } fn make_intersection_type_specifier(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_intersection_type_specifier(self.state_mut(), arg0, arg1, arg2) } fn make_error(&mut self, arg0 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0]); Self::Output::make_error(self.state_mut(), arg0) } fn make_list_item(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_list_item(self.state_mut(), arg0, arg1) } fn make_enum_class_label_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_enum_class_label_expression(self.state_mut(), arg0, arg1, arg2) } fn make_module_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output, arg4 : Self::Output, arg5 : Self::Output, arg6 : Self::Output, arg7 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7]); Self::Output::make_module_declaration(self.state_mut(), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) } fn make_module_exports(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_module_exports(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_module_imports(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output, arg3 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2, &arg3]); Self::Output::make_module_imports(self.state_mut(), arg0, arg1, arg2, arg3) } fn make_module_membership_declaration(&mut self, arg0 : Self::Output, arg1 : Self::Output, arg2 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1, &arg2]); Self::Output::make_module_membership_declaration(self.state_mut(), arg0, arg1, arg2) } fn make_package_expression(&mut self, arg0 : Self::Output, arg1 : Self::Output) -> Self::Output { self.state_mut().next(&[&arg0, &arg1]); Self::Output::make_package_expression(self.state_mut(), arg0, arg1) } }
Rust
hhvm/hphp/hack/src/parser/syntax_trait.rs
// Copyright (c) Facebook, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use crate::indexed_source_text::IndexedSourceText; use crate::indexed_source_text::Pos; use crate::source_text::SourceText; /// SyntaxTrait defines basic functionality implemented by each Syntax. /// It corresponds to Syntax_sig::Syntax_S in OCaml implementation. It is a trait /// and not an inherent implementation, because different syntaxes have different /// data to work with; for example full_width is already cached inside /// PositionedSyntax, while MinimalSyntax will have to iterate through entire /// subtree to compute it. Because of bugs in implementation and nothing ever /// enforcing it, in practice the values often will be different depending on /// the syntax, so be careful. pub trait SyntaxTrait { fn offset(&self) -> Option<usize>; fn width(&self) -> usize; fn leading_width(&self) -> usize; fn trailing_width(&self) -> usize; fn full_width(&self) -> usize; fn leading_start_offset(&self) -> usize; fn extract_text<'a>(&self, source_text: &'a SourceText<'_>) -> Option<&'a str>; fn start_offset(&self) -> usize { self.leading_start_offset() + self.leading_width() } fn end_offset(&self) -> usize { self.start_offset() + self.width().saturating_sub(1) } fn position_exclusive(&self, source_text: &IndexedSourceText<'_>) -> Option<Pos> { let start_offset = self.start_offset(); let end_offset = self.end_offset() + 1; Some(source_text.relative_pos(start_offset, end_offset)) } fn position(&self, source_text: &IndexedSourceText<'_>) -> Option<Pos> { let start_offset = self.start_offset(); let end_offset = self.end_offset(); Some(source_text.relative_pos(start_offset, end_offset)) } fn text<'a>(&self, source_text: &'a SourceText<'_>) -> &'a str { source_text.sub_as_str(self.start_offset(), self.width()) } fn full_text<'a>(&self, source_text: &'a SourceText<'_>) -> &'a [u8] { source_text.sub(self.leading_start_offset(), self.full_width()) } fn leading_text<'a>(&self, source_text: &'a SourceText<'_>) -> &'a str { source_text.sub_as_str(self.leading_start_offset(), self.leading_width()) } }
Rust
hhvm/hphp/hack/src/parser/syntax_tree.rs
// Copyright (Constructor) Facebook, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use std::borrow::Borrow; use crate::lexable_token::LexableToken; use crate::source_text::SourceText; use crate::syntax_by_ref::syntax::Syntax; use crate::syntax_error::SyntaxError; use crate::syntax_trait::SyntaxTrait; pub struct SyntaxTree<'a, Syntax, State> { text: &'a SourceText<'a>, root: Syntax, errors: Vec<SyntaxError>, mode: Option<FileMode>, state: State, } impl<'arena, T, V, State> SyntaxTree<'_, Syntax<'arena, T, V>, State> where T: LexableToken, Syntax<'arena, T, V>: SyntaxTrait, { pub fn errors<'r>(&'r self) -> Vec<&SyntaxError> where State: Clone, 'r: 'arena, { let mut errs: Vec<&SyntaxError> = if self.is_hhi() { self.errors .iter() .filter(|e| !Self::is_in_body(&self.root, e.start_offset)) .collect() } else { self.errors.iter().collect() }; Self::remove_duplicates(&mut errs, SyntaxError::equal_offset); errs } fn is_in_body<'r>(node: &'r Syntax<'arena, T, V>, position: usize) -> bool where 'r: 'arena, { let p = Self::parentage(node, position); for i in 1..p.len() { if p[i - 1].is_compound_statement() && (p[i].is_methodish_declaration() || p[i].is_function_declaration()) { return true; } } false } // TODO:(shiqicao) move this function to SyntaxTrait, see D18359931 fn parentage<'r>( node: &'r Syntax<'arena, T, V>, position: usize, ) -> Vec<&'r Syntax<'arena, T, V>> where 'r: 'arena, { let mut acc = vec![]; if position < node.full_width() { Self::parentage_(node, position, &mut acc); } acc } fn parentage_<'r>( node: &'r Syntax<'arena, T, V>, mut position: usize, acc: &mut Vec<&'r Syntax<'arena, T, V>>, ) where 'r: 'arena, { for c in node.iter_children() { let width = node.full_width(); if position < width { Self::parentage_(c, position, acc); break; } else { position -= width; } } acc.push(node) } } impl<'a, Syntax, State> SyntaxTree<'a, Syntax, State> where State: Clone, { pub fn build( text: &'a SourceText<'a>, root: Syntax, errors: Vec<SyntaxError>, mode: Option<FileMode>, state: State, ) -> Self { Self { text, root, errors, mode, state, } } // Convert a foreign pointer to a `SyntaTree` reference, the tree is borrowed // from forgein caller, therefore Rust shouldn't drop the content. pub unsafe fn ffi_pointer_as_ref( ptr: usize, text: &'a SourceText<'a>, ) -> Result<&'a Self, String> { let raw_tree = ptr as *mut SyntaxTree<'_, Syntax, State>; let tree = match raw_tree.as_mut() { Some(t) => t, None => return Err("null raw tree pointer".into()), }; // The tree already contains source text, but this source text contains a pointer // into OCaml heap, which might have been invalidated by GC in the meantime. // Replacing the source text with a current one prevents it. This will still end // horribly if the tree starts storing some other pointers into source text, // but it's not the case at the moment. tree.replace_text_unsafe(text); Ok(tree) } // Convert a foreign pointer to boxed `SyntaxTree`. This function can be used when foreign // caller moves a `SyntaxTree` to Rust, when `Box` goes out of scope the SyntaxTree will // be dropped. pub unsafe fn ffi_pointer_into_boxed(ptr: usize, text: &'a SourceText<'a>) -> Box<Self> { let tree_pointer = ptr as *mut Self; let mut tree = Box::from_raw(tree_pointer); // The tree already contains source text, but this source text contains a pointer // into OCaml heap, which might have been invalidated by GC in the meantime. // Replacing the source text with a current one prevents it. // This will still end horribly if the tree starts storing some // other pointers into source text, but it's not the case at the moment. tree.replace_text_unsafe(text); tree } pub fn create( text: &'a SourceText<'a>, root: Syntax, mut errors: Vec<SyntaxError>, mode: Option<FileMode>, state: State, ) -> Self { Self::process_errors(&mut errors); Self::build(text, root, errors, mode, state) } fn remove_duplicates<F>(errors: &mut Vec<impl Borrow<SyntaxError>>, equals: F) where F: Fn(&SyntaxError, &SyntaxError) -> bool, { errors.dedup_by(|e1, e2| equals((*e1).borrow(), (*e2).borrow())); } fn process_errors(errors: &mut Vec<SyntaxError>) { /* We've got the lexical errors and the parser errors together, both with lexically later errors earlier in the list. We want to reverse the list so that later errors come later, and then do a stable sort to put the lexical and parser errors together. */ errors.reverse(); // Vec::sort_by is a stable sort, which is required here errors.sort_by(SyntaxError::compare_offset); Self::remove_duplicates(errors, SyntaxError::weak_equal); } pub fn root(&self) -> &Syntax { &self.root } pub fn text(&self) -> &'a SourceText<'a> { self.text } pub fn all_errors(&self) -> &[SyntaxError] { &self.errors } pub fn mode(&self) -> Option<FileMode> { self.mode } pub fn sc_state(&self) -> &State { &self.state } pub fn is_strict(&self) -> bool { self.mode == Some(FileMode::Strict) } pub fn is_hhi(&self) -> bool { self.mode == Some(FileMode::Hhi) } // "unsafe" because it can break the invariant that text is consistent with other syntax // tree members pub fn replace_text_unsafe(&mut self, text: &'a SourceText<'a>) { self.text = text } pub fn drop_state(self) -> SyntaxTree<'a, Syntax, ()> { SyntaxTree { text: self.text, root: self.root, errors: self.errors, mode: self.mode, state: (), } } //TODO: to_json require some unimplemented methods in syntax.rs, particularly // Hh_json.to_json } impl<'a, Syntax, State> AsRef<SyntaxTree<'a, Syntax, State>> for SyntaxTree<'a, Syntax, State> { fn as_ref(&self) -> &Self { self } } #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] #[repr(u8)] pub enum FileMode { /// just declare signatures, don't check anything Hhi, /// check everything! Strict, } #[cfg(test)] mod tests { use crate::syntax_error; use crate::syntax_tree::SyntaxTree; #[test] fn test_process_errors() { let mut test_errors = vec![ syntax_error::SyntaxError::make(0, 10, syntax_error::error0001, vec![]), syntax_error::SyntaxError::make(10, 20, syntax_error::error0001, vec![]), syntax_error::SyntaxError::make(0, 10, syntax_error::error0001, vec![]), ]; SyntaxTree::<(), ()>::process_errors(&mut test_errors); assert_eq!( vec![ syntax_error::SyntaxError::make(0, 10, syntax_error::error0001, vec![]), syntax_error::SyntaxError::make(10, 20, syntax_error::error0001, vec![]), ], test_errors ); } }
Rust
hhvm/hphp/hack/src/parser/syntax_type.rs
/** * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. An additional * directory. * ** * * THIS FILE IS @generated; DO NOT EDIT IT * To regenerate this file, run * * buck run //hphp/hack/src:generate_full_fidelity * ** * */ use crate::syntax::*; pub trait SyntaxType<C>: SyntaxTypeBase<C> { fn make_end_of_file(ctx: &C, end_of_file_token: Self) -> Self; fn make_script(ctx: &C, script_declarations: Self) -> Self; fn make_qualified_name(ctx: &C, qualified_name_parts: Self) -> Self; fn make_module_name(ctx: &C, module_name_parts: Self) -> Self; fn make_simple_type_specifier(ctx: &C, simple_type_specifier: Self) -> Self; fn make_literal_expression(ctx: &C, literal_expression: Self) -> Self; fn make_prefixed_string_expression(ctx: &C, prefixed_string_name: Self, prefixed_string_str: Self) -> Self; fn make_prefixed_code_expression(ctx: &C, prefixed_code_prefix: Self, prefixed_code_left_backtick: Self, prefixed_code_body: Self, prefixed_code_right_backtick: Self) -> Self; fn make_variable_expression(ctx: &C, variable_expression: Self) -> Self; fn make_pipe_variable_expression(ctx: &C, pipe_variable_expression: Self) -> Self; fn make_file_attribute_specification(ctx: &C, file_attribute_specification_left_double_angle: Self, file_attribute_specification_keyword: Self, file_attribute_specification_colon: Self, file_attribute_specification_attributes: Self, file_attribute_specification_right_double_angle: Self) -> Self; fn make_enum_declaration(ctx: &C, enum_attribute_spec: Self, enum_modifiers: Self, enum_keyword: Self, enum_name: Self, enum_colon: Self, enum_base: Self, enum_type: Self, enum_left_brace: Self, enum_use_clauses: Self, enum_enumerators: Self, enum_right_brace: Self) -> Self; fn make_enum_use(ctx: &C, enum_use_keyword: Self, enum_use_names: Self, enum_use_semicolon: Self) -> Self; fn make_enumerator(ctx: &C, enumerator_name: Self, enumerator_equal: Self, enumerator_value: Self, enumerator_semicolon: Self) -> Self; fn make_enum_class_declaration(ctx: &C, enum_class_attribute_spec: Self, enum_class_modifiers: Self, enum_class_enum_keyword: Self, enum_class_class_keyword: Self, enum_class_name: Self, enum_class_colon: Self, enum_class_base: Self, enum_class_extends: Self, enum_class_extends_list: Self, enum_class_left_brace: Self, enum_class_elements: Self, enum_class_right_brace: Self) -> Self; fn make_enum_class_enumerator(ctx: &C, enum_class_enumerator_modifiers: Self, enum_class_enumerator_type: Self, enum_class_enumerator_name: Self, enum_class_enumerator_initializer: Self, enum_class_enumerator_semicolon: Self) -> Self; fn make_alias_declaration(ctx: &C, alias_attribute_spec: Self, alias_modifiers: Self, alias_module_kw_opt: Self, alias_keyword: Self, alias_name: Self, alias_generic_parameter: Self, alias_constraint: Self, alias_equal: Self, alias_type: Self, alias_semicolon: Self) -> Self; fn make_context_alias_declaration(ctx: &C, ctx_alias_attribute_spec: Self, ctx_alias_keyword: Self, ctx_alias_name: Self, ctx_alias_generic_parameter: Self, ctx_alias_as_constraint: Self, ctx_alias_equal: Self, ctx_alias_context: Self, ctx_alias_semicolon: Self) -> Self; fn make_case_type_declaration(ctx: &C, case_type_attribute_spec: Self, case_type_modifiers: Self, case_type_case_keyword: Self, case_type_type_keyword: Self, case_type_name: Self, case_type_generic_parameter: Self, case_type_as: Self, case_type_bounds: Self, case_type_equal: Self, case_type_variants: Self, case_type_semicolon: Self) -> Self; fn make_case_type_variant(ctx: &C, case_type_variant_bar: Self, case_type_variant_type: Self) -> Self; fn make_property_declaration(ctx: &C, property_attribute_spec: Self, property_modifiers: Self, property_type: Self, property_declarators: Self, property_semicolon: Self) -> Self; fn make_property_declarator(ctx: &C, property_name: Self, property_initializer: Self) -> Self; fn make_namespace_declaration(ctx: &C, namespace_header: Self, namespace_body: Self) -> Self; fn make_namespace_declaration_header(ctx: &C, namespace_keyword: Self, namespace_name: Self) -> Self; fn make_namespace_body(ctx: &C, namespace_left_brace: Self, namespace_declarations: Self, namespace_right_brace: Self) -> Self; fn make_namespace_empty_body(ctx: &C, namespace_semicolon: Self) -> Self; fn make_namespace_use_declaration(ctx: &C, namespace_use_keyword: Self, namespace_use_kind: Self, namespace_use_clauses: Self, namespace_use_semicolon: Self) -> Self; fn make_namespace_group_use_declaration(ctx: &C, namespace_group_use_keyword: Self, namespace_group_use_kind: Self, namespace_group_use_prefix: Self, namespace_group_use_left_brace: Self, namespace_group_use_clauses: Self, namespace_group_use_right_brace: Self, namespace_group_use_semicolon: Self) -> Self; fn make_namespace_use_clause(ctx: &C, namespace_use_clause_kind: Self, namespace_use_name: Self, namespace_use_as: Self, namespace_use_alias: Self) -> Self; fn make_function_declaration(ctx: &C, function_attribute_spec: Self, function_declaration_header: Self, function_body: Self) -> Self; fn make_function_declaration_header(ctx: &C, function_modifiers: Self, function_keyword: Self, function_name: Self, function_type_parameter_list: Self, function_left_paren: Self, function_parameter_list: Self, function_right_paren: Self, function_contexts: Self, function_colon: Self, function_readonly_return: Self, function_type: Self, function_where_clause: Self) -> Self; fn make_contexts(ctx: &C, contexts_left_bracket: Self, contexts_types: Self, contexts_right_bracket: Self) -> Self; fn make_where_clause(ctx: &C, where_clause_keyword: Self, where_clause_constraints: Self) -> Self; fn make_where_constraint(ctx: &C, where_constraint_left_type: Self, where_constraint_operator: Self, where_constraint_right_type: Self) -> Self; fn make_methodish_declaration(ctx: &C, methodish_attribute: Self, methodish_function_decl_header: Self, methodish_function_body: Self, methodish_semicolon: Self) -> Self; fn make_methodish_trait_resolution(ctx: &C, methodish_trait_attribute: Self, methodish_trait_function_decl_header: Self, methodish_trait_equal: Self, methodish_trait_name: Self, methodish_trait_semicolon: Self) -> Self; fn make_classish_declaration(ctx: &C, classish_attribute: Self, classish_modifiers: Self, classish_xhp: Self, classish_keyword: Self, classish_name: Self, classish_type_parameters: Self, classish_extends_keyword: Self, classish_extends_list: Self, classish_implements_keyword: Self, classish_implements_list: Self, classish_where_clause: Self, classish_body: Self) -> Self; fn make_classish_body(ctx: &C, classish_body_left_brace: Self, classish_body_elements: Self, classish_body_right_brace: Self) -> Self; fn make_trait_use(ctx: &C, trait_use_keyword: Self, trait_use_names: Self, trait_use_semicolon: Self) -> Self; fn make_require_clause(ctx: &C, require_keyword: Self, require_kind: Self, require_name: Self, require_semicolon: Self) -> Self; fn make_const_declaration(ctx: &C, const_attribute_spec: Self, const_modifiers: Self, const_keyword: Self, const_type_specifier: Self, const_declarators: Self, const_semicolon: Self) -> Self; fn make_constant_declarator(ctx: &C, constant_declarator_name: Self, constant_declarator_initializer: Self) -> Self; fn make_type_const_declaration(ctx: &C, type_const_attribute_spec: Self, type_const_modifiers: Self, type_const_keyword: Self, type_const_type_keyword: Self, type_const_name: Self, type_const_type_parameters: Self, type_const_type_constraints: Self, type_const_equal: Self, type_const_type_specifier: Self, type_const_semicolon: Self) -> Self; fn make_context_const_declaration(ctx: &C, context_const_modifiers: Self, context_const_const_keyword: Self, context_const_ctx_keyword: Self, context_const_name: Self, context_const_type_parameters: Self, context_const_constraint: Self, context_const_equal: Self, context_const_ctx_list: Self, context_const_semicolon: Self) -> Self; fn make_decorated_expression(ctx: &C, decorated_expression_decorator: Self, decorated_expression_expression: Self) -> Self; fn make_parameter_declaration(ctx: &C, parameter_attribute: Self, parameter_visibility: Self, parameter_call_convention: Self, parameter_readonly: Self, parameter_type: Self, parameter_name: Self, parameter_default_value: Self) -> Self; fn make_variadic_parameter(ctx: &C, variadic_parameter_call_convention: Self, variadic_parameter_type: Self, variadic_parameter_ellipsis: Self) -> Self; fn make_old_attribute_specification(ctx: &C, old_attribute_specification_left_double_angle: Self, old_attribute_specification_attributes: Self, old_attribute_specification_right_double_angle: Self) -> Self; fn make_attribute_specification(ctx: &C, attribute_specification_attributes: Self) -> Self; fn make_attribute(ctx: &C, attribute_at: Self, attribute_attribute_name: Self) -> Self; fn make_inclusion_expression(ctx: &C, inclusion_require: Self, inclusion_filename: Self) -> Self; fn make_inclusion_directive(ctx: &C, inclusion_expression: Self, inclusion_semicolon: Self) -> Self; fn make_compound_statement(ctx: &C, compound_left_brace: Self, compound_statements: Self, compound_right_brace: Self) -> Self; fn make_expression_statement(ctx: &C, expression_statement_expression: Self, expression_statement_semicolon: Self) -> Self; fn make_markup_section(ctx: &C, markup_hashbang: Self, markup_suffix: Self) -> Self; fn make_markup_suffix(ctx: &C, markup_suffix_less_than_question: Self, markup_suffix_name: Self) -> Self; fn make_unset_statement(ctx: &C, unset_keyword: Self, unset_left_paren: Self, unset_variables: Self, unset_right_paren: Self, unset_semicolon: Self) -> Self; fn make_declare_local_statement(ctx: &C, declare_local_keyword: Self, declare_local_variable: Self, declare_local_colon: Self, declare_local_type: Self, declare_local_initializer: Self, declare_local_semicolon: Self) -> Self; fn make_using_statement_block_scoped(ctx: &C, using_block_await_keyword: Self, using_block_using_keyword: Self, using_block_left_paren: Self, using_block_expressions: Self, using_block_right_paren: Self, using_block_body: Self) -> Self; fn make_using_statement_function_scoped(ctx: &C, using_function_await_keyword: Self, using_function_using_keyword: Self, using_function_expression: Self, using_function_semicolon: Self) -> Self; fn make_while_statement(ctx: &C, while_keyword: Self, while_left_paren: Self, while_condition: Self, while_right_paren: Self, while_body: Self) -> Self; fn make_if_statement(ctx: &C, if_keyword: Self, if_left_paren: Self, if_condition: Self, if_right_paren: Self, if_statement: Self, if_else_clause: Self) -> Self; fn make_else_clause(ctx: &C, else_keyword: Self, else_statement: Self) -> Self; fn make_try_statement(ctx: &C, try_keyword: Self, try_compound_statement: Self, try_catch_clauses: Self, try_finally_clause: Self) -> Self; fn make_catch_clause(ctx: &C, catch_keyword: Self, catch_left_paren: Self, catch_type: Self, catch_variable: Self, catch_right_paren: Self, catch_body: Self) -> Self; fn make_finally_clause(ctx: &C, finally_keyword: Self, finally_body: Self) -> Self; fn make_do_statement(ctx: &C, do_keyword: Self, do_body: Self, do_while_keyword: Self, do_left_paren: Self, do_condition: Self, do_right_paren: Self, do_semicolon: Self) -> Self; fn make_for_statement(ctx: &C, for_keyword: Self, for_left_paren: Self, for_initializer: Self, for_first_semicolon: Self, for_control: Self, for_second_semicolon: Self, for_end_of_loop: Self, for_right_paren: Self, for_body: Self) -> Self; fn make_foreach_statement(ctx: &C, foreach_keyword: Self, foreach_left_paren: Self, foreach_collection: Self, foreach_await_keyword: Self, foreach_as: Self, foreach_key: Self, foreach_arrow: Self, foreach_value: Self, foreach_right_paren: Self, foreach_body: Self) -> Self; fn make_switch_statement(ctx: &C, switch_keyword: Self, switch_left_paren: Self, switch_expression: Self, switch_right_paren: Self, switch_left_brace: Self, switch_sections: Self, switch_right_brace: Self) -> Self; fn make_switch_section(ctx: &C, switch_section_labels: Self, switch_section_statements: Self, switch_section_fallthrough: Self) -> Self; fn make_switch_fallthrough(ctx: &C, fallthrough_keyword: Self, fallthrough_semicolon: Self) -> Self; fn make_case_label(ctx: &C, case_keyword: Self, case_expression: Self, case_colon: Self) -> Self; fn make_default_label(ctx: &C, default_keyword: Self, default_colon: Self) -> Self; fn make_match_statement(ctx: &C, match_statement_keyword: Self, match_statement_left_paren: Self, match_statement_expression: Self, match_statement_right_paren: Self, match_statement_left_brace: Self, match_statement_arms: Self, match_statement_right_brace: Self) -> Self; fn make_match_statement_arm(ctx: &C, match_statement_arm_pattern: Self, match_statement_arm_arrow: Self, match_statement_arm_body: Self) -> Self; fn make_return_statement(ctx: &C, return_keyword: Self, return_expression: Self, return_semicolon: Self) -> Self; fn make_yield_break_statement(ctx: &C, yield_break_keyword: Self, yield_break_break: Self, yield_break_semicolon: Self) -> Self; fn make_throw_statement(ctx: &C, throw_keyword: Self, throw_expression: Self, throw_semicolon: Self) -> Self; fn make_break_statement(ctx: &C, break_keyword: Self, break_semicolon: Self) -> Self; fn make_continue_statement(ctx: &C, continue_keyword: Self, continue_semicolon: Self) -> Self; fn make_echo_statement(ctx: &C, echo_keyword: Self, echo_expressions: Self, echo_semicolon: Self) -> Self; fn make_concurrent_statement(ctx: &C, concurrent_keyword: Self, concurrent_statement: Self) -> Self; fn make_simple_initializer(ctx: &C, simple_initializer_equal: Self, simple_initializer_value: Self) -> Self; fn make_anonymous_class(ctx: &C, anonymous_class_class_keyword: Self, anonymous_class_left_paren: Self, anonymous_class_argument_list: Self, anonymous_class_right_paren: Self, anonymous_class_extends_keyword: Self, anonymous_class_extends_list: Self, anonymous_class_implements_keyword: Self, anonymous_class_implements_list: Self, anonymous_class_body: Self) -> Self; fn make_anonymous_function(ctx: &C, anonymous_attribute_spec: Self, anonymous_async_keyword: Self, anonymous_function_keyword: Self, anonymous_left_paren: Self, anonymous_parameters: Self, anonymous_right_paren: Self, anonymous_ctx_list: Self, anonymous_colon: Self, anonymous_readonly_return: Self, anonymous_type: Self, anonymous_use: Self, anonymous_body: Self) -> Self; fn make_anonymous_function_use_clause(ctx: &C, anonymous_use_keyword: Self, anonymous_use_left_paren: Self, anonymous_use_variables: Self, anonymous_use_right_paren: Self) -> Self; fn make_variable_pattern(ctx: &C, variable_pattern_variable: Self) -> Self; fn make_constructor_pattern(ctx: &C, constructor_pattern_constructor: Self, constructor_pattern_left_paren: Self, constructor_pattern_members: Self, constructor_pattern_right_paren: Self) -> Self; fn make_refinement_pattern(ctx: &C, refinement_pattern_variable: Self, refinement_pattern_colon: Self, refinement_pattern_specifier: Self) -> Self; fn make_lambda_expression(ctx: &C, lambda_attribute_spec: Self, lambda_async: Self, lambda_signature: Self, lambda_arrow: Self, lambda_body: Self) -> Self; fn make_lambda_signature(ctx: &C, lambda_left_paren: Self, lambda_parameters: Self, lambda_right_paren: Self, lambda_contexts: Self, lambda_colon: Self, lambda_readonly_return: Self, lambda_type: Self) -> Self; fn make_cast_expression(ctx: &C, cast_left_paren: Self, cast_type: Self, cast_right_paren: Self, cast_operand: Self) -> Self; fn make_scope_resolution_expression(ctx: &C, scope_resolution_qualifier: Self, scope_resolution_operator: Self, scope_resolution_name: Self) -> Self; fn make_member_selection_expression(ctx: &C, member_object: Self, member_operator: Self, member_name: Self) -> Self; fn make_safe_member_selection_expression(ctx: &C, safe_member_object: Self, safe_member_operator: Self, safe_member_name: Self) -> Self; fn make_embedded_member_selection_expression(ctx: &C, embedded_member_object: Self, embedded_member_operator: Self, embedded_member_name: Self) -> Self; fn make_yield_expression(ctx: &C, yield_keyword: Self, yield_operand: Self) -> Self; fn make_prefix_unary_expression(ctx: &C, prefix_unary_operator: Self, prefix_unary_operand: Self) -> Self; fn make_postfix_unary_expression(ctx: &C, postfix_unary_operand: Self, postfix_unary_operator: Self) -> Self; fn make_binary_expression(ctx: &C, binary_left_operand: Self, binary_operator: Self, binary_right_operand: Self) -> Self; fn make_is_expression(ctx: &C, is_left_operand: Self, is_operator: Self, is_right_operand: Self) -> Self; fn make_as_expression(ctx: &C, as_left_operand: Self, as_operator: Self, as_right_operand: Self) -> Self; fn make_nullable_as_expression(ctx: &C, nullable_as_left_operand: Self, nullable_as_operator: Self, nullable_as_right_operand: Self) -> Self; fn make_upcast_expression(ctx: &C, upcast_left_operand: Self, upcast_operator: Self, upcast_right_operand: Self) -> Self; fn make_conditional_expression(ctx: &C, conditional_test: Self, conditional_question: Self, conditional_consequence: Self, conditional_colon: Self, conditional_alternative: Self) -> Self; fn make_eval_expression(ctx: &C, eval_keyword: Self, eval_left_paren: Self, eval_argument: Self, eval_right_paren: Self) -> Self; fn make_isset_expression(ctx: &C, isset_keyword: Self, isset_left_paren: Self, isset_argument_list: Self, isset_right_paren: Self) -> Self; fn make_function_call_expression(ctx: &C, function_call_receiver: Self, function_call_type_args: Self, function_call_left_paren: Self, function_call_argument_list: Self, function_call_right_paren: Self) -> Self; fn make_function_pointer_expression(ctx: &C, function_pointer_receiver: Self, function_pointer_type_args: Self) -> Self; fn make_parenthesized_expression(ctx: &C, parenthesized_expression_left_paren: Self, parenthesized_expression_expression: Self, parenthesized_expression_right_paren: Self) -> Self; fn make_braced_expression(ctx: &C, braced_expression_left_brace: Self, braced_expression_expression: Self, braced_expression_right_brace: Self) -> Self; fn make_et_splice_expression(ctx: &C, et_splice_expression_dollar: Self, et_splice_expression_left_brace: Self, et_splice_expression_expression: Self, et_splice_expression_right_brace: Self) -> Self; fn make_embedded_braced_expression(ctx: &C, embedded_braced_expression_left_brace: Self, embedded_braced_expression_expression: Self, embedded_braced_expression_right_brace: Self) -> Self; fn make_list_expression(ctx: &C, list_keyword: Self, list_left_paren: Self, list_members: Self, list_right_paren: Self) -> Self; fn make_collection_literal_expression(ctx: &C, collection_literal_name: Self, collection_literal_left_brace: Self, collection_literal_initializers: Self, collection_literal_right_brace: Self) -> Self; fn make_object_creation_expression(ctx: &C, object_creation_new_keyword: Self, object_creation_object: Self) -> Self; fn make_constructor_call(ctx: &C, constructor_call_type: Self, constructor_call_left_paren: Self, constructor_call_argument_list: Self, constructor_call_right_paren: Self) -> Self; fn make_darray_intrinsic_expression(ctx: &C, darray_intrinsic_keyword: Self, darray_intrinsic_explicit_type: Self, darray_intrinsic_left_bracket: Self, darray_intrinsic_members: Self, darray_intrinsic_right_bracket: Self) -> Self; fn make_dictionary_intrinsic_expression(ctx: &C, dictionary_intrinsic_keyword: Self, dictionary_intrinsic_explicit_type: Self, dictionary_intrinsic_left_bracket: Self, dictionary_intrinsic_members: Self, dictionary_intrinsic_right_bracket: Self) -> Self; fn make_keyset_intrinsic_expression(ctx: &C, keyset_intrinsic_keyword: Self, keyset_intrinsic_explicit_type: Self, keyset_intrinsic_left_bracket: Self, keyset_intrinsic_members: Self, keyset_intrinsic_right_bracket: Self) -> Self; fn make_varray_intrinsic_expression(ctx: &C, varray_intrinsic_keyword: Self, varray_intrinsic_explicit_type: Self, varray_intrinsic_left_bracket: Self, varray_intrinsic_members: Self, varray_intrinsic_right_bracket: Self) -> Self; fn make_vector_intrinsic_expression(ctx: &C, vector_intrinsic_keyword: Self, vector_intrinsic_explicit_type: Self, vector_intrinsic_left_bracket: Self, vector_intrinsic_members: Self, vector_intrinsic_right_bracket: Self) -> Self; fn make_element_initializer(ctx: &C, element_key: Self, element_arrow: Self, element_value: Self) -> Self; fn make_subscript_expression(ctx: &C, subscript_receiver: Self, subscript_left_bracket: Self, subscript_index: Self, subscript_right_bracket: Self) -> Self; fn make_embedded_subscript_expression(ctx: &C, embedded_subscript_receiver: Self, embedded_subscript_left_bracket: Self, embedded_subscript_index: Self, embedded_subscript_right_bracket: Self) -> Self; fn make_awaitable_creation_expression(ctx: &C, awaitable_attribute_spec: Self, awaitable_async: Self, awaitable_compound_statement: Self) -> Self; fn make_xhp_children_declaration(ctx: &C, xhp_children_keyword: Self, xhp_children_expression: Self, xhp_children_semicolon: Self) -> Self; fn make_xhp_children_parenthesized_list(ctx: &C, xhp_children_list_left_paren: Self, xhp_children_list_xhp_children: Self, xhp_children_list_right_paren: Self) -> Self; fn make_xhp_category_declaration(ctx: &C, xhp_category_keyword: Self, xhp_category_categories: Self, xhp_category_semicolon: Self) -> Self; fn make_xhp_enum_type(ctx: &C, xhp_enum_like: Self, xhp_enum_keyword: Self, xhp_enum_left_brace: Self, xhp_enum_values: Self, xhp_enum_right_brace: Self) -> Self; fn make_xhp_lateinit(ctx: &C, xhp_lateinit_at: Self, xhp_lateinit_keyword: Self) -> Self; fn make_xhp_required(ctx: &C, xhp_required_at: Self, xhp_required_keyword: Self) -> Self; fn make_xhp_class_attribute_declaration(ctx: &C, xhp_attribute_keyword: Self, xhp_attribute_attributes: Self, xhp_attribute_semicolon: Self) -> Self; fn make_xhp_class_attribute(ctx: &C, xhp_attribute_decl_type: Self, xhp_attribute_decl_name: Self, xhp_attribute_decl_initializer: Self, xhp_attribute_decl_required: Self) -> Self; fn make_xhp_simple_class_attribute(ctx: &C, xhp_simple_class_attribute_type: Self) -> Self; fn make_xhp_simple_attribute(ctx: &C, xhp_simple_attribute_name: Self, xhp_simple_attribute_equal: Self, xhp_simple_attribute_expression: Self) -> Self; fn make_xhp_spread_attribute(ctx: &C, xhp_spread_attribute_left_brace: Self, xhp_spread_attribute_spread_operator: Self, xhp_spread_attribute_expression: Self, xhp_spread_attribute_right_brace: Self) -> Self; fn make_xhp_open(ctx: &C, xhp_open_left_angle: Self, xhp_open_name: Self, xhp_open_attributes: Self, xhp_open_right_angle: Self) -> Self; fn make_xhp_expression(ctx: &C, xhp_open: Self, xhp_body: Self, xhp_close: Self) -> Self; fn make_xhp_close(ctx: &C, xhp_close_left_angle: Self, xhp_close_name: Self, xhp_close_right_angle: Self) -> Self; fn make_type_constant(ctx: &C, type_constant_left_type: Self, type_constant_separator: Self, type_constant_right_type: Self) -> Self; fn make_vector_type_specifier(ctx: &C, vector_type_keyword: Self, vector_type_left_angle: Self, vector_type_type: Self, vector_type_trailing_comma: Self, vector_type_right_angle: Self) -> Self; fn make_keyset_type_specifier(ctx: &C, keyset_type_keyword: Self, keyset_type_left_angle: Self, keyset_type_type: Self, keyset_type_trailing_comma: Self, keyset_type_right_angle: Self) -> Self; fn make_tuple_type_explicit_specifier(ctx: &C, tuple_type_keyword: Self, tuple_type_left_angle: Self, tuple_type_types: Self, tuple_type_right_angle: Self) -> Self; fn make_varray_type_specifier(ctx: &C, varray_keyword: Self, varray_left_angle: Self, varray_type: Self, varray_trailing_comma: Self, varray_right_angle: Self) -> Self; fn make_function_ctx_type_specifier(ctx: &C, function_ctx_type_keyword: Self, function_ctx_type_variable: Self) -> Self; fn make_type_parameter(ctx: &C, type_attribute_spec: Self, type_reified: Self, type_variance: Self, type_name: Self, type_param_params: Self, type_constraints: Self) -> Self; fn make_type_constraint(ctx: &C, constraint_keyword: Self, constraint_type: Self) -> Self; fn make_context_constraint(ctx: &C, ctx_constraint_keyword: Self, ctx_constraint_ctx_list: Self) -> Self; fn make_darray_type_specifier(ctx: &C, darray_keyword: Self, darray_left_angle: Self, darray_key: Self, darray_comma: Self, darray_value: Self, darray_trailing_comma: Self, darray_right_angle: Self) -> Self; fn make_dictionary_type_specifier(ctx: &C, dictionary_type_keyword: Self, dictionary_type_left_angle: Self, dictionary_type_members: Self, dictionary_type_right_angle: Self) -> Self; fn make_closure_type_specifier(ctx: &C, closure_outer_left_paren: Self, closure_readonly_keyword: Self, closure_function_keyword: Self, closure_inner_left_paren: Self, closure_parameter_list: Self, closure_inner_right_paren: Self, closure_contexts: Self, closure_colon: Self, closure_readonly_return: Self, closure_return_type: Self, closure_outer_right_paren: Self) -> Self; fn make_closure_parameter_type_specifier(ctx: &C, closure_parameter_call_convention: Self, closure_parameter_readonly: Self, closure_parameter_type: Self) -> Self; fn make_type_refinement(ctx: &C, type_refinement_type: Self, type_refinement_keyword: Self, type_refinement_left_brace: Self, type_refinement_members: Self, type_refinement_right_brace: Self) -> Self; fn make_type_in_refinement(ctx: &C, type_in_refinement_keyword: Self, type_in_refinement_name: Self, type_in_refinement_type_parameters: Self, type_in_refinement_constraints: Self, type_in_refinement_equal: Self, type_in_refinement_type: Self) -> Self; fn make_ctx_in_refinement(ctx: &C, ctx_in_refinement_keyword: Self, ctx_in_refinement_name: Self, ctx_in_refinement_type_parameters: Self, ctx_in_refinement_constraints: Self, ctx_in_refinement_equal: Self, ctx_in_refinement_ctx_list: Self) -> Self; fn make_classname_type_specifier(ctx: &C, classname_keyword: Self, classname_left_angle: Self, classname_type: Self, classname_trailing_comma: Self, classname_right_angle: Self) -> Self; fn make_field_specifier(ctx: &C, field_question: Self, field_name: Self, field_arrow: Self, field_type: Self) -> Self; fn make_field_initializer(ctx: &C, field_initializer_name: Self, field_initializer_arrow: Self, field_initializer_value: Self) -> Self; fn make_shape_type_specifier(ctx: &C, shape_type_keyword: Self, shape_type_left_paren: Self, shape_type_fields: Self, shape_type_ellipsis: Self, shape_type_right_paren: Self) -> Self; fn make_shape_expression(ctx: &C, shape_expression_keyword: Self, shape_expression_left_paren: Self, shape_expression_fields: Self, shape_expression_right_paren: Self) -> Self; fn make_tuple_expression(ctx: &C, tuple_expression_keyword: Self, tuple_expression_left_paren: Self, tuple_expression_items: Self, tuple_expression_right_paren: Self) -> Self; fn make_generic_type_specifier(ctx: &C, generic_class_type: Self, generic_argument_list: Self) -> Self; fn make_nullable_type_specifier(ctx: &C, nullable_question: Self, nullable_type: Self) -> Self; fn make_like_type_specifier(ctx: &C, like_tilde: Self, like_type: Self) -> Self; fn make_soft_type_specifier(ctx: &C, soft_at: Self, soft_type: Self) -> Self; fn make_attributized_specifier(ctx: &C, attributized_specifier_attribute_spec: Self, attributized_specifier_type: Self) -> Self; fn make_reified_type_argument(ctx: &C, reified_type_argument_reified: Self, reified_type_argument_type: Self) -> Self; fn make_type_arguments(ctx: &C, type_arguments_left_angle: Self, type_arguments_types: Self, type_arguments_right_angle: Self) -> Self; fn make_type_parameters(ctx: &C, type_parameters_left_angle: Self, type_parameters_parameters: Self, type_parameters_right_angle: Self) -> Self; fn make_tuple_type_specifier(ctx: &C, tuple_left_paren: Self, tuple_types: Self, tuple_right_paren: Self) -> Self; fn make_union_type_specifier(ctx: &C, union_left_paren: Self, union_types: Self, union_right_paren: Self) -> Self; fn make_intersection_type_specifier(ctx: &C, intersection_left_paren: Self, intersection_types: Self, intersection_right_paren: Self) -> Self; fn make_error(ctx: &C, error_error: Self) -> Self; fn make_list_item(ctx: &C, list_item: Self, list_separator: Self) -> Self; fn make_enum_class_label_expression(ctx: &C, enum_class_label_qualifier: Self, enum_class_label_hash: Self, enum_class_label_expression: Self) -> Self; fn make_module_declaration(ctx: &C, module_declaration_attribute_spec: Self, module_declaration_new_keyword: Self, module_declaration_module_keyword: Self, module_declaration_name: Self, module_declaration_left_brace: Self, module_declaration_exports: Self, module_declaration_imports: Self, module_declaration_right_brace: Self) -> Self; fn make_module_exports(ctx: &C, module_exports_exports_keyword: Self, module_exports_left_brace: Self, module_exports_exports: Self, module_exports_right_brace: Self) -> Self; fn make_module_imports(ctx: &C, module_imports_imports_keyword: Self, module_imports_left_brace: Self, module_imports_imports: Self, module_imports_right_brace: Self) -> Self; fn make_module_membership_declaration(ctx: &C, module_membership_declaration_module_keyword: Self, module_membership_declaration_name: Self, module_membership_declaration_semicolon: Self) -> Self; fn make_package_expression(ctx: &C, package_expression_keyword: Self, package_expression_name: Self) -> Self; }
Rust
hhvm/hphp/hack/src/parser/token_factory.rs
// Copyright (c) 2019, Facebook, Inc. // All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use std::fmt::Debug; use crate::lexable_token::LexableToken; use crate::lexable_trivia::LexableTrivia; use crate::token_kind::TokenKind; use crate::trivia_factory::SimpleTriviaFactory; use crate::trivia_factory::SimpleTriviaFactoryImpl; use crate::trivia_factory::TriviaFactory; pub type Trivia<TF> = <<TF as TokenFactory>::Token as LexableToken>::Trivia; pub type Trivium<TF> = <<<TF as TokenFactory>::Token as LexableToken>::Trivia as LexableTrivia>::Trivium; pub trait TokenFactory: Clone { type Token: LexableToken; type TriviaFactory: TriviaFactory<Trivia = Trivia<Self>>; fn make( &mut self, kind: TokenKind, offset: usize, width: usize, leading: Trivia<Self>, trailing: Trivia<Self>, ) -> Self::Token; fn with_leading(&mut self, token: Self::Token, trailing: Trivia<Self>) -> Self::Token; fn with_trailing(&mut self, token: Self::Token, trailing: Trivia<Self>) -> Self::Token; fn with_kind(&mut self, token: Self::Token, kind: TokenKind) -> Self::Token; fn trivia_factory_mut(&mut self) -> &mut Self::TriviaFactory; } pub trait SimpleTokenFactory: LexableToken { fn make( kind: TokenKind, offset: usize, width: usize, leading: <Self as LexableToken>::Trivia, trailing: <Self as LexableToken>::Trivia, ) -> Self; fn with_leading(self, leading: <Self as LexableToken>::Trivia) -> Self; fn with_trailing(self, trailing: <Self as LexableToken>::Trivia) -> Self; fn with_kind(self, kind: TokenKind) -> Self; } #[derive(Clone)] pub struct SimpleTokenFactoryImpl<Token: SimpleTokenFactory>( std::marker::PhantomData<Token>, SimpleTriviaFactoryImpl<<Token as LexableToken>::Trivia>, ); impl<Token: SimpleTokenFactory> SimpleTokenFactoryImpl<Token> { pub fn new() -> Self { Self(std::marker::PhantomData, SimpleTriviaFactoryImpl::new()) } } impl<T> TokenFactory for SimpleTokenFactoryImpl<T> where T: SimpleTokenFactory + Debug, <T as LexableToken>::Trivia: SimpleTriviaFactory, { type Token = T; type TriviaFactory = SimpleTriviaFactoryImpl<<T as LexableToken>::Trivia>; fn make( &mut self, kind: TokenKind, offset: usize, width: usize, leading: Trivia<Self>, trailing: Trivia<Self>, ) -> Self::Token { T::make(kind, offset, width, leading, trailing) } fn with_leading( &mut self, token: Self::Token, leading: <Self::Token as LexableToken>::Trivia, ) -> Self::Token { token.with_leading(leading) } fn with_trailing( &mut self, token: Self::Token, trailing: <Self::Token as LexableToken>::Trivia, ) -> Self::Token { token.with_trailing(trailing) } fn with_kind(&mut self, token: Self::Token, kind: TokenKind) -> Self::Token { token.with_kind(kind) } fn trivia_factory_mut(&mut self) -> &mut Self::TriviaFactory { &mut self.1 } } pub trait TokenMutator: TokenFactory { fn trim_left(&mut self, t: &Self::Token, n: usize) -> Self::Token; fn trim_right(&mut self, t: &Self::Token, n: usize) -> Self::Token; fn concatenate(&mut self, s: &Self::Token, e: &Self::Token) -> Self::Token; }
Rust
hhvm/hphp/hack/src/parser/token_kind.rs
/** * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. An additional * directory. * ** * * THIS FILE IS @generated; DO NOT EDIT IT * To regenerate this file, run * * buck run //hphp/hack/src:generate_full_fidelity * ** * */ use std::num::NonZeroUsize; use ocamlrep::{FromOcamlRep, ToOcamlRep}; #[allow(non_camel_case_types)] // allow Include_once and Require_once #[derive(Debug, Copy, Clone, PartialEq, Ord, Eq, PartialOrd, FromOcamlRep, ToOcamlRep)] #[repr(u8)] pub enum TokenKind { // No text tokens EndOfFile = 0, // Given text tokens Abstract = 1, Arraykey = 2, As = 3, Async = 4, Attribute = 5, Await = 6, Backslash = 7, Binary = 8, Bool = 9, Boolean = 10, Break = 11, Case = 12, Catch = 13, Category = 14, Children = 15, Class = 16, Classname = 17, Clone = 18, Concurrent = 19, Const = 20, Construct = 21, Continue = 22, Ctx = 23, Darray = 24, Default = 25, Dict = 26, Do = 27, Double = 28, Echo = 29, Else = 30, Empty = 31, Endif = 32, Enum = 33, Eval = 34, Exports = 35, Extends = 36, Fallthrough = 37, Float = 38, File = 39, Final = 40, Finally = 41, For = 42, Foreach = 43, Function = 44, Global = 45, If = 46, Implements = 47, Imports = 48, Include = 49, Include_once = 50, Inout = 51, Instanceof = 52, Insteadof = 53, Int = 54, Integer = 55, Interface = 56, Is = 57, Isset = 58, Keyset = 59, Lateinit = 60, List = 61, Match = 62, Mixed = 63, Module = 64, Namespace = 65, New = 66, Newctx = 67, Newtype = 68, Noreturn = 69, Num = 70, Parent = 71, Print = 72, Private = 73, Protected = 74, Public = 75, Real = 76, Reify = 77, Require = 78, Require_once = 79, Required = 80, Resource = 81, Return = 82, SelfToken = 83, Shape = 84, Static = 85, String = 86, Super = 87, Switch = 88, This = 89, Throw = 90, Trait = 91, Try = 92, Tuple = 93, Type = 94, Unset = 95, Upcast = 96, Use = 97, Using = 98, Var = 99, Varray = 100, Vec = 101, Void = 102, With = 103, Where = 104, While = 105, Yield = 106, NullLiteral = 107, LeftBracket = 108, RightBracket = 109, LeftParen = 110, RightParen = 111, LeftBrace = 112, RightBrace = 113, Dot = 114, MinusGreaterThan = 115, PlusPlus = 116, MinusMinus = 117, StarStar = 118, Star = 119, Plus = 120, Minus = 121, Tilde = 122, Exclamation = 123, Dollar = 124, Slash = 125, Percent = 126, LessThanEqualGreaterThan = 127, LessThanLessThan = 128, GreaterThanGreaterThan = 129, LessThan = 130, GreaterThan = 131, LessThanEqual = 132, GreaterThanEqual = 133, EqualEqual = 134, EqualEqualEqual = 135, ExclamationEqual = 136, ExclamationEqualEqual = 137, Carat = 138, Bar = 139, Ampersand = 140, AmpersandAmpersand = 141, BarBar = 142, Question = 143, QuestionAs = 144, QuestionColon = 145, QuestionQuestion = 146, QuestionQuestionEqual = 147, Colon = 148, Semicolon = 149, Equal = 150, StarStarEqual = 151, StarEqual = 152, SlashEqual = 153, PercentEqual = 154, PlusEqual = 155, MinusEqual = 156, DotEqual = 157, LessThanLessThanEqual = 158, GreaterThanGreaterThanEqual = 159, AmpersandEqual = 160, CaratEqual = 161, BarEqual = 162, Comma = 163, At = 164, ColonColon = 165, EqualGreaterThan = 166, EqualEqualGreaterThan = 167, QuestionMinusGreaterThan = 168, DotDotDot = 169, DollarDollar = 170, BarGreaterThan = 171, SlashGreaterThan = 172, LessThanSlash = 173, LessThanQuestion = 174, Backtick = 175, XHP = 176, Hash = 177, Readonly = 178, Internal = 179, Package = 180, Let = 181, // Variable text tokens ErrorToken = 182, Name = 183, Variable = 184, DecimalLiteral = 185, OctalLiteral = 186, HexadecimalLiteral = 187, BinaryLiteral = 188, FloatingLiteral = 189, SingleQuotedStringLiteral = 190, DoubleQuotedStringLiteral = 191, DoubleQuotedStringLiteralHead = 192, StringLiteralBody = 193, DoubleQuotedStringLiteralTail = 194, HeredocStringLiteral = 195, HeredocStringLiteralHead = 196, HeredocStringLiteralTail = 197, NowdocStringLiteral = 198, BooleanLiteral = 199, XHPCategoryName = 200, XHPElementName = 201, XHPClassName = 202, XHPStringLiteral = 203, XHPBody = 204, XHPComment = 205, Hashbang = 206, } impl TokenKind { pub fn to_string(self) -> &'static str { match self { // No text tokens TokenKind::EndOfFile => "end_of_file", // Given text tokens TokenKind::Abstract => "abstract", TokenKind::Arraykey => "arraykey", TokenKind::As => "as", TokenKind::Async => "async", TokenKind::Attribute => "attribute", TokenKind::Await => "await", TokenKind::Backslash => "\\", TokenKind::Binary => "binary", TokenKind::Bool => "bool", TokenKind::Boolean => "boolean", TokenKind::Break => "break", TokenKind::Case => "case", TokenKind::Catch => "catch", TokenKind::Category => "category", TokenKind::Children => "children", TokenKind::Class => "class", TokenKind::Classname => "classname", TokenKind::Clone => "clone", TokenKind::Concurrent => "concurrent", TokenKind::Const => "const", TokenKind::Construct => "__construct", TokenKind::Continue => "continue", TokenKind::Ctx => "ctx", TokenKind::Darray => "darray", TokenKind::Default => "default", TokenKind::Dict => "dict", TokenKind::Do => "do", TokenKind::Double => "double", TokenKind::Echo => "echo", TokenKind::Else => "else", TokenKind::Empty => "empty", TokenKind::Endif => "endif", TokenKind::Enum => "enum", TokenKind::Eval => "eval", TokenKind::Exports => "exports", TokenKind::Extends => "extends", TokenKind::Fallthrough => "fallthrough", TokenKind::Float => "float", TokenKind::File => "file", TokenKind::Final => "final", TokenKind::Finally => "finally", TokenKind::For => "for", TokenKind::Foreach => "foreach", TokenKind::Function => "function", TokenKind::Global => "global", TokenKind::If => "if", TokenKind::Implements => "implements", TokenKind::Imports => "imports", TokenKind::Include => "include", TokenKind::Include_once => "include_once", TokenKind::Inout => "inout", TokenKind::Instanceof => "instanceof", TokenKind::Insteadof => "insteadof", TokenKind::Int => "int", TokenKind::Integer => "integer", TokenKind::Interface => "interface", TokenKind::Is => "is", TokenKind::Isset => "isset", TokenKind::Keyset => "keyset", TokenKind::Lateinit => "lateinit", TokenKind::List => "list", TokenKind::Match => "match", TokenKind::Mixed => "mixed", TokenKind::Module => "module", TokenKind::Namespace => "namespace", TokenKind::New => "new", TokenKind::Newctx => "newctx", TokenKind::Newtype => "newtype", TokenKind::Noreturn => "noreturn", TokenKind::Num => "num", TokenKind::Parent => "parent", TokenKind::Print => "print", TokenKind::Private => "private", TokenKind::Protected => "protected", TokenKind::Public => "public", TokenKind::Real => "real", TokenKind::Reify => "reify", TokenKind::Require => "require", TokenKind::Require_once => "require_once", TokenKind::Required => "required", TokenKind::Resource => "resource", TokenKind::Return => "return", TokenKind::SelfToken => "self", TokenKind::Shape => "shape", TokenKind::Static => "static", TokenKind::String => "string", TokenKind::Super => "super", TokenKind::Switch => "switch", TokenKind::This => "this", TokenKind::Throw => "throw", TokenKind::Trait => "trait", TokenKind::Try => "try", TokenKind::Tuple => "tuple", TokenKind::Type => "type", TokenKind::Unset => "unset", TokenKind::Upcast => "upcast", TokenKind::Use => "use", TokenKind::Using => "using", TokenKind::Var => "var", TokenKind::Varray => "varray", TokenKind::Vec => "vec", TokenKind::Void => "void", TokenKind::With => "with", TokenKind::Where => "where", TokenKind::While => "while", TokenKind::Yield => "yield", TokenKind::NullLiteral => "null", TokenKind::LeftBracket => "[", TokenKind::RightBracket => "]", TokenKind::LeftParen => "(", TokenKind::RightParen => ")", TokenKind::LeftBrace => "{", TokenKind::RightBrace => "}", TokenKind::Dot => ".", TokenKind::MinusGreaterThan => "->", TokenKind::PlusPlus => "++", TokenKind::MinusMinus => "--", TokenKind::StarStar => "**", TokenKind::Star => "*", TokenKind::Plus => "+", TokenKind::Minus => "-", TokenKind::Tilde => "~", TokenKind::Exclamation => "!", TokenKind::Dollar => "$", TokenKind::Slash => "/", TokenKind::Percent => "%", TokenKind::LessThanEqualGreaterThan => "<=>", TokenKind::LessThanLessThan => "<<", TokenKind::GreaterThanGreaterThan => ">>", TokenKind::LessThan => "<", TokenKind::GreaterThan => ">", TokenKind::LessThanEqual => "<=", TokenKind::GreaterThanEqual => ">=", TokenKind::EqualEqual => "==", TokenKind::EqualEqualEqual => "===", TokenKind::ExclamationEqual => "!=", TokenKind::ExclamationEqualEqual => "!==", TokenKind::Carat => "^", TokenKind::Bar => "|", TokenKind::Ampersand => "&", TokenKind::AmpersandAmpersand => "&&", TokenKind::BarBar => "||", TokenKind::Question => "?", TokenKind::QuestionAs => "?as", TokenKind::QuestionColon => "?:", TokenKind::QuestionQuestion => "??", TokenKind::QuestionQuestionEqual => "??=", TokenKind::Colon => ":", TokenKind::Semicolon => ";", TokenKind::Equal => "=", TokenKind::StarStarEqual => "**=", TokenKind::StarEqual => "*=", TokenKind::SlashEqual => "/=", TokenKind::PercentEqual => "%=", TokenKind::PlusEqual => "+=", TokenKind::MinusEqual => "-=", TokenKind::DotEqual => ".=", TokenKind::LessThanLessThanEqual => "<<=", TokenKind::GreaterThanGreaterThanEqual => ">>=", TokenKind::AmpersandEqual => "&=", TokenKind::CaratEqual => "^=", TokenKind::BarEqual => "|=", TokenKind::Comma => ",", TokenKind::At => "@", TokenKind::ColonColon => "::", TokenKind::EqualGreaterThan => "=>", TokenKind::EqualEqualGreaterThan => "==>", TokenKind::QuestionMinusGreaterThan => "?->", TokenKind::DotDotDot => "...", TokenKind::DollarDollar => "$$", TokenKind::BarGreaterThan => "|>", TokenKind::SlashGreaterThan => "/>", TokenKind::LessThanSlash => "</", TokenKind::LessThanQuestion => "<?", TokenKind::Backtick => "`", TokenKind::XHP => "xhp", TokenKind::Hash => "#", TokenKind::Readonly => "readonly", TokenKind::Internal => "internal", TokenKind::Package => "package", TokenKind::Let => "let", // Variable text tokes TokenKind::ErrorToken => "error_token", TokenKind::Name => "name", TokenKind::Variable => "variable", TokenKind::DecimalLiteral => "decimal_literal", TokenKind::OctalLiteral => "octal_literal", TokenKind::HexadecimalLiteral => "hexadecimal_literal", TokenKind::BinaryLiteral => "binary_literal", TokenKind::FloatingLiteral => "floating_literal", TokenKind::SingleQuotedStringLiteral => "single_quoted_string_literal", TokenKind::DoubleQuotedStringLiteral => "double_quoted_string_literal", TokenKind::DoubleQuotedStringLiteralHead => "double_quoted_string_literal_head", TokenKind::StringLiteralBody => "string_literal_body", TokenKind::DoubleQuotedStringLiteralTail => "double_quoted_string_literal_tail", TokenKind::HeredocStringLiteral => "heredoc_string_literal", TokenKind::HeredocStringLiteralHead => "heredoc_string_literal_head", TokenKind::HeredocStringLiteralTail => "heredoc_string_literal_tail", TokenKind::NowdocStringLiteral => "nowdoc_string_literal", TokenKind::BooleanLiteral => "boolean_literal", TokenKind::XHPCategoryName => "XHP_category_name", TokenKind::XHPElementName => "XHP_element_name", TokenKind::XHPClassName => "XHP_class_name", TokenKind::XHPStringLiteral => "XHP_string_literal", TokenKind::XHPBody => "XHP_body", TokenKind::XHPComment => "XHP_comment", TokenKind::Hashbang => "hashbang", } } pub fn from_string( keyword: &[u8], only_reserved: bool, ) -> Option<Self> { match keyword { b"true" if !only_reserved => Some(TokenKind::BooleanLiteral), b"false" if !only_reserved => Some(TokenKind::BooleanLiteral), b"abstract" => Some(TokenKind::Abstract), b"arraykey" if !only_reserved => Some(TokenKind::Arraykey), b"as" => Some(TokenKind::As), b"async" => Some(TokenKind::Async), b"attribute" if !only_reserved => Some(TokenKind::Attribute), b"await" => Some(TokenKind::Await), b"\\" => Some(TokenKind::Backslash), b"binary" if !only_reserved => Some(TokenKind::Binary), b"bool" if !only_reserved => Some(TokenKind::Bool), b"boolean" if !only_reserved => Some(TokenKind::Boolean), b"break" => Some(TokenKind::Break), b"case" => Some(TokenKind::Case), b"catch" => Some(TokenKind::Catch), b"category" if !only_reserved => Some(TokenKind::Category), b"children" if !only_reserved => Some(TokenKind::Children), b"class" => Some(TokenKind::Class), b"classname" if !only_reserved => Some(TokenKind::Classname), b"clone" => Some(TokenKind::Clone), b"concurrent" => Some(TokenKind::Concurrent), b"const" => Some(TokenKind::Const), b"__construct" => Some(TokenKind::Construct), b"continue" => Some(TokenKind::Continue), b"ctx" => Some(TokenKind::Ctx), b"darray" if !only_reserved => Some(TokenKind::Darray), b"default" => Some(TokenKind::Default), b"dict" if !only_reserved => Some(TokenKind::Dict), b"do" => Some(TokenKind::Do), b"double" if !only_reserved => Some(TokenKind::Double), b"echo" => Some(TokenKind::Echo), b"else" => Some(TokenKind::Else), b"empty" => Some(TokenKind::Empty), b"endif" => Some(TokenKind::Endif), b"enum" if !only_reserved => Some(TokenKind::Enum), b"eval" => Some(TokenKind::Eval), b"exports" if !only_reserved => Some(TokenKind::Exports), b"extends" => Some(TokenKind::Extends), b"fallthrough" if !only_reserved => Some(TokenKind::Fallthrough), b"float" if !only_reserved => Some(TokenKind::Float), b"file" if !only_reserved => Some(TokenKind::File), b"final" => Some(TokenKind::Final), b"finally" => Some(TokenKind::Finally), b"for" => Some(TokenKind::For), b"foreach" => Some(TokenKind::Foreach), b"function" => Some(TokenKind::Function), b"global" => Some(TokenKind::Global), b"if" => Some(TokenKind::If), b"implements" => Some(TokenKind::Implements), b"imports" if !only_reserved => Some(TokenKind::Imports), b"include" => Some(TokenKind::Include), b"include_once" => Some(TokenKind::Include_once), b"inout" => Some(TokenKind::Inout), b"instanceof" => Some(TokenKind::Instanceof), b"insteadof" => Some(TokenKind::Insteadof), b"int" if !only_reserved => Some(TokenKind::Int), b"integer" if !only_reserved => Some(TokenKind::Integer), b"interface" => Some(TokenKind::Interface), b"is" if !only_reserved => Some(TokenKind::Is), b"isset" => Some(TokenKind::Isset), b"keyset" if !only_reserved => Some(TokenKind::Keyset), b"lateinit" => Some(TokenKind::Lateinit), b"list" => Some(TokenKind::List), b"match" if !only_reserved => Some(TokenKind::Match), b"mixed" if !only_reserved => Some(TokenKind::Mixed), b"module" => Some(TokenKind::Module), b"namespace" => Some(TokenKind::Namespace), b"new" => Some(TokenKind::New), b"newctx" if !only_reserved => Some(TokenKind::Newctx), b"newtype" if !only_reserved => Some(TokenKind::Newtype), b"noreturn" if !only_reserved => Some(TokenKind::Noreturn), b"num" if !only_reserved => Some(TokenKind::Num), b"parent" if !only_reserved => Some(TokenKind::Parent), b"print" => Some(TokenKind::Print), b"private" => Some(TokenKind::Private), b"protected" => Some(TokenKind::Protected), b"public" => Some(TokenKind::Public), b"real" if !only_reserved => Some(TokenKind::Real), b"reify" if !only_reserved => Some(TokenKind::Reify), b"require" => Some(TokenKind::Require), b"require_once" => Some(TokenKind::Require_once), b"required" => Some(TokenKind::Required), b"resource" if !only_reserved => Some(TokenKind::Resource), b"return" => Some(TokenKind::Return), b"self" if !only_reserved => Some(TokenKind::SelfToken), b"shape" => Some(TokenKind::Shape), b"static" => Some(TokenKind::Static), b"string" if !only_reserved => Some(TokenKind::String), b"super" if !only_reserved => Some(TokenKind::Super), b"switch" => Some(TokenKind::Switch), b"this" if !only_reserved => Some(TokenKind::This), b"throw" => Some(TokenKind::Throw), b"trait" => Some(TokenKind::Trait), b"try" => Some(TokenKind::Try), b"tuple" => Some(TokenKind::Tuple), b"type" if !only_reserved => Some(TokenKind::Type), b"unset" => Some(TokenKind::Unset), b"upcast" if !only_reserved => Some(TokenKind::Upcast), b"use" => Some(TokenKind::Use), b"using" => Some(TokenKind::Using), b"var" => Some(TokenKind::Var), b"varray" if !only_reserved => Some(TokenKind::Varray), b"vec" if !only_reserved => Some(TokenKind::Vec), b"void" if !only_reserved => Some(TokenKind::Void), b"with" if !only_reserved => Some(TokenKind::With), b"where" if !only_reserved => Some(TokenKind::Where), b"while" => Some(TokenKind::While), b"yield" => Some(TokenKind::Yield), b"null" if !only_reserved => Some(TokenKind::NullLiteral), b"[" => Some(TokenKind::LeftBracket), b"]" => Some(TokenKind::RightBracket), b"(" => Some(TokenKind::LeftParen), b")" => Some(TokenKind::RightParen), b"{" => Some(TokenKind::LeftBrace), b"}" => Some(TokenKind::RightBrace), b"." => Some(TokenKind::Dot), b"->" => Some(TokenKind::MinusGreaterThan), b"++" => Some(TokenKind::PlusPlus), b"--" => Some(TokenKind::MinusMinus), b"**" => Some(TokenKind::StarStar), b"*" => Some(TokenKind::Star), b"+" => Some(TokenKind::Plus), b"-" => Some(TokenKind::Minus), b"~" => Some(TokenKind::Tilde), b"!" => Some(TokenKind::Exclamation), b"$" => Some(TokenKind::Dollar), b"/" => Some(TokenKind::Slash), b"%" => Some(TokenKind::Percent), b"<=>" => Some(TokenKind::LessThanEqualGreaterThan), b"<<" => Some(TokenKind::LessThanLessThan), b">>" => Some(TokenKind::GreaterThanGreaterThan), b"<" => Some(TokenKind::LessThan), b">" => Some(TokenKind::GreaterThan), b"<=" => Some(TokenKind::LessThanEqual), b">=" => Some(TokenKind::GreaterThanEqual), b"==" => Some(TokenKind::EqualEqual), b"===" => Some(TokenKind::EqualEqualEqual), b"!=" => Some(TokenKind::ExclamationEqual), b"!==" => Some(TokenKind::ExclamationEqualEqual), b"^" => Some(TokenKind::Carat), b"|" => Some(TokenKind::Bar), b"&" => Some(TokenKind::Ampersand), b"&&" => Some(TokenKind::AmpersandAmpersand), b"||" => Some(TokenKind::BarBar), b"?" => Some(TokenKind::Question), b"?as" => Some(TokenKind::QuestionAs), b"?:" => Some(TokenKind::QuestionColon), b"??" => Some(TokenKind::QuestionQuestion), b"??=" => Some(TokenKind::QuestionQuestionEqual), b":" => Some(TokenKind::Colon), b";" => Some(TokenKind::Semicolon), b"=" => Some(TokenKind::Equal), b"**=" => Some(TokenKind::StarStarEqual), b"*=" => Some(TokenKind::StarEqual), b"/=" => Some(TokenKind::SlashEqual), b"%=" => Some(TokenKind::PercentEqual), b"+=" => Some(TokenKind::PlusEqual), b"-=" => Some(TokenKind::MinusEqual), b".=" => Some(TokenKind::DotEqual), b"<<=" => Some(TokenKind::LessThanLessThanEqual), b">>=" => Some(TokenKind::GreaterThanGreaterThanEqual), b"&=" => Some(TokenKind::AmpersandEqual), b"^=" => Some(TokenKind::CaratEqual), b"|=" => Some(TokenKind::BarEqual), b"," => Some(TokenKind::Comma), b"@" => Some(TokenKind::At), b"::" => Some(TokenKind::ColonColon), b"=>" => Some(TokenKind::EqualGreaterThan), b"==>" => Some(TokenKind::EqualEqualGreaterThan), b"?->" => Some(TokenKind::QuestionMinusGreaterThan), b"..." => Some(TokenKind::DotDotDot), b"$$" => Some(TokenKind::DollarDollar), b"|>" => Some(TokenKind::BarGreaterThan), b"/>" => Some(TokenKind::SlashGreaterThan), b"</" => Some(TokenKind::LessThanSlash), b"<?" => Some(TokenKind::LessThanQuestion), b"`" => Some(TokenKind::Backtick), b"xhp" if !only_reserved => Some(TokenKind::XHP), b"#" => Some(TokenKind::Hash), b"readonly" => Some(TokenKind::Readonly), b"internal" if !only_reserved => Some(TokenKind::Internal), b"package" => Some(TokenKind::Package), b"let" if !only_reserved => Some(TokenKind::Let), _ => None, } } pub fn ocaml_tag(self) -> u8 { match self { TokenKind::EndOfFile => 0, TokenKind::Abstract => 1, TokenKind::Arraykey => 2, TokenKind::As => 3, TokenKind::Async => 4, TokenKind::Attribute => 5, TokenKind::Await => 6, TokenKind::Backslash => 7, TokenKind::Binary => 8, TokenKind::Bool => 9, TokenKind::Boolean => 10, TokenKind::Break => 11, TokenKind::Case => 12, TokenKind::Catch => 13, TokenKind::Category => 14, TokenKind::Children => 15, TokenKind::Class => 16, TokenKind::Classname => 17, TokenKind::Clone => 18, TokenKind::Concurrent => 19, TokenKind::Const => 20, TokenKind::Construct => 21, TokenKind::Continue => 22, TokenKind::Ctx => 23, TokenKind::Darray => 24, TokenKind::Default => 25, TokenKind::Dict => 26, TokenKind::Do => 27, TokenKind::Double => 28, TokenKind::Echo => 29, TokenKind::Else => 30, TokenKind::Empty => 31, TokenKind::Endif => 32, TokenKind::Enum => 33, TokenKind::Eval => 34, TokenKind::Exports => 35, TokenKind::Extends => 36, TokenKind::Fallthrough => 37, TokenKind::Float => 38, TokenKind::File => 39, TokenKind::Final => 40, TokenKind::Finally => 41, TokenKind::For => 42, TokenKind::Foreach => 43, TokenKind::Function => 44, TokenKind::Global => 45, TokenKind::If => 46, TokenKind::Implements => 47, TokenKind::Imports => 48, TokenKind::Include => 49, TokenKind::Include_once => 50, TokenKind::Inout => 51, TokenKind::Instanceof => 52, TokenKind::Insteadof => 53, TokenKind::Int => 54, TokenKind::Integer => 55, TokenKind::Interface => 56, TokenKind::Is => 57, TokenKind::Isset => 58, TokenKind::Keyset => 59, TokenKind::Lateinit => 60, TokenKind::List => 61, TokenKind::Match => 62, TokenKind::Mixed => 63, TokenKind::Module => 64, TokenKind::Namespace => 65, TokenKind::New => 66, TokenKind::Newctx => 67, TokenKind::Newtype => 68, TokenKind::Noreturn => 69, TokenKind::Num => 70, TokenKind::Parent => 71, TokenKind::Print => 72, TokenKind::Private => 73, TokenKind::Protected => 74, TokenKind::Public => 75, TokenKind::Real => 76, TokenKind::Reify => 77, TokenKind::Require => 78, TokenKind::Require_once => 79, TokenKind::Required => 80, TokenKind::Resource => 81, TokenKind::Return => 82, TokenKind::SelfToken => 83, TokenKind::Shape => 84, TokenKind::Static => 85, TokenKind::String => 86, TokenKind::Super => 87, TokenKind::Switch => 88, TokenKind::This => 89, TokenKind::Throw => 90, TokenKind::Trait => 91, TokenKind::Try => 92, TokenKind::Tuple => 93, TokenKind::Type => 94, TokenKind::Unset => 95, TokenKind::Upcast => 96, TokenKind::Use => 97, TokenKind::Using => 98, TokenKind::Var => 99, TokenKind::Varray => 100, TokenKind::Vec => 101, TokenKind::Void => 102, TokenKind::With => 103, TokenKind::Where => 104, TokenKind::While => 105, TokenKind::Yield => 106, TokenKind::NullLiteral => 107, TokenKind::LeftBracket => 108, TokenKind::RightBracket => 109, TokenKind::LeftParen => 110, TokenKind::RightParen => 111, TokenKind::LeftBrace => 112, TokenKind::RightBrace => 113, TokenKind::Dot => 114, TokenKind::MinusGreaterThan => 115, TokenKind::PlusPlus => 116, TokenKind::MinusMinus => 117, TokenKind::StarStar => 118, TokenKind::Star => 119, TokenKind::Plus => 120, TokenKind::Minus => 121, TokenKind::Tilde => 122, TokenKind::Exclamation => 123, TokenKind::Dollar => 124, TokenKind::Slash => 125, TokenKind::Percent => 126, TokenKind::LessThanEqualGreaterThan => 127, TokenKind::LessThanLessThan => 128, TokenKind::GreaterThanGreaterThan => 129, TokenKind::LessThan => 130, TokenKind::GreaterThan => 131, TokenKind::LessThanEqual => 132, TokenKind::GreaterThanEqual => 133, TokenKind::EqualEqual => 134, TokenKind::EqualEqualEqual => 135, TokenKind::ExclamationEqual => 136, TokenKind::ExclamationEqualEqual => 137, TokenKind::Carat => 138, TokenKind::Bar => 139, TokenKind::Ampersand => 140, TokenKind::AmpersandAmpersand => 141, TokenKind::BarBar => 142, TokenKind::Question => 143, TokenKind::QuestionAs => 144, TokenKind::QuestionColon => 145, TokenKind::QuestionQuestion => 146, TokenKind::QuestionQuestionEqual => 147, TokenKind::Colon => 148, TokenKind::Semicolon => 149, TokenKind::Equal => 150, TokenKind::StarStarEqual => 151, TokenKind::StarEqual => 152, TokenKind::SlashEqual => 153, TokenKind::PercentEqual => 154, TokenKind::PlusEqual => 155, TokenKind::MinusEqual => 156, TokenKind::DotEqual => 157, TokenKind::LessThanLessThanEqual => 158, TokenKind::GreaterThanGreaterThanEqual => 159, TokenKind::AmpersandEqual => 160, TokenKind::CaratEqual => 161, TokenKind::BarEqual => 162, TokenKind::Comma => 163, TokenKind::At => 164, TokenKind::ColonColon => 165, TokenKind::EqualGreaterThan => 166, TokenKind::EqualEqualGreaterThan => 167, TokenKind::QuestionMinusGreaterThan => 168, TokenKind::DotDotDot => 169, TokenKind::DollarDollar => 170, TokenKind::BarGreaterThan => 171, TokenKind::SlashGreaterThan => 172, TokenKind::LessThanSlash => 173, TokenKind::LessThanQuestion => 174, TokenKind::Backtick => 175, TokenKind::XHP => 176, TokenKind::Hash => 177, TokenKind::Readonly => 178, TokenKind::Internal => 179, TokenKind::Package => 180, TokenKind::Let => 181, TokenKind::ErrorToken => 182, TokenKind::Name => 183, TokenKind::Variable => 184, TokenKind::DecimalLiteral => 185, TokenKind::OctalLiteral => 186, TokenKind::HexadecimalLiteral => 187, TokenKind::BinaryLiteral => 188, TokenKind::FloatingLiteral => 189, TokenKind::SingleQuotedStringLiteral => 190, TokenKind::DoubleQuotedStringLiteral => 191, TokenKind::DoubleQuotedStringLiteralHead => 192, TokenKind::StringLiteralBody => 193, TokenKind::DoubleQuotedStringLiteralTail => 194, TokenKind::HeredocStringLiteral => 195, TokenKind::HeredocStringLiteralHead => 196, TokenKind::HeredocStringLiteralTail => 197, TokenKind::NowdocStringLiteral => 198, TokenKind::BooleanLiteral => 199, TokenKind::XHPCategoryName => 200, TokenKind::XHPElementName => 201, TokenKind::XHPClassName => 202, TokenKind::XHPStringLiteral => 203, TokenKind::XHPBody => 204, TokenKind::XHPComment => 205, TokenKind::Hashbang => 206, } } pub fn try_from_u8(tag: u8) -> Option<Self> { match tag { 0 => Some(TokenKind::EndOfFile), 1 => Some(TokenKind::Abstract), 2 => Some(TokenKind::Arraykey), 3 => Some(TokenKind::As), 4 => Some(TokenKind::Async), 5 => Some(TokenKind::Attribute), 6 => Some(TokenKind::Await), 7 => Some(TokenKind::Backslash), 8 => Some(TokenKind::Binary), 9 => Some(TokenKind::Bool), 10 => Some(TokenKind::Boolean), 11 => Some(TokenKind::Break), 12 => Some(TokenKind::Case), 13 => Some(TokenKind::Catch), 14 => Some(TokenKind::Category), 15 => Some(TokenKind::Children), 16 => Some(TokenKind::Class), 17 => Some(TokenKind::Classname), 18 => Some(TokenKind::Clone), 19 => Some(TokenKind::Concurrent), 20 => Some(TokenKind::Const), 21 => Some(TokenKind::Construct), 22 => Some(TokenKind::Continue), 23 => Some(TokenKind::Ctx), 24 => Some(TokenKind::Darray), 25 => Some(TokenKind::Default), 26 => Some(TokenKind::Dict), 27 => Some(TokenKind::Do), 28 => Some(TokenKind::Double), 29 => Some(TokenKind::Echo), 30 => Some(TokenKind::Else), 31 => Some(TokenKind::Empty), 32 => Some(TokenKind::Endif), 33 => Some(TokenKind::Enum), 34 => Some(TokenKind::Eval), 35 => Some(TokenKind::Exports), 36 => Some(TokenKind::Extends), 37 => Some(TokenKind::Fallthrough), 38 => Some(TokenKind::Float), 39 => Some(TokenKind::File), 40 => Some(TokenKind::Final), 41 => Some(TokenKind::Finally), 42 => Some(TokenKind::For), 43 => Some(TokenKind::Foreach), 44 => Some(TokenKind::Function), 45 => Some(TokenKind::Global), 46 => Some(TokenKind::If), 47 => Some(TokenKind::Implements), 48 => Some(TokenKind::Imports), 49 => Some(TokenKind::Include), 50 => Some(TokenKind::Include_once), 51 => Some(TokenKind::Inout), 52 => Some(TokenKind::Instanceof), 53 => Some(TokenKind::Insteadof), 54 => Some(TokenKind::Int), 55 => Some(TokenKind::Integer), 56 => Some(TokenKind::Interface), 57 => Some(TokenKind::Is), 58 => Some(TokenKind::Isset), 59 => Some(TokenKind::Keyset), 60 => Some(TokenKind::Lateinit), 61 => Some(TokenKind::List), 62 => Some(TokenKind::Match), 63 => Some(TokenKind::Mixed), 64 => Some(TokenKind::Module), 65 => Some(TokenKind::Namespace), 66 => Some(TokenKind::New), 67 => Some(TokenKind::Newctx), 68 => Some(TokenKind::Newtype), 69 => Some(TokenKind::Noreturn), 70 => Some(TokenKind::Num), 71 => Some(TokenKind::Parent), 72 => Some(TokenKind::Print), 73 => Some(TokenKind::Private), 74 => Some(TokenKind::Protected), 75 => Some(TokenKind::Public), 76 => Some(TokenKind::Real), 77 => Some(TokenKind::Reify), 78 => Some(TokenKind::Require), 79 => Some(TokenKind::Require_once), 80 => Some(TokenKind::Required), 81 => Some(TokenKind::Resource), 82 => Some(TokenKind::Return), 83 => Some(TokenKind::SelfToken), 84 => Some(TokenKind::Shape), 85 => Some(TokenKind::Static), 86 => Some(TokenKind::String), 87 => Some(TokenKind::Super), 88 => Some(TokenKind::Switch), 89 => Some(TokenKind::This), 90 => Some(TokenKind::Throw), 91 => Some(TokenKind::Trait), 92 => Some(TokenKind::Try), 93 => Some(TokenKind::Tuple), 94 => Some(TokenKind::Type), 95 => Some(TokenKind::Unset), 96 => Some(TokenKind::Upcast), 97 => Some(TokenKind::Use), 98 => Some(TokenKind::Using), 99 => Some(TokenKind::Var), 100 => Some(TokenKind::Varray), 101 => Some(TokenKind::Vec), 102 => Some(TokenKind::Void), 103 => Some(TokenKind::With), 104 => Some(TokenKind::Where), 105 => Some(TokenKind::While), 106 => Some(TokenKind::Yield), 107 => Some(TokenKind::NullLiteral), 108 => Some(TokenKind::LeftBracket), 109 => Some(TokenKind::RightBracket), 110 => Some(TokenKind::LeftParen), 111 => Some(TokenKind::RightParen), 112 => Some(TokenKind::LeftBrace), 113 => Some(TokenKind::RightBrace), 114 => Some(TokenKind::Dot), 115 => Some(TokenKind::MinusGreaterThan), 116 => Some(TokenKind::PlusPlus), 117 => Some(TokenKind::MinusMinus), 118 => Some(TokenKind::StarStar), 119 => Some(TokenKind::Star), 120 => Some(TokenKind::Plus), 121 => Some(TokenKind::Minus), 122 => Some(TokenKind::Tilde), 123 => Some(TokenKind::Exclamation), 124 => Some(TokenKind::Dollar), 125 => Some(TokenKind::Slash), 126 => Some(TokenKind::Percent), 127 => Some(TokenKind::LessThanEqualGreaterThan), 128 => Some(TokenKind::LessThanLessThan), 129 => Some(TokenKind::GreaterThanGreaterThan), 130 => Some(TokenKind::LessThan), 131 => Some(TokenKind::GreaterThan), 132 => Some(TokenKind::LessThanEqual), 133 => Some(TokenKind::GreaterThanEqual), 134 => Some(TokenKind::EqualEqual), 135 => Some(TokenKind::EqualEqualEqual), 136 => Some(TokenKind::ExclamationEqual), 137 => Some(TokenKind::ExclamationEqualEqual), 138 => Some(TokenKind::Carat), 139 => Some(TokenKind::Bar), 140 => Some(TokenKind::Ampersand), 141 => Some(TokenKind::AmpersandAmpersand), 142 => Some(TokenKind::BarBar), 143 => Some(TokenKind::Question), 144 => Some(TokenKind::QuestionAs), 145 => Some(TokenKind::QuestionColon), 146 => Some(TokenKind::QuestionQuestion), 147 => Some(TokenKind::QuestionQuestionEqual), 148 => Some(TokenKind::Colon), 149 => Some(TokenKind::Semicolon), 150 => Some(TokenKind::Equal), 151 => Some(TokenKind::StarStarEqual), 152 => Some(TokenKind::StarEqual), 153 => Some(TokenKind::SlashEqual), 154 => Some(TokenKind::PercentEqual), 155 => Some(TokenKind::PlusEqual), 156 => Some(TokenKind::MinusEqual), 157 => Some(TokenKind::DotEqual), 158 => Some(TokenKind::LessThanLessThanEqual), 159 => Some(TokenKind::GreaterThanGreaterThanEqual), 160 => Some(TokenKind::AmpersandEqual), 161 => Some(TokenKind::CaratEqual), 162 => Some(TokenKind::BarEqual), 163 => Some(TokenKind::Comma), 164 => Some(TokenKind::At), 165 => Some(TokenKind::ColonColon), 166 => Some(TokenKind::EqualGreaterThan), 167 => Some(TokenKind::EqualEqualGreaterThan), 168 => Some(TokenKind::QuestionMinusGreaterThan), 169 => Some(TokenKind::DotDotDot), 170 => Some(TokenKind::DollarDollar), 171 => Some(TokenKind::BarGreaterThan), 172 => Some(TokenKind::SlashGreaterThan), 173 => Some(TokenKind::LessThanSlash), 174 => Some(TokenKind::LessThanQuestion), 175 => Some(TokenKind::Backtick), 176 => Some(TokenKind::XHP), 177 => Some(TokenKind::Hash), 178 => Some(TokenKind::Readonly), 179 => Some(TokenKind::Internal), 180 => Some(TokenKind::Package), 181 => Some(TokenKind::Let), 182 => Some(TokenKind::ErrorToken), 183 => Some(TokenKind::Name), 184 => Some(TokenKind::Variable), 185 => Some(TokenKind::DecimalLiteral), 186 => Some(TokenKind::OctalLiteral), 187 => Some(TokenKind::HexadecimalLiteral), 188 => Some(TokenKind::BinaryLiteral), 189 => Some(TokenKind::FloatingLiteral), 190 => Some(TokenKind::SingleQuotedStringLiteral), 191 => Some(TokenKind::DoubleQuotedStringLiteral), 192 => Some(TokenKind::DoubleQuotedStringLiteralHead), 193 => Some(TokenKind::StringLiteralBody), 194 => Some(TokenKind::DoubleQuotedStringLiteralTail), 195 => Some(TokenKind::HeredocStringLiteral), 196 => Some(TokenKind::HeredocStringLiteralHead), 197 => Some(TokenKind::HeredocStringLiteralTail), 198 => Some(TokenKind::NowdocStringLiteral), 199 => Some(TokenKind::BooleanLiteral), 200 => Some(TokenKind::XHPCategoryName), 201 => Some(TokenKind::XHPElementName), 202 => Some(TokenKind::XHPClassName), 203 => Some(TokenKind::XHPStringLiteral), 204 => Some(TokenKind::XHPBody), 205 => Some(TokenKind::XHPComment), 206 => Some(TokenKind::Hashbang), _ => None, } } pub fn fixed_width(self) -> Option<NonZeroUsize> { match self { TokenKind::Abstract => Some(unsafe { NonZeroUsize::new_unchecked(8) }), TokenKind::Arraykey => Some(unsafe { NonZeroUsize::new_unchecked(8) }), TokenKind::As => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::Async => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Attribute => Some(unsafe { NonZeroUsize::new_unchecked(9) }), TokenKind::Await => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Backslash => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::Binary => Some(unsafe { NonZeroUsize::new_unchecked(6) }), TokenKind::Bool => Some(unsafe { NonZeroUsize::new_unchecked(4) }), TokenKind::Boolean => Some(unsafe { NonZeroUsize::new_unchecked(7) }), TokenKind::Break => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Case => Some(unsafe { NonZeroUsize::new_unchecked(4) }), TokenKind::Catch => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Category => Some(unsafe { NonZeroUsize::new_unchecked(8) }), TokenKind::Children => Some(unsafe { NonZeroUsize::new_unchecked(8) }), TokenKind::Class => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Classname => Some(unsafe { NonZeroUsize::new_unchecked(9) }), TokenKind::Clone => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Concurrent => Some(unsafe { NonZeroUsize::new_unchecked(10) }), TokenKind::Const => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Construct => Some(unsafe { NonZeroUsize::new_unchecked(11) }), TokenKind::Continue => Some(unsafe { NonZeroUsize::new_unchecked(8) }), TokenKind::Ctx => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::Darray => Some(unsafe { NonZeroUsize::new_unchecked(6) }), TokenKind::Default => Some(unsafe { NonZeroUsize::new_unchecked(7) }), TokenKind::Dict => Some(unsafe { NonZeroUsize::new_unchecked(4) }), TokenKind::Do => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::Double => Some(unsafe { NonZeroUsize::new_unchecked(6) }), TokenKind::Echo => Some(unsafe { NonZeroUsize::new_unchecked(4) }), TokenKind::Else => Some(unsafe { NonZeroUsize::new_unchecked(4) }), TokenKind::Empty => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Endif => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Enum => Some(unsafe { NonZeroUsize::new_unchecked(4) }), TokenKind::Eval => Some(unsafe { NonZeroUsize::new_unchecked(4) }), TokenKind::Exports => Some(unsafe { NonZeroUsize::new_unchecked(7) }), TokenKind::Extends => Some(unsafe { NonZeroUsize::new_unchecked(7) }), TokenKind::Fallthrough => Some(unsafe { NonZeroUsize::new_unchecked(11) }), TokenKind::Float => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::File => Some(unsafe { NonZeroUsize::new_unchecked(4) }), TokenKind::Final => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Finally => Some(unsafe { NonZeroUsize::new_unchecked(7) }), TokenKind::For => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::Foreach => Some(unsafe { NonZeroUsize::new_unchecked(7) }), TokenKind::Function => Some(unsafe { NonZeroUsize::new_unchecked(8) }), TokenKind::Global => Some(unsafe { NonZeroUsize::new_unchecked(6) }), TokenKind::If => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::Implements => Some(unsafe { NonZeroUsize::new_unchecked(10) }), TokenKind::Imports => Some(unsafe { NonZeroUsize::new_unchecked(7) }), TokenKind::Include => Some(unsafe { NonZeroUsize::new_unchecked(7) }), TokenKind::Include_once => Some(unsafe { NonZeroUsize::new_unchecked(12) }), TokenKind::Inout => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Instanceof => Some(unsafe { NonZeroUsize::new_unchecked(10) }), TokenKind::Insteadof => Some(unsafe { NonZeroUsize::new_unchecked(9) }), TokenKind::Int => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::Integer => Some(unsafe { NonZeroUsize::new_unchecked(7) }), TokenKind::Interface => Some(unsafe { NonZeroUsize::new_unchecked(9) }), TokenKind::Is => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::Isset => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Keyset => Some(unsafe { NonZeroUsize::new_unchecked(6) }), TokenKind::Lateinit => Some(unsafe { NonZeroUsize::new_unchecked(8) }), TokenKind::List => Some(unsafe { NonZeroUsize::new_unchecked(4) }), TokenKind::Match => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Mixed => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Module => Some(unsafe { NonZeroUsize::new_unchecked(6) }), TokenKind::Namespace => Some(unsafe { NonZeroUsize::new_unchecked(9) }), TokenKind::New => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::Newctx => Some(unsafe { NonZeroUsize::new_unchecked(6) }), TokenKind::Newtype => Some(unsafe { NonZeroUsize::new_unchecked(7) }), TokenKind::Noreturn => Some(unsafe { NonZeroUsize::new_unchecked(8) }), TokenKind::Num => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::Parent => Some(unsafe { NonZeroUsize::new_unchecked(6) }), TokenKind::Print => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Private => Some(unsafe { NonZeroUsize::new_unchecked(7) }), TokenKind::Protected => Some(unsafe { NonZeroUsize::new_unchecked(9) }), TokenKind::Public => Some(unsafe { NonZeroUsize::new_unchecked(6) }), TokenKind::Real => Some(unsafe { NonZeroUsize::new_unchecked(4) }), TokenKind::Reify => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Require => Some(unsafe { NonZeroUsize::new_unchecked(7) }), TokenKind::Require_once => Some(unsafe { NonZeroUsize::new_unchecked(12) }), TokenKind::Required => Some(unsafe { NonZeroUsize::new_unchecked(8) }), TokenKind::Resource => Some(unsafe { NonZeroUsize::new_unchecked(8) }), TokenKind::Return => Some(unsafe { NonZeroUsize::new_unchecked(6) }), TokenKind::SelfToken => Some(unsafe { NonZeroUsize::new_unchecked(4) }), TokenKind::Shape => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Static => Some(unsafe { NonZeroUsize::new_unchecked(6) }), TokenKind::String => Some(unsafe { NonZeroUsize::new_unchecked(6) }), TokenKind::Super => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Switch => Some(unsafe { NonZeroUsize::new_unchecked(6) }), TokenKind::This => Some(unsafe { NonZeroUsize::new_unchecked(4) }), TokenKind::Throw => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Trait => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Try => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::Tuple => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Type => Some(unsafe { NonZeroUsize::new_unchecked(4) }), TokenKind::Unset => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Upcast => Some(unsafe { NonZeroUsize::new_unchecked(6) }), TokenKind::Use => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::Using => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Var => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::Varray => Some(unsafe { NonZeroUsize::new_unchecked(6) }), TokenKind::Vec => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::Void => Some(unsafe { NonZeroUsize::new_unchecked(4) }), TokenKind::With => Some(unsafe { NonZeroUsize::new_unchecked(4) }), TokenKind::Where => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::While => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::Yield => Some(unsafe { NonZeroUsize::new_unchecked(5) }), TokenKind::NullLiteral => Some(unsafe { NonZeroUsize::new_unchecked(4) }), TokenKind::LeftBracket => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::RightBracket => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::LeftParen => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::RightParen => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::LeftBrace => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::RightBrace => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::Dot => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::MinusGreaterThan => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::PlusPlus => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::MinusMinus => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::StarStar => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::Star => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::Plus => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::Minus => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::Tilde => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::Exclamation => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::Dollar => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::Slash => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::Percent => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::LessThanEqualGreaterThan => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::LessThanLessThan => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::GreaterThanGreaterThan => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::LessThan => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::GreaterThan => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::LessThanEqual => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::GreaterThanEqual => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::EqualEqual => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::EqualEqualEqual => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::ExclamationEqual => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::ExclamationEqualEqual => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::Carat => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::Bar => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::Ampersand => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::AmpersandAmpersand => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::BarBar => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::Question => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::QuestionAs => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::QuestionColon => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::QuestionQuestion => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::QuestionQuestionEqual => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::Colon => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::Semicolon => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::Equal => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::StarStarEqual => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::StarEqual => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::SlashEqual => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::PercentEqual => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::PlusEqual => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::MinusEqual => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::DotEqual => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::LessThanLessThanEqual => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::GreaterThanGreaterThanEqual => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::AmpersandEqual => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::CaratEqual => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::BarEqual => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::Comma => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::At => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::ColonColon => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::EqualGreaterThan => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::EqualEqualGreaterThan => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::QuestionMinusGreaterThan => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::DotDotDot => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::DollarDollar => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::BarGreaterThan => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::SlashGreaterThan => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::LessThanSlash => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::LessThanQuestion => Some(unsafe { NonZeroUsize::new_unchecked(2) }), TokenKind::Backtick => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::XHP => Some(unsafe { NonZeroUsize::new_unchecked(3) }), TokenKind::Hash => Some(unsafe { NonZeroUsize::new_unchecked(1) }), TokenKind::Readonly => Some(unsafe { NonZeroUsize::new_unchecked(8) }), TokenKind::Internal => Some(unsafe { NonZeroUsize::new_unchecked(8) }), TokenKind::Package => Some(unsafe { NonZeroUsize::new_unchecked(7) }), TokenKind::Let => Some(unsafe { NonZeroUsize::new_unchecked(3) }), _ => None, } } }
Rust
hhvm/hphp/hack/src/parser/to_ocaml_impl.rs
// Copyright (c) Facebook, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use ocamlrep::ptr::UnsafeOcamlPtr; use ocamlrep::Allocator; use ocamlrep::ToOcamlRep; use ocamlrep::Value; use parser_core_types::lexable_token::LexableToken; use parser_core_types::positioned_trivia::PositionedTrivium; use parser_core_types::syntax_by_ref::positioned_token::PositionedToken; use parser_core_types::syntax_by_ref::positioned_value::PositionedValue; use parser_core_types::syntax_by_ref::syntax::Syntax; use parser_core_types::syntax_by_ref::syntax_variant_generated::SyntaxVariant; use parser_core_types::syntax_kind::SyntaxKind; pub struct WithContext<'a, T: ?Sized> { pub t: &'a T, pub source_text: UnsafeOcamlPtr, } pub trait ToOcaml { fn to_ocaml<'a, A: Allocator>(&'a self, alloc: &'a A, source_text: UnsafeOcamlPtr) -> Value<'a>; } impl<T: ToOcaml> ToOcaml for [T] { fn to_ocaml<'a, A: Allocator>( &'a self, alloc: &'a A, source_text: UnsafeOcamlPtr, ) -> Value<'a> { let mut hd = alloc.add(&()); for val in self.iter().rev() { let mut block = alloc.block_with_size(2); alloc.set_field(&mut block, 0, val.to_ocaml(alloc, source_text)); alloc.set_field(&mut block, 1, hd); hd = block.build(); } hd } } impl ToOcaml for Syntax<'_, PositionedToken<'_>, PositionedValue<'_>> { fn to_ocaml<'a, A: Allocator>( &'a self, alloc: &'a A, source_text: UnsafeOcamlPtr, ) -> Value<'a> { let value = self.value.to_ocaml(alloc, source_text); let syntax = match &self.children { SyntaxVariant::Missing => alloc.add_copy(SyntaxKind::Missing.ocaml_tag() as usize), SyntaxVariant::Token(t) => { let kind = t.kind(); let t = t.to_ocaml(alloc, source_text); let mut block = alloc.block_with_size_and_tag(1, SyntaxKind::Token(kind).ocaml_tag()); alloc.set_field(&mut block, 0, t); block.build() } SyntaxVariant::SyntaxList(l) => { let l = l.to_ocaml(alloc, source_text); let mut block = alloc.block_with_size_and_tag(1, SyntaxKind::SyntaxList.ocaml_tag()); alloc.set_field(&mut block, 0, l); block.build() } _ => { // TODO: rewrite this iteratively. let tag = self.kind().ocaml_tag(); let n = self.iter_children().count(); let mut block = alloc.block_with_size_and_tag(n, tag); stack_limit::maybe_grow(|| { for (i, field) in self.iter_children().enumerate() { let field = field.to_ocaml(alloc, source_text); alloc.set_field(&mut block, i, field); } }); block.build() } }; let mut block = alloc.block_with_size_and_tag(2, 0); alloc.set_field(&mut block, 0, syntax); alloc.set_field(&mut block, 1, value); block.build() } } impl ToOcaml for PositionedTrivium { fn to_ocaml<'a, A: Allocator>( &'a self, alloc: &'a A, source_text: UnsafeOcamlPtr, ) -> Value<'a> { // From full_fidelity_positioned_trivia.ml: // type t = { // kind: TriviaKind.t; // source_text : SourceText.t; // offset : int; // width : int // } let mut block = alloc.block_with_size_and_tag(4, 0); alloc.set_field(&mut block, 0, self.kind.to_ocamlrep(alloc)); alloc.set_field(&mut block, 1, alloc.add_copy(source_text)); alloc.set_field(&mut block, 2, self.offset.to_ocamlrep(alloc)); alloc.set_field(&mut block, 3, self.width.to_ocamlrep(alloc)); block.build() } } impl ToOcaml for PositionedToken<'_> { fn to_ocaml<'a, A: Allocator>( &'a self, alloc: &'a A, source_text: UnsafeOcamlPtr, ) -> Value<'a> { // From full_fidelity_positioned_token.ml: // type t = { // kind: TokenKind.t; // source_text: SourceText.t; // offset: int; (* Beginning of first trivia *) // leading_width: int; // width: int; (* Width of actual token, not counting trivia *) // trailing_width: int; // trivia: LazyTrivia.t; // } let mut block = alloc.block_with_size_and_tag(7, 0); alloc.set_field(&mut block, 0, alloc.add_copy(self.kind())); alloc.set_field(&mut block, 1, alloc.add_copy(source_text)); alloc.set_field(&mut block, 2, alloc.add_copy(self.offset())); alloc.set_field(&mut block, 3, alloc.add_copy(self.leading_width())); alloc.set_field(&mut block, 4, alloc.add_copy(self.width())); alloc.set_field(&mut block, 5, alloc.add_copy(self.trailing_width())); alloc.set_field( &mut block, 6, alloc.add_copy((self.leading_kinds().bits() | self.trailing_kinds().bits()) as usize), ); block.build() } } const TOKEN_VALUE_VARIANT: u8 = 0; const TOKEN_SPAN_VARIANT: u8 = 1; const MISSING_VALUE_VARIANT: u8 = 2; impl ToOcaml for PositionedValue<'_> { fn to_ocaml<'a, A: Allocator>( &'a self, alloc: &'a A, source_text: UnsafeOcamlPtr, ) -> Value<'a> { match self { PositionedValue::TokenValue(t) => { let mut block = alloc.block_with_size_and_tag(1, TOKEN_VALUE_VARIANT); alloc.set_field(&mut block, 0, t.to_ocaml(alloc, source_text)); block.build() } PositionedValue::TokenSpan(l, r) => { let mut block = alloc.block_with_size_and_tag(2, TOKEN_SPAN_VARIANT); alloc.set_field(&mut block, 0, l.to_ocaml(alloc, source_text)); alloc.set_field(&mut block, 1, r.to_ocaml(alloc, source_text)); block.build() } PositionedValue::Missing { offset } => { let mut block = alloc.block_with_size_and_tag(2, MISSING_VALUE_VARIANT); alloc.set_field(&mut block, 0, alloc.add_copy(source_text)); alloc.set_field(&mut block, 1, offset.to_ocamlrep(alloc)); block.build() } } } }
Rust
hhvm/hphp/hack/src/parser/trivia_factory.rs
// Copyright (c) 2019, Facebook, Inc. // All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use crate::lexable_trivia::LexableTrivia; pub trait TriviaFactory: Clone { type Trivia: LexableTrivia; fn make(&mut self) -> Self::Trivia; } pub trait SimpleTriviaFactory: Sized { fn make() -> Self; } #[derive(Clone)] pub struct SimpleTriviaFactoryImpl<T>(std::marker::PhantomData<T>); impl<T> SimpleTriviaFactoryImpl<T> { pub fn new() -> Self { Self(std::marker::PhantomData) } } impl<T: LexableTrivia + SimpleTriviaFactory> TriviaFactory for SimpleTriviaFactoryImpl<T> { type Trivia = T; fn make(&mut self) -> Self::Trivia { T::make() } }
Rust
hhvm/hphp/hack/src/parser/trivia_kind.rs
/** * Copyright (c) 2016, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. An additional * directory. * ** * * THIS FILE IS @generated; DO NOT EDIT IT * To regenerate this file, run * * buck run //hphp/hack/src:generate_full_fidelity * ** * */ use ocamlrep::{FromOcamlRep, ToOcamlRep}; #[derive(Debug, Copy, Clone, FromOcamlRep, ToOcamlRep, PartialEq)] #[repr(u8)] pub enum TriviaKind { WhiteSpace = 0, EndOfLine = 1, DelimitedComment = 2, SingleLineComment = 3, FixMe = 4, IgnoreError = 5, FallThrough = 6, ExtraTokenError = 7, } impl TriviaKind { pub fn to_string(&self) -> &str { match self { TriviaKind::WhiteSpace => "whitespace", TriviaKind::EndOfLine => "end_of_line", TriviaKind::DelimitedComment => "delimited_comment", TriviaKind::SingleLineComment => "single_line_comment", TriviaKind::FixMe => "fix_me", TriviaKind::IgnoreError => "ignore_error", TriviaKind::FallThrough => "fall_through", TriviaKind::ExtraTokenError => "extra_token_error", } } pub const fn ocaml_tag(self) -> u8 { self as u8 } }
Rust
hhvm/hphp/hack/src/parser/api/cst_and_decl_parser.rs
// Copyright (c) Facebook, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use bumpalo::Bump; use direct_decl_smart_constructors::DirectDeclSmartConstructors; use direct_decl_smart_constructors::NoSourceTextAllocator; use oxidized::decl_parser_options::DeclParserOptions; use oxidized_by_ref::direct_decl_parser::ParsedFile; use oxidized_by_ref::file_info; use pair_smart_constructors::PairSmartConstructors; use parser::parser::Parser; use parser::syntax_by_ref; use parser::syntax_by_ref::positioned_syntax::PositionedSyntax; use parser::NoState; use parser_core_types::parser_env::ParserEnv; use parser_core_types::source_text::SourceText; use parser_core_types::syntax_tree::SyntaxTree; pub type ConcreteSyntaxTree<'src, 'arena> = SyntaxTree<'src, PositionedSyntax<'arena>, NoState>; type CstSmartConstructors<'a> = positioned_smart_constructors::PositionedSmartConstructors< PositionedSyntax<'a>, syntax_by_ref::positioned_token::TokenFactory<'a>, syntax_by_ref::arena_state::State<'a>, >; pub fn parse_script<'a, 'o>( opts: &'o DeclParserOptions, env: ParserEnv, source: &'a SourceText<'a>, mode: Option<file_info::Mode>, arena: &'a Bump, ) -> ( ConcreteSyntaxTree<'a, 'a>, direct_decl_parser::ParsedFile<'a>, ) { let sc0 = { let tf = syntax_by_ref::positioned_token::TokenFactory::new(arena); let state = syntax_by_ref::arena_state::State { arena }; CstSmartConstructors::new(state, tf) }; let sc1 = DirectDeclSmartConstructors::new( opts, source, mode.unwrap_or(file_info::Mode::Mstrict), arena, NoSourceTextAllocator, false, // elaborate_xhp_namespaces_for_facts ); let sc = PairSmartConstructors::new(sc0, sc1); let mut parser = Parser::new(source, env, sc); let root = parser.parse_script(); let errors = parser.errors(); let has_first_pass_parse_errors = !errors.is_empty(); let sc_state = parser.into_sc_state(); let cst = ConcreteSyntaxTree::build(source, root.0, errors, mode.map(Into::into), NoState); let file_attributes = sc_state.1.file_attributes; let mut attrs = bumpalo::collections::Vec::with_capacity_in(file_attributes.len(), arena); attrs.extend(file_attributes.iter().copied()); // Direct decl parser populates state.file_attributes in reverse of // syntactic order, so reverse it. attrs.reverse(); let parsed_file = ParsedFile { mode, file_attributes: attrs.into_bump_slice(), decls: sc_state.1.decls, has_first_pass_parse_errors, disable_xhp_element_mangling: opts.disable_xhp_element_mangling, }; (cst, parsed_file) }
Rust
hhvm/hphp/hack/src/parser/api/ddp_test.rs
// Copyright (c) Facebook, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use std::path::PathBuf; use anyhow::Result; use bumpalo::Bump; use clap::Parser; use direct_decl_parser::DeclParserOptions; use hh_config::HhConfig; use relative_path::Prefix; use relative_path::RelativePath; #[derive(Parser)] struct Opts { path: PathBuf, #[clap(long)] root: Option<PathBuf>, } fn main() -> Result<()> { let opts = Opts::parse(); let dp_opts = match opts.root { Some(root) => { let hh_config = HhConfig::from_root(root, &Default::default())?; DeclParserOptions::from_parser_options(&hh_config.opts) } None => Default::default(), }; let text = std::fs::read(&opts.path)?; let rpath = RelativePath::make(Prefix::Tmp, opts.path); let arena = Bump::new(); println!( "{:#?}", direct_decl_parser::parse_decls_for_bytecode(&dp_opts, rpath.clone(), &text, &arena) ); drop(arena); let arena = Bump::new(); println!( "{:#?}", direct_decl_parser::parse_decls_for_typechecking(&dp_opts, rpath, &text, &arena) ); Ok(()) }
Rust
hhvm/hphp/hack/src/parser/api/decl_mode_parser.rs
// Copyright (c) Facebook, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. //! This is a version of [`positioned_parser`]([../positioned_parser/) which skips //! method bodies in produced syntax tree. When performing type inference in a file, Hack //! needs to know types of entities in other files, but the method bodies of those entities are not //! relevant, while also constituting majority of allocated data. Using this parser for this //! purpose makes computing declarations much more efficient. //! //! The above is a slight lie and in reality function bodies _can_ affect the declaration //! of a function, for example based on presence of `yield` statement which turns a function into //! generator. This parser tracks and returns this kind of data in its state. use bumpalo::Bump; use decl_mode_smart_constructors::DeclModeSmartConstructors; use decl_mode_smart_constructors::State as DeclModeState; use parser::parser::Parser; use parser::parser_env::ParserEnv; use parser::smart_constructors_wrappers::WithKind; use parser::source_text::SourceText; use parser::syntax_by_ref::positioned_syntax::PositionedSyntax; use parser::syntax_by_ref::positioned_token::PositionedToken; use parser::syntax_by_ref::positioned_token::TokenFactory; use parser::syntax_by_ref::positioned_value::PositionedValue; use parser::syntax_error::SyntaxError; pub type SmartConstructors<'src, 'arena> = WithKind< DeclModeSmartConstructors< 'src, 'arena, PositionedSyntax<'arena>, PositionedToken<'arena>, PositionedValue<'arena>, TokenFactory<'arena>, >, >; pub type ScState<'src, 'arena> = DeclModeState<'src, 'arena, PositionedSyntax<'arena>>; pub fn parse_script<'src, 'arena>( arena: &'arena Bump, source: &SourceText<'src>, env: ParserEnv, ) -> ( PositionedSyntax<'arena>, Vec<SyntaxError>, ScState<'src, 'arena>, ) { let sc = WithKind::new(DeclModeSmartConstructors::new( source, TokenFactory::new(arena), arena, )); let mut parser = Parser::new(source, env, sc); let root = parser.parse_script(); let errors = parser.errors(); let sc_state = parser.into_sc_state(); (root, errors, sc_state) }
Rust
hhvm/hphp/hack/src/parser/api/direct_decl_parser.rs
// Copyright (c) Facebook, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use std::sync::Arc; use bumpalo::Bump; use direct_decl_smart_constructors::ArenaSourceTextAllocator; use direct_decl_smart_constructors::DirectDeclSmartConstructors; use direct_decl_smart_constructors::NoSourceTextAllocator; use direct_decl_smart_constructors::SourceTextAllocator; use mode_parser::parse_mode; pub use oxidized::decl_parser_options::DeclParserOptions; pub use oxidized_by_ref::direct_decl_parser::Decls; pub use oxidized_by_ref::direct_decl_parser::ParsedFile; use oxidized_by_ref::file_info; pub use oxidized_by_ref::typing_defs::UserAttribute; use parser::parser::Parser; use parser_core_types::parser_env::ParserEnv; use parser_core_types::source_text::SourceText; use relative_path::RelativePath; /// Parse decls for typechecking. /// - References the source text to avoid spending time or space copying /// identifiers into the arena (when possible). /// /// WARNING /// This function (1) doesn't respect po_deregister_php_stdlib which filters+adjusts certain /// decls from hhi files, (2) produces decls in reverse order, (3) includes subsequent decls /// in case of name-clash, rather than just the first. Unless you the caller have thought /// through your desired semantics in these cases, you're probably buggy. pub fn parse_decls_for_typechecking<'a>( opts: &DeclParserOptions, filename: RelativePath, text: &'a [u8], arena: &'a Bump, ) -> ParsedFile<'a> { parse_script_with_text_allocator( opts, filename, text, arena, NoSourceTextAllocator, false, // elaborate_xhp_namespaces_for_facts ) } /// The same as 'parse_decls_for_typechecking' except /// - Returns decls without reference to the source text to avoid the need to /// keep the source text in memory when caching decls. /// /// WARNING /// This function (1) doesn't respect po_deregister_php_stdlib which filters+adjusts certain /// decls from hhi files, (2) produces decls in reverse order, (3) includes subsequent decls /// in case of name-clash, rather than just the first. Unless you the caller have thought /// through your desired semantics in these cases, you're probably buggy. pub fn parse_decls_for_typechecking_without_reference_text<'a, 'text>( opts: &DeclParserOptions, filename: RelativePath, text: &'text [u8], arena: &'a Bump, ) -> ParsedFile<'a> { parse_script_with_text_allocator( opts, filename, text, arena, ArenaSourceTextAllocator(arena), false, // elaborate_xhp_namespaces_for_facts ) } /// Parse decls for bytecode compilation. /// - Returns decls without reference to the source text to avoid the need to /// keep the source text in memory when caching decls. /// - Expects the keep_user_attributes option to be set as it is necessary for /// producing facts. (This means that you'll get decl_hash answers that differ /// from parse_decls). pub fn parse_decls_for_bytecode<'a, 'text>( opts: &DeclParserOptions, filename: RelativePath, text: &'text [u8], arena: &'a Bump, ) -> ParsedFile<'a> { parse_script_with_text_allocator( opts, filename, text, arena, ArenaSourceTextAllocator(arena), true, // elaborate_xhp_namespaces_for_facts ) } fn collect_file_attributes<'a>( arena: &'a Bump, file_attributes: impl Iterator<Item = &'a UserAttribute<'a>>, len: usize, ) -> &'a [&'a UserAttribute<'a>] { let mut attrs = bumpalo::collections::Vec::with_capacity_in(len, arena); attrs.extend(file_attributes); // Direct decl parser populates state.file_attributes in reverse of // syntactic order, so reverse it. attrs.reverse(); attrs.into_bump_slice() } fn parse_script_with_text_allocator<'a, 'o, 't, S: SourceTextAllocator<'t, 'a>>( opts: &'o DeclParserOptions, filename: RelativePath, text: &'t [u8], arena: &'a Bump, source_text_allocator: S, elaborate_xhp_namespaces_for_facts: bool, ) -> ParsedFile<'a> { let source = SourceText::make(Arc::new(filename), text); let env = ParserEnv::from(opts); let (_, mode_opt) = parse_mode(&source); let mode_opt = mode_opt.map(file_info::Mode::from); let mode = mode_opt.unwrap_or(file_info::Mode::Mstrict); let sc = DirectDeclSmartConstructors::new( opts, &source, mode, arena, source_text_allocator, elaborate_xhp_namespaces_for_facts, ); let mut parser = Parser::new(&source, env, sc); let _root = parser.parse_script(); // doing it for the side effect, not the return value let errors = parser.errors(); let sc_state = parser.into_sc_state(); ParsedFile { mode: mode_opt, file_attributes: collect_file_attributes( arena, sc_state.file_attributes.iter().copied(), sc_state.file_attributes.len(), ), decls: sc_state.decls, disable_xhp_element_mangling: opts.disable_xhp_element_mangling, has_first_pass_parse_errors: !errors.is_empty(), } }
Rust
hhvm/hphp/hack/src/parser/api/ocaml_positioned_parser.rs
// Copyright (c) Facebook, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use ocaml_syntax::OcamlContextState; use ocaml_syntax::OcamlSyntax; use parser::parser::Parser; use parser::parser_env::ParserEnv; use parser::positioned_syntax::PositionedValue; use parser::positioned_token::PositionedToken; use parser::smart_constructors_wrappers::WithKind; use parser::source_text::SourceText; use parser::syntax_error::SyntaxError; use parser::token_factory::SimpleTokenFactoryImpl; use positioned_smart_constructors::*; use stack_limit::StackLimit; pub type SmartConstructors<'src> = WithKind< PositionedSmartConstructors< OcamlSyntax<PositionedValue>, SimpleTokenFactoryImpl<PositionedToken>, OcamlContextState<'src>, >, >; pub type ScState<'src> = OcamlContextState<'src>; pub fn parse_script<'src>( source: &SourceText<'src>, env: ParserEnv, stack_limit: Option<&'src StackLimit>, ) -> ( OcamlSyntax<PositionedValue>, Vec<SyntaxError>, ScState<'src>, ) { let sc = WithKind::new(PositionedSmartConstructors::new( OcamlContextState::initial(source), SimpleTokenFactoryImpl::new(), )); let mut parser = Parser::new(&source, env, sc); let root = parser.parse_script(stack_limit); let errors = parser.errors(); let sc_state = parser.into_sc_state(); (root, errors, sc_state) }
Rust
hhvm/hphp/hack/src/parser/api/positioned_by_ref_parser.rs
// Copyright (c) Facebook, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use bumpalo::Bump; use parser::lexer::Lexer; use parser::parser::Parser; use parser::parser_env::ParserEnv; use parser::source_text::SourceText; use parser::syntax_by_ref::arena_state::State; use parser::syntax_by_ref::positioned_token::PositionedToken; use parser::syntax_by_ref::positioned_token::TokenFactory; use parser::syntax_by_ref::positioned_token::TokenFactoryFullTrivia; use parser::syntax_by_ref::positioned_trivia::PositionedTrivia; use parser::syntax_by_ref::positioned_value::PositionedValue; use parser::syntax_by_ref::syntax; use parser::syntax_error::SyntaxError; use positioned_smart_constructors::*; type Syntax<'a> = syntax::Syntax<'a, PositionedToken<'a>, PositionedValue<'a>>; pub type SmartConstructors<'a> = PositionedSmartConstructors<Syntax<'a>, TokenFactory<'a>, State<'a>>; pub fn parse_script<'src, 'arena>( arena: &'arena Bump, source: &SourceText<'src>, env: ParserEnv, ) -> (Syntax<'arena>, Vec<SyntaxError>, State<'arena>) { let tf = TokenFactory::new(arena); let sc = SmartConstructors::new(State { arena }, tf); let mut parser = Parser::new(source, env, sc); let root = parser.parse_script(); let errors = parser.errors(); let sc_state = parser.into_sc_state(); (root, errors, sc_state) } pub fn parse_header_only<'src, 'arena>( env: ParserEnv, arena: &'arena Bump, source: &SourceText<'src>, ) -> Option<Syntax<'arena>> { let tf = TokenFactory::new(arena); let sc = SmartConstructors::new(State { arena }, tf); Parser::parse_header_only(env, source, sc) } fn trivia_lexer<'a>( arena: &'a Bump, source_text: &'a SourceText<'a>, offset: usize, ) -> Lexer<'a, TokenFactoryFullTrivia<'a>> { Lexer::make_at(source_text, offset, TokenFactoryFullTrivia::new(arena)) } pub fn scan_leading_xhp_trivia<'a>( arena: &'a Bump, source_text: &'a SourceText<'a>, offset: usize, width: usize, ) -> PositionedTrivia<'a> { trivia_lexer(arena, source_text, offset).scan_leading_xhp_trivia_with_width(width) } pub fn scan_trailing_xhp_trivia<'a>( arena: &'a Bump, source_text: &'a SourceText<'a>, offset: usize, _width: usize, ) -> PositionedTrivia<'a> { trivia_lexer(arena, source_text, offset).scan_trailing_xhp_trivia() } pub fn scan_leading_php_trivia<'a>( arena: &'a Bump, source_text: &'a SourceText<'a>, offset: usize, width: usize, ) -> PositionedTrivia<'a> { trivia_lexer(arena, source_text, offset).scan_leading_php_trivia_with_width(width) } pub fn scan_trailing_php_trivia<'a>( arena: &'a Bump, source_text: &'a SourceText<'a>, offset: usize, _width: usize, ) -> PositionedTrivia<'a> { trivia_lexer(arena, source_text, offset).scan_trailing_php_trivia() }
Rust
hhvm/hphp/hack/src/parser/api/positioned_full_trivia_parser.rs
// Copyright (c) Facebook, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use bumpalo::Bump; use parser::indexed_source_text::IndexedSourceText; use parser::parser::Parser; use parser::parser_env::ParserEnv; use parser::source_text::SourceText; use parser::syntax_by_ref::arena_state::State; use parser::syntax_by_ref::positioned_token::PositionedTokenFullTrivia; use parser::syntax_by_ref::positioned_token::TokenFactoryFullTrivia; use parser::syntax_by_ref::positioned_value::PositionedValueFullTrivia; use parser::syntax_by_ref::serialize; use parser::syntax_by_ref::syntax; use parser::syntax_error::SyntaxError; use positioned_smart_constructors::*; use serde::Serialize; use serde::Serializer; pub type Syntax<'a> = syntax::Syntax<'a, PositionedTokenFullTrivia<'a>, PositionedValueFullTrivia<'a>>; pub type SmartConstructors<'a> = PositionedSmartConstructors<Syntax<'a>, TokenFactoryFullTrivia<'a>, State<'a>>; pub fn parse_script<'src, 'arena>( arena: &'arena Bump, source: &SourceText<'src>, env: ParserEnv, ) -> (Syntax<'arena>, Vec<SyntaxError>) { let tf = TokenFactoryFullTrivia::new(arena); let sc = SmartConstructors::new(State { arena }, tf); let mut parser = Parser::new(source, env, sc); let root = parser.parse_script(); let errors = parser.errors(); (root, errors) } pub fn parse_script_to_json<'src, 'arena, S: Serializer>( arena: &'arena Bump, s: S, source: &IndexedSourceText<'src>, env: ParserEnv, ) -> Result<S::Ok, S::Error> { #[derive(Serialize)] struct Output<'a> { parse_tree: serialize::WithContext<'a, Syntax<'a>>, program_text: &'a str, version: &'static str, } let tf = TokenFactoryFullTrivia::new(arena); let sc = SmartConstructors::new(State { arena }, tf); let mut parser = Parser::new(source.source_text(), env, sc); let root = parser.parse_script(); let parse_tree = serialize::WithContext(source, &root); let output = Output { parse_tree, program_text: source.source_text().text_as_str(), version: full_fidelity_schema_version_number::VERSION, }; output.serialize(s) }
Rust
hhvm/hphp/hack/src/parser/api/positioned_parser.rs
// Copyright (c) Facebook, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. //! `positioned_parser` produces concrete syntax tree parametrized with //! `PositionedToken` / `PositionedTrivia`. This is probably what you want //! to use for most applications. //! //! As opposed to [minimal_parser](../minimal_parser/), nodes contain more //! information (like their offset within the file) making it easier to //! consume (at the cost of taking more memory and more time to produce due //! to cost of all additional allocations). //! //! The structure should be identical to one produced by `minimal_parser` //! and it *should* be possible to transform minimal tree to positioned one //! without reparsing the file, but due to bugs in implementations there //! are multiple small incompatibilities. //! //! [coroutine_parser_leak_tree](../coroutine_parser_leak_tree/) and //! [positioned_coroutine_parser](../positioned_coroutine_parser/) are the //! versions of the same parser with some small tweaks necessary for //! particular applications in `hackc` / `hh_server`. use parser::lexer::Lexer; use parser::parser::Parser; use parser::parser_env::ParserEnv; use parser::positioned_syntax::PositionedSyntax; use parser::positioned_token::PositionedToken; use parser::positioned_trivia::PositionedTrivium; use parser::smart_constructors_wrappers::WithKind; use parser::source_text::SourceText; use parser::syntax_error::SyntaxError; use parser::token_factory::SimpleTokenFactoryImpl; use parser::NoState; use positioned_smart_constructors::*; pub type SmartConstructors = WithKind< PositionedSmartConstructors<PositionedSyntax, SimpleTokenFactoryImpl<PositionedToken>, NoState>, >; pub type ScState = NoState; pub fn parse_script<'a>( source: &SourceText<'a>, env: ParserEnv, ) -> (PositionedSyntax, Vec<SyntaxError>, NoState) { let sc = WithKind::new(PositionedSmartConstructors::new( NoState, SimpleTokenFactoryImpl::new(), )); let mut parser = Parser::new(source, env, sc); let root = parser.parse_script(); let errors = parser.errors(); let sc_state = parser.into_sc_state(); (root, errors, sc_state) } fn trivia_lexer<'a>( source_text: &SourceText<'a>, offset: usize, ) -> Lexer<'a, SimpleTokenFactoryImpl<PositionedToken>> { Lexer::make_at(source_text, offset, SimpleTokenFactoryImpl::new()) } pub fn scan_leading_xhp_trivia( source_text: &SourceText<'_>, offset: usize, width: usize, ) -> Vec<PositionedTrivium> { trivia_lexer(source_text, offset).scan_leading_xhp_trivia_with_width(width) } pub fn scan_trailing_xhp_trivia( source_text: &SourceText<'_>, offset: usize, ) -> Vec<PositionedTrivium> { trivia_lexer(source_text, offset).scan_trailing_xhp_trivia() } pub fn scan_leading_php_trivia( source_text: &SourceText<'_>, offset: usize, width: usize, ) -> Vec<PositionedTrivium> { trivia_lexer(source_text, offset).scan_leading_php_trivia_with_width(width) } pub fn scan_trailing_php_trivia( source_text: &SourceText<'_>, offset: usize, ) -> Vec<PositionedTrivium> { trivia_lexer(source_text, offset).scan_trailing_php_trivia() }
Rust
hhvm/hphp/hack/src/parser/api/rescan_trivia.rs
// Copyright (c) 2019, Facebook, Inc. // All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use parser::lexable_token::LexableToken; use parser::positioned_trivia::PositionedTrivium; use parser::source_text::SourceText; use parser::syntax_by_ref::positioned_token::PositionedToken; use parser::token_kind::TokenKind; pub trait RescanTrivia<Trivium> { fn scan_leading(&self, source_text: &SourceText<'_>) -> Vec<Trivium>; fn scan_trailing(&self, source_text: &SourceText<'_>) -> Vec<Trivium>; } impl RescanTrivia<PositionedTrivium> for PositionedToken<'_> { fn scan_leading(&self, source_text: &SourceText<'_>) -> Vec<PositionedTrivium> { let f = if self.kind() == TokenKind::XHPBody { positioned_parser::scan_leading_xhp_trivia } else { positioned_parser::scan_leading_php_trivia }; f( source_text, self.leading_start_offset().unwrap(), self.leading_width(), ) } fn scan_trailing(&self, source_text: &SourceText<'_>) -> Vec<PositionedTrivium> { let f = if self.kind() == TokenKind::XHPBody { positioned_parser::scan_trailing_xhp_trivia } else { positioned_parser::scan_trailing_php_trivia }; f(source_text, self.leading_start_offset().unwrap()) } }
TOML
hhvm/hphp/hack/src/parser/api/cargo/cst_and_decl_parser/Cargo.toml
# @generated by autocargo [package] name = "cst_and_decl_parser" version = "0.0.0" edition = "2021" [lib] path = "../../cst_and_decl_parser.rs" test = false doctest = false [dependencies] bumpalo = { version = "3.11.1", features = ["collections"] } direct_decl_parser = { version = "0.0.0", path = "../direct_decl_parser" } direct_decl_smart_constructors = { version = "0.0.0", path = "../../../../decl/direct_decl_smart_constructors" } oxidized = { version = "0.0.0", path = "../../../../oxidized" } oxidized_by_ref = { version = "0.0.0", path = "../../../../oxidized_by_ref" } pair_smart_constructors = { version = "0.0.0", path = "../../../cargo/pair_smart_constructors" } parser = { version = "0.0.0", path = "../../../core" } parser_core_types = { version = "0.0.0", path = "../../../cargo/core_types" } positioned_smart_constructors = { version = "0.0.0", path = "../../../cargo/positioned_smart_constructors" }
TOML
hhvm/hphp/hack/src/parser/api/cargo/ddp_test/Cargo.toml
# @generated by autocargo [package] name = "ddp_test" version = "0.0.0" edition = "2021" [[bin]] name = "ddp_test" path = "../../ddp_test.rs" test = false [dependencies] anyhow = "1.0.71" bumpalo = { version = "3.11.1", features = ["collections"] } clap = { version = "4.3.5", features = ["derive", "env", "string", "unicode", "wrap_help"] } direct_decl_parser = { version = "0.0.0", path = "../direct_decl_parser" } hh_config = { version = "0.0.0", path = "../../../../utils/hh_config/cargo" } relative_path = { version = "0.0.0", path = "../../../../utils/rust/relative_path" }
TOML
hhvm/hphp/hack/src/parser/api/cargo/decl_mode_parser/Cargo.toml
# @generated by autocargo [package] name = "decl_mode_parser" version = "0.0.0" edition = "2021" [lib] path = "../../decl_mode_parser.rs" test = false doctest = false [dependencies] bumpalo = { version = "3.11.1", features = ["collections"] } decl_mode_smart_constructors = { version = "0.0.0", path = "../../../cargo/decl_mode_parser" } parser = { version = "0.0.0", path = "../../../core" }
TOML
hhvm/hphp/hack/src/parser/api/cargo/direct_decl_parser/Cargo.toml
# @generated by autocargo [package] name = "direct_decl_parser" version = "0.0.0" edition = "2021" [lib] path = "../../direct_decl_parser.rs" test = false doctest = false [dependencies] bumpalo = { version = "3.11.1", features = ["collections"] } direct_decl_smart_constructors = { version = "0.0.0", path = "../../../../decl/direct_decl_smart_constructors" } mode_parser = { version = "0.0.0", path = "../../../cargo/mode_parser" } oxidized = { version = "0.0.0", path = "../../../../oxidized" } oxidized_by_ref = { version = "0.0.0", path = "../../../../oxidized_by_ref" } parser = { version = "0.0.0", path = "../../../core" } parser_core_types = { version = "0.0.0", path = "../../../cargo/core_types" } relative_path = { version = "0.0.0", path = "../../../../utils/rust/relative_path" }
TOML
hhvm/hphp/hack/src/parser/api/cargo/positioned_by_ref_parser/Cargo.toml
# @generated by autocargo [package] name = "positioned_by_ref_parser" version = "0.0.0" edition = "2021" [lib] path = "../../positioned_by_ref_parser.rs" test = false doctest = false [dependencies] bumpalo = { version = "3.11.1", features = ["collections"] } parser = { version = "0.0.0", path = "../../../core" } positioned_smart_constructors = { version = "0.0.0", path = "../../../cargo/positioned_smart_constructors" }
TOML
hhvm/hphp/hack/src/parser/api/cargo/positioned_full_trivia_parser/Cargo.toml
# @generated by autocargo [package] name = "positioned_full_trivia_parser" version = "0.0.0" edition = "2021" [lib] path = "../../positioned_full_trivia_parser.rs" test = false doctest = false [dependencies] bumpalo = { version = "3.11.1", features = ["collections"] } full_fidelity_schema_version_number = { version = "0.0.0", path = "../../../schema" } parser = { version = "0.0.0", path = "../../../core" } positioned_smart_constructors = { version = "0.0.0", path = "../../../cargo/positioned_smart_constructors" } serde = { version = "1.0.176", features = ["derive", "rc"] }
TOML
hhvm/hphp/hack/src/parser/api/cargo/positioned_parser/Cargo.toml
# @generated by autocargo [package] name = "positioned_parser" version = "0.0.0" edition = "2021" [lib] path = "../../positioned_parser.rs" test = false doctest = false [dependencies] parser = { version = "0.0.0", path = "../../../core" } positioned_smart_constructors = { version = "0.0.0", path = "../../../cargo/positioned_smart_constructors" }
TOML
hhvm/hphp/hack/src/parser/api/cargo/rescan_trivia/Cargo.toml
# @generated by autocargo [package] name = "rescan_trivia" version = "0.0.0" edition = "2021" [lib] path = "../../rescan_trivia.rs" test = false doctest = false [dependencies] parser = { version = "0.0.0", path = "../../../core" } positioned_parser = { version = "0.0.0", path = "../positioned_parser" }
Rust
hhvm/hphp/hack/src/parser/bench/bench.rs
// Copyright (c) 2019, Facebook, Inc. // All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use std::collections::HashSet; use std::fs; use std::path::PathBuf; use std::sync::Arc; use std::time::Duration; use aast_parser::rust_aast_parser_types::Env as AastParserEnv; use bumpalo::Bump; use clap::Parser; use criterion::Criterion; use parser_core_types::indexed_source_text::IndexedSourceText; use parser_core_types::source_text::SourceText; use relative_path::Prefix; use relative_path::RelativePath; #[derive(Debug, Parser)] struct Options { files: Vec<PathBuf>, // The total time in seconds to spend measuring each parser. #[clap(long, default_value = "10")] measurement_time: u64, // If true, only benchmark the direct decl parser. #[clap(long)] direct_decl_only: bool, } fn main() { let opts = Options::parse(); let mut criterion = Criterion::default() .warm_up_time(Duration::from_secs(2)) .sample_size(50) .measurement_time(Duration::from_secs(opts.measurement_time)); let filenames_and_contents = get_contents(&opts.files); let files = filenames_and_contents .iter() .map(|(path, text)| (Arc::clone(path), text.as_bytes())) .collect::<Vec<_>>(); if opts.direct_decl_only { bench_direct_decl_parse(&mut criterion, &files); } else { bench_aast_full_parse(&mut criterion, &files); bench_aast_quick_parse(&mut criterion, &files); bench_direct_decl_parse(&mut criterion, &files); bench_cst_and_decl_parse(&mut criterion, &files); bench_ast_and_decl_parse(&mut criterion, &files); } criterion.final_summary(); } fn get_contents(filenames: &[PathBuf]) -> Vec<(Arc<RelativePath>, String)> { filenames .iter() .map(|file| { ( Arc::new(RelativePath::make(Prefix::Dummy, PathBuf::from(file))), fs::read_to_string(file) .unwrap_or_else(|_| panic!("Could not read file {}", file.display())), ) }) .collect() } fn bench_direct_decl_parse(c: &mut Criterion, files: &[(Arc<RelativePath>, &[u8])]) { let mut arena = Bump::with_capacity(1024 * 1024); // 1 MB let opts = Default::default(); c.bench_function("direct_decl_parse", |b| { b.iter(|| { for (filename, text) in files { let _ = direct_decl_parser::parse_decls_for_typechecking( &opts, (**filename).clone(), text, &arena, ); arena.reset(); } }) }); } fn bench_cst_and_decl_parse(c: &mut Criterion, files: &[(Arc<RelativePath>, &[u8])]) { let mut arena = Bump::with_capacity(1024 * 1024); // 1 MB let opts = Default::default(); c.bench_function("cst_and_decl_parse", |b| { b.iter(|| { for (filename, text) in files { let text = SourceText::make(Arc::clone(filename), text); let _ = cst_and_decl_parser::parse_script( &opts, Default::default(), &text, None, &arena, ); arena.reset(); } }) }); } fn bench_ast_and_decl_parse(c: &mut Criterion, files: &[(Arc<RelativePath>, &[u8])]) { let mut arena = Bump::with_capacity(1024 * 1024); // 1 MB c.bench_function("ast_and_decl_parse", |b| { b.iter(|| { for (filename, text) in files { let text = SourceText::make(Arc::clone(filename), text); let indexed_source_text = IndexedSourceText::new(text.clone()); let _ = ast_and_decl_parser::from_text( &Default::default(), &indexed_source_text, &arena, ); arena.reset(); } }) }); } fn bench_aast_full_parse(c: &mut Criterion, files: &[(Arc<RelativePath>, &[u8])]) { c.bench_function("aast_full_parse", |b| { b.iter(|| { for (filename, text) in files { let text = SourceText::make(Arc::clone(filename), text); let indexed_source_text = IndexedSourceText::new(text.clone()); aast_parser::AastParser::from_text( &AastParserEnv::default(), &indexed_source_text, HashSet::default(), ) .unwrap(); } }) }); } fn bench_aast_quick_parse(c: &mut Criterion, files: &[(Arc<RelativePath>, &[u8])]) { c.bench_function("aast_quick_parse", |b| { b.iter(|| { for (filename, text) in files { let text = SourceText::make(Arc::clone(filename), text); let indexed_source_text = IndexedSourceText::new(text.clone()); aast_parser::AastParser::from_text( &AastParserEnv { quick_mode: true, ..AastParserEnv::default() }, &indexed_source_text, HashSet::default(), ) .unwrap(); } }) }); }
TOML
hhvm/hphp/hack/src/parser/cargo/aast_parser/Cargo.toml
# @generated by autocargo [package] name = "aast_parser" version = "0.0.0" edition = "2021" [lib] path = "../../aast_parser_lib.rs" [dependencies] bitflags = "1.3" bumpalo = { version = "3.11.1", features = ["collections"] } core_utils_rust = { version = "0.0.0", path = "../../../utils/core" } decl_mode_parser = { version = "0.0.0", path = "../../api/cargo/decl_mode_parser" } hash = { version = "0.0.0", path = "../../../utils/hash" } hh_autoimport_rust = { version = "0.0.0", path = "../hh_autoimport" } lowerer = { version = "0.0.0", path = "../../lowerer" } mode_parser = { version = "0.0.0", path = "../mode_parser" } namespaces_rust = { version = "0.0.0", path = "../namespaces" } naming_special_names_rust = { version = "0.0.0", path = "../../../naming" } ocamlrep = { version = "0.1.0", git = "https://github.com/facebook/ocamlrep/", branch = "main" } oxidized = { version = "0.0.0", path = "../../../oxidized" } parser_core_types = { version = "0.0.0", path = "../core_types" } positioned_by_ref_parser = { version = "0.0.0", path = "../../api/cargo/positioned_by_ref_parser" } rust_aast_parser_types = { version = "0.0.0", path = "../rust_aast_parser_types" } rust_parser_errors = { version = "0.0.0", path = "../errors" } smart_constructors = { version = "0.0.0", path = "../smart_constructors" } stack_limit = { version = "0.0.0", path = "../../../utils/stack_limit" }
TOML
hhvm/hphp/hack/src/parser/cargo/aast_parser_ffi/Cargo.toml
# @generated by autocargo [package] name = "aast_parser_ffi" version = "0.0.0" edition = "2021" [lib] path = "../../aast_parser_ffi.rs" test = false doctest = false crate-type = ["lib", "staticlib"] [dependencies] aast_parser = { version = "0.0.0", path = "../aast_parser" } ocamlrep = { version = "0.1.0", git = "https://github.com/facebook/ocamlrep/", branch = "main" } ocamlrep_ocamlpool = { version = "0.1.0", git = "https://github.com/facebook/ocamlrep/", branch = "main" } parser_core_types = { version = "0.0.0", path = "../core_types" }
TOML
hhvm/hphp/hack/src/parser/cargo/ast_and_decl_parser/Cargo.toml
# @generated by autocargo [package] name = "ast_and_decl_parser" version = "0.0.0" edition = "2021" [lib] path = "../../ast_and_decl_parser.rs" [dependencies] aast_parser = { version = "0.0.0", path = "../aast_parser" } bumpalo = { version = "3.11.1", features = ["collections"] } cst_and_decl_parser = { version = "0.0.0", path = "../../api/cargo/cst_and_decl_parser" } oxidized = { version = "0.0.0", path = "../../../oxidized" } oxidized_by_ref = { version = "0.0.0", path = "../../../oxidized_by_ref" } parser_core_types = { version = "0.0.0", path = "../core_types" } rust_aast_parser_types = { version = "0.0.0", path = "../rust_aast_parser_types" }
TOML
hhvm/hphp/hack/src/parser/cargo/bench/Cargo.toml
# @generated by autocargo [package] name = "bench" version = "0.0.0" edition = "2021" [[bin]] name = "bench" path = "../../bench/bench.rs" [dependencies] aast_parser = { version = "0.0.0", path = "../aast_parser" } ast_and_decl_parser = { version = "0.0.0", path = "../ast_and_decl_parser" } bumpalo = { version = "3.11.1", features = ["collections"] } clap = { version = "4.3.5", features = ["derive", "env", "string", "unicode", "wrap_help"] } criterion = "=0.3.1" cst_and_decl_parser = { version = "0.0.0", path = "../../api/cargo/cst_and_decl_parser" } direct_decl_parser = { version = "0.0.0", path = "../../api/cargo/direct_decl_parser" } parser_core_types = { version = "0.0.0", path = "../core_types" } relative_path = { version = "0.0.0", path = "../../../utils/rust/relative_path" }
TOML
hhvm/hphp/hack/src/parser/cargo/core_types/Cargo.toml
# @generated by autocargo [package] name = "parser_core_types" version = "0.0.0" edition = "2021" [lib] path = "../../parser_core_types_lib.rs" [dependencies] bitflags = "1.3" bumpalo = { version = "3.11.1", features = ["collections"] } itertools = "0.10.3" line_break_map = { version = "0.0.0", path = "../../../utils/line_break_map" } ocaml_helper = { version = "0.0.0", path = "../../../utils/ocaml_helper" } ocamlrep = { version = "0.1.0", git = "https://github.com/facebook/ocamlrep/", branch = "main" } relative_path = { version = "0.0.0", path = "../../../utils/rust/relative_path" } serde = { version = "1.0.176", features = ["derive", "rc"] }
TOML
hhvm/hphp/hack/src/parser/cargo/decl_mode_parser/Cargo.toml
# @generated by autocargo [package] name = "decl_mode_smart_constructors" version = "0.0.0" edition = "2021" [lib] path = "../../decl_mode_smart_constructors.rs" test = false doctest = false [dependencies] bumpalo = { version = "3.11.1", features = ["collections"] } ocamlrep = { version = "0.1.0", git = "https://github.com/facebook/ocamlrep/", branch = "main" } parser_core_types = { version = "0.0.0", path = "../core_types" } smart_constructors = { version = "0.0.0", path = "../smart_constructors" } syntax_smart_constructors = { version = "0.0.0", path = "../syntax_smart_constructors" }
TOML
hhvm/hphp/hack/src/parser/cargo/errors/Cargo.toml
# @generated by autocargo [package] name = "rust_parser_errors" version = "0.0.0" edition = "2021" [lib] path = "../../rust_parser_errors.rs" test = false doctest = false [dependencies] escaper = { version = "0.0.0", path = "../../../utils/escaper" } hash = { version = "0.0.0", path = "../../../utils/hash" } hh_autoimport_rust = { version = "0.0.0", path = "../hh_autoimport" } itertools = "0.10.3" naming_special_names_rust = { version = "0.0.0", path = "../../../naming" } oxidized = { version = "0.0.0", path = "../../../oxidized" } parser_core_types = { version = "0.0.0", path = "../core_types" } stack_limit = { version = "0.0.0", path = "../../../utils/stack_limit" } strum = { version = "0.24", features = ["derive"] }
TOML
hhvm/hphp/hack/src/parser/cargo/flatten_smart_constructors/Cargo.toml
# @generated by autocargo [package] name = "flatten_smart_constructors" version = "0.0.0" edition = "2021" [lib] path = "../../flatten_smart_constructors.rs" test = false doctest = false [dependencies] parser_core_types = { version = "0.0.0", path = "../core_types" } smart_constructors = { version = "0.0.0", path = "../smart_constructors" }
TOML
hhvm/hphp/hack/src/parser/cargo/hh_autoimport/Cargo.toml
# @generated by autocargo [package] name = "hh_autoimport_rust" version = "0.0.0" edition = "2021" [lib] path = "../../hh_autoimport.rs" [dependencies] lazy_static = "1.4"
TOML
hhvm/hphp/hack/src/parser/cargo/mode_parser/Cargo.toml
# @generated by autocargo [package] name = "mode_parser" version = "0.0.0" edition = "2021" [lib] path = "../../mode_parser.rs" [dependencies] bumpalo = { version = "3.11.1", features = ["collections"] } parser_core_types = { version = "0.0.0", path = "../core_types" } positioned_by_ref_parser = { version = "0.0.0", path = "../../api/cargo/positioned_by_ref_parser" }
TOML
hhvm/hphp/hack/src/parser/cargo/namespaces/Cargo.toml
# @generated by autocargo [package] name = "namespaces_rust" version = "0.0.0" edition = "2021" [lib] path = "../../namespaces.rs" [dependencies] bumpalo = { version = "3.11.1", features = ["collections"] } core_utils_rust = { version = "0.0.0", path = "../../../utils/core" } naming_special_names_rust = { version = "0.0.0", path = "../../../naming" } oxidized = { version = "0.0.0", path = "../../../oxidized" } oxidized_by_ref = { version = "0.0.0", path = "../../../oxidized_by_ref" }
TOML
hhvm/hphp/hack/src/parser/cargo/operator/Cargo.toml
# @generated by autocargo [package] name = "operator" version = "0.0.0" edition = "2021" [lib] path = "../../operator.rs" [dependencies] ocamlrep = { version = "0.1.0", git = "https://github.com/facebook/ocamlrep/", branch = "main" } parser_core_types = { version = "0.0.0", path = "../core_types" }
TOML
hhvm/hphp/hack/src/parser/cargo/pair_smart_constructors/Cargo.toml
# @generated by autocargo [package] name = "pair_smart_constructors" version = "0.0.0" edition = "2021" [lib] path = "../../pair_smart_constructors.rs" test = false doctest = false [dependencies] parser_core_types = { version = "0.0.0", path = "../core_types" } smart_constructors = { version = "0.0.0", path = "../smart_constructors" }
TOML
hhvm/hphp/hack/src/parser/cargo/positioned_by_ref_parser_ffi/Cargo.toml
# @generated by autocargo [package] name = "positioned_by_ref_parser_ffi" version = "0.0.0" edition = "2021" [lib] path = "../../positioned_by_ref_parser_ffi.rs" test = false doctest = false crate-type = ["lib", "staticlib"] [dependencies] ocamlrep = { version = "0.1.0", git = "https://github.com/facebook/ocamlrep/", branch = "main" } ocamlrep_ocamlpool = { version = "0.1.0", git = "https://github.com/facebook/ocamlrep/", branch = "main" } oxidized = { version = "0.0.0", path = "../../../oxidized" } positioned_by_ref_parser = { version = "0.0.0", path = "../../api/cargo/positioned_by_ref_parser" } rust_parser_ffi = { version = "0.0.0", path = "../rust_parser_ffi" }
TOML
hhvm/hphp/hack/src/parser/cargo/positioned_smart_constructors/Cargo.toml
# @generated by autocargo [package] name = "positioned_smart_constructors" version = "0.0.0" edition = "2021" [lib] path = "../../positioned_smart_constructors.rs" test = false doctest = false [dependencies] parser_core_types = { version = "0.0.0", path = "../core_types" } smart_constructors = { version = "0.0.0", path = "../smart_constructors" } syntax_smart_constructors = { version = "0.0.0", path = "../syntax_smart_constructors" }
TOML
hhvm/hphp/hack/src/parser/cargo/rust_aast_parser_types/Cargo.toml
# @generated by autocargo [package] name = "rust_aast_parser_types" version = "0.0.0" edition = "2021" [lib] path = "../../rust_aast_parser_types.rs" [dependencies] lint_rust = { version = "0.0.0", path = "../../../utils/lint" } ocamlrep = { version = "0.1.0", git = "https://github.com/facebook/ocamlrep/", branch = "main" } oxidized = { version = "0.0.0", path = "../../../oxidized" } parser_core_types = { version = "0.0.0", path = "../core_types" }
TOML
hhvm/hphp/hack/src/parser/cargo/rust_parser_errors_ffi/Cargo.toml
# @generated by autocargo [package] name = "rust_parser_errors_ffi" version = "0.0.0" edition = "2021" [lib] path = "../../rust_parser_errors_ffi/rust_parser_errors_ffi.rs" test = false doctest = false crate-type = ["lib", "staticlib"] [dependencies] bumpalo = { version = "3.11.1", features = ["collections"] } ocamlrep = { version = "0.1.0", git = "https://github.com/facebook/ocamlrep/", branch = "main" } ocamlrep_ocamlpool = { version = "0.1.0", git = "https://github.com/facebook/ocamlrep/", branch = "main" } oxidized = { version = "0.0.0", path = "../../../oxidized" } parser_core_types = { version = "0.0.0", path = "../core_types" } rust_parser_errors = { version = "0.0.0", path = "../errors" }
TOML
hhvm/hphp/hack/src/parser/cargo/rust_parser_ffi/Cargo.toml
# @generated by autocargo [package] name = "rust_parser_ffi" version = "0.0.0" edition = "2021" [lib] path = "../../rust_parser_ffi.rs" test = false doctest = false crate-type = ["lib", "staticlib"] [dependencies] bumpalo = { version = "3.11.1", features = ["collections"] } mode_parser = { version = "0.0.0", path = "../mode_parser" } ocamlrep = { version = "0.1.0", git = "https://github.com/facebook/ocamlrep/", branch = "main" } ocamlrep_ocamlpool = { version = "0.1.0", git = "https://github.com/facebook/ocamlrep/", branch = "main" } operator = { version = "0.0.0", path = "../operator" } oxidized = { version = "0.0.0", path = "../../../oxidized" } parser_core_types = { version = "0.0.0", path = "../core_types" } positioned_by_ref_parser = { version = "0.0.0", path = "../../api/cargo/positioned_by_ref_parser" } to_ocaml_impl = { version = "0.0.0", path = "../to_ocaml_impl" }
TOML
hhvm/hphp/hack/src/parser/cargo/smart_constructors/Cargo.toml
# @generated by autocargo [package] name = "smart_constructors" version = "0.0.0" edition = "2021" [lib] path = "../../smart_constructors.rs" [dependencies] ocamlrep = { version = "0.1.0", git = "https://github.com/facebook/ocamlrep/", branch = "main" } parser_core_types = { version = "0.0.0", path = "../core_types" }
TOML
hhvm/hphp/hack/src/parser/cargo/syntax_smart_constructors/Cargo.toml
# @generated by autocargo [package] name = "syntax_smart_constructors" version = "0.0.0" edition = "2021" [lib] path = "../../syntax_smart_constructors.rs" test = false doctest = false [dependencies] parser_core_types = { version = "0.0.0", path = "../core_types" } smart_constructors = { version = "0.0.0", path = "../smart_constructors" }
TOML
hhvm/hphp/hack/src/parser/cargo/to_ocaml_impl/Cargo.toml
# @generated by autocargo [package] name = "to_ocaml_impl" version = "0.0.0" edition = "2021" [lib] path = "../../to_ocaml_impl.rs" test = false doctest = false [dependencies] ocamlrep = { version = "0.1.0", git = "https://github.com/facebook/ocamlrep/", branch = "main" } parser_core_types = { version = "0.0.0", path = "../core_types" } stack_limit = { version = "0.0.0", path = "../../../utils/stack_limit" }
TOML
hhvm/hphp/hack/src/parser/core/Cargo.toml
# @generated by autocargo [package] name = "parser" version = "0.0.0" edition = "2021" [lib] path = "lib.rs" [dependencies] heapless = "0.7.15" operator = { version = "0.0.0", path = "../cargo/operator" } parser_core_types = { version = "0.0.0", path = "../cargo/core_types" } smart_constructors = { version = "0.0.0", path = "../cargo/smart_constructors" } stack_limit = { version = "0.0.0", path = "../../utils/stack_limit" } static_assertions = "1.1.0"
Rust
hhvm/hphp/hack/src/parser/core/declaration_parser.rs
// Copyright (c) 2019, Facebook, Inc. // All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use parser_core_types::lexable_token::LexableToken; use parser_core_types::syntax_error::SyntaxError; use parser_core_types::syntax_error::{self as Errors}; use parser_core_types::token_kind::TokenKind; use parser_core_types::trivia_kind::TriviaKind; use crate::expression_parser::ExpressionParser; use crate::lexer::Lexer; use crate::parser_env::ParserEnv; use crate::parser_trait::Context; use crate::parser_trait::ExpectedTokens; use crate::parser_trait::ParserTrait; use crate::parser_trait::SeparatedListKind; use crate::smart_constructors::NodeType; use crate::smart_constructors::SmartConstructors; use crate::smart_constructors::Token; use crate::statement_parser::StatementParser; use crate::type_parser::TypeParser; #[derive(Clone)] pub struct DeclarationParser<'a, S> where S: SmartConstructors, S::Output: NodeType, { lexer: Lexer<'a, S::Factory>, env: ParserEnv, context: Context<Token<S>>, errors: Vec<SyntaxError>, sc: S, } impl<'a, S> ParserTrait<'a, S> for DeclarationParser<'a, S> where S: SmartConstructors, S::Output: NodeType, { fn make( lexer: Lexer<'a, S::Factory>, env: ParserEnv, context: Context<Token<S>>, errors: Vec<SyntaxError>, sc: S, ) -> Self { Self { lexer, env, context, errors, sc, } } fn into_parts( self, ) -> ( Lexer<'a, S::Factory>, Context<Token<S>>, Vec<SyntaxError>, S, ) { (self.lexer, self.context, self.errors, self.sc) } fn lexer(&self) -> &Lexer<'a, S::Factory> { &self.lexer } fn lexer_mut(&mut self) -> &mut Lexer<'a, S::Factory> { &mut self.lexer } fn continue_from<P: ParserTrait<'a, S>>(&mut self, other: P) { let (lexer, context, errors, sc) = other.into_parts(); self.lexer = lexer; self.context = context; self.errors = errors; self.sc = sc; } fn add_error(&mut self, error: SyntaxError) { self.errors.push(error) } fn env(&self) -> &ParserEnv { &self.env } fn sc_mut(&mut self) -> &mut S { &mut self.sc } fn drain_skipped_tokens(&mut self) -> std::vec::Drain<'_, Token<S>> { self.context.skipped_tokens.drain(..) } fn skipped_tokens(&self) -> &[Token<S>] { &self.context.skipped_tokens } fn context_mut(&mut self) -> &mut Context<Token<S>> { &mut self.context } fn context(&self) -> &Context<Token<S>> { &self.context } } impl<'a, S> DeclarationParser<'a, S> where S: SmartConstructors, S::Output: NodeType, { fn with_type_parser<F, U>(&mut self, f: F) -> U where F: Fn(&mut TypeParser<'a, S>) -> U, { let mut type_parser: TypeParser<'_, S> = TypeParser::make( self.lexer.clone(), self.env.clone(), self.context.clone(), self.errors.clone(), self.sc.clone(), ); let res = f(&mut type_parser); self.continue_from(type_parser); res } fn parse_type_specifier(&mut self, allow_var: bool, allow_attr: bool) -> S::Output { self.with_type_parser(|p: &mut TypeParser<'a, S>| { p.parse_type_specifier(allow_var, allow_attr) }) } fn with_statement_parser<F, U>(&mut self, f: F) -> U where F: Fn(&mut StatementParser<'a, S>) -> U, { let mut statement_parser: StatementParser<'_, S> = StatementParser::make( self.lexer.clone(), self.env.clone(), self.context.clone(), self.errors.clone(), self.sc.clone(), ); let res = f(&mut statement_parser); self.continue_from(statement_parser); res } fn parse_simple_type_or_type_constant(&mut self) -> S::Output { self.with_type_parser(|x: &mut TypeParser<'a, S>| x.parse_simple_type_or_type_constant()) } fn parse_simple_type_or_generic(&mut self) -> S::Output { self.with_type_parser(|p: &mut TypeParser<'a, S>| p.parse_simple_type_or_generic()) } fn with_expression_parser<F, U>(&mut self, f: F) -> U where F: Fn(&mut ExpressionParser<'a, S>) -> U, { let mut expression_parser: ExpressionParser<'_, S> = ExpressionParser::make( self.lexer.clone(), self.env.clone(), self.context.clone(), self.errors.clone(), self.sc.clone(), ); let res = f(&mut expression_parser); self.continue_from(expression_parser); res } fn parse_expression(&mut self) -> S::Output { self.with_expression_parser(|p: &mut ExpressionParser<'a, S>| p.parse_expression()) } fn parse_compound_statement(&mut self) -> S::Output { self.with_statement_parser(|p: &mut StatementParser<'a, S>| p.parse_compound_statement()) } // SPEC: // enum-use: // use enum-name-list ; // // enum-name-list: // name // enum-name-list , name fn parse_enum_use(&mut self) -> Option<S::Output> { match self.peek_token_kind_with_lookahead(1) { TokenKind::Equal => None, _ => match self.peek_token_kind() { TokenKind::Use => { let use_token = self.assert_token(TokenKind::Use); let enum_name_list = self.parse_special_type_list(); let semi = self.require_semicolon(); Some(self.sc_mut().make_enum_use(use_token, enum_name_list, semi)) } _ => None, }, } } fn parse_enum_use_list_opt(&mut self) -> S::Output { self.parse_list_until_none(|x: &mut Self| x.parse_enum_use()) } fn parse_enumerator_list_opt(&mut self) -> S::Output { // SPEC // enumerator-list: // enumerator // enumerator-list enumerator // self.parse_terminated_list(|x: &mut Self| x.parse_enumerator(), TokenKind::RightBrace) } fn parse_enum_class_element(&mut self) -> S::Output { // We need to identify an element of an enum class. Possibilities // are: // // // type-constant-declaration: // const type name = type-specifier ; // abstract const type name ; // // // enum-class-enumerator: // type-specifier name = expression ; // abstract type-specifier name ; let attr = self.parse_attribute_specification_opt(); let kind0 = self.peek_token_kind_with_lookahead(0); let kind1 = self.peek_token_kind_with_lookahead(1); let kind2 = self.peek_token_kind_with_lookahead(2); match (kind0, kind1, kind2) { (TokenKind::Abstract, TokenKind::Const, TokenKind::Type) | (TokenKind::Const, TokenKind::Type, _) => { let modifiers = self.parse_modifiers(); let const_ = self.assert_token(TokenKind::Const); self.parse_type_const_declaration(attr, modifiers, const_) } _ => { if !attr.is_missing() { self.with_error(Errors::no_attributes_on_enum_class_enumerator) } self.parse_enum_class_enumerator() } } } fn parse_enum_class_element_list_opt(&mut self) -> S::Output { self.parse_terminated_list( |x: &mut Self| x.parse_enum_class_element(), TokenKind::RightBrace, ) } fn parse_enum_declaration(&mut self, attrs: S::Output, modifiers: S::Output) -> S::Output { // enum-declaration: // 'enum' name ':' type type-constraint-opt '{' enum-use-clause-list-opt; enumerator-list-opt '}' let enum_ = self.assert_token(TokenKind::Enum); let name = self.require_name(); let token_kind = self.peek_token_kind(); let (colon, base) = if token_kind == TokenKind::LeftBrace { // enum Foo {} // The user has forgotten the base type. Mark it as missing and keep parsing. let pos = self.pos(); let missing1 = self.sc_mut().make_missing(pos); let missing2 = self.sc_mut().make_missing(pos); (missing1, missing2) } else { // enum Foo: Bar {} // The syntax is correct. let colon = self.require_colon(); let base = self.parse_type_specifier(false /* allow_var */, true /* allow_attr */); (colon, base) }; let enum_type = self.parse_type_constraint_opt(false); let left_brace = self.require_left_brace(); let use_clauses = self.parse_enum_use_list_opt(); let enumerators = self.parse_enumerator_list_opt(); let right_brace = self.require_right_brace(); self.sc_mut().make_enum_declaration( attrs, modifiers, enum_, name, colon, base, enum_type, left_brace, use_clauses, enumerators, right_brace, ) } fn parse_enum_class_declaration( &mut self, attrs: S::Output, modifiers: S::Output, ) -> S::Output { // enum-class-declaration: // attribute-specification-opt modifiers-opt enum class name : base { enum-class-enumerator-list-opt } let enum_kw = self.assert_token(TokenKind::Enum); let class_kw = self.assert_token(TokenKind::Class); let name = self.require_name(); let colon = self.require_colon(); let base = self.parse_type_specifier(false /* allow_var */, false /* allow_attr */); let (classish_extends, classish_extends_list) = self.parse_extends_opt(); let left_brace = self.require_left_brace(); let elements = self.parse_enum_class_element_list_opt(); let right_brace = self.require_right_brace(); self.sc_mut().make_enum_class_declaration( attrs, modifiers, enum_kw, class_kw, name, colon, base, classish_extends, classish_extends_list, left_brace, elements, right_brace, ) } fn parse_enum_or_enum_class_declaration( &mut self, attrs: S::Output, modifiers: S::Output, ) -> S::Output { match self.peek_token_kind_with_lookahead(1) { TokenKind::Class => self.parse_enum_class_declaration(attrs, modifiers), _ => self.parse_enum_declaration(attrs, modifiers), } } pub fn parse_leading_markup_section(&mut self) -> Option<S::Output> { let mut parser1 = self.clone(); let (markup_section, has_suffix) = parser1.with_statement_parser(|p: &mut StatementParser<'a, S>| p.parse_header()); // proceed successfully if we've consumed <?..., or dont need it // We purposefully ignore leading trivia before the <?hh, and handle // the error on a later pass let file_path = self.lexer().source().file_path(); if has_suffix { self.continue_from(parser1); Some(markup_section) } else if self.lexer().source().length() > 0 { if file_path.has_extension("php") { self.with_error(Errors::error1001); None } else if !markup_section.is_missing() { // Anything without a `.php` or `.hackpartial` extension // should be treated like a `.hack` file (strict), which // can include a shebang (hashbang). // // parse the shebang correctly and continue // // Executables do not require an extension. self.continue_from(parser1); Some(markup_section) } else { None } } else { None } } fn parse_namespace_body(&mut self) -> S::Output { match self.peek_token_kind() { TokenKind::Semicolon => { let token = self.fetch_token(); self.sc_mut().make_namespace_empty_body(token) } TokenKind::LeftBrace => { let left = self.fetch_token(); let body = self.parse_terminated_list( |x: &mut Self| x.parse_declaration(), TokenKind::RightBrace, ); let right = self.require_right_brace(); self.sc_mut().make_namespace_body(left, body, right) } _ => { // ERROR RECOVERY: return an inert namespace (one with all of its // components 'missing'), and recover--without advancing the parser-- // back to the level that the namespace was declared in. self.with_error(Errors::error1038); let pos = self.pos(); let missing1 = self.sc_mut().make_missing(pos); let pos = self.pos(); let missing2 = self.sc_mut().make_missing(pos); let pos = self.pos(); let missing3 = self.sc_mut().make_missing(pos); self.sc_mut() .make_namespace_body(missing1, missing2, missing3) } } } fn is_group_use(&self) -> bool { let mut parser = self.clone(); // We want a heuristic to determine whether to parse the use clause as // a group use or normal use clause. We distinguish the two by (1) whether // there is a namespace prefix -- in this case it is definitely a group use // clause -- or, if there is a name followed by a curly. That's illegal, but // we should give an informative error message about that. parser.assert_token(TokenKind::Use); parser.parse_namespace_use_kind_opt(); let token = parser.next_token(); match token.kind() { TokenKind::Backslash => { let pos = parser.pos(); let missing = parser.sc_mut().make_missing(pos); let backslash = parser.sc_mut().make_token(token); let (_name, is_backslash) = parser.scan_qualified_name_extended(missing, backslash); is_backslash || parser.peek_token_kind() == TokenKind::LeftBrace } TokenKind::Name => { let token = parser.sc_mut().make_token(token); let token_ref = &token as *const _; let (name, is_backslash) = parser.scan_remaining_qualified_name_extended(token); // Here we rely on the implementation details of // scan_remaining_qualified_name_extended. It's returning // *exactly* token if there is nothing except it in the name. is_backslash && (&name as *const _ == token_ref) || parser.peek_token_kind() == TokenKind::LeftBrace } _ => false, } } fn parse_namespace_use_kind_opt(&mut self) -> S::Output { // SPEC // namespace-use-kind: // namespace // function // const let mut parser1 = self.clone(); let token = parser1.next_token(); match token.kind() { TokenKind::Type | TokenKind::Namespace | TokenKind::Function | TokenKind::Const => { self.continue_from(parser1); self.sc_mut().make_token(token) } _ => { let pos = self.pos(); self.sc_mut().make_missing(pos) } } } fn parse_group_use(&mut self) -> S::Output { // See below for grammar. let use_token = self.assert_token(TokenKind::Use); let use_kind = self.parse_namespace_use_kind_opt(); // We already know that this is a name, qualified name, or prefix. // If this is not a prefix, it will be detected as an error in a later pass let prefix = self.scan_name_or_qualified_name(); let (left, clauses, right) = self.parse_braced_comma_list_opt_allow_trailing(|x: &mut Self| { x.parse_namespace_use_clause() }); let semi = self.require_semicolon(); self.sc_mut().make_namespace_group_use_declaration( use_token, use_kind, prefix, left, clauses, right, semi, ) } fn parse_namespace_use_clause(&mut self) -> S::Output { // SPEC // namespace-use-clause: // qualified-name namespace-aliasing-clauseopt // namespace-use-kind-clause: // namespace-use-kind-opt qualified-name namespace-aliasing-clauseopt // namespace-aliasing-clause: // as name // let use_kind = self.parse_namespace_use_kind_opt(); let name = self.require_qualified_name(); let (as_token, alias) = if self.peek_token_kind() == TokenKind::As { let as_token = self.next_token(); let as_token = self.sc_mut().make_token(as_token); let alias = self.require_xhp_class_name_or_name(); (as_token, alias) } else { let pos = self.pos(); let missing1 = self.sc_mut().make_missing(pos); let pos = self.pos(); let missing2 = self.sc_mut().make_missing(pos); (missing1, missing2) }; self.sc_mut() .make_namespace_use_clause(use_kind, name, as_token, alias) } fn parse_namespace_use_declaration(&mut self) -> S::Output { // SPEC // namespace-use-declaration: // use namespace-use-kind-opt namespace-use-clauses ; // use namespace-use-kind namespace-name-as-a-prefix // { namespace-use-clauses } ; // use namespace-name-as-a-prefix { namespace-use-kind-clauses } ; // // TODO: Add the grammar for the namespace-use-clauses; ensure that it // indicates that trailing commas are allowed in the list. // // ERROR RECOVERY // In the "simple" format, the kind may only be specified up front. // // The grammar in the specification says that in the "group" // format, if the kind is specified up front then it may not // be specified in each clause. However, HHVM's parser disallows // the kind in each clause regardless of whether it is specified up front. // We will fix the specification to match HHVM. // // The grammar in the specification also says that in the "simple" format, // the kind may only be specified up front. But HHVM allows the kind to // be specified in each clause. Again, we will fix the specification to match // HHVM. // // TODO: Update the grammar comment above when the specification is fixed. // (This work is being tracked by spec work items 102, 103 and 104.) // // We do not enforce these rules here. Rather, we allow the kind to be anywhere, // and detect the errors in a later pass. if self.is_group_use() { self.parse_group_use() } else { let use_token = self.assert_token(TokenKind::Use); let use_kind = self.parse_namespace_use_kind_opt(); let (clauses, _) = self.parse_comma_list_allow_trailing( TokenKind::Semicolon, Errors::error1004, |x: &mut Self| x.parse_namespace_use_clause(), ); let semi = self.require_semicolon(); self.sc_mut() .make_namespace_use_declaration(use_token, use_kind, clauses, semi) } } fn parse_namespace_declaration(&mut self) -> S::Output { // SPEC // namespace-definition: // namespace namespace-name ; // namespace namespace-name-opt { declaration-list } // // TODO: An error case not caught by the parser that should be caught // in a later pass: // Qualified names are a superset of legal namespace names. let namespace_token = self.assert_token(TokenKind::Namespace); let name = match self.peek_token_kind() { TokenKind::Name => { let token = self.next_token(); let token = self.sc_mut().make_token(token); self.scan_remaining_qualified_name(token) } TokenKind::LeftBrace => { let pos = self.pos(); self.sc_mut().make_missing(pos) } TokenKind::Semicolon => { // ERROR RECOVERY Plainly the name is missing. self.with_error(Errors::error1004); let pos = self.pos(); self.sc_mut().make_missing(pos) } _ => // TODO: Death to PHPisms; keywords as namespace names { self.require_name_allow_non_reserved() } }; let header = self .sc_mut() .make_namespace_declaration_header(namespace_token, name); let body = self.parse_namespace_body(); self.sc_mut().make_namespace_declaration(header, body) } pub fn parse_classish_declaration(&mut self, attribute_spec: S::Output) -> S::Output { let modifiers = self.parse_classish_modifiers(); if self.peek_token_kind() == TokenKind::Enum { return self.parse_enum_or_enum_class_declaration(attribute_spec, modifiers); } let (xhp, is_xhp_class) = self.parse_xhp_keyword(); // Error on the XHP token unless it's been explicitly enabled if is_xhp_class && !self.env.enable_xhp_class_modifier { self.with_error(Errors::error1057("XHP")); } let token = self.parse_classish_token(); let name = if is_xhp_class { self.require_xhp_class_name() } else { self.require_maybe_xhp_class_name() }; let generic_type_parameter_list = self.with_type_parser(|p: &mut TypeParser<'a, S>| { p.parse_generic_type_parameter_list_opt() }); let (classish_extends, classish_extends_list) = self.parse_extends_opt(); let (classish_implements, classish_implements_list) = self.parse_classish_implements_opt(); let classish_where_clause = self.parse_classish_where_clause_opt(); let body = self.parse_classish_body(); self.sc_mut().make_classish_declaration( attribute_spec, modifiers, xhp, token, name, generic_type_parameter_list, classish_extends, classish_extends_list, classish_implements, classish_implements_list, classish_where_clause, body, ) } fn parse_classish_where_clause_opt(&mut self) -> S::Output { if self.peek_token_kind() == TokenKind::Where { self.parse_where_clause() } else { let pos = self.pos(); self.sc_mut().make_missing(pos) } } fn parse_classish_implements_opt(&mut self) -> (S::Output, S::Output) { if self.peek_token_kind() != TokenKind::Implements { let pos = self.pos(); let missing1 = self.sc_mut().make_missing(pos); let pos = self.pos(); let missing2 = self.sc_mut().make_missing(pos); (missing1, missing2) } else { let implements_token = self.next_token(); let implements_token = self.sc_mut().make_token(implements_token); let implements_list = self.parse_special_type_list(); (implements_token, implements_list) } } fn parse_xhp_keyword(&mut self) -> (S::Output, bool) { let xhp = self.optional_token(TokenKind::XHP); let is_missing = xhp.is_missing(); (xhp, !is_missing) } fn parse_classish_modifiers(&mut self) -> S::Output { let mut acc = vec![]; loop { match self.peek_token_kind() { TokenKind::Abstract | TokenKind::Final | TokenKind::Internal | TokenKind::Public => { // TODO(T25649779) let token = self.next_token(); let token = self.sc_mut().make_token(token); acc.push(token); } _ => { let pos = self.pos(); return self.sc_mut().make_list(acc, pos); } } } } fn parse_classish_token(&mut self) -> S::Output { let spellcheck_tokens = vec![TokenKind::Class, TokenKind::Trait, TokenKind::Interface]; let token_str = &self.current_token_text(); let token_kind = self.peek_token_kind(); match token_kind { TokenKind::Class | TokenKind::Trait | TokenKind::Interface => { let token = self.next_token(); self.sc_mut().make_token(token) } // Spellcheck case TokenKind::Name if Self::is_misspelled_from(&spellcheck_tokens, token_str) => { // Default won't be used, since we already checked is_misspelled_from let suggested_kind = Self::suggested_kind_from(&spellcheck_tokens, token_str) .unwrap_or(TokenKind::Name); self.skip_and_log_misspelled_token(suggested_kind); let pos = self.pos(); self.sc_mut().make_missing(pos) } _ => { self.with_error(Errors::error1035); let pos = self.pos(); self.sc_mut().make_missing(pos) } } } fn parse_special_type(&mut self) -> (S::Output, bool) { let mut parser1 = self.clone(); let token = parser1.next_xhp_class_name_or_other_token(); match token.kind() { TokenKind::Comma => { // ERROR RECOVERY. We expected a type but we got a comma. // Give the error that we expected a type, not a name, even though // not every type is legal here. self.continue_from(parser1); self.with_error(Errors::error1007); let comma = self.sc_mut().make_token(token); let pos = self.pos(); let missing = self.sc_mut().make_missing(pos); let list_item = self.sc_mut().make_list_item(missing, comma); (list_item, false) } TokenKind::Backslash | TokenKind::Namespace | TokenKind::Name | TokenKind::XHPClassName => { let item = self .parse_type_specifier(false /* allow_var */, true /* allow_attr */); let comma = self.optional_token(TokenKind::Comma); let is_missing = comma.is_missing(); let list_item = self.sc_mut().make_list_item(item, comma); (list_item, is_missing) } TokenKind::Enum | TokenKind::Shape if self.env.hhvm_compat_mode => { // HHVM allows these keywords here for some reason let item = self.parse_simple_type_or_type_constant(); let comma = self.optional_token(TokenKind::Comma); let is_missing = comma.is_missing(); let list_item = self.sc_mut().make_list_item(item, comma); (list_item, is_missing) } _ => { // ERROR RECOVERY: We are expecting a type; give an error as above. // Don't eat the offending token. self.with_error(Errors::error1007); let pos = self.pos(); let missing1 = self.sc_mut().make_missing(pos); let pos = self.pos(); let missing2 = self.sc_mut().make_missing(pos); let list_item = self.sc_mut().make_list_item(missing1, missing2); (list_item, true) } } } fn parse_special_type_list(&mut self) -> S::Output { // An extends / implements / enum_use list is a comma-separated list of types, // but very special types; we want the types to consist of a name and an // optional generic type argument list. // // TODO: Can the type name be of the form "foo::bar"? Those do not // necessarily start with names. Investigate this. // // Normally we'd use one of the separated list helpers, but there is no // specific end token we could use to detect the end of the list, and we // want to bail out if we get something that is not a type of the right form. // So we have custom logic here. // // TODO: This is one of the rare cases in Hack where a comma-separated list // may not have a trailing comma. Is that desirable, or was that an // oversight when the trailing comma rules were added? If possible we // should keep the rule as-is, and disallow the trailing comma; it makes // parsing and error recovery easier. let mut items = vec![]; loop { let (item, is_missing) = self.parse_special_type(); items.push(item); if is_missing { break; } } let pos = self.pos(); self.sc_mut().make_list(items, pos) } fn parse_extends_opt(&mut self) -> (S::Output, S::Output) { let token_kind = self.peek_token_kind(); if token_kind != TokenKind::Extends { let pos = self.pos(); let missing1 = self.sc_mut().make_missing(pos); let pos = self.pos(); let missing2 = self.sc_mut().make_missing(pos); (missing1, missing2) } else { let token = self.next_token(); let extends_token = self.sc_mut().make_token(token); let extends_list = self.parse_special_type_list(); (extends_token, extends_list) } } fn parse_classish_body(&mut self) -> S::Output { let left_brace_token = self.require_left_brace(); let classish_element_list = self.parse_classish_element_list_opt(); let right_brace_token = self.require_right_brace(); self.sc_mut() .make_classish_body(left_brace_token, classish_element_list, right_brace_token) } fn parse_classish_element_list_opt(&mut self) -> S::Output { // TODO: ERROR RECOVERY: consider bailing if the token cannot possibly // start a classish element. // ERROR RECOVERY: we're in the body of a classish, so we add visibility // modifiers to our context. self.expect_in_new_scope(ExpectedTokens::Visibility); let element_list = self.parse_terminated_list( |x: &mut Self| x.parse_classish_element(), TokenKind::RightBrace, ); self.pop_scope(ExpectedTokens::Visibility); element_list } fn parse_xhp_children_paren(&mut self) -> S::Output { // SPEC (Draft) // ( xhp-children-expressions ) // // xhp-children-expressions: // xhp-children-expression // xhp-children-expressions , xhp-children-expression // // TODO: The parenthesized list of children expressions is NOT allowed // to be comma-terminated. Is this intentional? It is inconsistent with // practice throughout the rest of Hack. There is no syntactic difficulty // in allowing a comma before the close paren. Consider allowing it. let (left, exprs, right) = self.parse_parenthesized_comma_list(|x: &mut Self| x.parse_xhp_children_expression()); self.sc_mut() .make_xhp_children_parenthesized_list(left, exprs, right) } fn parse_xhp_children_term(&mut self) -> S::Output { // SPEC (Draft) // xhp-children-term: // ( xhp-children-expressions ) trailing-opt // name trailing-opt // xhp-class-name trailing-opt // xhp-category-name trailing-opt // trailing: * ? + // // name should be 'pcdata', 'any', or 'empty', however any name is // currently permitted // // Note that there may be only zero or one trailing unary operator. // "foo*?" is not a legal xhp child expression. // let mut parser1 = self.clone(); let token = parser1.next_xhp_children_name_or_other(); let kind = token.kind(); let name = parser1.sc_mut().make_token(token); match kind { TokenKind::Name => { self.continue_from(parser1); self.parse_xhp_children_trailing(name) } TokenKind::XHPClassName | TokenKind::XHPCategoryName => { self.continue_from(parser1); self.parse_xhp_children_trailing(name) } TokenKind::LeftParen => { let term = self.parse_xhp_children_paren(); self.parse_xhp_children_trailing(term) } _ => { // ERROR RECOVERY: Eat the offending token, keep going. self.with_error(Errors::error1053); name } } } fn parse_xhp_children_trailing(&mut self, term: S::Output) -> S::Output { let token_kind = self.peek_token_kind(); match token_kind { TokenKind::Star | TokenKind::Plus | TokenKind::Question => { let token = self.next_token(); let token = self.sc_mut().make_token(token); self.sc_mut().make_postfix_unary_expression(term, token) } _ => term, } } fn parse_xhp_children_bar(&mut self, left: S::Output) -> S::Output { let token_kind = self.peek_token_kind(); match token_kind { TokenKind::Bar => { let token = self.next_token(); let token = self.sc_mut().make_token(token); let right = self.parse_xhp_children_term(); let result = self.sc_mut().make_binary_expression(left, token, right); self.parse_xhp_children_bar(result) } _ => left, } } fn parse_xhp_children_expression(&mut self) -> S::Output { // SPEC (Draft) // xhp-children-expression: // xhp-children-term // xhp-children-expression | xhp-children-term // // Note that the bar operator is left-associative. (Not that it matters // semantically. let term = self.parse_xhp_children_term(); self.parse_xhp_children_bar(term) } fn parse_xhp_children_declaration(&mut self) -> S::Output { // SPEC (Draft) // xhp-children-declaration: // children empty ; // children xhp-children-expression ; let children = self.assert_token(TokenKind::Children); if self.env.disable_xhp_children_declarations { self.with_error(Errors::error1064); } let token_kind = self.peek_token_kind(); let expr = match token_kind { TokenKind::Empty => { let token = self.next_token(); self.sc_mut().make_token(token) } _ => self.parse_xhp_children_expression(), }; let semi = self.require_semicolon(); self.sc_mut() .make_xhp_children_declaration(children, expr, semi) } fn parse_xhp_category(&mut self) -> S::Output { let token = self.next_xhp_category_name(); let token_kind = token.kind(); let category = self.sc_mut().make_token(token); match token_kind { TokenKind::XHPCategoryName => category, _ => { self.with_error(Errors::error1052); category } } } fn parse_xhp_attribute_enum(&mut self) -> S::Output { let like_token = if self.peek_token_kind() == TokenKind::Tilde { self.assert_token(TokenKind::Tilde) } else { let pos = self.pos(); self.sc_mut().make_missing(pos) }; let enum_token = self.assert_token(TokenKind::Enum); let (left_brace, values, right_brace) = self.parse_braced_comma_list_opt_allow_trailing(|x: &mut Self| x.parse_expression()); self.sc_mut() .make_xhp_enum_type(like_token, enum_token, left_brace, values, right_brace) } fn parse_xhp_type_specifier(&mut self) -> S::Output { // SPEC (Draft) // xhp-type-specifier: // (enum | ~enum) { xhp-attribute-enum-list ,-opt } // type-specifier // // The list of enum values must have at least one value and can be // comma-terminated. // // xhp-enum-list: // xhp-attribute-enum-value // xhp-enum-list , xhp-attribute-enum-value // // xhp-attribute-enum-value: // any integer literal // any single-quoted-string literal // any double-quoted-string literal // // TODO: What are the semantics of encapsulated expressions in double-quoted // string literals here? // // An empty list is illegal, but we allow it here and give an error in // a later pass. match self.peek_token_kind() { TokenKind::Tilde if self.peek_token_kind_with_lookahead(1) == TokenKind::Enum => { self.parse_xhp_attribute_enum() } TokenKind::Enum => self.parse_xhp_attribute_enum(), _ => self.parse_type_specifier(true, true), } } fn parse_xhp_required_opt(&mut self) -> S::Output { // SPEC (Draft) // xhp-required : // @ (required | lateinit) // // Note that these are two tokens. They can have whitespace between them. if self.peek_token_kind() == TokenKind::At { let at = self.assert_token(TokenKind::At); let req_kind = self.next_token(); let kind = req_kind.kind(); let req = self.sc_mut().make_token(req_kind); match kind { TokenKind::Required => self.sc_mut().make_xhp_required(at, req), TokenKind::Lateinit => self.sc_mut().make_xhp_lateinit(at, req), _ => { self.with_error(Errors::error1051); let pos = self.pos(); self.sc_mut().make_missing(pos) } } } else { let pos = self.pos(); self.sc_mut().make_missing(pos) } } fn parse_xhp_class_attribute_typed(&mut self) -> S::Output { // xhp-type-specifier xhp-name initializer-opt xhp-required-opt let ty = self.parse_xhp_type_specifier(); let name = self.require_xhp_name(); let init = self.parse_simple_initializer_opt(); let req = self.parse_xhp_required_opt(); self.sc_mut().make_xhp_class_attribute(ty, name, init, req) } fn parse_xhp_category_declaration(&mut self) -> S::Output { // SPEC (Draft) // xhp-category-declaration: // category xhp-category-list ,-opt ; // // xhp-category-list: // xhp-category-name // xhp-category-list , xhp-category-name let category = self.assert_token(TokenKind::Category); let (items, _) = self.parse_comma_list_allow_trailing( TokenKind::Semicolon, Errors::error1052, |x: &mut Self| x.parse_xhp_category(), ); let semi = self.require_semicolon(); self.sc_mut() .make_xhp_category_declaration(category, items, semi) } fn parse_xhp_class_attribute(&mut self) -> S::Output { // SPEC (Draft) // xhp-attribute-declaration: // xhp-class-name // xhp-type-specifier xhp-name initializer-opt xhp-required-opt // // ERROR RECOVERY: // The xhp type specifier could be an xhp class name. To disambiguate we peek // ahead a token; if it's a comma or semi, we're done. If not, then we assume // that we are in the more complex case. if self.is_next_xhp_class_name() { let mut parser1 = self.clone(); let class_name = parser1.require_maybe_xhp_class_name(); match parser1.peek_token_kind() { TokenKind::Comma | TokenKind::Semicolon => { self.continue_from(parser1); let type_specifier = self.sc_mut().make_simple_type_specifier(class_name); self.sc_mut() .make_xhp_simple_class_attribute(type_specifier) } _ => self.parse_xhp_class_attribute_typed(), } } else { self.parse_xhp_class_attribute_typed() } } fn parse_xhp_class_attribute_declaration(&mut self) -> S::Output { // SPEC: (Draft) // xhp-class-attribute-declaration : // attribute xhp-attribute-declaration-list ; // // xhp-attribute-declaration-list: // xhp-attribute-declaration // xhp-attribute-declaration-list , xhp-attribute-declaration // // TODO: The list of attributes may NOT be terminated with a trailing comma // before the semicolon. This is inconsistent with the rest of Hack. // Allowing a comma before the semi does not introduce any syntactic // difficulty; consider allowing it. let attr_token = self.assert_token(TokenKind::Attribute); // TODO: Better error message. let attrs = self.parse_comma_list(TokenKind::Semicolon, Errors::error1004, |x: &mut Self| { x.parse_xhp_class_attribute() }); let semi = self.require_semicolon(); self.sc_mut() .make_xhp_class_attribute_declaration(attr_token, attrs, semi) } fn parse_qualified_name_type(&mut self) -> S::Output { // Here we're parsing a name followed by an optional generic type // argument list; if we don't have a name, give an error. match self.peek_token_kind() { TokenKind::Backslash | TokenKind::Name => self.parse_simple_type_or_generic(), _ => self.require_qualified_name(), } } fn parse_require_clause(&mut self) -> S::Output { // SPEC // require-extends-clause: // require extends qualified-name ; // // require-implements-clause: // require implements qualified-name ; // // require-class-clause: // require class qualified-name ; // // We must also parse "require extends :foo;" // TODO: What about "require extends :foo<int>;" ? // TODO: The spec is incomplete; we need to be able to parse // require extends Foo<int>; // (This work is being tracked by spec issue 105.) // TODO: Check whether we also need to handle // require extends foo::bar // and so on. // // ERROR RECOVERY: Detect if the implements/extends/class, name and semi // are missing. let req = self.assert_token(TokenKind::Require); let token_kind = self.peek_token_kind(); let req_kind = match token_kind { TokenKind::Implements | TokenKind::Extends | TokenKind::Class => { let req_kind_token = self.next_token(); self.sc_mut().make_token(req_kind_token) } _ => { self.with_error(Errors::error1045); let pos = self.pos(); self.sc_mut().make_missing(pos) } }; let name = if self.is_next_xhp_class_name() { self.parse_simple_type_or_generic() } else { self.parse_qualified_name_type() }; let semi = self.require_semicolon(); self.sc_mut().make_require_clause(req, req_kind, name, semi) } fn parse_methodish_or_property(&mut self, attribute_spec: S::Output) -> S::Output { let modifiers = self.parse_modifiers(); // ERROR RECOVERY: match against two tokens, because if one token is // in error but the next isn't, then it's likely that the user is // simply still typing. Throw an error on what's being typed, then eat // it and keep going. let current_token_kind = self.peek_token_kind(); let next_token = self.peek_token_with_lookahead(1); let next_token_kind = next_token.kind(); match (current_token_kind, next_token_kind) { // Detected the usual start to a method, so continue parsing as method. (TokenKind::Async, _) | (TokenKind::Function, _) => { self.parse_methodish(attribute_spec, modifiers) } (TokenKind::LeftParen, _) => self.parse_property_declaration(attribute_spec, modifiers), // We encountered one unexpected token, but the next still indicates that // we should be parsing a methodish. Throw an error, process the token // as an extra, and keep going. (_, TokenKind::Async) | (_, TokenKind::Function) if !(next_token.has_leading_trivia_kind(TriviaKind::EndOfLine)) => { self.with_error_on_whole_token(Errors::error1056( self.token_text(&self.peek_token()), )); self.skip_and_log_unexpected_token(false); self.parse_methodish(attribute_spec, modifiers) } // Otherwise, continue parsing as a property (which might be a lambda). _ => self.parse_property_declaration(attribute_spec, modifiers), } } // SPEC: // trait-use-clause: // use trait-name-list ; // // trait-name-list: // qualified-name generic-type-parameter-listopt // trait-name-list , qualified-name generic-type-parameter-listopt fn parse_trait_name_list<P>(&mut self, predicate: P) -> S::Output where P: Fn(TokenKind) -> bool, { let (items, _, _) = self.parse_separated_list_predicate( |x| x == TokenKind::Comma, SeparatedListKind::NoTrailing, predicate, Errors::error1004, |x: &mut Self| x.parse_qualified_name_type(), ); items } fn parse_trait_use(&mut self) -> S::Output { let use_token = self.assert_token(TokenKind::Use); let trait_name_list = self.parse_trait_name_list(|x| x == TokenKind::Semicolon || x == TokenKind::LeftBrace); let semi = self.require_semicolon(); self.sc_mut() .make_trait_use(use_token, trait_name_list, semi) } fn parse_property_declaration( &mut self, attribute_spec: S::Output, modifiers: S::Output, ) -> S::Output { // SPEC: // property-declaration: // attribute-spec-opt property-modifier type-specifier // property-declarator-list ; // // property-declarator-list: // property-declarator // property-declarator-list , property-declarator // // The type specifier is optional in non-strict mode and required in // strict mode. We give an error in a later pass. let prop_type = match self.peek_token_kind() { TokenKind::Variable => { let pos = self.pos(); self.sc_mut().make_missing(pos) } _ => self.parse_type_specifier(false /* allow_var */, false /* allow_attr */), }; let decls = self.parse_comma_list(TokenKind::Semicolon, Errors::error1008, |x: &mut Self| { x.parse_property_declarator() }); let semi = self.require_semicolon(); self.sc_mut() .make_property_declaration(attribute_spec, modifiers, prop_type, decls, semi) } fn parse_property_declarator(&mut self) -> S::Output { // SPEC: // property-declarator: // variable-name property-initializer-opt // property-initializer: // = expression let name = self.require_variable(); let simple_init = self.parse_simple_initializer_opt(); self.sc_mut().make_property_declarator(name, simple_init) } fn is_type_in_const(&self) -> bool { let mut parser1 = self.clone(); let _ = parser1.parse_type_specifier(false, true); let _ = parser1.require_name_allow_all_keywords(); self.errors.len() == parser1.errors.len() } // SPEC: // const-declaration: // abstract_opt const type-specifier_opt constant-declarator-list ; // visibility const type-specifier_opt constant-declarator-list ; // constant-declarator-list: // constant-declarator // constant-declarator-list , constant-declarator // constant-declarator: // name constant-initializer_opt // constant-initializer: // = const-expression fn parse_const_declaration( &mut self, attributes: S::Output, modifiers: S::Output, const_: S::Output, ) -> S::Output { let type_spec = if self.is_type_in_const() { self.parse_type_specifier(/* allow_var = */ false, /* allow_attr = */ true) } else { let pos = self.pos(); self.sc_mut().make_missing(pos) }; let const_list = self.parse_comma_list(TokenKind::Semicolon, Errors::error1004, |x: &mut Self| { x.parse_constant_declarator() }); let semi = self.require_semicolon(); self.sc_mut() .make_const_declaration(attributes, modifiers, const_, type_spec, const_list, semi) } fn parse_constant_declarator(&mut self) -> S::Output { // TODO: We allow const names to be keywords here; in particular we // require that const string TRUE = "true"; be legal. Likely this // should be more strict. What are the rules for which keywords are // legal constant names and which are not? // Note that if this logic is changed, it should be changed in // is_type_in_const above as well. // // This permits abstract variables to have an initializer, and vice-versa. // This is deliberate, and those errors will be detected after the syntax // tree is created. self.sc_mut().begin_constant_declarator(); let const_name = self.require_name_allow_all_keywords(); let initializer_ = self.parse_simple_initializer_opt(); self.sc_mut() .make_constant_declarator(const_name, initializer_) } // SPEC: // type-constant-declaration: // abstract-type-constant-declaration // concrete-type-constant-declaration // abstract-type-constant-declaration: // abstract const type name type-constraint-list_opt ; // concrete-type-constant-declaration: // const type name type-constraint-list_opt = type-specifier ; // type-constraint-list: // as name // super name // type-constraint-list as name // type-constraint-list super name // // ERROR RECOVERY: // // An abstract type constant may only occur in an interface or an abstract // class. We allow that to be parsed here, and the type checker detects the // error. // CONSIDER: We could detect this error in a post-parse pass; it is entirely // syntactic. Consider moving the error detection out of the type checker. // // An interface may not contain a non-abstract type constant that has a // type constraint. We allow that to be parsed here, and the type checker // detects the error. // CONSIDER: We could detect this error in a post-parse pass; it is entirely // syntactic. Consider moving the error detection out of the type checker. fn parse_type_const_declaration( &mut self, attributes: S::Output, modifiers: S::Output, const_: S::Output, ) -> S::Output { let type_token = self.assert_token(TokenKind::Type); let (name, type_parameters) = self.parse_nonreserved_name_maybe_parameterized(); let type_constraints = self.parse_type_constraints(true); let (equal_token, type_specifier) = self.parse_equal_type(); let semicolon = self.require_semicolon(); self.sc_mut().make_type_const_declaration( attributes, modifiers, const_, type_token, name, type_parameters, type_constraints, equal_token, type_specifier, semicolon, ) } /// Parses a non-reserved name optionally followed by type parameter list fn parse_nonreserved_name_maybe_parameterized(&mut self) -> (S::Output, S::Output) { let name = self.require_name_allow_non_reserved(); let type_parameter_list = self.with_type_parser(|p: &mut TypeParser<'a, S>| { p.parse_generic_type_parameter_list_opt() }); (name, type_parameter_list) } fn parse_equal_type(&mut self) -> (S::Output, S::Output) { if self.peek_token_kind() == TokenKind::Equal { let equal_token = self.assert_token(TokenKind::Equal); let type_spec = self .parse_type_specifier(/* allow_var = */ false, /* allow_attr = */ true); (equal_token, type_spec) } else { let pos = self.pos(); let missing1 = self.sc_mut().make_missing(pos); let pos = self.pos(); let missing2 = self.sc_mut().make_missing(pos); (missing1, missing2) } } fn parse_context_const_declaration( &mut self, modifiers: S::Output, const_: S::Output, ) -> S::Output { // SPEC // context-constant-declaration: // abstract-context-constant-declaration // concrete-context-constant-declaration // abstract-context-constant-declaration: // abstract const ctx name context-constraint* ; // concrete-context-constant-declaration: // const ctx name context-constraint* = context-list ; let ctx_keyword = self.assert_token(TokenKind::Ctx); let name = self.require_name_allow_non_reserved(); let (tparam_list, ctx_constraints) = self.with_type_parser(|p| { ( p.parse_generic_type_parameter_list_opt(), p.parse_list_until_none(|p| p.parse_context_constraint_opt()), ) }); let (equal, ctx_list) = self.parse_equal_contexts(); let semicolon = self.require_semicolon(); self.sc_mut().make_context_const_declaration( modifiers, const_, ctx_keyword, name, tparam_list, ctx_constraints, equal, ctx_list, semicolon, ) } fn parse_equal_contexts(&mut self) -> (S::Output, S::Output) { if self.peek_token_kind() == TokenKind::Equal { let equal = self.assert_token(TokenKind::Equal); let ctx_list = self.with_type_parser(|p| p.parse_contexts()); (equal, ctx_list) } else { let pos = self.pos(); let missing1 = self.sc_mut().make_missing(pos); let pos = self.pos(); let missing2 = self.sc_mut().make_missing(pos); (missing1, missing2) } } pub(crate) fn parse_refinement_member(&mut self) -> S::Output { // SPEC: // type-refinement-member: // type name type-constraints // type name = type-specifier // type name type-constraints // ctx name ctx-constraints // ctx name = context-list // // type-constraints: // type-constraint // type-constraint type-constraints // // ctx-constraints: // context-constraint // context-constraint ctx-constraints match self.peek_token_kind() { TokenKind::Type => { let keyword = self.assert_token(TokenKind::Type); let (name, type_params) = self.parse_nonreserved_name_maybe_parameterized(); let constraints = self.with_type_parser(|p| { p.parse_list_until_none(|p| p.parse_type_constraint_opt(true)) }); let (equal_token, type_specifier) = self.parse_equal_type(); self.sc_mut().make_type_in_refinement( keyword, name, type_params, constraints, equal_token, type_specifier, ) } TokenKind::Ctx => { let keyword = self.assert_token(TokenKind::Ctx); let (name, type_params) = self.parse_nonreserved_name_maybe_parameterized(); let constraints = self.with_type_parser(|p| { p.parse_list_until_none(|p| p.parse_context_constraint_opt()) }); let (equal_token, ctx_list) = self.parse_equal_contexts(); self.sc_mut().make_ctx_in_refinement( keyword, name, type_params, constraints, equal_token, ctx_list, ) } _ => { let pos = self.pos(); self.sc_mut().make_missing(pos) } } } // SPEC: // attribute_specification := // attribute_list // old_attribute_specification // attribute_list := // attribute // attribute_list attribute // attribute := @ attribute_name attribute_value_list_opt // old_attribute_specification := << old_attribute_list >> // old_attribute_list := // old_attribute // old_attribute_list , old_attribute // old_attribute := attribute_name attribute_value_list_opt // attribute_name := name // attribute_value_list := ( attribute_values_opt ) // attribute_values := // attribute_value // attribute_values , attribute_value // attribute_value := expression // // TODO: The list of attrs can have a trailing comma. Update the spec. // TODO: The list of values can have a trailing comma. Update the spec. // (Both these work items are tracked by spec issue 106.) pub fn parse_old_attribute_specification_opt(&mut self) -> S::Output { if self.peek_token_kind() == TokenKind::LessThanLessThan { let (left, items, right) = self.parse_double_angled_comma_list_allow_trailing(|x: &mut Self| { x.parse_old_attribute() }); self.sc_mut() .make_old_attribute_specification(left, items, right) } else { let pos = self.pos(); self.sc_mut().make_missing(pos) } } fn parse_file_attribute_specification_opt(&mut self) -> S::Output { if self.peek_token_kind() == TokenKind::LessThanLessThan { let left = self.assert_token(TokenKind::LessThanLessThan); let keyword = self.assert_token(TokenKind::File); let colon = self.require_colon(); let (items, _) = self.parse_comma_list_allow_trailing( TokenKind::GreaterThanGreaterThan, Errors::expected_user_attribute, |x: &mut Self| x.parse_old_attribute(), ); let right = self.require_token(TokenKind::GreaterThanGreaterThan, Errors::error1029); self.sc_mut() .make_file_attribute_specification(left, keyword, colon, items, right) } else { let pos = self.pos(); self.sc_mut().make_missing(pos) } } fn parse_return_readonly_opt(&mut self) -> S::Output { let token_kind = self.peek_token_kind(); if token_kind == TokenKind::Readonly { let token = self.next_token(); return self.sc_mut().make_token(token); } else { let pos = self.pos(); return self.sc_mut().make_missing(pos); } } fn parse_return_type_hint_opt(&mut self) -> (S::Output, S::Output, S::Output) { let token_kind = self.peek_token_kind(); if token_kind == TokenKind::Colon { let token = self.next_token(); let colon_token = self.sc_mut().make_token(token); let readonly_opt = self.parse_return_readonly_opt(); // if no readonly keyword return type must exist // else return type is optional let return_type = if readonly_opt.is_missing() { self.with_type_parser(|p: &mut TypeParser<'a, S>| p.parse_return_type()) } else { self.with_type_parser(|p: &mut TypeParser<'a, S>| p.parse_return_type_opt()) }; (colon_token, readonly_opt, return_type) } else { let pos = self.pos(); let missing1 = self.sc_mut().make_missing(pos); let pos = self.pos(); let missing2 = self.sc_mut().make_missing(pos); let pos = self.pos(); let missing3 = self.sc_mut().make_missing(pos); (missing1, missing2, missing3) } } pub fn parse_parameter_list_opt(&mut self) -> (S::Output, S::Output, S::Output) { // SPEC // TODO: The specification is wrong in several respects concerning // variadic parameters. Variadic parameters are permitted to have a // type and name but this is not mentioned in the spec. And variadic // parameters are not mentioned at all in the grammar for constructor // parameter lists. (This is tracked by spec issue 107.) // // parameter-list: // variadic-parameter // parameter-declaration-list // parameter-declaration-list , // parameter-declaration-list , variadic-parameter // // parameter-declaration-list: // parameter-declaration // parameter-declaration-list , parameter-declaration // // variadic-parameter: // ... // attribute-specification-opt visiblity-modifier-opt type-specifier \ // ... variable-name // // This function parses the parens as well. // ERROR RECOVERY: We allow variadic parameters in all positions; a later // pass gives an error if a variadic parameter is in an incorrect position // or followed by a trailing comma, or if the parameter has a // default value. self.parse_parenthesized_comma_list_opt_allow_trailing(|x: &mut Self| x.parse_parameter()) } fn parse_parameter(&mut self) -> S::Output { let mut parser1 = self.clone(); let token = parser1.next_token(); match token.kind() { TokenKind::DotDotDot => { let next_kind = parser1.peek_token_kind(); if next_kind == TokenKind::Variable { self.parse_parameter_declaration() } else { let pos = self.pos(); let missing1 = parser1.sc_mut().make_missing(pos); let pos = self.pos(); let missing2 = parser1.sc_mut().make_missing(pos); self.continue_from(parser1); let token = self.sc_mut().make_token(token); self.sc_mut() .make_variadic_parameter(missing1, missing2, token) } } _ => self.parse_parameter_declaration(), } } fn parse_parameter_declaration(&mut self) -> S::Output { // SPEC // // TODO: Add call-convention-opt to the specification. // (This work is tracked by task T22582676.) // // TODO: Update grammar for inout parameters. // (This work is tracked by task T22582715.) // // parameter-declaration: // attribute-specification-opt \ // call-convention-opt \ // mutability-opt \ // type-specifier variable-name \ // default-argument-specifier-opt // // ERROR RECOVERY // In strict mode, we require a type specifier. This error is not caught // at parse time but rather by a later pass. // Visibility modifiers are only legal in constructor parameter // lists; we give an error in a later pass. // Variadic params cannot be declared inout; we permit that here but // give an error in a later pass. // Variadic params and inout params cannot have default values; these // errors are also reported in a later pass. let attrs = self.parse_attribute_specification_opt(); let visibility = self.parse_visibility_modifier_opt(); let callconv = self.parse_call_convention_opt(); let readonly = self.parse_readonly_opt(); let token = self.peek_token(); let type_specifier = match token.kind() { TokenKind::Variable | TokenKind::DotDotDot => { let pos = self.pos(); self.sc_mut().make_missing(pos) } _ => { self.parse_type_specifier(/* allow_var = */ false, /* allow_attr */ false) } }; let name = self.parse_decorated_variable_opt(); let default = self.parse_simple_initializer_opt(); self.sc_mut().make_parameter_declaration( attrs, visibility, callconv, readonly, type_specifier, name, default, ) } fn parse_decorated_variable_opt(&mut self) -> S::Output { match self.peek_token_kind() { TokenKind::DotDotDot => self.parse_decorated_variable(), _ => self.require_variable(), } } // TODO: This is wrong. The variable here is not anexpression* that has // an optional decoration on it. It's a declaration. We shouldn't be using the // same data structure for a decorated expression as a declaration; one // is ause* and the other is a *definition*. fn parse_decorated_variable(&mut self) -> S::Output { // ERROR RECOVERY // Detection of (variadic, byRef) inout params happens in post-parsing. // Although a parameter can have at most one variadic/reference decorator, // we deliberately allow multiple decorators in the initial parse and produce // an error in a later pass. let decorator = self.fetch_token(); let variable = match self.peek_token_kind() { TokenKind::DotDotDot => self.parse_decorated_variable(), _ => self.require_variable(), }; self.sc_mut().make_decorated_expression(decorator, variable) } fn parse_visibility_modifier_opt(&mut self) -> S::Output { let token_kind = self.peek_token_kind(); match token_kind { TokenKind::Public | TokenKind::Protected | TokenKind::Private | TokenKind::Internal => { let token = self.next_token(); self.sc_mut().make_token(token) } _ => { let pos = self.pos(); self.sc_mut().make_missing(pos) } } } // SPEC // // TODO: Add this to the specification. // (This work is tracked by task T22582676.) // // call-convention: // inout fn parse_call_convention_opt(&mut self) -> S::Output { let token_kind = self.peek_token_kind(); match token_kind { TokenKind::Inout => { let token = self.next_token(); self.sc_mut().make_token(token) } _ => { let pos = self.pos(); self.sc_mut().make_missing(pos) } } } // SPEC // // TODO: Add this to the specification. // (This work is tracked by task T22582676.) // // readonly: // readonly fn parse_readonly_opt(&mut self) -> S::Output { let token_kind = self.peek_token_kind(); match token_kind { TokenKind::Readonly => { let token = self.next_token(); self.sc_mut().make_token(token) } _ => { let pos = self.pos(); self.sc_mut().make_missing(pos) } } } // SPEC // default-argument-specifier: // = const-expression // // constant-initializer: // = const-expression fn parse_simple_initializer_opt(&mut self) -> S::Output { let token_kind = self.peek_token_kind(); match token_kind { TokenKind::Equal => { let token = self.next_token(); // TODO: Detect if expression is not const let token = self.sc_mut().make_token(token); let default_value = self.parse_expression(); self.sc_mut().make_simple_initializer(token, default_value) } _ => { let pos = self.pos(); self.sc_mut().make_missing(pos) } } } pub fn parse_function_declaration(&mut self, attribute_specification: S::Output) -> S::Output { let modifiers = self.parse_modifiers(); let header = self.parse_function_declaration_header(modifiers, /* is_methodish =*/ false); let body = self.parse_compound_statement(); self.sc_mut() .make_function_declaration(attribute_specification, header, body) } fn parse_constraint_operator(&mut self) -> S::Output { // TODO: Put this in the specification // (This work is tracked by spec issue 100.) // constraint-operator: // = // as // super let token_kind = self.peek_token_kind(); match token_kind { TokenKind::Equal | TokenKind::As | TokenKind::Super => { let token = self.next_token(); self.sc_mut().make_token(token) } _ => // ERROR RECOVERY: don't eat the offending token. // TODO: Give parse error { let pos = self.pos(); self.sc_mut().make_missing(pos) } } } fn parse_where_constraint(&mut self) -> S::Output { // TODO: Put this in the specification // (This work is tracked by spec issue 100.) // constraint: // type-specifier constraint-operator type-specifier let left = self.parse_type_specifier(/* allow_var = */ false, /* allow_attr = */ true); let op = self.parse_constraint_operator(); let right = self.parse_type_specifier(/* allow_var = */ false, /* allow_attr = */ true); self.sc_mut().make_where_constraint(left, op, right) } fn parse_where_constraint_list_item(&mut self) -> Option<S::Output> { match self.peek_token_kind() { TokenKind::Semicolon | TokenKind::LeftBrace => None, _ => { let where_constraint = self.parse_where_constraint(); let comma = self.optional_token(TokenKind::Comma); let result = self.sc_mut().make_list_item(where_constraint, comma); Some(result) } } } fn parse_where_clause(&mut self) -> S::Output { // TODO: Add this to the specification // (This work is tracked by spec issue 100.) // where-clause: // where constraint-list // // constraint-list: // constraint // constraint-list , constraint let keyword = self.assert_token(TokenKind::Where); let constraints = self.parse_list_until_none(|x: &mut Self| x.parse_where_constraint_list_item()); self.sc_mut().make_where_clause(keyword, constraints) } fn parse_where_clause_opt(&mut self) -> S::Output { if self.peek_token_kind() != TokenKind::Where { let pos = self.pos(); self.sc_mut().make_missing(pos) } else { self.parse_where_clause() } } fn parse_function_declaration_header( &mut self, modifiers: S::Output, is_methodish: bool, ) -> S::Output { // SPEC // function-definition-header: // attribute-specification-opt async-opt function name / // generic-type-parameter-list-opt ( parameter-list-opt ) : / // return-type where-clause-opt // TODO: The spec does not specify "where" clauses. Add them. // (This work is tracked by spec issue 100.) // // In strict mode, we require a type specifier. This error is not caught // at parse time but rather by a later pass. let function_token = self.require_function(); let label = self.parse_function_label_opt(is_methodish); let generic_type_parameter_list = self.with_type_parser(|p: &mut TypeParser<'a, S>| { p.parse_generic_type_parameter_list_opt() }); let (left_paren_token, parameter_list, right_paren_token) = self.parse_parameter_list_opt(); let contexts = self.with_type_parser(|p: &mut TypeParser<'a, S>| p.parse_contexts()); let (colon_token, readonly_opt, return_type) = self.parse_return_type_hint_opt(); let where_clause = self.parse_where_clause_opt(); self.sc_mut().make_function_declaration_header( modifiers, function_token, label, generic_type_parameter_list, left_paren_token, parameter_list, right_paren_token, contexts, colon_token, readonly_opt, return_type, where_clause, ) } // A function label is either a function name or a __construct label. fn parse_function_label_opt(&mut self, is_methodish: bool) -> S::Output { let report_error = |x: &mut Self, token: Token<S>| { x.with_error(Errors::error1044); let token = x.sc_mut().make_token(token); x.sc_mut().make_error(token) }; let token_kind = self.peek_token_kind(); match token_kind { TokenKind::Name | TokenKind::Construct => { let token = self.next_token(); self.sc_mut().make_token(token) } TokenKind::LeftParen => { // It turns out, it was just a verbose lambda; YOLO PHP let pos = self.pos(); self.sc_mut().make_missing(pos) } TokenKind::Isset | TokenKind::Unset | TokenKind::Empty => { // We need to parse those as names as they are defined in hhi let token = self.next_token_as_name(); self.sc_mut().make_token(token) } _ => { let token = if is_methodish { self.next_token_as_name() } else { self.next_token_non_reserved_as_name() }; if token.kind() == TokenKind::Name { self.sc_mut().make_token(token) } else { // ERROR RECOVERY: Eat the offending token. report_error(self, token) } } } } fn parse_old_attribute(&mut self) -> S::Output { self.with_expression_parser(|p: &mut ExpressionParser<'a, S>| p.parse_constructor_call()) } pub fn parse_attribute_specification_opt(&mut self) -> S::Output { match self.peek_token_kind() { TokenKind::At if self.env.allow_new_attribute_syntax => { self.parse_new_attribute_specification_opt() } TokenKind::LessThanLessThan => self.parse_old_attribute_specification_opt(), _ => { let pos = self.pos(); self.sc_mut().make_missing(pos) } } } fn parse_new_attribute_specification_opt(&mut self) -> S::Output { let attributes = self.parse_list_while( |p: &mut Self| p.parse_new_attribute(), |p: &Self| p.peek_token_kind() == TokenKind::At, ); self.sc_mut().make_attribute_specification(attributes) } fn parse_new_attribute(&mut self) -> S::Output { let at = self.assert_token(TokenKind::At); let token = self.peek_token(); let constructor_call = match token.kind() { TokenKind::Name => self.with_expression_parser(|p: &mut ExpressionParser<'a, S>| { p.parse_constructor_call() }), _ => { self.with_error(Errors::expected_user_attribute); let pos = self.pos(); self.sc_mut().make_missing(pos) } }; self.sc_mut().make_attribute(at, constructor_call) } // Parses modifiers and passes them into the parse methods for the // respective class body element. fn parse_methodish_or_property_or_const_or_type_const( &mut self, attribute_spec: S::Output, ) -> S::Output { let mut parser1 = self.clone(); let modifiers = parser1.parse_modifiers(); let kind0 = parser1.peek_token_kind_with_lookahead(0); let kind1 = parser1.peek_token_kind_with_lookahead(1); let kind2 = parser1.peek_token_kind_with_lookahead(2); match (kind0, kind1, kind2) { (TokenKind::Const, TokenKind::Type, TokenKind::Semicolon) => { self.continue_from(parser1); let const_ = self.assert_token(TokenKind::Const); self.parse_const_declaration(attribute_spec, modifiers, const_) } (TokenKind::Const, TokenKind::Type, _) if kind2 != TokenKind::Equal => { let modifiers = self.parse_modifiers(); let const_ = self.assert_token(TokenKind::Const); self.parse_type_const_declaration(attribute_spec, modifiers, const_) } (TokenKind::Const, TokenKind::Ctx, _) if kind2 != TokenKind::Equal => { let modifiers = self.parse_modifiers(); let const_ = self.assert_token(TokenKind::Const); self.parse_context_const_declaration(modifiers, const_) } (TokenKind::Const, _, _) => { self.continue_from(parser1); let const_ = self.assert_token(TokenKind::Const); self.parse_const_declaration(attribute_spec, modifiers, const_) } _ => self.parse_methodish_or_property(attribute_spec), } } // SPEC // method-declaration: // attribute-spec-opt method-modifiers function-definition // attribute-spec-opt method-modifiers function-definition-header ; // method-modifiers: // method-modifier // method-modifiers method-modifier // method-modifier: // visibility-modifier (i.e. private, public, protected) // static // abstract // final fn parse_methodish(&mut self, attribute_spec: S::Output, modifiers: S::Output) -> S::Output { let header = self.parse_function_declaration_header(modifiers, /* is_methodish:*/ true); let token_kind = self.peek_token_kind(); match token_kind { TokenKind::LeftBrace => { let body = self.parse_compound_statement(); let pos = self.pos(); let missing = self.sc_mut().make_missing(pos); self.sc_mut() .make_methodish_declaration(attribute_spec, header, body, missing) } TokenKind::Semicolon => { let pos = self.pos(); let token = self.next_token(); let missing = self.sc_mut().make_missing(pos); let semicolon = self.sc_mut().make_token(token); self.sc_mut() .make_methodish_declaration(attribute_spec, header, missing, semicolon) } TokenKind::Equal => { let equal = self.assert_token(TokenKind::Equal); let qualifier = self.parse_qualified_name_type(); let cc_token = self.require_coloncolon(); let name = self.require_token_one_of( &[TokenKind::Name, TokenKind::Construct], Errors::error1004, ); let name = self .sc_mut() .make_scope_resolution_expression(qualifier, cc_token, name); let semi = self.require_semicolon(); self.sc_mut().make_methodish_trait_resolution( attribute_spec, header, equal, name, semi, ) } _ => { // ERROR RECOVERY: We expected either a block or a semicolon; we got // neither. Use the offending token as the body of the method. // TODO: Is this the right error recovery? let pos = self.pos(); let token = self.next_token(); self.with_error(Errors::error1041); let token = self.sc_mut().make_token(token); let error = self.sc_mut().make_error(token); let missing = self.sc_mut().make_missing(pos); self.sc_mut() .make_methodish_declaration(attribute_spec, header, error, missing) } } } fn parse_modifiers(&mut self) -> S::Output { let mut items = vec![]; loop { let token_kind = self.peek_token_kind(); match token_kind { TokenKind::Abstract | TokenKind::Static | TokenKind::Public | TokenKind::Protected | TokenKind::Private | TokenKind::Async | TokenKind::Internal | TokenKind::Final | TokenKind::Readonly => { let token = self.next_token(); let item = self.sc_mut().make_token(token); items.push(item) } _ => break, } } let pos = self.pos(); self.sc_mut().make_list(items, pos) } fn parse_toplevel_with_attributes_or_visibility(&mut self) -> S::Output { // An enum, type alias, function, interface, trait or class may all // begin with an attribute. let attribute_specification = match self.peek_token_kind() { TokenKind::At | TokenKind::LessThanLessThan => self.parse_attribute_specification_opt(), _ => { let pos = self.pos(); self.sc_mut().make_missing(pos) } }; // Check for internal keyword; if internal, we want to track that info and look at the token after to determine // what we're parsing // For most toplevel entities we will parse internal as another modifier with no issues, // but we will need to lookahead at least 1 extra spot to see what we're actually parsing. let next_token_kind = self.peek_token_kind(); let (token_maybe_after_internal, has_visibility) = if next_token_kind == TokenKind::Internal || next_token_kind == TokenKind::Public { (self.peek_token_kind_with_lookahead(1), true) } else { (next_token_kind, false) }; match token_maybe_after_internal { TokenKind::Enum => { let modifiers = if has_visibility { self.parse_modifiers() } else { let pos = self.pos(); self.sc_mut().make_missing(pos) }; self.parse_enum_or_enum_class_declaration(attribute_specification, modifiers) } TokenKind::Module if !has_visibility && self.peek_token_kind_with_lookahead(1) == TokenKind::Newtype => { self.parse_type_alias_declaration(attribute_specification, true) } TokenKind::Type | TokenKind::Newtype => { self.parse_type_alias_declaration(attribute_specification, false) } TokenKind::Newctx => self.parse_ctx_alias_declaration(attribute_specification), TokenKind::Case => self.parse_case_type_declaration(attribute_specification), TokenKind::Async | TokenKind::Function => { if attribute_specification.is_missing() && !has_visibility { // if attribute section is missing - it might be either // function declaration or expression statement containing // anonymous function - use statement parser to determine in which case // we are currently in self.with_statement_parser(|p: &mut StatementParser<'a, S>| { p.parse_possible_php_function(/* toplevel=*/ true) }) } else { self.parse_function_declaration(attribute_specification) } } TokenKind::Abstract | TokenKind::Final | TokenKind::Interface | TokenKind::Trait | TokenKind::XHP | TokenKind::Class => self.parse_classish_declaration(attribute_specification), // The only thing that can put an attribute on a new is a module declaration TokenKind::New if !has_visibility && self.peek_token_kind_with_lookahead(1) == TokenKind::Module => { self.parse_module_declaration(attribute_specification) } _ => { // ERROR RECOVERY: we encountered an unexpected token, raise an error and continue // TODO: This is wrong; we have lost the attribute specification // from the tree. let token = self.next_token(); self.with_error(Errors::error1057(self.token_text(&token))); let token = self.sc_mut().make_token(token); self.sc_mut().make_error(token) } } } fn parse_classish_element(&mut self) -> S::Output { // We need to identify an element of a class, trait, etc. Possibilities // are: // // // constant-declaration: // const T $x = v ; // abstract const T $x ; // public const T $x = v ; // PHP7 only // // // type-constant-declaration // const type T = X; // abstract const type T; // // // property-declaration: // public/private/protected/internal/static T $x; // TODO: We may wish to parse "T $x" and give an error indicating // TODO: that we were expecting either const or public. // Note that a visibility modifier is required; static is optional; // any order is allowed. // // // method-declaration // <<attr>> public/private/protected/abstract/final/static async function // Note that a modifier is required, the attr and async are optional. // TODO: Hack requires a visibility modifier, unless "static" is supplied, // TODO: in which case the method is considered to be public. Is this // TODO: desired? Resolve this disagreement with the spec. // // // constructor-declaration // <<attr>> public/private/protected/abstract/final function __construct // Note that we allow static constructors in this parser; we produce an // error in the post-parse error detection pass. // // // trait clauses // require extends qualified-name // require implements qualified-name // // // XHP class attribute declaration // attribute ... ; // // // XHP category declaration // category ... ; // // // XHP children declaration // children ... ; match self.peek_token_kind() { TokenKind::Children => self.parse_xhp_children_declaration(), TokenKind::Category => self.parse_xhp_category_declaration(), TokenKind::Use => self.parse_trait_use(), TokenKind::Const | TokenKind::Abstract | TokenKind::Public | TokenKind::Protected | TokenKind::Private | TokenKind::Readonly | TokenKind::Internal | TokenKind::Static | TokenKind::Async | TokenKind::Final | TokenKind::LessThanLessThan => { let attr = self.parse_attribute_specification_opt(); self.parse_methodish_or_property_or_const_or_type_const(attr) } TokenKind::At if self.env.allow_new_attribute_syntax => { let attr = self.parse_attribute_specification_opt(); self.parse_methodish_or_property_or_const_or_type_const(attr) } TokenKind::Require => { // We give an error if these are found where they should not be, // in a later pass. self.parse_require_clause() } TokenKind::Attribute => self.parse_xhp_class_attribute_declaration(), TokenKind::Function => { // ERROR RECOVERY // Hack requires that a function inside a class be marked // with a visibility modifier, but PHP does not have this requirement. // We accept the lack of a modifier here, and produce an error in // a later pass. let pos = self.pos(); let missing1 = self.sc_mut().make_missing(pos); let pos = self.pos(); let missing2 = self.sc_mut().make_missing(pos); self.parse_methodish(missing1, missing2) } kind if self.expects(kind) => { let pos = self.pos(); self.sc_mut().make_missing(pos) } _ => { // If this is a property declaration which is missing its visibility // modifier, accept it here, but emit an error in a later pass. let mut parser1 = self.clone(); let pos = self.pos(); let missing1 = parser1.sc_mut().make_missing(pos); let pos = self.pos(); let missing2 = parser1.sc_mut().make_missing(pos); let property = parser1.parse_property_declaration(missing1, missing2); if self.errors.len() == parser1.errors.len() { self.continue_from(parser1); property } else { // TODO ERROR RECOVERY could be improved here. let token = self.fetch_token(); self.with_error(Errors::error1033); self.sc_mut().make_error(token) // Parser does not detect the error where non-static instance variables // or methods are within abstract final classes in its first pass, but // instead detects it in its second pass. } } } } fn parse_type_constraint_opt(&mut self, allow_super: bool) -> S::Output { self.with_type_parser(|p: &mut TypeParser<'a, S>| { p.parse_type_constraint_opt(allow_super).unwrap_or_else(|| { let pos = p.pos(); p.sc_mut().make_missing(pos) }) }) } fn parse_type_constraints(&mut self, allow_super: bool) -> S::Output { self.with_type_parser(|p: &mut TypeParser<'a, S>| { p.parse_list_until_none(|p| p.parse_type_constraint_opt(allow_super)) }) } fn parse_type_alias_declaration(&mut self, attr: S::Output, module_newtype: bool) -> S::Output { // SPEC // alias-declaration: // attribute-spec-opt modifiers type name // generic-type-parameter-list-opt = type-specifier ; // attribute-spec-opt modifiers newtype name // generic-type-parameter-list-opt type-constraint-opt // = type-specifier ; let modifiers = self.parse_modifiers(); let module_kw_opt = if module_newtype { self.assert_token(TokenKind::Module) } else { let pos = self.pos(); self.sc_mut().make_missing(pos) }; let token = self.fetch_token(); // Not `require_name` but `require_name_allow_non_reserved`, because the parser // must allow keywords in the place of identifiers; at least to parse .hhi // files. let name = self.require_name_allow_non_reserved(); let generic = self.with_type_parser(|p: &mut TypeParser<'a, S>| { p.parse_generic_type_parameter_list_opt() }); let constraints = self.parse_type_constraints(true); let equal = self.require_equal(); let ty = self.parse_type_specifier(false /* allow_var */, true /* allow_attr */); let semi = self.require_semicolon(); self.sc_mut().make_alias_declaration( attr, modifiers, module_kw_opt, token, name, generic, constraints, equal, ty, semi, ) } fn parse_case_type_declaration(&mut self, attr: S::Output) -> S::Output { // SPEC // case-type-declaration: // attribute-spec-opt modifiers case type name // generic-type-parameter-list-opt case-type-bounds = case-type-variants ; let modifiers = self.parse_modifiers(); let case_keyword = self.assert_token(TokenKind::Case); let type_keyword = self.require_token(TokenKind::Type, Errors::type_keyword); let name = self.require_name(); let generic_parameter = self.with_type_parser(|p: &mut TypeParser<'a, S>| { p.parse_generic_type_parameter_list_opt() }); let (as_kw, bounds) = self.parse_case_type_bounds(); let equal = self.require_equal(); let variants = self.parse_case_type_variants(); let semi = self.require_semicolon(); self.sc_mut().make_case_type_declaration( attr, modifiers, case_keyword, type_keyword, name, generic_parameter, as_kw, bounds, equal, variants, semi, ) } fn parse_case_type_bounds(&mut self) -> (S::Output, S::Output) { // SPEC // case-type-bounds: // as type-specifier, type-specifier if self.peek_token_kind() == TokenKind::As { let as_kw = self.fetch_token(); let bounds = self.with_type_parser(|p: &mut TypeParser<'a, S>| { p.parse_comma_list(TokenKind::Equal, Errors::error1007, |p| { p.parse_type_specifier(false /* allow_var */, false /* allow_attr */) }) }); (as_kw, bounds) } else { let pos = self.pos(); let as_kw = self.sc_mut().make_missing(pos); let bounds = self.sc_mut().make_missing(pos); (as_kw, bounds) } } fn parse_case_type_variants(&mut self) -> S::Output { // SPEC // case-type-variant: // | type-specifier // type-specifier // Error Reporting: If the next token is a `;` that means no type-specifier was given. // `parse_terminated_list` won't report an error in this case, so let's handle it here if self.peek_token_kind() == TokenKind::Semicolon { self.with_error(Errors::error1007); let pos = self.pos(); self.sc_mut().make_missing(pos) } else { let mut is_first = true; self.parse_terminated_list( |this: &mut Self| { // For the first variant in the list the leading `|` is optional let bar = if is_first { is_first = false; this.optional_token(TokenKind::Bar) } else { let token = this.require_token(TokenKind::Bar, Errors::expected_bar_or_semicolon); // Error Recovery: If we are missing a `|` don't bother parsing anything else. // It is likely a `;` is missing, so bail out if token.is_missing() { let pos = this.pos(); return this.sc_mut().make_missing(pos); } token }; let typ = this.with_type_parser(|p: &mut TypeParser<'a, S>| { p.parse_type_specifier_opt(false, false) }); // Error Recovery: We use `parse_type_specifier_opt` so we can handle error recovery directly. // If we didn't get a type specifier, report an error then consider the whole case-type-variant // to be missing. This will prevent the parser from consuming too many tokens in the error case if typ.is_missing() { this.with_error_on_whole_token(Errors::error1007); let pos = this.pos(); this.sc_mut().make_missing(pos) } else { this.sc_mut().make_case_type_variant(bar, typ) } }, TokenKind::Semicolon, ) } } fn parse_ctx_alias_declaration(&mut self, attr: S::Output) -> S::Output { // SPEC // ctx-alias-declaration: // newctx name type-constraint-opt = type-specifier ; let token = self.fetch_token(); let name = self.require_name(); let pos = self.pos(); let generic = self.sc_mut().make_missing(pos); let constr = self .with_type_parser(|p| p.parse_list_until_none(|p| p.parse_context_constraint_opt())); let (equal, ty) = if self.peek_token_kind() == TokenKind::Equal { let equal = self.require_equal(); let ty = self.with_type_parser(|p| p.parse_contexts()); (equal, ty) } else { let pos = self.pos(); let equal = self.sc_mut().make_missing(pos); let pos = self.pos(); let ty = self.sc_mut().make_missing(pos); (equal, ty) }; let semi = self.require_semicolon(); self.sc_mut() .make_context_alias_declaration(attr, token, name, generic, constr, equal, ty, semi) } fn parse_enumerator(&mut self) -> S::Output { // SPEC // enumerator: // enumerator-constant = constant-expression ; // enumerator-constant: // name // // TODO: Add an error to a later pass that determines the value is // a constant. // TODO: We must allow TRUE to be a legal enum member name; here we allow // any keyword. Consider making this more strict. self.sc_mut().begin_enumerator(); let name = self.require_name_allow_all_keywords(); let equal = self.require_equal(); let value = self.parse_expression(); let semicolon = self.require_semicolon(); self.sc_mut().make_enumerator(name, equal, value, semicolon) } fn parse_enum_class_enumerator(&mut self) -> S::Output { // SPEC // enum-class-enumerator: // type-specifier name = expression ; // abstract type-specifier name ; // Taken from parse_enumerator: // TODO: We must allow TRUE to be a legal enum member name; here we allow // any keyword. Consider making this more strict. self.sc_mut().begin_enum_class_enumerator(); let modifiers = self.parse_modifiers(); let ty = self.parse_type_specifier(/*allow_var*/ false, /*allow_attr*/ false); let name = self.require_name_allow_all_keywords(); let initializer_ = self.parse_simple_initializer_opt(); let semicolon = self.require_semicolon(); self.sc_mut() .make_enum_class_enumerator(modifiers, ty, name, initializer_, semicolon) } fn parse_inclusion_directive(&mut self) -> S::Output { // SPEC: // inclusion-directive: // require-multiple-directive // require-once-directive // // require-multiple-directive: // require include-filename ; // // include-filename: // expression // // require-once-directive: // require_once include-filename ; // // In non-strict mode we allow an inclusion directive (without semi) to be // used as an expression. It is therefore easier to actually parse this as: // // inclusion-directive: // inclusion-expression ; // // inclusion-expression: // require include-filename // require_once include-filename let expr = self.parse_expression(); let semi = self.require_semicolon(); self.sc_mut().make_inclusion_directive(expr, semi) } fn parse_module_declaration(&mut self, attrs: S::Output) -> S::Output { let new_kw = self.assert_token(TokenKind::New); let module_kw = self.assert_token(TokenKind::Module); let name = self.require_qualified_module_name(); let lb = self.require_left_brace(); let pos = self.pos(); let mut exports_block = self.sc_mut().make_missing(pos); let mut imports_block = self.sc_mut().make_missing(pos); loop { let kind = self.peek_token_kind(); match kind { TokenKind::Exports => { let exports = self.require_token(TokenKind::Exports, Errors::error1004); let exports_lb = self.require_left_brace(); let clauses = self.parse_comma_list_allow_trailing_opt( TokenKind::RightBrace, Errors::error1004, |x: &mut Self| x.require_qualified_referenced_module_name(), ); let exports_rb = self.require_right_brace(); if !exports_block.is_missing() { self.with_error(Errors::error1066); } exports_block = self .sc_mut() .make_module_exports(exports, exports_lb, clauses, exports_rb); } TokenKind::Imports => { let imports = self.require_token(TokenKind::Imports, Errors::error1004); let imports_lb = self.require_left_brace(); let clauses = self.parse_comma_list_allow_trailing_opt( TokenKind::RightBrace, Errors::error1004, |x: &mut Self| x.require_qualified_referenced_module_name(), ); let imports_rb = self.require_right_brace(); if !imports_block.is_missing() { self.with_error(Errors::error1067); } imports_block = self .sc_mut() .make_module_imports(imports, imports_lb, clauses, imports_rb); } _ => { let rb = self.require_right_brace(); return self.sc_mut().make_module_declaration( attrs, new_kw, module_kw, name, lb, exports_block, imports_block, rb, ); } } } } fn parse_module_membership_declaration(&mut self) -> S::Output { let module_kw = self.assert_token(TokenKind::Module); let name = self.require_qualified_module_name(); let semicolon = self.require_semicolon(); self.sc_mut() .make_module_membership_declaration(module_kw, name, semicolon) } fn parse_declaration(&mut self) -> S::Output { self.expect_in_new_scope(ExpectedTokens::Classish); let mut parser1 = self.clone(); let token = parser1.next_token(); let result = match token.kind() { TokenKind::Include | TokenKind::Include_once | TokenKind::Require | TokenKind::Require_once => self.parse_inclusion_directive(), TokenKind::Type | TokenKind::Newtype if { let kind = parser1.peek_token_kind(); kind == TokenKind::Name || kind == TokenKind::Classname } => { let pos = self.pos(); let missing = self.sc_mut().make_missing(pos); self.parse_type_alias_declaration(missing, false) } TokenKind::Newctx => { let pos = self.pos(); let missing = self.sc_mut().make_missing(pos); self.parse_ctx_alias_declaration(missing) } TokenKind::Case => { let pos = self.pos(); let missing = self.sc_mut().make_missing(pos); self.parse_case_type_declaration(missing) } TokenKind::Enum => { let pos = self.pos(); let missing_attr = self.sc_mut().make_missing(pos); let pos = self.pos(); let missing_mod = self.sc_mut().make_missing(pos); self.parse_enum_or_enum_class_declaration(missing_attr, missing_mod) } // The keyword namespace before a name should be parsed as // "the current namespace we are in", essentially a no op. // example: // namespace\f1(); should be parsed as a call to the function f1 in // the current namespace. TokenKind::Namespace if parser1.peek_token_kind() == TokenKind::Backslash => { self.with_statement_parser(|p: &mut StatementParser<'a, S>| p.parse_statement()) } TokenKind::Namespace => self.parse_namespace_declaration(), TokenKind::Use => self.parse_namespace_use_declaration(), TokenKind::Trait | TokenKind::Interface | TokenKind::Class => { let pos = self.pos(); let missing = self.sc_mut().make_missing(pos); self.parse_classish_declaration(missing) } TokenKind::Abstract | TokenKind::Final | TokenKind::XHP => { let pos = self.pos(); let missing = self.sc_mut().make_missing(pos); self.parse_classish_declaration(missing) } TokenKind::Async | TokenKind::Function => { self.with_statement_parser(|p: &mut StatementParser<'a, S>| { p.parse_possible_php_function(true) }) } TokenKind::Internal => self.parse_toplevel_with_attributes_or_visibility(), TokenKind::Public => self.parse_toplevel_with_attributes_or_visibility(), TokenKind::At if self.env.allow_new_attribute_syntax => { self.parse_toplevel_with_attributes_or_visibility() } TokenKind::LessThanLessThan => match parser1.peek_token_kind() { TokenKind::File if parser1.peek_token_kind_with_lookahead(1) == TokenKind::Colon => { self.parse_file_attribute_specification_opt() } _ => self.parse_toplevel_with_attributes_or_visibility(), }, // TODO figure out what global const differs from class const TokenKind::Const => { let pos = self.pos(); let missing1 = parser1.sc_mut().make_missing(pos); let pos = self.pos(); let missing2 = parser1.sc_mut().make_missing(pos); self.continue_from(parser1); let token = self.sc_mut().make_token(token); self.parse_const_declaration(missing1, missing2, token) } TokenKind::Module if parser1.peek_token_kind() == TokenKind::Newtype => { let pos = self.pos(); let missing = self.sc_mut().make_missing(pos); self.parse_type_alias_declaration(missing, true) } TokenKind::Module => self.parse_module_membership_declaration(), // If we see new as a token, it's a module definition TokenKind::New if parser1.peek_token_kind() == TokenKind::Module => { let pos = self.pos(); let missing = self.sc_mut().make_missing(pos); self.parse_module_declaration(missing) } // TODO: What if it's not a legal statement? Do we still make progress here? _ => self.with_statement_parser(|p: &mut StatementParser<'a, S>| p.parse_statement()), }; self.pop_scope(ExpectedTokens::Classish); result } pub fn parse_script(&mut self) -> S::Output { let header = self.parse_leading_markup_section(); let mut declarations = vec![]; if let Some(x) = header { declarations.push(x) }; loop { let token_kind = self.peek_token_kind(); match token_kind { TokenKind::EndOfFile => { let token = self.next_token(); let token = self.sc_mut().make_token(token); let end_of_file = self.sc_mut().make_end_of_file(token); declarations.push(end_of_file); break; } _ => declarations.push(self.parse_declaration()), } } let pos = self.pos(); let declarations = self.sc_mut().make_list(declarations, pos); let result = self.sc_mut().make_script(declarations); assert_eq!(self.peek_token_kind(), TokenKind::EndOfFile); result } }
Rust
hhvm/hphp/hack/src/parser/core/expression_parser.rs
// Copyright (c) 2019, Facebook, Inc. // All rights reserved. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use std::borrow::Cow; use std::marker::PhantomData; use parser_core_types::lexable_token::LexableToken; use parser_core_types::syntax_error::SyntaxError; use parser_core_types::syntax_error::{self as Errors}; use parser_core_types::token_factory::TokenFactory; use parser_core_types::token_kind::TokenKind; use crate::declaration_parser::DeclarationParser; use crate::lexer::Lexer; use crate::lexer::StringLiteralKind; use crate::operator::Assoc; use crate::operator::Operator; use crate::parser_env::ParserEnv; use crate::parser_trait::Context; use crate::parser_trait::ParserTrait; use crate::smart_constructors::NodeType; use crate::smart_constructors::SmartConstructors; use crate::smart_constructors::Token; use crate::statement_parser::StatementParser; use crate::type_parser::TypeParser; #[derive(PartialEq)] pub enum BinaryExpressionPrefixKind<P> { PrefixAssignment, PrefixLessThan(P), PrefixNone, } impl<P> BinaryExpressionPrefixKind<P> { pub fn is_assignment(&self) -> bool { match self { BinaryExpressionPrefixKind::PrefixAssignment => true, BinaryExpressionPrefixKind::PrefixNone => false, BinaryExpressionPrefixKind::PrefixLessThan(_) => false, } } } /// The result of parse_remaining_expression. enum ParseContinuation<NT, P> { // All done. Done(NT), // Need to run parse_remaining_binary_expression. Binary(NT, BinaryExpressionPrefixKind<(NT, P)>), // Rerun parse_remaining_expression with the result. Reparse(NT), } #[derive(Clone)] pub struct ExpressionParser<'a, S> where S: SmartConstructors, S::Output: NodeType, { lexer: Lexer<'a, S::Factory>, env: ParserEnv, context: Context<Token<S>>, errors: Vec<SyntaxError>, sc: S, precedence: usize, allow_as_expressions: bool, in_expression_tree: bool, _phantom: PhantomData<S>, } impl<'a, S> ParserTrait<'a, S> for ExpressionParser<'a, S> where S: SmartConstructors, S::Output: NodeType, { fn make( lexer: Lexer<'a, S::Factory>, env: ParserEnv, context: Context<Token<S>>, errors: Vec<SyntaxError>, sc: S, ) -> Self { Self { lexer, env, precedence: 0, context, errors, sc, allow_as_expressions: true, in_expression_tree: false, _phantom: PhantomData, } } fn into_parts( self, ) -> ( Lexer<'a, S::Factory>, Context<Token<S>>, Vec<SyntaxError>, S, ) { (self.lexer, self.context, self.errors, self.sc) } fn lexer(&self) -> &Lexer<'a, S::Factory> { &self.lexer } fn lexer_mut(&mut self) -> &mut Lexer<'a, S::Factory> { &mut self.lexer } fn continue_from<P: ParserTrait<'a, S>>(&mut self, other: P) { let (lexer, context, errors, sc) = other.into_parts(); self.lexer = lexer; self.context = context; self.errors = errors; self.sc = sc; } fn add_error(&mut self, error: SyntaxError) { self.errors.push(error) } fn env(&self) -> &ParserEnv { &self.env } fn sc_mut(&mut self) -> &mut S { &mut self.sc } fn drain_skipped_tokens(&mut self) -> std::vec::Drain<'_, Token<S>> { self.context.skipped_tokens.drain(..) } fn skipped_tokens(&self) -> &[Token<S>] { &self.context.skipped_tokens } fn context_mut(&mut self) -> &mut Context<Token<S>> { &mut self.context } fn context(&self) -> &Context<Token<S>> { &self.context } } impl<'a, S> ExpressionParser<'a, S> where S: SmartConstructors, S::Output: NodeType, { fn allow_as_expressions(&self) -> bool { self.allow_as_expressions } fn in_expression_tree(&self) -> bool { self.in_expression_tree } pub fn with_as_expressions<F, U>(&mut self, enabled: bool, f: F) -> U where F: Fn(&mut Self) -> U, { let old_enabled = self.allow_as_expressions(); self.allow_as_expressions = enabled; let r = f(self); self.allow_as_expressions = old_enabled; r } fn with_type_parser<F, U>(&mut self, f: F) -> U where F: Fn(&mut TypeParser<'a, S>) -> U, { let mut type_parser: TypeParser<'_, S> = TypeParser::make( self.lexer.clone(), self.env.clone(), self.context.clone(), self.errors.clone(), self.sc.clone(), ); let res = f(&mut type_parser); self.continue_from(type_parser); res } fn parse_remaining_type_specifier(&mut self, name: S::Output) -> S::Output { let mut type_parser: TypeParser<'_, S> = TypeParser::make( self.lexer.clone(), self.env.clone(), self.context.clone(), self.errors.clone(), self.sc.clone(), ); let res = type_parser.parse_remaining_type_specifier(name); self.continue_from(type_parser); res } fn parse_generic_type_arguments(&mut self) -> (S::Output, bool) { self.with_type_parser(|x| x.parse_generic_type_argument_list()) } fn with_decl_parser<F, U>(&mut self, f: F) -> U where F: Fn(&mut DeclarationParser<'a, S>) -> U, { let mut decl_parser: DeclarationParser<'_, S> = DeclarationParser::make( self.lexer.clone(), self.env.clone(), self.context.clone(), self.errors.clone(), self.sc.clone(), ); let res = f(&mut decl_parser); self.continue_from(decl_parser); res } fn with_statement_parser<F, U>(&mut self, f: F) -> U where F: Fn(&mut StatementParser<'a, S>) -> U, { let mut statement_parser: StatementParser<'_, S> = StatementParser::make( self.lexer.clone(), self.env.clone(), self.context.clone(), self.errors.clone(), self.sc.clone(), ); let res = f(&mut statement_parser); self.continue_from(statement_parser); res } fn parse_compound_statement(&mut self) -> S::Output { self.with_statement_parser(|x| x.parse_compound_statement()) } fn parse_parameter_list_opt(&mut self) -> (S::Output, S::Output, S::Output) { self.with_decl_parser(|x| x.parse_parameter_list_opt()) } pub fn parse_expression(&mut self) -> S::Output { stack_limit::maybe_grow(|| { let term = self.parse_term(); self.parse_remaining_expression(term) }) } fn with_reset_precedence<U, F: FnOnce(&mut Self) -> U>(&mut self, parse_function: F) -> U { self.with_numeric_precedence(0, parse_function) } fn parse_expression_with_reset_precedence(&mut self) -> S::Output { self.with_reset_precedence(|x| x.parse_expression()) } fn parse_expression_with_operator_precedence(&mut self, operator: Operator) -> S::Output { self.with_operator_precedence(operator, |x| x.parse_expression()) } fn with_precedence(&mut self, precedence: usize) { self.precedence = precedence } fn with_numeric_precedence<U, F: FnOnce(&mut Self) -> U>( &mut self, new_precedence: usize, parse_function: F, ) -> U { let old_precedence = self.precedence; self.with_precedence(new_precedence); let result = parse_function(self); self.with_precedence(old_precedence); result } fn with_operator_precedence<F: FnOnce(&mut Self) -> S::Output>( &mut self, operator: Operator, parse_function: F, ) -> S::Output { let new_precedence = operator.precedence(&self.env); self.with_numeric_precedence(new_precedence, parse_function) } fn parse_as_name_or_error(&mut self) -> S::Output { let mut parser1 = self.clone(); let token = parser1.next_token_non_reserved_as_name(); match token.kind() { TokenKind::Namespace | TokenKind::Name => { self.continue_from(parser1); let token = self.sc_mut().make_token(token); let name = self.scan_remaining_qualified_name(token); self.parse_name_or_collection_literal_expression(name) } kind if self.expects_here(kind) => { // ERROR RECOVERY: If we're encountering a token that matches a kind in // the previous scope of the expected stack, don't eat it--just mark the // name missing and continue parsing, starting from the offending token. self.with_error(Errors::error1015); let pos = self.pos(); self.sc_mut().make_missing(pos) } _ => { self.continue_from(parser1); // ERROR RECOVERY: If we're encountering anything other than a TokenKind::Name // or the next expected kind, eat the offending token. // TODO: Increase the coverage of PrecedenceParser.expects_next, so that // we wind up eating fewer of the tokens that'll be needed by the outer // statement / declaration parsers. self.with_error(Errors::error1015); self.sc_mut().make_token(token) } } } fn parse_term(&mut self) -> S::Output { let mut parser1 = self.clone(); let token = parser1.next_xhp_class_name_or_other_token(); let allow_new_attr = self.env.allow_new_attribute_syntax; match token.kind() { TokenKind::DecimalLiteral | TokenKind::OctalLiteral | TokenKind::HexadecimalLiteral | TokenKind::BinaryLiteral | TokenKind::FloatingLiteral | TokenKind::SingleQuotedStringLiteral | TokenKind::NowdocStringLiteral | TokenKind::DoubleQuotedStringLiteral | TokenKind::BooleanLiteral | TokenKind::NullLiteral => { self.continue_from(parser1); self.parse_null(token) } TokenKind::HeredocStringLiteral => { // We have a heredoc string literal but it might contain embedded // expressions. Start over. let (token, name) = self.next_docstring_header(); self.parse_heredoc_string(token, name) } TokenKind::HeredocStringLiteralHead | TokenKind::DoubleQuotedStringLiteralHead => { self.continue_from(parser1); self.parse_double_quoted_like_string(token, StringLiteralKind::LiteralDoubleQuoted) } TokenKind::Variable => self.parse_variable_or_lambda(), TokenKind::XHPClassName => { self.continue_from(parser1); self.parse_xhp_class_name(token) } TokenKind::Name => { self.continue_from(parser1); self.parse_name(token) } TokenKind::Backslash => { self.continue_from(parser1); self.parse_backslash(token) } TokenKind::SelfToken | TokenKind::Parent => self.parse_scope_resolution_or_name(), TokenKind::Static => self.parse_anon_or_awaitable_or_scope_resolution_or_name(), TokenKind::Yield => self.parse_yield_expression(), TokenKind::Dollar => self.parse_dollar_expression(true), TokenKind::Exclamation | TokenKind::PlusPlus | TokenKind::MinusMinus | TokenKind::Tilde | TokenKind::Minus | TokenKind::Plus | TokenKind::Await | TokenKind::Readonly | TokenKind::Clone | TokenKind::Print => self.parse_prefix_unary_expression(), // Allow error suppression prefix when not using new attributes TokenKind::At if !allow_new_attr => self.parse_prefix_unary_expression(), TokenKind::LeftParen => self.parse_cast_or_parenthesized_or_lambda_expression(), TokenKind::LessThan => { self.continue_from(parser1); self.parse_possible_xhp_expression(/*in_xhp_body:*/ false, token) } TokenKind::List => self.parse_list_expression(), TokenKind::New => self.parse_object_creation_expression(), TokenKind::Varray => self.parse_varray_intrinsic_expression(), TokenKind::Vec => self.parse_vector_intrinsic_expression(), TokenKind::Darray => self.parse_darray_intrinsic_expression(), TokenKind::Dict => self.parse_dictionary_intrinsic_expression(), TokenKind::Keyset => self.parse_keyset_intrinsic_expression(), TokenKind::Tuple => self.parse_tuple_expression(), TokenKind::Shape => self.parse_shape_expression(), TokenKind::Function => self.parse_function(), TokenKind::DollarDollar => { self.continue_from(parser1); self.parse_dollar_dollar(token) } // LessThanLessThan start attribute spec that is allowed on anonymous // functions or lambdas TokenKind::LessThanLessThan | TokenKind::Async => { self.parse_anon_or_lambda_or_awaitable() } TokenKind::At if allow_new_attr => self.parse_anon_or_lambda_or_awaitable(), TokenKind::Include | TokenKind::Include_once | TokenKind::Require | TokenKind::Require_once => self.parse_inclusion_expression(), TokenKind::Isset => self.parse_isset_expression(), TokenKind::Eval => self.parse_eval_expression(), TokenKind::Hash => { let pos = self.pos(); let qualifier = self.sc_mut().make_missing(pos); self.parse_enum_class_label_expression(qualifier) } TokenKind::Package => self.parse_package_expression(), TokenKind::Empty => self.parse_empty(), kind if self.expects(kind) => { // ERROR RECOVERY: if we've prematurely found a token we're expecting // later, mark the expression missing, throw an error, and do not advance // the parser. self.parse_error1015() } _ => self.parse_as_name_or_error(), } } fn parse_null(&mut self, token: Token<S>) -> S::Output { let token = self.sc_mut().make_token(token); self.sc_mut().make_literal_expression(token) } fn parse_xhp_class_name(&mut self, token: Token<S>) -> S::Output { let token = self.sc_mut().make_token(token); self.parse_name_or_collection_literal_expression(token) } fn parse_backslash(&mut self, token: Token<S>) -> S::Output { let pos = self.pos(); let missing = self.sc_mut().make_missing(pos); let backslash = self.sc_mut().make_token(token); let qualified_name = self.scan_qualified_name(missing, backslash); self.parse_name_or_collection_literal_expression(qualified_name) } fn parse_function(&mut self) -> S::Output { let pos = self.pos(); let attribute_spec = self.sc_mut().make_missing(pos); self.parse_anon(attribute_spec) } fn parse_dollar_dollar(&mut self, token: Token<S>) -> S::Output { let token = self.sc_mut().make_token(token); self.sc_mut().make_pipe_variable_expression(token) } fn parse_empty(&mut self) -> S::Output { self.with_error(Errors::empty_expression_illegal); let token = self.next_token_non_reserved_as_name(); self.sc_mut().make_token(token) } fn parse_error1015(&mut self) -> S::Output { self.with_error(Errors::error1015); let pos = self.pos(); self.sc_mut().make_missing(pos) } fn parse_name(&mut self, token: Token<S>) -> S::Output { let token = self.sc_mut().make_token(token); let qualified_name = self.scan_remaining_qualified_name(token); let mut parser1 = self.clone(); let str_maybe = parser1.next_token_no_trailing(); match str_maybe.kind() { TokenKind::NowdocStringLiteral | TokenKind::HeredocStringLiteral => { // for now, try generic type argument list with attributes before // resorting to bad prefix match self.try_parse_specified_function_call(&qualified_name) { Some((type_arguments, p)) => { self.continue_from(p); let result = self.do_parse_specified_function_call(qualified_name, type_arguments); self.parse_remaining_expression(result) } _ => { self.with_error(Errors::prefixed_invalid_string_kind); self.parse_name_or_collection_literal_expression(qualified_name) } } } TokenKind::HeredocStringLiteralHead => { // Treat as an attempt to prefix a non-double-quoted string self.with_error(Errors::prefixed_invalid_string_kind); self.parse_name_or_collection_literal_expression(qualified_name) } TokenKind::SingleQuotedStringLiteral | TokenKind::DoubleQuotedStringLiteral => { // This name prefixes a double-quoted string or a single // quoted string self.continue_from(parser1); let str_ = self.sc_mut().make_token(str_maybe); let str_ = self.sc_mut().make_literal_expression(str_); self.sc_mut() .make_prefixed_string_expression(qualified_name, str_) } TokenKind::DoubleQuotedStringLiteralHead => { self.continue_from(parser1); // This name prefixes a double-quoted string containing embedded expressions let str_ = self.parse_double_quoted_like_string( str_maybe, StringLiteralKind::LiteralDoubleQuoted, ); self.sc_mut() .make_prefixed_string_expression(qualified_name, str_) } _ => { // Not a prefixed string or an attempt at one self.parse_name_or_collection_literal_expression(qualified_name) } } } fn parse_eval_expression(&mut self) -> S::Output { // TODO: This is a PHP-ism. Open questions: // * Should we allow a trailing comma? it is not a function call and // never has more than one argument. See D4273242 for discussion. // * Is there any restriction on the kind of expression this can be? // * Should this be an error in strict mode? // * Should this be in the specification? // * Eval is case-insensitive. Should use of non-lowercase be an error? // // TODO: The original Hack and HHVM parsers accept "eval" as an // identifier, so we do too; consider whether it should be reserved. let mut parser1 = self.clone(); let keyword = parser1.assert_token(TokenKind::Eval); if parser1.peek_token_kind() == TokenKind::LeftParen { self.continue_from(parser1); let left = self.assert_token(TokenKind::LeftParen); let arg = self.parse_expression_with_reset_precedence(); let right = self.require_right_paren(); self.sc_mut() .make_eval_expression(keyword, left, arg, right) } else { self.parse_as_name_or_error() } } fn parse_isset_expression(&mut self) -> S::Output { // TODO: This is a PHP-ism. Open questions: // * Should we allow a trailing comma? See D4273242 for discussion. // * Is there any restriction on the kind of expression the arguments can be? // * Should this be an error in strict mode? // * Should this be in the specification? // * PHP requires that there be at least one argument; should we require // that? if so, should we give the error in the parser or a later pass? // * Isset is case-insensitive. Should use of non-lowercase be an error? // // TODO: The original Hack and HHVM parsers accept "isset" as an // identifier, so we do too; consider whether it should be reserved. let mut parser1 = self.clone(); let keyword = parser1.assert_token(TokenKind::Isset); if parser1.peek_token_kind() == TokenKind::LeftParen { self.continue_from(parser1); let (left, args, right) = self.parse_expression_list_opt(); self.sc_mut() .make_isset_expression(keyword, left, args, right) } else { self.parse_as_name_or_error() } } fn parse_double_quoted_like_string( &mut self, head: Token<S>, literal_kind: StringLiteralKind, ) -> S::Output { self.parse_string_literal(head, literal_kind) } fn parse_heredoc_string(&mut self, head: Token<S>, name: &[u8]) -> S::Output { self.parse_string_literal( head, StringLiteralKind::LiteralHeredoc { heredoc: name.to_vec(), }, ) } fn parse_braced_expression_in_string( &mut self, left_brace: Token<S>, dollar_inside_braces: bool, ) -> S::Output { // We are parsing something like "abc{$x}def" or "abc${x}def", and we // are at the left brace. // // We know that the left brace will not be preceded by trivia. However in the // second of the two cases mentioned above it is legal for there to be trivia // following the left brace. If we are in the first case, we've already // verified that there is no trailing trivia after the left brace. // // The expression may be followed by arbitrary trivia, including // newlines and comments. That means that the closing brace may have // leading trivia. But under no circumstances does the closing brace have // trailing trivia. // // It's an error for the closing brace to be missing. // // Therefore we lex the left brace normally, parse the expression normally, // but require that there be a right brace. We do not lex the trailing trivia // on the right brace. // // ERROR RECOVERY: If the right brace is missing, treat the remainder as // string text. let is_assignment_op = |token| { Operator::is_trailing_operator_token(token) && Operator::trailing_from_token(token).is_assignment() }; let left_brace_trailing_is_empty = left_brace.trailing_is_empty(); let left_brace = self.sc_mut().make_token(left_brace); let mut parser1 = self.clone(); let name_or_keyword_as_name = parser1.next_token_as_name(); let after_name = parser1.next_token_no_trailing(); let (expr, right_brace) = match (name_or_keyword_as_name.kind(), after_name.kind()) { (TokenKind::Name, TokenKind::RightBrace) => { self.continue_from(parser1); let expr = self.sc_mut().make_token(name_or_keyword_as_name); let right_brace = self.sc_mut().make_token(after_name); (expr, right_brace) } (TokenKind::Name, TokenKind::LeftBracket) if !dollar_inside_braces && left_brace_trailing_is_empty && name_or_keyword_as_name.leading_is_empty() && name_or_keyword_as_name.trailing_is_empty() => { // The case of "${x}" should be treated as if we were interpolating $x // (rather than interpolating the constant `x`). // // But we can also put other expressions in between the braces, such as // "${foo()}". In that case, `foo()` is evaluated, and then the result is // used as the variable name to interpolate. // // Considering that both start with `${ident`, how does the parser tell the // difference? It appears that PHP special-cases two forms to be treated as // direct variable interpolation: // // 1) `${x}` is semantically the same as `{$x}`. // // No whitespace may come between `{` and `x`, or else the `x` is // treated as a constant. // // 2) `${x[expr()]}` should be treated as `{$x[expr()]}`. More than one // subscript expression, such as `${x[expr1()][expr2()]}`, is illegal. // // No whitespace may come between either the `{` and `x` or the `x` and // the `[`, or else the `x` is treated as a constant, and therefore // arbitrary expressions are allowed in the curly braces. (This amounts // to a variable-variable.) // // This is very similar to the grammar detailed in the specification // discussed in `parse_string_literal` below, except that `${x=>y}` is not // valid; it appears to be treated the same as performing member access on // the constant `x` rather than the variable `$x`, which is not valid // syntax. // // The first case can already be parsed successfully because `x` is a valid // expression, so we special-case only the second case here. self.continue_from(parser1); let receiver = self.sc_mut().make_token(name_or_keyword_as_name); let left_bracket = self.sc_mut().make_token(after_name); let index = self.parse_expression_with_reset_precedence(); let right_bracket = self.require_right_bracket(); let expr = self.sc_mut().make_subscript_expression( receiver, left_bracket, index, right_bracket, ); let mut parser1 = self.clone(); let right_brace = parser1.next_token_no_trailing(); let right_brace = if right_brace.kind() == TokenKind::RightBrace { self.continue_from(parser1); self.sc_mut().make_token(right_brace) } else { self.with_error(Errors::error1006); let pos = self.pos(); self.sc_mut().make_missing(pos) }; (expr, right_brace) } (TokenKind::Name, maybe_assignment_op) if is_assignment_op(maybe_assignment_op) => { // PHP compatibility: expressions like `${x + 1}` are okay, but // expressions like `${x = 1}` are not okay, since `x` is parsed as if it // were a constant, and you can't use an assignment operator with a // constant. Flag the issue by reporting that a right brace is expected. self.continue_from(parser1); let expr = self.sc_mut().make_token(name_or_keyword_as_name); let mut parser1 = self.clone(); let right_brace = parser1.next_token_no_trailing(); let right_brace = if right_brace.kind() == TokenKind::RightBrace { self.continue_from(parser1); self.sc_mut().make_token(right_brace) } else { self.with_error(Errors::error1006); let pos = self.pos(); self.sc_mut().make_missing(pos) }; (expr, right_brace) } (_, _) => { let start_offset = self.lexer().start(); let expr = self.parse_expression_with_reset_precedence(); let end_offset = self.lexer().start(); // PHP compatibility: only allow a handful of expression types in // {$...}-expressions. if dollar_inside_braces && !(expr.is_function_call_expression() || expr.is_subscript_expression() || expr.is_member_selection_expression() || expr.is_safe_member_selection_expression() || expr.is_variable_expression() // This is actually checking to see if we have a // variable-variable, which is allowed here. Variable-variables are // parsed as prefix unary expressions with `$` as the operator. We // cannot directly check the operator in this prefix unary // expression, but we already know that `dollar_inside_braces` is // true, so that operator must have been `$`. || expr.is_prefix_unary_expression()) { let error = SyntaxError::make( start_offset, end_offset, Errors::illegal_interpolated_brace_with_embedded_dollar_expression, vec![], ); self.add_error(error); }; let mut parser1 = self.clone(); let token = parser1.next_token_no_trailing(); let right_brace = if token.kind() == TokenKind::RightBrace { self.continue_from(parser1); self.sc_mut().make_token(token) } else { self.with_error(Errors::error1006); let pos = self.pos(); self.sc_mut().make_missing(pos) }; (expr, right_brace) } }; self.sc_mut() .make_embedded_braced_expression(left_brace, expr, right_brace) } fn parse_string_literal( &mut self, head: Token<S>, literal_kind: StringLiteralKind, ) -> S::Output { // SPEC // // Double-quoted string literals and heredoc string literals use basically // the same rules; here we have just the grammar for double-quoted string // literals. // // string-variable:: // variable-name offset-or-property-opt // // offset-or-property:: // offset-in-string // property-in-string // // offset-in-string:: // [ name ] // [ variable-name ] // [ integer-literal ] // // property-in-string:: // -> name // // TODO: What about ?-> // // The actual situation is considerably more complex than indicated // in the specification. // // TODO: Consider updating the specification. // // The tokens in the grammar above have no leading or trailing trivia. // // An embedded variable expression may also be enclosed in curly braces; // however, the $ of the variable expression must follow immediately after // the left brace. // // An embedded variable expression inside braces allows trivia between // the tokens and before the right brace. // // An embedded variable expression inside braces can be a much more complex // expression than indicated by the grammar above. For example, // {$c->x->y[0]} is good, and {$c[$x is foo ? 0 : 1]} is good, // but {$c is foo ? $x : $y} is not. It is not clear to me what // the legal grammar here is; it seems best in this situation to simply // parse any expression and do an error pass later. // // Note that the braced expressions can include double-quoted strings. // {$c["abc"]} is good, for instance. // // ${ is illegal in strict mode. In non-strict mode, ${varname is treated // the same as {$varname, and may be an arbitrary expression. // // TODO: We need to produce errors if there are unbalanced brackets, // example: "$x[0" is illegal. // // TODO: Similarly for any non-valid thing following the left bracket, // including trivia. example: "$x[ 0]" is illegal. // // let merge = |parser: &mut Self, token: Token<S>, head: Option<Token<S>>| { // TODO: Assert that new head has no leading trivia, old head has no // trailing trivia. // Invariant: A token inside a list of string fragments is always a head, // body or tail. // TODO: Is this invariant what we want? We could preserve the parse of // the string. That is, something like "a${b}c${d}e" is at present // represented as head, expr, body, expr, tail. It could be instead // head, dollar, left brace, expr, right brace, body, dollar, left // brace, expr, right brace, tail. Is that better? // // TODO: Similarly we might want to preserve the structure of // heredoc strings in the parse: that there is a header consisting of // an identifier, and so on, and then body text, etc. match head { Some(head) => { let k = match (head.kind(), token.kind()) { ( TokenKind::DoubleQuotedStringLiteralHead, TokenKind::DoubleQuotedStringLiteralTail, ) => TokenKind::DoubleQuotedStringLiteral, ( TokenKind::HeredocStringLiteralHead, TokenKind::HeredocStringLiteralTail, ) => TokenKind::HeredocStringLiteral, (TokenKind::DoubleQuotedStringLiteralHead, _) => { TokenKind::DoubleQuotedStringLiteralHead } (TokenKind::HeredocStringLiteralHead, _) => { TokenKind::HeredocStringLiteralHead } (_, TokenKind::DoubleQuotedStringLiteralTail) => { TokenKind::DoubleQuotedStringLiteralTail } (_, TokenKind::HeredocStringLiteralTail) => { TokenKind::HeredocStringLiteralTail } _ => TokenKind::StringLiteralBody, }; // this is incorrect for minimal tokens let o = head.leading_start_offset().unwrap_or(0); let w = head.width() + token.width(); let (l, _, _) = head.into_trivia_and_width(); let (_, _, t) = token.into_trivia_and_width(); // TODO: Make a "position" type that is a tuple of source and offset. Some(parser.sc_mut().token_factory_mut().make(k, o, w, l, t)) } None => { let token = match token.kind() { TokenKind::StringLiteralBody | TokenKind::HeredocStringLiteralTail | TokenKind::DoubleQuotedStringLiteralTail => token, _ => parser .sc_mut() .token_factory_mut() .with_kind(token, TokenKind::StringLiteralBody), }; Some(token) } } }; let put_opt = |parser: &mut Self, head: Option<Token<S>>, acc: &mut Vec<S::Output>| { if let Some(h) = head { let token = parser.sc_mut().make_token(h); acc.push(token) } }; let parse_embedded_expression = |parser: &mut Self, token: Token<S>| { let token = parser.sc_mut().make_token(token); let var_expr = parser.sc_mut().make_variable_expression(token); let mut parser1 = parser.clone(); let token1 = parser1.next_token_in_string(&literal_kind); let mut parser2 = parser1.clone(); let token2 = parser2.next_token_in_string(&literal_kind); let mut parser3 = parser2.clone(); let token3 = parser3.next_token_in_string(&literal_kind); match (token1.kind(), token2.kind(), token3.kind()) { (TokenKind::MinusGreaterThan, TokenKind::Name, _) => { parser.continue_from(parser2); let token1 = parser.sc_mut().make_token(token1); let token2 = parser.sc_mut().make_token(token2); parser .sc_mut() .make_embedded_member_selection_expression(var_expr, token1, token2) } (TokenKind::LeftBracket, TokenKind::Name, TokenKind::RightBracket) => { parser.continue_from(parser3); let token1 = parser.sc_mut().make_token(token1); let token2 = parser.sc_mut().make_token(token2); let token3 = parser.sc_mut().make_token(token3); parser .sc_mut() .make_embedded_subscript_expression(var_expr, token1, token2, token3) } (TokenKind::LeftBracket, TokenKind::Variable, TokenKind::RightBracket) => { parser.continue_from(parser3); let token1 = parser.sc_mut().make_token(token1); let token2 = parser.sc_mut().make_token(token2); let expr = parser.sc_mut().make_variable_expression(token2); let token3 = parser.sc_mut().make_token(token3); parser .sc_mut() .make_embedded_subscript_expression(var_expr, token1, expr, token3) } (TokenKind::LeftBracket, TokenKind::DecimalLiteral, TokenKind::RightBracket) | (TokenKind::LeftBracket, TokenKind::OctalLiteral, TokenKind::RightBracket) | ( TokenKind::LeftBracket, TokenKind::HexadecimalLiteral, TokenKind::RightBracket, ) | (TokenKind::LeftBracket, TokenKind::BinaryLiteral, TokenKind::RightBracket) => { parser.continue_from(parser3); let token1 = parser.sc_mut().make_token(token1); let token2 = parser.sc_mut().make_token(token2); let expr = parser.sc_mut().make_literal_expression(token2); let token3 = parser.sc_mut().make_token(token3); parser .sc_mut() .make_embedded_subscript_expression(var_expr, token1, expr, token3) } (TokenKind::LeftBracket, _, _) => { // PHP compatibility: throw an error if we encounter an // insufficiently-simple expression for a string like "$b[<expr>]", or if // the expression or closing bracket are missing. parser.continue_from(parser1); let token1 = parser.sc_mut().make_token(token1); let pos = parser.pos(); let token2 = parser.sc_mut().make_missing(pos); let pos = parser.pos(); let token3 = parser.sc_mut().make_missing(pos); parser.with_error(Errors::expected_simple_offset_expression); parser .sc_mut() .make_embedded_subscript_expression(var_expr, token1, token2, token3) } _ => var_expr, } }; let handle_left_brace = |parser: &mut Self, left_brace: Token<S>, head: Option<Token<S>>, acc: &mut Vec<S::Output>| { // Note that here we use next_token_in_string because we need to know // whether there is trivia between the left brace and the $x which follows. let mut parser1 = parser.clone(); let token = parser1.next_token_in_string(&literal_kind); // TODO: What about "{$$}" ? match token.kind() { TokenKind::Dollar | TokenKind::Variable => { put_opt(parser, head, acc); // TODO(leoo) check with kasper (was self) let expr = parser.parse_braced_expression_in_string( left_brace, /* dollar_inside_braces:*/ true, ); acc.push(expr); None } _ => { // We do not support {$ inside a string unless the $ begins a // variable name. Append the { and start again on the $. // TODO: Is this right? Suppose we have "{${x}". Is that the same // as "{"."${x}" ? Double check this. // TODO: Give an error. // We got a { not followed by a $. Ignore it. // TODO: Give a warning? merge(parser, left_brace, head) } } }; let handle_dollar = |parser: &mut Self, dollar, head: Option<Token<S>>, acc: &mut Vec<S::Output>| { // We need to parse ${x} as though it was {$x} // TODO: This should be an error in strict mode. // We must not have trivia between the $ and the {, but we can have // trivia after the {. That's why we use next_token_in_string here. let mut parser1 = parser.clone(); let token = parser1.next_token_in_string(&literal_kind); match token.kind() { TokenKind::LeftBrace => { // The thing in the braces has to be an expression that begins // with a variable, and the variable does *not* begin with a $. It's // just the word. // // Unlike the {$var} case, there *can* be trivia before the expression, // which means that trivia is likely the trailing trivia of the brace, // not leading trivia of the expression. // TODO: Enforce these rules by producing an error if they are // violated. // TODO: Make the parse tree for the leading word in the expression // a variable expression, not a qualified name expression. parser.continue_from(parser1); put_opt(parser, head, acc); let dollar = parser.sc_mut().make_token(dollar); let expr = parser.parse_braced_expression_in_string( token, /*dollar_inside_braces:*/ false, ); acc.push(dollar); acc.push(expr); None } _ => { // We got a $ not followed by a { or variable name. Ignore it. // TODO: Give a warning? merge(parser, dollar, head) } } }; let mut acc = vec![]; let mut head = Some(head); loop { let token = self.next_token_in_string(&literal_kind); match token.kind() { TokenKind::HeredocStringLiteralTail | TokenKind::DoubleQuotedStringLiteralTail => { let head = merge(self, token, head); put_opt(self, head, &mut acc); break; } TokenKind::LeftBrace => head = handle_left_brace(self, token, head, &mut acc), TokenKind::Variable => { put_opt(self, head, &mut acc); let expr = parse_embedded_expression(self, token); head = None; acc.push(expr) } TokenKind::Dollar => head = handle_dollar(self, token, head, &mut acc), _ => head = merge(self, token, head), } } // If we've ended up with a single string literal with no internal // structure, do not represent that as a list with one item. let results = if acc.len() == 1 { acc.pop().unwrap() } else { let pos = self.pos(); self.sc_mut().make_list(acc, pos) }; self.sc_mut().make_literal_expression(results) } fn parse_inclusion_expression(&mut self) -> S::Output { // SPEC: // inclusion-directive: // require-multiple-directive // require-once-directive // // require-multiple-directive: // require include-filename ; // // include-filename: // expression // // require-once-directive: // require_once include-filename ; // // In non-strict mode we allow an inclusion directive (without semi) to be // used as an expression. It is therefore easier to actually parse this as: // // inclusion-directive: // inclusion-expression ; // // inclusion-expression: // require include-filename // require_once include-filename // // TODO: We allow "include" and "include_once" as well, which are PHP-isms // specified as not supported in Hack. Do we need to produce an error in // strict mode? // // TODO: Produce an error if this is used in an expression context // in strict mode. let require = self.next_token(); let operator = Operator::prefix_unary_from_token(require.kind()); let require = self.sc_mut().make_token(require); let filename = self.parse_expression_with_operator_precedence(operator); self.sc_mut().make_inclusion_expression(require, filename) } fn parse_package_expression(&mut self) -> S::Output { // SPEC: // package package-name let package_kw = self.next_token(); let package_name = self.parse_expression_with_operator_precedence( Operator::prefix_unary_from_token(package_kw.kind()), ); if !package_name.is_name() { self.with_error(Errors::error1004); } let package_kw = self.sc_mut().make_token(package_kw); self.sc_mut() .make_package_expression(package_kw, package_name) } fn peek_next_kind_if_operator(&self) -> Option<TokenKind> { let kind = self.peek_token_kind(); if Operator::is_trailing_operator_token(kind) { Some(kind) } else { None } } fn operator_has_lower_precedence(&self, operator_kind: TokenKind) -> bool { let operator = Operator::trailing_from_token(operator_kind); operator.precedence(&self.env) < self.precedence } fn next_is_lower_precedence(&self) -> bool { match self.peek_next_kind_if_operator() { None => true, Some(kind) => self.operator_has_lower_precedence(kind), } } fn try_parse_specified_function_call(&mut self, term: &S::Output) -> Option<(S::Output, Self)> { if !Self::can_term_take_type_args(term) { return None; } if self.peek_token_kind_with_possible_attributized_type_list() != TokenKind::LessThan { return None; } let mut parser1 = self.clone(); let (type_arguments, no_arg_is_missing) = parser1.parse_generic_type_arguments(); if no_arg_is_missing && self.errors.len() == parser1.errors.len() { Some((type_arguments, parser1)) } else { // Parse empty <> for function pointer without targ let mut parser2 = self.clone(); let open_angle = parser2.fetch_token(); if parser2.peek_token_kind() == TokenKind::GreaterThan { let pos = parser2.pos(); let missing = parser2.sc_mut().make_missing(pos); let close_angle = parser2.assert_token(TokenKind::GreaterThan); let empty_targs = self.sc_mut() .make_type_arguments(open_angle, missing, close_angle); return Some((empty_targs, parser2)); } None } } fn do_parse_specified_function_call( &mut self, term: S::Output, type_arguments: S::Output, ) -> S::Output { match self.peek_token_kind() { TokenKind::ColonColon => { // handle a<type-args>::... case let type_specifier = self .sc_mut() .make_generic_type_specifier(term, type_arguments); self.parse_scope_resolution_expression(type_specifier) } TokenKind::LeftParen => { let (left, args, right) = self.parse_expression_list_opt(); self.sc_mut() .make_function_call_expression(term, type_arguments, left, args, right) } _ => self .sc_mut() .make_function_pointer_expression(term, type_arguments), } } fn can_be_used_as_lvalue(t: &S::Output) -> bool { t.is_variable_expression() || t.is_subscript_expression() || t.is_member_selection_expression() || t.is_scope_resolution_expression() } // detects if left_term and operator can be treated as a beginning of // assignment (respecting the precedence of operator on the left of // left term). Returns // - PrefixNone - either operator is not one of assignment operators or // precedence of the operator on the left is higher than precedence of // assignment. // - PrefixAssignment - left_term and operator can be interpreted as a // prefix of assignment // - Prefix:LessThan - is the start of a specified function call f<T>(...) fn check_if_should_override_normal_precedence( &mut self, left_term: &S::Output, operator: TokenKind, left_precedence: usize, ) -> BinaryExpressionPrefixKind<(S::Output, Self)> { // We need to override the precedence of the < operator in the case where it // is the start of a specified function call. let maybe_prefix = if self.peek_token_kind_with_possible_attributized_type_list() == TokenKind::LessThan { self.try_parse_specified_function_call(left_term) .map(BinaryExpressionPrefixKind::PrefixLessThan) } else { None }; match maybe_prefix { Some(r) => r, None => { // in PHP precedence of assignment in expression is bumped up to // recognize cases like !$x = ... or $a == $b || $c = ... // which should be parsed as !($x = ...) and $a == $b || ($c = ...) if left_precedence >= Operator::precedence_for_assignment_in_expressions() { BinaryExpressionPrefixKind::PrefixNone } else { match operator { TokenKind::Equal if left_term.is_list_expression() => { BinaryExpressionPrefixKind::PrefixAssignment } TokenKind::Equal | TokenKind::PlusEqual | TokenKind::MinusEqual | TokenKind::StarEqual | TokenKind::SlashEqual | TokenKind::StarStarEqual | TokenKind::DotEqual | TokenKind::PercentEqual | TokenKind::AmpersandEqual | TokenKind::BarEqual | TokenKind::CaratEqual | TokenKind::LessThanLessThanEqual | TokenKind::GreaterThanGreaterThanEqual | TokenKind::QuestionQuestionEqual if Self::can_be_used_as_lvalue(left_term) => { BinaryExpressionPrefixKind::PrefixAssignment } _ => BinaryExpressionPrefixKind::PrefixNone, } } } } } fn can_term_take_type_args(term: &S::Output) -> bool { term.is_name() || term.is_qualified_name() || term.is_member_selection_expression() || term.is_safe_member_selection_expression() || term.is_scope_resolution_expression() } fn parse_remaining_expression(&mut self, mut term: S::Output) -> S::Output { // This method is intentionally kept small and simple so that any recursion it does // only uses a small amount of stack space for this frame. loop { match self.parse_remaining_expression_helper(term) { ParseContinuation::Done(result) => return result, ParseContinuation::Binary(result, assignment_prefix_kind) => { // Special-case binary exprs here to recurse using a much smaller stack frame, // then iterate on the result. term = self.parse_remaining_binary_expression(result, assignment_prefix_kind); } ParseContinuation::Reparse(result) => term = result, } } } // Avoid inlining to keep down the stack frame size of recursing functions. #[inline(never)] fn parse_remaining_expression_helper( &mut self, term: S::Output, ) -> ParseContinuation<S::Output, Self> { match self.peek_next_kind_if_operator() { None => ParseContinuation::Done(term), Some(token) => { let assignment_prefix_kind = self.check_if_should_override_normal_precedence(&term, token, self.precedence); // stop parsing expression if: // - precedence of the operator is less than precedence of the operator // on the left // AND // - <term> <operator> does not look like a prefix of // some assignment expression match assignment_prefix_kind { BinaryExpressionPrefixKind::PrefixLessThan((type_args, parser1)) => { self.continue_from(parser1); let result = self.do_parse_specified_function_call(term, type_args); ParseContinuation::Reparse(result) } BinaryExpressionPrefixKind::PrefixNone if self.operator_has_lower_precedence(token) => { ParseContinuation::Done(term) } _ => match token { // Binary operators // TODO Add an error if PHP style <> is used in Hack. TokenKind::Plus | TokenKind::Minus | TokenKind::Star | TokenKind::Slash | TokenKind::StarStar | TokenKind::Equal | TokenKind::BarEqual | TokenKind::PlusEqual | TokenKind::StarEqual | TokenKind::StarStarEqual | TokenKind::SlashEqual | TokenKind::DotEqual | TokenKind::MinusEqual | TokenKind::PercentEqual | TokenKind::CaratEqual | TokenKind::AmpersandEqual | TokenKind::LessThanLessThanEqual | TokenKind::GreaterThanGreaterThanEqual | TokenKind::EqualEqualEqual | TokenKind::LessThan | TokenKind::GreaterThan | TokenKind::Percent | TokenKind::Dot | TokenKind::EqualEqual | TokenKind::AmpersandAmpersand | TokenKind::BarBar | TokenKind::ExclamationEqual | TokenKind::ExclamationEqualEqual | TokenKind::LessThanEqual | TokenKind::LessThanEqualGreaterThan | TokenKind::GreaterThanEqual | TokenKind::Ampersand | TokenKind::Bar | TokenKind::LessThanLessThan | TokenKind::GreaterThanGreaterThan | TokenKind::Carat | TokenKind::BarGreaterThan | TokenKind::QuestionColon | TokenKind::QuestionQuestion | TokenKind::QuestionQuestionEqual => { ParseContinuation::Binary(term, assignment_prefix_kind) } TokenKind::Instanceof => { self.with_error(Errors::instanceof_disabled); let _ = self.assert_token(TokenKind::Instanceof); ParseContinuation::Done(term) } TokenKind::Is => { let result = self.parse_is_expression(term); ParseContinuation::Reparse(result) } TokenKind::As if self.allow_as_expressions() => { let result = self.parse_as_expression(term); ParseContinuation::Reparse(result) } TokenKind::QuestionAs => { let result = self.parse_nullable_as_expression(term); ParseContinuation::Reparse(result) } TokenKind::Upcast => { let result = self.parse_upcast_expression(term); ParseContinuation::Reparse(result) } TokenKind::QuestionMinusGreaterThan | TokenKind::MinusGreaterThan => { let result = self.parse_member_selection_expression(term); ParseContinuation::Reparse(result) } TokenKind::ColonColon => { let result = self.parse_scope_resolution_expression(term); ParseContinuation::Reparse(result) } TokenKind::PlusPlus | TokenKind::MinusMinus => { let result = self.parse_postfix_unary(term); ParseContinuation::Done(result) } TokenKind::Hash => { let result = self.parse_enum_class_label_expression(term); ParseContinuation::Reparse(result) } TokenKind::LeftParen => { let result = self.parse_function_call(term); ParseContinuation::Reparse(result) } TokenKind::LeftBracket | TokenKind::LeftBrace => { let result = self.parse_subscript(term); ParseContinuation::Reparse(result) } TokenKind::Question => { let token = self.assert_token(TokenKind::Question); let result = self.parse_conditional_expression(term, token); ParseContinuation::Reparse(result) } _ => ParseContinuation::Done(term), }, } } } } fn parse_member_selection_expression(&mut self, term: S::Output) -> S::Output { // SPEC: // member-selection-expression: // postfix-expression => name // postfix-expression => variable-name // postfix-expression => xhp-class-name (DRAFT XHP SPEC) // // null-safe-member-selection-expression: // postfix-expression ?=> name // postfix-expression ?=> variable-name // postfix-expression ?=> xhp-class-name (DRAFT XHP SPEC) // // PHP allows $a=>{$b}; to be more compatible with PHP, and give // good errors, we allow that here as well. // // TODO: Produce an error if the braced syntax is used in Hack. let token = self.next_token(); let token_kind = token.kind(); let op = self.sc_mut().make_token(token); // TODO: We are putting the name / variable into the tree as a token // leaf, rather than as a name or variable expression. Is that right? let name = match self.peek_token_kind() { TokenKind::LeftBrace => self.parse_braced_expression(), TokenKind::Variable if self.env.php5_compat_mode => { self.parse_variable_in_php5_compat_mode() } TokenKind::Dollar => self.parse_dollar_expression(false), _ => self.require_xhp_class_name_or_name_or_variable(), }; if token_kind == TokenKind::MinusGreaterThan { self.sc_mut() .make_member_selection_expression(term, op, name) } else { self.sc_mut() .make_safe_member_selection_expression(term, op, name) } } fn parse_variable_in_php5_compat_mode(&mut self) -> S::Output { // PHP7 had a breaking change in parsing variables: // (https://wiki.php.net/rfc/uniform_variable_syntax). // Hack parser by default uses PHP7 compatible more which interprets // variables accesses left-to-right. It usually matches PHP5 behavior // except for cases with '$' operator, member accesses and scope resolution // operators: // $$a[1][2] => ($$a)[1][2] // $a=>$b[c] => ($a=>$b)[c] // X::$a[b]() => (X::$a)[b]() // // In order to preserve backward compatibility we can parse // variable/subscript expressions and treat them as if // braced expressions to enfore PHP5 semantics // $$a[1][2] => ${$a[1][2]} // $a=>$b[c] => $a=>{$b[c]} // X::$a[b]() => X::{$a[b]}() let old_precedence = self.precedence; let precedence = Operator::IndexingOperator.precedence(&self.env); self.with_precedence(precedence); let e = self.parse_expression(); self.with_precedence(old_precedence); e } fn parse_subscript(&mut self, term: S::Output) -> S::Output { // SPEC // subscript-expression: // postfix-expression [ expression-opt ] // postfix-expression { expression-opt } [Deprecated form] // // TODO: Produce an error for brace case in a later pass let left = self.next_token(); match (left.kind(), self.peek_token_kind()) { (TokenKind::LeftBracket, TokenKind::RightBracket) | (TokenKind::LeftBrace, TokenKind::RightBrace) => { let right = self.next_token(); let left = self.sc_mut().make_token(left); let pos = self.pos(); let missing = self.sc_mut().make_missing(pos); let right = self.sc_mut().make_token(right); self.sc_mut() .make_subscript_expression(term, left, missing, right) } (left_kind, _) => { let left_token = self.sc_mut().make_token(left); let index = self.with_as_expressions(/* enabled :*/ true, |x| { x.with_reset_precedence(|x| x.parse_expression()) }); let right = match left_kind { TokenKind::LeftBracket => self.require_right_bracket(), _ => self.require_right_brace(), }; self.sc_mut() .make_subscript_expression(term, left_token, index, right) } } } fn parse_expression_list_opt(&mut self) -> (S::Output, S::Output, S::Output) { // SPEC // // TODO: This business of allowing ... does not appear in the spec. Add it. // // TODO: Add call-convention-opt to the specification. // (This work is tracked by task T22582676.) // // TODO: Update grammar for inout parameters. // (This work is tracked by task T22582715.) // // ERROR RECOVERY: A ... expression can only appear at the end of a // formal parameter list. However, we parse it everywhere without error, // and detect the error in a later pass. // // Note that it *is* legal for a ... expression be followed by a trailing // comma, even though it is not legal for such in a formal parameter list. // // TODO: Can *any* expression appear after the ... ? // // argument-expression-list: // argument-expressions ,-opt // argument-expressions: // expression // ... expression // call-convention-opt expression // argument-expressions , expression // // This function parses the parens as well. self.parse_parenthesized_comma_list_opt_allow_trailing(|x| { x.with_reset_precedence(|x| x.parse_decorated_expression_opt()) }) } fn parse_decorated_expression_opt(&mut self) -> S::Output { match self.peek_token_kind() { TokenKind::DotDotDot | TokenKind::Inout => { let decorator = self.fetch_token(); let expr = self.parse_expression(); self.sc_mut().make_decorated_expression(decorator, expr) } _ => self.parse_expression(), } } fn parse_start_of_type_specifier(&mut self, start_token: Token<S>) -> Option<S::Output> { let name = if start_token.kind() == TokenKind::Backslash { let pos = self.pos(); let missing = self.sc_mut().make_missing(pos); let backslash = self.sc_mut().make_token(start_token); self.scan_qualified_name(missing, backslash) } else { let start_token = self.sc_mut().make_token(start_token); self.scan_remaining_qualified_name(start_token) }; match self.peek_token_kind_with_possible_attributized_type_list() { TokenKind::LeftParen | TokenKind::LessThan => Some(name), _ => None, } } fn parse_designator(&mut self) -> S::Output { // SPEC: // class-type-designator: // parent // self // static // member-selection-expression // null-safe-member-selection-expression // qualified-name // scope-resolution-expression // subscript-expression // variable-name // // TODO: Update the spec to allow qualified-name < type arguments > // TODO: This will need to be fixed to allow situations where the qualified name // is also a non-reserved token. let default = |x: &mut Self| x.parse_expression_with_operator_precedence(Operator::NewOperator); let mut parser1 = self.clone(); let token = parser1.next_token(); match token.kind() { TokenKind::Parent | TokenKind::SelfToken => { match parser1.peek_token_kind_with_possible_attributized_type_list() { TokenKind::LeftParen => { self.continue_from(parser1); self.sc_mut().make_token(token) } TokenKind::LessThan => { let (type_arguments, no_arg_is_missing) = parser1.parse_generic_type_arguments(); if no_arg_is_missing && self.errors.len() == parser1.errors.len() { self.continue_from(parser1); let token = self.sc_mut().make_token(token); let type_specifier = self .sc_mut() .make_generic_type_specifier(token, type_arguments); type_specifier } else { default(self) } } _ => default(self), } } TokenKind::Static if parser1.peek_token_kind() == TokenKind::LeftParen => { self.continue_from(parser1); self.sc_mut().make_token(token) } TokenKind::Name | TokenKind::Backslash => { match parser1.parse_start_of_type_specifier(token) { Some(name) => { // We want to parse new C() and new C<int>() as types, but // new C::$x() as an expression. self.continue_from(parser1); self.parse_remaining_type_specifier(name) } None => default(self), } } _ => { default(self) // TODO: We need to verify in a later pass that the expression is a // scope resolution (that does not end in class!), a member selection, // a name, a variable, a property, or an array subscript expression. } } } fn parse_object_creation_expression(&mut self) -> S::Output { // SPEC // object-creation-expression: // new object-creation-what let new_token = self.assert_token(TokenKind::New); let new_what = self.parse_constructor_call(); self.sc_mut() .make_object_creation_expression(new_token, new_what) } pub fn parse_constructor_call(&mut self) -> S::Output { // SPEC // constructor-call: // class-type-designator ( argument-expression-list-opt ) // // PHP allows the entire expression list to be omitted. // TODO: SPEC ERROR: PHP allows the entire expression list to be omitted, // but Hack disallows this behavior. (See SyntaxError.error2038) However, // the Hack spec still states that the argument expression list is optional. // Update the spec to say that the argument expression list is required. let designator = self.parse_designator(); let (left, args, right) = if self.peek_token_kind() == TokenKind::LeftParen { self.parse_expression_list_opt() } else { let pos = self.pos(); let missing1 = self.sc_mut().make_missing(pos); let pos = self.pos(); let missing2 = self.sc_mut().make_missing(pos); let pos = self.pos(); let missing3 = self.sc_mut().make_missing(pos); (missing1, missing2, missing3) }; self.sc_mut() .make_constructor_call(designator, left, args, right) } fn parse_function_call(&mut self, receiver: S::Output) -> S::Output { // SPEC // function-call-expression: // postfix-expression ( argument-expression-list-opt ) let pos = self.pos(); let type_arguments = self.sc_mut().make_missing(pos); let old_enabled = self.allow_as_expressions(); self.allow_as_expressions = true; let (left, args, right) = self.parse_expression_list_opt(); let result = self.sc_mut().make_function_call_expression( receiver, type_arguments, left, args, right, ); self.allow_as_expressions = old_enabled; result } fn parse_variable_or_lambda(&mut self) -> S::Output { let mut parser1 = self.clone(); let variable = parser1.assert_token(TokenKind::Variable); if parser1.peek_token_kind() == TokenKind::EqualEqualGreaterThan { let pos = self.pos(); let attribute_spec = self.sc_mut().make_missing(pos); self.parse_lambda_expression(attribute_spec) } else { self.continue_from(parser1); self.sc_mut().make_variable_expression(variable) } } fn parse_yield_expression(&mut self) -> S::Output { // SPEC: // yield array-element-initializer // let yield_kw = self.assert_token(TokenKind::Yield); match self.peek_token_kind() { TokenKind::Semicolon => { let pos = self.pos(); let missing = self.sc_mut().make_missing(pos); self.sc_mut().make_yield_expression(yield_kw, missing) } _ => { let operand = self.parse_array_element_init(); self.sc_mut().make_yield_expression(yield_kw, operand) } } } pub fn parse_cast_or_parenthesized_or_lambda_expression(&mut self) -> S::Output { // We need to disambiguate between casts, lambdas and ordinary // parenthesized expressions. let mut parser1 = self.clone(); match parser1.possible_cast_expression() { Some((left, cast_type, right)) => { self.continue_from(parser1); let operand = self.parse_expression_with_operator_precedence(Operator::CastOperator); self.sc_mut() .make_cast_expression(left, cast_type, right, operand) } _ => { let mut parser1 = self.clone(); match parser1.possible_lambda_expression() { Some((attribute_spec, async_, signature)) => { self.continue_from(parser1); self.parse_lambda_expression_after_signature( attribute_spec, async_, signature, ) } None => self.parse_parenthesized_expression(), } } } } fn possible_cast_expression(&mut self) -> Option<(S::Output, S::Output, S::Output)> { // SPEC: // cast-expression: // ( cast-type ) unary-expression // cast-type: // bool, double, float, real, int, integer, object, string, binary // // TODO: This implies that a cast "(name)" can only be a simple name, but // I would expect that (\Foo\Bar), (:foo), and the like // should also be legal casts. If we implement that then we will need // a sophisticated heuristic to determine whether this is a cast or a // parenthesized expression. // // The cast expression introduces an ambiguity: (x)-y could be a // subtraction or a cast on top of a unary minus. We resolve this // ambiguity as follows: // // * If the thing in parens is one of the keywords mentioned above, then // it's a cast. // * Otherwise, it's a parenthesized expression. let left_paren = self.assert_token(TokenKind::LeftParen); let type_token = self.next_token(); let type_token_kind = type_token.kind(); let right_paren = self.next_token(); let is_cast = right_paren.kind() == TokenKind::RightParen && match type_token_kind { TokenKind::Bool | TokenKind::Boolean | TokenKind::Double | TokenKind::Float | TokenKind::Real | TokenKind::Int | TokenKind::Integer | TokenKind::String | TokenKind::Binary => true, _ => false, }; if is_cast { let type_token = self.sc_mut().make_token(type_token); let right_paren = self.sc_mut().make_token(right_paren); Some((left_paren, type_token, right_paren)) } else { None } } fn possible_lambda_expression(&mut self) -> Option<(S::Output, S::Output, S::Output)> { // We have a left paren in hand and we already know we're not in a cast. // We need to know whether this is a parenthesized expression or the // signature of a lambda. // // There are a number of difficulties. For example, we cannot simply // check to see if a colon follows the expression: // // $a = $b ? ($x) : ($y) ($x) is parenthesized expression // $a = $b ? ($x) : int ==> 1 : ($y) ($x) is lambda signature // // ERROR RECOVERY: // // What we'll do here is simply attempt to parse a lambda formal parameter // list. If we manage to do so *without error*, and the thing which follows // is ==>, then this is definitely a lambda. If those conditions are not // met then we assume we have a parenthesized expression in hand. // // TODO: There could be situations where we have good evidence that a // lambda is intended but these conditions are not met. Consider // a more sophisticated recovery strategy. For example, if we have // (x)==> then odds are pretty good that a lambda was intended and the // error should say that ($x)==> was expected. let old_errors = self.errors.len(); let pos = self.pos(); let attribute_spec = self.sc_mut().make_missing(pos); let (async_, signature) = self.parse_lambda_header(); if old_errors == self.errors.len() && self.peek_token_kind() == TokenKind::EqualEqualGreaterThan { Some((attribute_spec, async_, signature)) } else { None } } fn parse_lambda_expression(&mut self, attribute_spec: S::Output) -> S::Output { // SPEC // lambda-expression: // async-opt lambda-function-signature ==> lambda-body let (async_, signature) = self.parse_lambda_header(); let arrow = self.require_lambda_arrow(); let body = self.parse_lambda_body(); self.sc_mut() .make_lambda_expression(attribute_spec, async_, signature, arrow, body) } fn parse_lambda_expression_after_signature( &mut self, attribute_spec: S::Output, async_: S::Output, signature: S::Output, ) -> S::Output { // We had a signature with no async, and we disambiguated it // from a cast. let arrow = self.require_lambda_arrow(); let body = self.parse_lambda_body(); self.sc_mut() .make_lambda_expression(attribute_spec, async_, signature, arrow, body) } fn parse_lambda_header(&mut self) -> (S::Output, S::Output) { let async_ = self.optional_token(TokenKind::Async); let signature = self.parse_lambda_signature(); (async_, signature) } fn parse_lambda_signature(&mut self) -> S::Output { // SPEC: // lambda-function-signature: // variable-name // ( anonymous-function-parameter-declaration-list-opt ) / // anonymous-function-return-opt if self.peek_token_kind() == TokenKind::Variable { let token = self.next_token(); self.sc_mut().make_token(token) } else { let (left, params, right) = self.parse_parameter_list_opt(); let contexts = self.with_type_parser(|p: &mut TypeParser<'a, S>| p.parse_contexts()); let (colon, readonly_opt, return_type) = self.parse_optional_return(); self.sc_mut().make_lambda_signature( left, params, right, contexts, colon, readonly_opt, return_type, ) } } fn parse_lambda_body(&mut self) -> S::Output { // SPEC: // lambda-body: // expression // compound-statement if self.peek_token_kind() == TokenKind::LeftBrace { self.parse_compound_statement() } else { self.parse_expression_with_reset_precedence() } } fn parse_parenthesized_expression(&mut self) -> S::Output { let left_paren = self.assert_token(TokenKind::LeftParen); let expression = self.with_as_expressions( /* enabled:*/ true, |p| p.with_reset_precedence(|p| p.parse_expression()), ); let right_paren = self.require_right_paren(); self.sc_mut() .make_parenthesized_expression(left_paren, expression, right_paren) } fn parse_postfix_unary(&mut self, term: S::Output) -> S::Output { let token = self.fetch_token(); let term = self.sc_mut().make_postfix_unary_expression(term, token); self.parse_remaining_expression(term) } fn parse_prefix_unary_expression(&mut self) -> S::Output { // TODO: Operand to ++ and -- must be an lvalue. let token = self.next_token(); let kind = token.kind(); let operator = Operator::prefix_unary_from_token(kind); let token = self.sc_mut().make_token(token); let operand = self.parse_expression_with_operator_precedence(operator); self.sc_mut().make_prefix_unary_expression(token, operand) } pub fn parse_simple_variable(&mut self) -> S::Output { match self.peek_token_kind() { TokenKind::Variable => { let variable = self.next_token(); self.sc_mut().make_token(variable) } TokenKind::Dollar => self.parse_dollar_expression(false), _ => self.require_variable(), } } fn parse_dollar_expression(&mut self, is_term: bool) -> S::Output { let dollar = self.assert_token(TokenKind::Dollar); let operand = match self.peek_token_kind() { TokenKind::LeftBrace if is_term => { return self.parse_et_splice_expression(dollar); } TokenKind::LeftBrace => self.parse_braced_expression(), TokenKind::Variable if self.env.php5_compat_mode => { self.parse_variable_in_php5_compat_mode() } _ => self.parse_expression_with_operator_precedence(Operator::prefix_unary_from_token( TokenKind::Dollar, )), }; self.sc_mut().make_prefix_unary_expression(dollar, operand) } fn parse_is_as_helper<F>(&mut self, left: S::Output, kw: TokenKind, f: F) -> S::Output where F: Fn(&mut Self, S::Output, S::Output, S::Output) -> S::Output, { let op = self.assert_token(kw); let right = self.with_type_parser(|p: &mut TypeParser<'a, S>| p.parse_type_specifier(false, true)); f(self, left, op, right) } fn parse_is_expression(&mut self, left: S::Output) -> S::Output { // SPEC: // is-expression: // is-subject is type-specifier // // is-subject: // expression self.parse_is_as_helper(left, TokenKind::Is, |p, x, y, z| { p.sc_mut().make_is_expression(x, y, z) }) } fn parse_as_expression(&mut self, left: S::Output) -> S::Output { // SPEC: // as-expression: // as-subject as type-specifier // // as-subject: // expression self.parse_is_as_helper(left, TokenKind::As, |p, x, y, z| { p.sc_mut().make_as_expression(x, y, z) }) } fn parse_nullable_as_expression(&mut self, left: S::Output) -> S::Output { // SPEC: // nullable-as-expression: // as-subject ?as type-specifier self.parse_is_as_helper(left, TokenKind::QuestionAs, |p, x, y, z| { p.sc_mut().make_nullable_as_expression(x, y, z) }) } fn parse_upcast_expression(&mut self, left: S::Output) -> S::Output { // SPEC: // upcast-expression: // upcast-subject upcast type-specifier // // upcast-subject: // expression self.parse_is_as_helper(left, TokenKind::Upcast, |p, x, y, z| { p.sc_mut().make_upcast_expression(x, y, z) }) } // Avoid inlining to keep down the stack frame size of recursing functions. #[inline(never)] fn parse_remaining_binary_expression( &mut self, left_term: S::Output, assignment_prefix_kind: BinaryExpressionPrefixKind<(S::Output, Self)>, ) -> S::Output { // We have a left term. If we get here then we know that // we have a binary operator to its right, and that furthermore, // the binary operator is of equal or higher precedence than the // whatever is going on in the left term. // // Here's how this works. Suppose we have something like // // A x B y C // // where A, B and C are terms, and x and y are operators. // We must determine whether this parses as // // (A x B) y C // // or // // A x (B y C) // // We have the former if either x is higher precedence than y, // or x and y are the same precedence and x is left associative. // Otherwise, if x is lower precedence than y, or x is right // associative, then we have the latter. // // How are we going to figure this out? // // We have the term A in hand; the precedence is low. // We see that x follows A. // We obtain the precedence of x. It is higher than the precedence of A, // so we obtain B, and then we call a helper method that // collects together everything to the right of B that is // of higher precedence than x. (Or equal, and right-associative.) // // So, if x is of lower precedence than y (or equal and right-assoc) // then the helper will construct (B y C) as the right term, and then // we'll make A x (B y C), and we're done. Otherwise, the helper // will simply return B, we'll construct (A x B) and recurse with that // as the left term. let is_rhs_of_assignment = assignment_prefix_kind.is_assignment(); assert!(!self.next_is_lower_precedence() || is_rhs_of_assignment); let token = self.next_token(); let operator = Operator::trailing_from_token(token.kind()); let precedence = operator.precedence(&self.env); let token = self.sc_mut().make_token(token); let right_term = if is_rhs_of_assignment { // reset the current precedence to make sure that expression on // the right hand side of the assignment is fully consumed self.with_reset_precedence(|p| p.parse_term()) } else { self.parse_term() }; let right_term = self.parse_remaining_binary_expression_helper(right_term, precedence); self.sc_mut() .make_binary_expression(left_term, token, right_term) } fn parse_remaining_binary_expression_helper( &mut self, right_term: S::Output, left_precedence: usize, ) -> S::Output { // This gathers up terms to the right of an operator that are // operands of operators of higher precedence than the // operator to the left. For instance, if we have // A + B * C / D + E and we just parsed A +, then we want to // gather up B * C / D into the right side of the +. // In this case "right term" would be B and "left precedence" // would be the precedence of +. // See comments above for more details. let kind = self.peek_token_kind(); if Operator::is_trailing_operator_token(kind) && (kind != TokenKind::As || self.allow_as_expressions()) { let right_operator = Operator::trailing_from_token(kind); let right_precedence = right_operator.precedence(&self.env); let associativity = right_operator.associativity(&self.env); // check if this is the case ... $a = ... // where // 'left_precedence' - precedence of the operation on the left of $a // 'right_term' - $a // 'kind' - operator that follows right_term // // in case if right_term is valid left hand side for the assignment // and token is assignment operator and left_precedence is less than // bumped priority for the assignment we reset precedence before parsing // right hand side of the assignment to make sure it is consumed. match self.check_if_should_override_normal_precedence( &right_term, kind, left_precedence, ) { BinaryExpressionPrefixKind::PrefixLessThan(_) => { let old_precedence = self.precedence; let right_term = { self.with_precedence(left_precedence); self.parse_remaining_expression(right_term) }; self.with_precedence(old_precedence); self.parse_remaining_binary_expression_helper(right_term, left_precedence) } BinaryExpressionPrefixKind::PrefixAssignment => { let old_precedence = self.precedence; let right_term = self.with_reset_precedence(|p| p.parse_remaining_expression(right_term)); self.with_precedence(old_precedence); self.parse_remaining_binary_expression_helper(right_term, left_precedence) } BinaryExpressionPrefixKind::PrefixNone if right_precedence > left_precedence || (associativity == Assoc::RightAssociative && right_precedence == left_precedence) => { let old_precedence = self.precedence; let right_term = { self.with_precedence(right_precedence); self.parse_remaining_expression(right_term) }; self.with_precedence(old_precedence); self.parse_remaining_binary_expression_helper(right_term, left_precedence) } BinaryExpressionPrefixKind::PrefixNone => right_term, } } else { right_term } } fn parse_conditional_expression(&mut self, test: S::Output, question: S::Output) -> S::Output { // POSSIBLE SPEC PROBLEM // We allow any expression, including assignment expressions, to be in // the consequence and alternative of a conditional expression, even // though assignment is lower precedence than ?:. This is legal: // $a ? $b = $c : $d = $e // Interestingly, this is illegal in C and Java, which require parens, // but legal in C let kind = self.peek_token_kind(); // ERROR RECOVERY // e1 ?: e2 is legal and we parse it as a binary expression. However, // it is possible to treat it degenerately as a conditional with no // consequence. This introduces an ambiguity // x ? :y::m : z // Is that // x ?: y::m : z [1] // or // x ? :y::m : z [2] // // First consider a similar expression // x ? : y::m // If we assume XHP class names cannot have a space after the : , then // this only has one interpretation // x ?: y::m // // The first example also resolves cleanly to [2]. To reduce confusion, // we report an error for the e1 ? : e2 construction in a later pass. // // TODO: Add this to the XHP draft specification. let missing_consequence = kind == TokenKind::Colon && !(self.is_next_xhp_class_name()); let consequence = if missing_consequence { let pos = self.pos(); self.sc_mut().make_missing(pos) } else { self.with_reset_precedence(|p| p.parse_expression()) }; let colon = self.require_colon(); let term = self.parse_term(); let precedence = Operator::ConditionalQuestionOperator.precedence(&self.env); let alternative = self.parse_remaining_binary_expression_helper(term, precedence); self.sc_mut() .make_conditional_expression(test, question, consequence, colon, alternative) } /// Parse a name, a collection literal like vec[1, 2] or an /// expression tree literal Code`1`; fn parse_name_or_collection_literal_expression(&mut self, name: S::Output) -> S::Output { match self.peek_token_kind_with_possible_attributized_type_list() { TokenKind::LeftBrace => { let name = self.sc_mut().make_simple_type_specifier(name); self.parse_collection_literal_expression(name) } TokenKind::LessThan => { let mut parser1 = self.clone(); let (type_arguments, no_arg_is_missing) = parser1.parse_generic_type_arguments(); if no_arg_is_missing && self.errors.len() == parser1.errors.len() && parser1.peek_token_kind() == TokenKind::LeftBrace { self.continue_from(parser1); let name = self .sc_mut() .make_generic_type_specifier(name, type_arguments); self.parse_collection_literal_expression(name) } else { name } } TokenKind::LeftBracket => name, TokenKind::Backtick => { if self.in_expression_tree() { // If we see Foo` whilst parsing an expression tree // literal, it's a constant followed by a closing // backtick. For example: Bar`1 + Foo` name } else { // Opening backtick of an expression tree literal. let prefix = self.sc_mut().make_simple_type_specifier(name); let left_backtick = self.require_token(TokenKind::Backtick, Errors::error1065); self.in_expression_tree = true; let body = self.parse_lambda_body(); self.in_expression_tree = false; let right_backtick = self.require_token(TokenKind::Backtick, Errors::error1065); self.sc_mut().make_prefixed_code_expression( prefix, left_backtick, body, right_backtick, ) } } _ => name, } } fn parse_collection_literal_expression(&mut self, name: S::Output) -> S::Output { // SPEC // collection-literal: // key-collection-class-type { cl-initializer-list-with-keys-opt } // non-key-collection-class-type { cl-initializer-list-without-keys-opt } // pair-type { cl-element-value , cl-element-value } // // The types are grammatically qualified names; however the specification // states that they must be as follows: // * keyed collection type can be Map or ImmMap // * non-keyed collection type can be Vector, ImmVector, Set or ImmSet // * pair type can be Pair // // We will not attempt to determine if the names give the name of an // appropriate type here. That's for the type checker. // // The argumment lists are: // // * for keyed, an optional comma-separated list of // expression => expression pairs // * for non-keyed, an optional comma-separated list of expressions // * for pairs, a comma-separated list of exactly two expressions // // In all three cases, the lists may be comma-terminated. // TODO: This fact is not represented in the specification; it should be. // This work item is tracked by spec issue #109. let (left_brace, initialization_list, right_brace) = self.parse_braced_comma_list_opt_allow_trailing(|p| p.parse_init_expression()); // Validating the name is a collection type happens in a later phase self.sc_mut().make_collection_literal_expression( name, left_brace, initialization_list, right_brace, ) } fn parse_init_expression(&mut self) -> S::Output { // ERROR RECOVERY // We expect either a list of expr, expr, expr, ... or // expr => expr, expr => expr, expr => expr, ... // Rather than require at parse time that the list be all one or the other, // we allow both, and give an error in the type checker. let expr1 = self.parse_expression_with_reset_precedence(); if self.peek_token_kind() == TokenKind::EqualGreaterThan { let token = self.next_token(); let arrow = self.sc_mut().make_token(token); let expr2 = self.parse_expression_with_reset_precedence(); self.sc_mut().make_element_initializer(expr1, arrow, expr2) } else { expr1 } } fn parse_keyed_element_initializer(&mut self) -> S::Output { let expr1 = self.parse_expression_with_reset_precedence(); let arrow = self.require_arrow(); let expr2 = self.parse_expression_with_reset_precedence(); self.sc_mut().make_element_initializer(expr1, arrow, expr2) } fn parse_list_expression(&mut self) -> S::Output { // SPEC: // list-intrinsic: // list ( expression-list-opt ) // expression-list: // expression-opt // expression-list , expression-opt // // See https://github.com/hhvm/hack-langspec/issues/82 // // list-intrinsic must be used as the left-hand operand in a // simple-assignment-expression of which the right-hand operand // must be an expression that designates a vector-like array or // an instance of the class types Vector, ImmVector, or Pair // (the "source"). // // TODO: Produce an error later if the expressions in the list destructuring // are not lvalues. let keyword = self.assert_token(TokenKind::List); let (left, items, right) = self.parse_parenthesized_comma_list_opt_items_opt(|p| { p.parse_expression_with_reset_precedence() }); self.sc_mut() .make_list_expression(keyword, left, items, right) } fn parse_bracketed_collection_intrinsic_expression<F, G>( &mut self, keyword_token: TokenKind, parse_element_function: F, make_intrinsic_function: G, ) -> S::Output where F: Fn(&mut Self) -> S::Output, G: Fn(&mut Self, S::Output, S::Output, S::Output, S::Output, S::Output) -> S::Output, { let mut parser1 = self.clone(); let keyword = parser1.assert_token(keyword_token); let explicit_type = match parser1.peek_token_kind_with_possible_attributized_type_list() { TokenKind::LessThan => { let (type_arguments, _) = parser1.parse_generic_type_arguments(); // skip no_arg_is_missing check since there must only be 1 or 2 type arguments type_arguments } _ => { let pos = parser1.pos(); parser1.sc_mut().make_missing(pos) } }; let left_bracket = parser1.optional_token(TokenKind::LeftBracket); if left_bracket.is_missing() { // Fall back to dict being an ordinary name. Perhaps we're calling a // function whose name is indicated by the keyword_token, for example. self.parse_as_name_or_error() } else { self.continue_from(parser1); let members = self.parse_comma_list_opt_allow_trailing( TokenKind::RightBracket, Errors::error1015, parse_element_function, ); let right_bracket = self.require_right_bracket(); make_intrinsic_function( self, keyword, explicit_type, left_bracket, members, right_bracket, ) } } fn parse_darray_intrinsic_expression(&mut self) -> S::Output { // TODO: Create the grammar and add it to the spec. self.parse_bracketed_collection_intrinsic_expression( TokenKind::Darray, |p| p.parse_keyed_element_initializer(), |p, a, b, c, d, e| p.sc_mut().make_darray_intrinsic_expression(a, b, c, d, e), ) } fn parse_dictionary_intrinsic_expression(&mut self) -> S::Output { // TODO: Create the grammar and add it to the spec. // TODO: Can the list have a trailing comma? self.parse_bracketed_collection_intrinsic_expression( TokenKind::Dict, |p| p.parse_keyed_element_initializer(), |p, a, b, c, d, e| { p.sc_mut() .make_dictionary_intrinsic_expression(a, b, c, d, e) }, ) } fn parse_keyset_intrinsic_expression(&mut self) -> S::Output { self.parse_bracketed_collection_intrinsic_expression( TokenKind::Keyset, |p| p.parse_expression_with_reset_precedence(), |p, a, b, c, d, e| p.sc_mut().make_keyset_intrinsic_expression(a, b, c, d, e), ) } fn parse_varray_intrinsic_expression(&mut self) -> S::Output { // TODO: Create the grammar and add it to the spec. self.parse_bracketed_collection_intrinsic_expression( TokenKind::Varray, |p| p.parse_expression_with_reset_precedence(), |p, a, b, c, d, e| p.sc_mut().make_varray_intrinsic_expression(a, b, c, d, e), ) } fn parse_vector_intrinsic_expression(&mut self) -> S::Output { // TODO: Create the grammar and add it to the spec. // TODO: Can the list have a trailing comma? self.parse_bracketed_collection_intrinsic_expression( TokenKind::Vec, |p| p.parse_expression_with_reset_precedence(), |p, a, b, c, d, e| p.sc_mut().make_vector_intrinsic_expression(a, b, c, d, e), ) } // array-element-initializer := // expression // expression => expression fn parse_array_element_init(&mut self) -> S::Output { let expr1 = self.with_reset_precedence(|p| p.parse_expression()); match self.peek_token_kind() { TokenKind::EqualGreaterThan => { let token = self.next_token(); let arrow = self.sc_mut().make_token(token); let expr2 = self.with_reset_precedence(|p| p.parse_expression()); self.sc_mut().make_element_initializer(expr1, arrow, expr2) } _ => expr1, } } fn parse_field_initializer(&mut self) -> S::Output { // SPEC // field-initializer: // single-quoted-string-literal => expression // double_quoted_string_literal => expression // qualified-name => expression // scope-resolution-expression => expression // // Specification is wrong, and fixing it is being tracked by // https://github.com/hhvm/hack-langspec/issues/108 // // ERROR RECOVERY: We allow any expression on the left-hand side, // even though only some expressions are legal; // we will give an error in a later pass let name = self.with_reset_precedence(|p| p.parse_expression()); let arrow = self.require_arrow(); let value = self.with_reset_precedence(|p| p.parse_expression()); self.sc_mut().make_field_initializer(name, arrow, value) } fn parse_shape_expression(&mut self) -> S::Output { // SPEC // shape-literal: // shape ( field-initializer-list-opt ) // // field-initializer-list: // field-initializers ,-op // // field-initializers: // field-initializer // field-initializers , field-initializer let shape = self.assert_token(TokenKind::Shape); let (left_paren, fields, right_paren) = self.parse_parenthesized_comma_list_opt_allow_trailing(|p| p.parse_field_initializer()); self.sc_mut() .make_shape_expression(shape, left_paren, fields, right_paren) } fn parse_tuple_expression(&mut self) -> S::Output { // SPEC // tuple-literal: // tuple ( expression-list-one-or-more ) // // expression-list-one-or-more: // expression // expression-list-one-or-more , expression // // TODO: Can the list be comma-terminated? If so, update the spec. // TODO: We need to produce an error in a later pass if the list is empty. let keyword = self.assert_token(TokenKind::Tuple); let (left_paren, items, right_paren) = self .parse_parenthesized_comma_list_opt_allow_trailing(|p| { p.parse_expression_with_reset_precedence() }); self.sc_mut() .make_tuple_expression(keyword, left_paren, items, right_paren) } fn parse_use_variable(&mut self) -> S::Output { self.require_variable() } fn parse_anon_or_lambda_or_awaitable(&mut self) -> S::Output { // TODO: The original Hack parser accepts "async" as an identifier, and // so we do too. We might consider making it reserved. // Skip any async declarations that may be present. When we // feed the original parser into the syntax parsers. they will take care of // them as appropriate. let parser1 = self.clone(); let attribute_spec = self.with_decl_parser(|p| p.parse_attribute_specification_opt()); let mut parser2 = self.clone(); let _ = parser2.optional_token(TokenKind::Async); match parser2.peek_token_kind() { TokenKind::Function => self.parse_anon(attribute_spec), TokenKind::LeftBrace => self.parse_async_block(attribute_spec), TokenKind::Variable | TokenKind::LeftParen => { self.parse_lambda_expression(attribute_spec) } _ => { self.continue_from(parser1); let async_as_name = self.next_token_as_name(); self.sc_mut().make_token(async_as_name) } } } fn parse_async_block(&mut self, attribute_spec: S::Output) -> S::Output { // grammar: // awaitable-creation-expression : // async-opt compound-statement // TODO awaitable-creation-expression must not be used as the // anonymous-function-body in a lambda-expression let async_ = self.optional_token(TokenKind::Async); let stmt = self.parse_compound_statement(); self.sc_mut() .make_awaitable_creation_expression(attribute_spec, async_, stmt) } fn parse_anon_use_opt(&mut self) -> S::Output { // SPEC: // anonymous-function-use-clause: // use ( use-variable-name-list ,-opt ) // // use-variable-name-list: // variable-name // use-variable-name-list , variable-name let use_token = self.optional_token(TokenKind::Use); if use_token.is_missing() { use_token } else { let (left, vars, right) = self.parse_parenthesized_comma_list_opt_allow_trailing(|p| p.parse_use_variable()); self.sc_mut() .make_anonymous_function_use_clause(use_token, left, vars, right) } } fn parse_optional_readonly(&mut self) -> S::Output { self.optional_token(TokenKind::Readonly) } fn parse_optional_return(&mut self) -> (S::Output, S::Output, S::Output) { // Parse an optional "colon-folowed-by-return-type" let colon = self.optional_token(TokenKind::Colon); let (readonly_opt, return_type) = if colon.is_missing() { let pos = self.pos(); let missing1 = self.sc_mut().make_missing(pos); let pos = self.pos(); let missing2 = self.sc_mut().make_missing(pos); (missing1, missing2) } else { let readonly = self.parse_optional_readonly(); // If readonly keyword is present, return type can be missing let return_type = if readonly.is_missing() { self.with_type_parser(|p| p.parse_return_type()) } else { self.with_type_parser(|p| p.parse_return_type_opt()) }; (readonly, return_type) }; (colon, readonly_opt, return_type) } fn parse_anon(&mut self, attribute_spec: S::Output) -> S::Output { // SPEC // anonymous-function-creation-expression: // async-opt function // ( anonymous-function-parameter-list-opt ) // anonymous-function-return-opt // anonymous-function-use-clauseopt // compound-statement // // An anonymous function's formal parameter list is the same as a named // function's formal parameter list except that types are optional. // The "..." syntax and trailing commas are supported. We'll simply // parse an optional parameter list; it already takes care of making the // type annotations optional. let async_ = self.optional_token(TokenKind::Async); let fn_ = self.assert_token(TokenKind::Function); let (left_paren, params, right_paren) = self.parse_parameter_list_opt(); let ctx_list = self.with_type_parser(|p| p.parse_contexts()); let (colon, readonly_opt, return_type) = self.parse_optional_return(); let use_clause = self.parse_anon_use_opt(); // Detect if the user has the type in the wrong place // function() use(): T // wrong // function(): T use() // correct if !use_clause.is_missing() { let misplaced_colon = self.clone().optional_token(TokenKind::Colon); if !misplaced_colon.is_missing() { self.with_error(Cow::Borrowed( "Bad signature: use(...) should occur after the type", )); } } let body = self.parse_compound_statement(); self.sc_mut().make_anonymous_function( attribute_spec, async_, fn_, left_paren, params, right_paren, ctx_list, colon, readonly_opt, return_type, use_clause, body, ) } fn parse_et_splice_expression(&mut self, dollar: S::Output) -> S::Output { let left_brace = self.assert_token(TokenKind::LeftBrace); let expression = self.parse_expression_with_reset_precedence(); let right_brace = self.require_right_brace(); self.sc_mut() .make_et_splice_expression(dollar, left_brace, expression, right_brace) } fn parse_braced_expression(&mut self) -> S::Output { let left_brace = self.assert_token(TokenKind::LeftBrace); let expression = self.parse_expression_with_reset_precedence(); let right_brace = self.require_right_brace(); self.sc_mut() .make_braced_expression(left_brace, expression, right_brace) } fn require_right_brace_xhp(&mut self) -> S::Output { // do not consume trailing trivia for the right brace // it should be accounted as XHP text let mut parser1 = self.clone(); let token = parser1.next_token_no_trailing(); if token.kind() == TokenKind::RightBrace { self.continue_from(parser1); self.sc_mut().make_token(token) } else { // ERROR RECOVERY: Create a missing token for the expected token, // and continue on from the current token. Don't skip it. self.with_error(Errors::error1006); let pos = self.pos(); self.sc_mut().make_missing(pos) } } fn parse_xhp_body_braced_expression(&mut self) -> S::Output { // The difference between a regular braced expression and an // XHP body braced expression is: // <foo bar={$x}/*this_is_a_comment*/>{$y}/*this_is_body_text!*/</foo> let left_brace = self.assert_token(TokenKind::LeftBrace); let expression = self.parse_expression_with_reset_precedence(); let right_brace = self.require_right_brace_xhp(); self.sc_mut() .make_braced_expression(left_brace, expression, right_brace) } fn next_xhp_element_token(&mut self, no_trailing: bool) -> (Token<S>, &[u8]) { self.lexer_mut().next_xhp_element_token(no_trailing) } fn next_xhp_body_token(&mut self) -> Token<S> { self.lexer_mut().next_xhp_body_token() } fn parse_xhp_attribute(&mut self) -> Option<S::Output> { let mut parser1 = self.clone(); let (token, _) = parser1.next_xhp_element_token(false); match token.kind() { TokenKind::LeftBrace => self.parse_xhp_spread_attribute(), TokenKind::XHPElementName => { self.continue_from(parser1); let token = self.sc_mut().make_token(token); self.parse_xhp_simple_attribute(token) } _ => None, } } fn parse_xhp_spread_attribute(&mut self) -> Option<S::Output> { let (left_brace, _) = self.next_xhp_element_token(false); let left_brace = self.sc_mut().make_token(left_brace); let ellipsis = self.require_token(TokenKind::DotDotDot, Errors::expected_dotdotdot); let expression = self.parse_expression_with_reset_precedence(); let right_brace = self.require_right_brace(); let node = self.sc_mut() .make_xhp_spread_attribute(left_brace, ellipsis, expression, right_brace); Some(node) } fn parse_xhp_simple_attribute(&mut self, name: S::Output) -> Option<S::Output> { // Parse the attribute name and then defensively check for well-formed // attribute assignment let mut parser1 = self.clone(); let (token, _) = parser1.next_xhp_element_token(false); if token.kind() != TokenKind::Equal { self.with_error(Errors::error1016); self.continue_from(parser1); let pos = self.pos(); let missing1 = self.sc_mut().make_missing(pos); let pos = self.pos(); let missing2 = self.sc_mut().make_missing(pos); let node = self .sc_mut() .make_xhp_simple_attribute(name, missing1, missing2); // ERROR RECOVERY: The = is missing; assume that the name belongs // to the attribute, but that the remainder is missing, and start // looking for the next attribute. Some(node) } else { let equal = parser1.sc_mut().make_token(token); let mut parser2 = parser1.clone(); let (token, _text) = parser2.next_xhp_element_token(false); match token.kind() { TokenKind::XHPStringLiteral => { self.continue_from(parser2); let token = self.sc_mut().make_token(token); let node = self.sc_mut().make_xhp_simple_attribute(name, equal, token); Some(node) } TokenKind::LeftBrace => { self.continue_from(parser1); let expr = self.parse_braced_expression(); let node = self.sc_mut().make_xhp_simple_attribute(name, equal, expr); Some(node) } _ => { // ERROR RECOVERY: The expression is missing; assume that the "name =" // belongs to the attribute and start looking for the next attribute. self.continue_from(parser1); self.with_error(Errors::error1017); self.continue_from(parser2); let pos = self.pos(); let missing = self.sc_mut().make_missing(pos); let node = self .sc_mut() .make_xhp_simple_attribute(name, equal, missing); Some(node) } } } } fn parse_xhp_body_element(&mut self) -> Option<S::Output> { let mut parser1 = self.clone(); let token = parser1.next_xhp_body_token(); match token.kind() { TokenKind::XHPComment | TokenKind::XHPBody => { self.continue_from(parser1); let token = self.sc_mut().make_token(token); Some(token) } TokenKind::LeftBrace => { let expr = self.parse_xhp_body_braced_expression(); Some(expr) } TokenKind::RightBrace => { // If we find a free-floating right-brace in the middle of an XHP body // that's just fine. It's part of the text. However, it is also likely // to be a mis-edit, so we'll keep it as a right-brace token so that // tooling can flag it as suspicious. self.continue_from(parser1); let token = self.sc_mut().make_token(token); Some(token) } TokenKind::LessThan => { self.continue_from(parser1); let expr = self.parse_possible_xhp_expression(/* ~in_xhp_body:*/ true, token); Some(expr) } _ => None, } } fn parse_xhp_close(&mut self, consume_trailing_trivia: bool) -> S::Output { let (less_than_slash, _) = self.next_xhp_element_token(false); let less_than_slash_token_kind = less_than_slash.kind(); let less_than_slash_token = self.sc_mut().make_token(less_than_slash); if less_than_slash_token_kind == TokenKind::LessThanSlash { let mut parser1 = self.clone(); let (name, _name_text) = parser1.next_xhp_element_token(false); if name.kind() == TokenKind::XHPElementName { let name_token = parser1.sc_mut().make_token(name); // TODO: Check that the given and name_text are the same. let mut parser2 = parser1.clone(); let (greater_than, _) = parser2.next_xhp_element_token(!consume_trailing_trivia); if greater_than.kind() == TokenKind::GreaterThan { self.continue_from(parser2); let greater_than_token = self.sc_mut().make_token(greater_than); self.sc_mut().make_xhp_close( less_than_slash_token, name_token, greater_than_token, ) } else { // ERROR RECOVERY: self.continue_from(parser1); self.with_error(Errors::error1039); let pos = self.pos(); let missing = self.sc_mut().make_missing(pos); self.sc_mut() .make_xhp_close(less_than_slash_token, name_token, missing) } } else { // ERROR RECOVERY: self.with_error(Errors::error1039); let pos = self.pos(); let missing1 = self.sc_mut().make_missing(pos); let pos = self.pos(); let missing2 = self.sc_mut().make_missing(pos); self.sc_mut() .make_xhp_close(less_than_slash_token, missing1, missing2) } } else { // ERROR RECOVERY: We probably got a < without a following / or name. // TODO: For now we'll just bail out. We could use a more // sophisticated strategy here. self.with_error(Errors::error1039); let pos = self.pos(); let missing1 = self.sc_mut().make_missing(pos); let pos = self.pos(); let missing2 = self.sc_mut().make_missing(pos); self.sc_mut() .make_xhp_close(less_than_slash_token, missing1, missing2) } } fn parse_xhp_expression( &mut self, consume_trailing_trivia: bool, left_angle: S::Output, name: S::Output, ) -> S::Output { let attrs = self.parse_list_until_none(|p| p.parse_xhp_attribute()); let mut parser1 = self.clone(); let (token, _) = parser1.next_xhp_element_token(/*no_trailing:*/ true); match token.kind() { TokenKind::SlashGreaterThan => { let pos = self.pos(); // We have determined that this is a self-closing XHP tag, so // `consume_trailing_trivia` needs to be propagated down. let (token, _) = self.next_xhp_element_token(/* ~no_trailing:*/ !consume_trailing_trivia); let token = self.sc_mut().make_token(token); let xhp_open = self.sc_mut().make_xhp_open(left_angle, name, attrs, token); let missing1 = self.sc_mut().make_missing(pos); let missing2 = self.sc_mut().make_missing(pos); self.sc_mut() .make_xhp_expression(xhp_open, missing1, missing2) } TokenKind::GreaterThan => { // This is not a self-closing tag, so we are now in an XHP body context. // We can use the GreaterThan token as-is (i.e., lexed above with // ~no_trailing:true), since we don't want to lex trailing trivia inside // XHP bodies. self.continue_from(parser1); let token = self.sc_mut().make_token(token); let xhp_open = self.sc_mut().make_xhp_open(left_angle, name, attrs, token); let xhp_body = self.parse_list_until_none(|p| p.parse_xhp_body_element()); let xhp_close = self.parse_xhp_close(consume_trailing_trivia); self.sc_mut() .make_xhp_expression(xhp_open, xhp_body, xhp_close) } _ => { // ERROR RECOVERY: Assume the unexpected token belongs to whatever // comes next. let pos = self.pos(); let missing = self.sc_mut().make_missing(pos); let xhp_open = self .sc_mut() .make_xhp_open(left_angle, name, attrs, missing); let pos = self.pos(); let missing1 = parser1.sc_mut().make_missing(pos); let pos = self.pos(); let missing2 = parser1.sc_mut().make_missing(pos); self.continue_from(parser1); self.with_error(Errors::error1013); self.sc_mut() .make_xhp_expression(xhp_open, missing1, missing2) } } } fn parse_possible_xhp_expression( &mut self, in_xhp_body: bool, less_than: Token<S>, ) -> S::Output { // We got a < token where an expression was expected. //println!("assert_xhp_body_token start {}|", self.lexer().offset_as_string()); let less_than = self.sc_mut().make_token(less_than); //println!("assert_xhp_body_token end {}|", self.lexer().offset_as_string()); let mut parser1 = self.clone(); let (name, _text) = parser1.next_xhp_element_token(false); if name.kind() == TokenKind::XHPElementName { self.continue_from(parser1); let token = self.sc_mut().make_token(name); self.parse_xhp_expression(!in_xhp_body, less_than, token) } else { // ERROR RECOVERY // In an expression context, it's hard to say what to do here. We are // expecting an expression, so we could simply produce an error for the < and // call that the expression. Or we could assume the the left side of an // inequality is missing, give a missing node for the left side, and parse // the remainder as the right side. We'll go for the former for now. // // In an XHP body context, we certainly expect a name here, because the < // could only legally be the first token in another XHPExpression. let error = if in_xhp_body { Errors::error1004 } else { Errors::error1015 }; self.with_error(error); less_than } } fn parse_anon_or_awaitable_or_scope_resolution_or_name(&mut self) -> S::Output { // static is a legal identifier, if next token is scope resolution operatpr // - parse expresson as scope resolution operator, otherwise try to interpret // it as anonymous function (will fallback to name in case of failure) if self.peek_token_kind_with_lookahead(1) == TokenKind::ColonColon { self.parse_scope_resolution_or_name() } else { // allow_attribute_spec since we end up here after seeing static self.parse_anon_or_lambda_or_awaitable() } } fn parse_scope_resolution_or_name(&mut self) -> S::Output { // parent, self and static are legal identifiers. If the next // thing that follows is a scope resolution operator, parse them as // ordinary tokens, and then we'll pick them up as the operand to the // scope resolution operator when we call parse_remaining_expression. // Otherwise, parse them as ordinary names. let mut parser1 = self.clone(); let qualifier = parser1.next_token(); if parser1.peek_token_kind() == TokenKind::ColonColon { self.continue_from(parser1); self.sc_mut().make_token(qualifier) } else { let parent_or_self_or_static_as_name = self.next_token_as_name(); self.sc_mut().make_token(parent_or_self_or_static_as_name) } } fn parse_scope_resolution_expression(&mut self, qualifier: S::Output) -> S::Output { // SPEC // scope-resolution-expression: // scope-resolution-qualifier :: name // scope-resolution-qualifier :: class // // scope-resolution-qualifier: // qualified-name // variable-name // self // parent // static // // TODO: The left hand side can in fact be any expression in this parser; // we need to add a later error pass to detect that the left hand side is // a valid qualifier. // TODO: The right hand side, if a name or a variable, is treated as a // name or variabletoken* and not a name or variable *expression*. Is // that the desired tree topology? Give this more thought; it might impact // rename refactoring semantics. let op = self.require_coloncolon(); let name = { let mut parser1 = self.clone(); let token = parser1.next_token(); match token.kind() { TokenKind::Class => { self.continue_from(parser1); self.sc_mut().make_token(token) } TokenKind::Dollar => self.parse_dollar_expression(false), TokenKind::LeftBrace => self.parse_braced_expression(), TokenKind::Variable if self.env.php5_compat_mode => { let mut parser1 = self.clone(); let e = parser1.parse_variable_in_php5_compat_mode(); // for :: only do PHP5 transform for call expressions // in other cases fall back to the regular parsing logic if parser1.peek_token_kind() == TokenKind::LeftParen && // make sure the left parenthesis means a call // for the expression we are currently parsing, and // are not for example for a constructor call whose // name would be the result of this expression. !(self.operator_has_lower_precedence(TokenKind::LeftParen)) { self.continue_from(parser1); e } else { self.require_name_or_variable_or_error(Errors::error1048) } } _ => self.require_name_or_variable_or_error(Errors::error1048), } }; self.sc_mut() .make_scope_resolution_expression(qualifier, op, name) } fn parse_enum_class_label_expression(&mut self, qualifier: S::Output) -> S::Output { // SPEC // enum-class-label-expression: // enum-class-label-qualifier # name // // enum-class-label-expression: // qualified-name let hash = self.assert_token(TokenKind::Hash); let label_name = self.require_name_allow_all_keywords(); self.sc_mut() .make_enum_class_label_expression(qualifier, hash, label_name) } }