Something went wrong. Try again.
Actually just three programming languages in a trenchcoat
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263use super::*;use crate::{Parser, Spanned};use source_span::Span;use trilogy_scanner::{Token, TokenType::*};
/// The pre- and post-amble of the Trilogy file.#[derive(Clone, Debug, PrettyPrintSExpr)]pub(crate) struct Amble { pub start_of_file: Token, pub content: Document, pub end_of_file: Token,}
impl Spanned for Amble { fn span(&self) -> Span { self.start_of_file.span.union(self.end_of_file.span) }}
impl Amble { pub(crate) fn parse(parser: &mut Parser) -> Self { let start_of_file = parser .expect(StartOfFile) .expect("input should start with `StartOfFile`");
if let Ok(token) = parser.expect(ByteOrderMark) { #[cfg(feature = "lax")] parser.warn(SyntaxError::new( token.span, "the file contains a byte-order mark", ));
#[cfg(not(feature = "lax"))] parser.error(SyntaxError::new( token.span, "the file contains a byte-order mark", )); }
let content = Document::parse(parser);
let end_of_file = parser .expect(EndOfFile) .expect("input should end with `EndOfFile`");
Self { start_of_file, content, end_of_file, } }}
#[cfg(test)]mod test { use super::*;
test_parse_whole!(amble_empty: "" => Amble::parse => "(Amble _ (Document () []) _)"); test_parse_whole!(amble_empty_newline: "\n" => Amble::parse => "(Amble _ (Document () []) _)"); test_parse_whole_error!(amble_empty_bom: "\u{feff}" => Amble::parse => "the file contains a byte-order mark"); test_parse_whole_error!(amble_empty_bom_newline: "\u{feff}\n" => Amble::parse => "the file contains a byte-order mark");}