1 // Copyright (c) Facebook, Inc. and its affiliates.
3 // This source code is licensed under the MIT license found in the
4 // LICENSE file in the "hack" directory of this source tree.
6 use crate::source_text::SourceText;
8 // SyntaxTrait defines basic functionality implemented by each Syntax. It corresponds to
9 // Syntax_sig::Syntax_S in OCaml implementation. It's a trait and not an inherent implementation,
10 // because different syntaxes have different data to work with; for example full_width is already
11 // cached inside PositionedSyntax, while MinimalSyntax will have to iterate through entire subtree
13 // Because of bugs in implementation and nothing ever enforcing it, in practice the values often
14 // will be different depending on the syntax, so be careful.
15 pub trait SyntaxTrait {
16 fn offset(&self) -> Option<usize>;
17 fn width(&self) -> usize;
18 fn leading_width(&self) -> usize;
19 fn trailing_width(&self) -> usize;
20 fn full_width(&self) -> usize;
21 fn leading_start_offset(&self) -> usize;
22 fn extract_text<'a>(&self, source_text: &'a SourceText) -> Option<&'a str>;