pub fn parse_mode(text: &SourceText<'_>) -> (Language, Option<Mode>) {
    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(Mode::Mhhi))
                                } else {
                                    (Language::Hack, Some(Mode::Mstrict))
                                }
                            }
                        }
                    }
                    _ => {
                        // unreachable (parser either returns a value that matches
                        // the above expressions, or None)
                        (Language::Hack, Some(Mode::Mstrict))
                    }
                }
            }
            // unreachable (parser either returns a value that matches
            // the above expression, or None)
            _ => (Language::Hack, Some(Mode::Mstrict)),
        }
    } else {
        (Language::Hack, Some(Mode::Mstrict))
    }
}
// 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.
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.
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<Mode>) {
    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(Mode::Mhhi))
                                } else {
                                    (Language::Hack, Some(Mode::Mstrict))
                                }
                            }
                        }
                    }
                    _ => {
                        // unreachable (parser either returns a value that matches
                        // the above expressions, or None)
                        (Language::Hack, Some(Mode::Mstrict))
                    }
                }
            }
            // unreachable (parser either returns a value that matches
            // the above expression, or None)
            _ => (Language::Hack, Some(Mode::Mstrict)),
        }
    } else {
        (Language::Hack, Some(Mode::Mstrict))
    }
}
pub fn parse_mode ( text : & SourceText < ' _ > ) -> ( Language , Option < Mode > ) { 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 ( " " ) { ( Language :: Hack , Some ( Mode :: Mhhi ) ) } else { ( Language :: Hack , Some ( Mode :: Mstrict ) ) } } } } _ => { // unreachable (parser either returns a value that matches // the above expressions, or None) ( Language :: Hack , Some ( Mode :: Mstrict ) ) } } } // unreachable (parser either returns a value that matches // the above expression, or None) _ => ( Language :: Hack , Some ( Mode :: Mstrict ) ) , } } else { ( Language :: Hack , Some ( Mode :: Mstrict ) ) } }
Returns Language::PHP if text is a PHP file (has .php extension and starts
with anything other than <?hh).
Returns Language :: PHP if text is a PHP file ( has . php extension and starts with anything other than <?hh ) .
text
&SourceText<'_>
text
&SourceText<'_>