1#![allow(dead_code, unused_variables)]
2use std::ops::Range;
5
6pub mod codegen;
8pub mod compiler;
9pub mod converter;
10pub mod error;
11pub mod flags;
12pub mod parser;
13pub mod scanner;
14pub mod transformer;
15#[macro_use]
16pub mod util;
17
18#[cfg(feature = "serde")]
19use serde::Serialize;
20
21pub type Name<'a> = &'a str;
24
25#[derive(PartialEq, Eq, Clone)]
26pub struct Position {
27 pub offset: usize,
29 pub line: u32,
31 pub column: u32,
33}
34
35#[cfg(feature = "serde")]
36impl Serialize for Position {
37 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
38 where
39 S: serde::Serializer,
40 {
41 let s = format!(
42 "Pos: {}, Ln: {}, Col: {}",
44 self.offset,
45 self.line,
46 self.column,
47 );
48 serializer.serialize_str(&s)
49 }
50}
51
52impl Default for Position {
53 fn default() -> Self {
54 Self {
55 offset: 0,
56 line: 1,
57 column: 1,
58 }
59 }
60}
61
62#[derive(Default, PartialEq, Eq, Clone)]
63#[cfg_attr(feature = "serde", derive(Serialize))]
64pub struct SourceLocation {
65 pub start: Position,
66 pub end: Position,
67}
68
69impl From<SourceLocation> for Range<usize> {
70 fn from(location: SourceLocation) -> Self {
71 location.start.offset..location.end.offset
72 }
73}
74
75#[non_exhaustive]
77#[derive(Eq, PartialEq)]
78#[cfg_attr(feature = "serde", derive(Serialize))]
79pub enum Namespace {
80 Html,
81 Svg,
82 MathMl,
83 UserDefined(&'static str),
84}
85
86#[macro_export]
87macro_rules! cast {
88 ($target: expr, $pat: path) => {{
89 if let $pat(a, ..) = $target {
90 a
91 } else {
92 panic!("mismatch variant when cast to {}", stringify!($pat));
93 }
94 }};
95}
96
97#[cfg(test)]
98mod test {
99 use super::*;
100 #[test]
101 fn test_source_size() {
102 assert_eq!(std::mem::size_of::<Position>(), 16);
103 }
104}