tamer: xir::st::qname: New module
This moves and deduplicates the static `QName`s into a common area. DEV-7145main
parent
3da82b351e
commit
2b8e7e6031
|
@ -32,42 +32,16 @@
|
|||
use super::{super::LSPAN, section::XmleSections};
|
||||
use crate::{
|
||||
asg::{Ident, IdentKind},
|
||||
sym::{st::*, SymbolId},
|
||||
sym::{st::raw, SymbolId},
|
||||
xir::{
|
||||
iter::{elem_wrap, ElemWrapIter},
|
||||
st::qname::*,
|
||||
QName, Token,
|
||||
},
|
||||
};
|
||||
use arrayvec::ArrayVec;
|
||||
use std::{array, collections::hash_set, iter::Chain, vec};
|
||||
|
||||
qname_const! {
|
||||
QN_DESC: :L_DESC,
|
||||
QN_DIM: :L_DIM,
|
||||
QN_DTYPE: :L_DTYPE,
|
||||
QN_GENERATED: L_PREPROC:L_GENERATED,
|
||||
QN_L_DEP: L_L:L_DEP,
|
||||
QN_L_EXEC: L_L:L_EXEC,
|
||||
QN_L_FROM: L_L:L_FROM,
|
||||
QN_L_MAP_EXEC: L_L:L_MAP_EXEC,
|
||||
QN_L_MAP_FROM: L_L:L_MAP_FROM,
|
||||
QN_L_RETMAP_EXEC: L_L:L_RETMAP_EXEC,
|
||||
QN_L_STATIC: L_L:L_STATIC,
|
||||
QN_NAME: :L_NAME,
|
||||
QN_PACKAGE: :L_PACKAGE,
|
||||
QN_PARENT: :L_PARENT,
|
||||
QN_PROGRAM: :L_PROGRAM,
|
||||
QN_P_SYM: L_PREPROC:L_SYM,
|
||||
QN_SRC: :L_SRC,
|
||||
QN_TITLE: :L_TITLE,
|
||||
QN_TYPE: :L_TYPE,
|
||||
QN_UUROOTPATH: :L_UUROOTPATH,
|
||||
QN_XMLNS: :L_XMLNS,
|
||||
QN_XMLNS_L: L_XMLNS:L_L,
|
||||
QN_XMLNS_PREPROC: L_XMLNS:L_PREPROC,
|
||||
QN_YIELDS: :L_YIELDS,
|
||||
}
|
||||
|
||||
const HEADER_SIZE: usize = 14;
|
||||
type HeaderIter = array::IntoIter<Token, HEADER_SIZE>;
|
||||
|
||||
|
@ -167,7 +141,7 @@ impl<'a> DepListIter<'a> {
|
|||
}
|
||||
|
||||
self.toks_push_attr(QN_GENERATED, match src.generated {
|
||||
true => Some(L_TRUE.as_sym()),
|
||||
true => Some(raw::L_TRUE),
|
||||
false => None,
|
||||
});
|
||||
|
||||
|
|
|
@ -76,9 +76,6 @@ extern crate static_assertions;
|
|||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
#[macro_use]
|
||||
pub mod xir;
|
||||
|
||||
pub mod asg;
|
||||
pub mod convert;
|
||||
pub mod diagnose;
|
||||
|
@ -90,6 +87,7 @@ pub mod obj;
|
|||
pub mod parse;
|
||||
pub mod span;
|
||||
pub mod sym;
|
||||
pub mod xir;
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod test;
|
||||
|
|
|
@ -28,8 +28,8 @@ use crate::{
|
|||
TransitionResult, Transitionable,
|
||||
},
|
||||
span::Span,
|
||||
sym::{st::*, SymbolId},
|
||||
xir::{attr::Attr, flat::XirfToken as Xirf, QName},
|
||||
sym::{st::raw, SymbolId},
|
||||
xir::{attr::Attr, flat::XirfToken as Xirf, st::qname::*, QName},
|
||||
};
|
||||
|
||||
/// `xmlo` reader events.
|
||||
|
@ -130,35 +130,6 @@ impl Display for XmloToken {
|
|||
}
|
||||
}
|
||||
|
||||
qname_const! {
|
||||
QN_DESC: :L_DESC,
|
||||
QN_DIM: :L_DIM,
|
||||
QN_DTYPE: :L_DTYPE,
|
||||
QN_ELIG_CLASS_YIELDS: L_PREPROC:L_ELIG_CLASS_YIELDS,
|
||||
QN_EXTERN: :L_EXTERN,
|
||||
QN_FRAGMENT: L_PREPROC:L_FRAGMENT,
|
||||
QN_FRAGMENTS: L_PREPROC:L_FRAGMENTS,
|
||||
QN_FROM: L_PREPROC:L_FROM,
|
||||
QN_GENERATED: L_PREPROC:L_GENERATED,
|
||||
QN_ID: :L_ID,
|
||||
QN_ISOVERRIDE: :L_ISOVERRIDE,
|
||||
QN_LV_PACKAGE: L_LV:L_PACKAGE,
|
||||
QN_NAME: :L_NAME,
|
||||
QN_PACKAGE: :L_PACKAGE,
|
||||
QN_PARENT: :L_PARENT,
|
||||
QN_PROGRAM: :L_PROGRAM,
|
||||
QN_SRC: :L_SRC,
|
||||
QN_SYM: L_PREPROC:L_SYM,
|
||||
QN_SYMTABLE: L_PREPROC:L_SYMTABLE,
|
||||
QN_SYM_DEP: L_PREPROC:L_SYM_DEP,
|
||||
QN_SYM_DEPS: L_PREPROC:L_SYM_DEPS,
|
||||
QN_SYM_REF: L_PREPROC:L_SYM_REF,
|
||||
QN_TYPE: :L_TYPE,
|
||||
QN_UUROOTPATH: :L_UUROOTPATH,
|
||||
QN_VIRTUAL: :L_VIRTUAL,
|
||||
QN_YIELDS: :L_YIELDS,
|
||||
}
|
||||
|
||||
/// A parser capable of being composed with [`XmloReader`].
|
||||
pub trait XmloState = ParseState<Token = Xirf, Context = EmptyContext>
|
||||
where
|
||||
|
|
|
@ -32,8 +32,7 @@
|
|||
use crate::parse;
|
||||
use crate::span::Span;
|
||||
use crate::sym::{
|
||||
st_as_sym, CIdentStaticSymbolId, GlobalSymbolIntern,
|
||||
GlobalSymbolInternBytes, StaticSymbolId, SymbolId, TameIdentStaticSymbolId,
|
||||
st_as_sym, GlobalSymbolIntern, GlobalSymbolInternBytes, SymbolId,
|
||||
};
|
||||
use memchr::memchr;
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
|
@ -46,13 +45,15 @@ pub use error::Error;
|
|||
mod escape;
|
||||
pub use escape::{DefaultEscaper, Escaper};
|
||||
|
||||
use self::error::SpanlessError;
|
||||
use error::SpanlessError;
|
||||
use st::qname::QNameCompatibleStaticSymbolId;
|
||||
|
||||
pub mod attr;
|
||||
pub mod flat;
|
||||
pub mod iter;
|
||||
pub mod pred;
|
||||
pub mod reader;
|
||||
pub mod st;
|
||||
pub mod tree;
|
||||
pub mod writer;
|
||||
|
||||
|
@ -73,44 +74,6 @@ pub trait TokenStream = Iterator<Item = Token>;
|
|||
/// consider using [`TokenStream`].
|
||||
pub trait TokenResultStream = Iterator<Item = Result<Token, Error>>;
|
||||
|
||||
/// A static symbol that can be safely converted into a [`QName`] without
|
||||
/// any checks.
|
||||
///
|
||||
/// This must only be implemented on static symbol types that are known to
|
||||
/// be valid QNames.
|
||||
pub trait QNameCompatibleStaticSymbolId: StaticSymbolId {}
|
||||
|
||||
impl QNameCompatibleStaticSymbolId for CIdentStaticSymbolId {}
|
||||
impl QNameCompatibleStaticSymbolId for TameIdentStaticSymbolId {}
|
||||
|
||||
#[doc(hidden)]
|
||||
macro_rules! qname_const_inner {
|
||||
($name:ident = :$local:ident) => {
|
||||
const $name: crate::xir::QName =
|
||||
crate::xir::QName::st_cid_local(&$local);
|
||||
};
|
||||
|
||||
($name:ident = $prefix:ident:$local:ident) => {
|
||||
const $name: crate::xir::QName =
|
||||
crate::xir::QName::st_cid(&$prefix, &$local);
|
||||
};
|
||||
}
|
||||
|
||||
/// Construct a series of [`QName`] constants.
|
||||
///
|
||||
/// The syntax for each constant is `NAME: [PREFIX]:LOCAL`,
|
||||
/// where `PREFIX` is optional.
|
||||
///
|
||||
/// See [`crate::sym::st`] for usable symbol constants.
|
||||
#[macro_export]
|
||||
macro_rules! qname_const {
|
||||
($($name:ident: $($prefix:ident)? : $local:ident,)*) => {
|
||||
$(
|
||||
qname_const_inner!($name = $($prefix)?:$local);
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
/// XML Name minus `":"`.
|
||||
///
|
||||
/// The intent is to check a string for validity _before_ interning;
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
// Static XML symbols
|
||||
//
|
||||
// Copyright (C) 2014-2022 Ryan Specialty Group, LLC.
|
||||
//
|
||||
// This file is part of TAME.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Static XML symbols.
|
||||
//!
|
||||
//! This is analogous to [`crate::sym::st`].
|
||||
|
||||
pub mod qname {
|
||||
//! Static [`QName`]s.
|
||||
|
||||
use crate::sym::st::*;
|
||||
use crate::sym::{
|
||||
CIdentStaticSymbolId, StaticSymbolId, TameIdentStaticSymbolId,
|
||||
};
|
||||
|
||||
#[cfg(doc)]
|
||||
use super::super::QName;
|
||||
|
||||
/// A static symbol that can be safely converted into a [`QName`] without
|
||||
/// any checks.
|
||||
///
|
||||
/// This must only be implemented on static symbol types that are known to
|
||||
/// be valid QNames.
|
||||
pub trait QNameCompatibleStaticSymbolId: StaticSymbolId {}
|
||||
|
||||
impl QNameCompatibleStaticSymbolId for CIdentStaticSymbolId {}
|
||||
impl QNameCompatibleStaticSymbolId for TameIdentStaticSymbolId {}
|
||||
|
||||
#[doc(hidden)]
|
||||
macro_rules! qname_const_inner {
|
||||
($name:ident = :$local:ident) => {
|
||||
pub const $name: crate::xir::QName =
|
||||
crate::xir::QName::st_cid_local(&$local);
|
||||
};
|
||||
|
||||
($name:ident = $prefix:ident:$local:ident) => {
|
||||
pub const $name: crate::xir::QName =
|
||||
crate::xir::QName::st_cid(&$prefix, &$local);
|
||||
};
|
||||
}
|
||||
|
||||
/// Construct a series of [`QName`] constants.
|
||||
///
|
||||
/// The syntax for each constant is `NAME: [PREFIX]:LOCAL`,
|
||||
/// where `PREFIX` is optional.
|
||||
///
|
||||
/// See [`crate::sym::st`] for usable symbol constants.
|
||||
macro_rules! qname_const {
|
||||
($($name:ident: $($prefix:ident)? : $local:ident,)*) => {
|
||||
$(
|
||||
qname_const_inner!($name = $($prefix)?:$local);
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
qname_const! {
|
||||
QN_DESC: :L_DESC,
|
||||
QN_DIM: :L_DIM,
|
||||
QN_DTYPE: :L_DTYPE,
|
||||
QN_ELIG_CLASS_YIELDS: L_PREPROC:L_ELIG_CLASS_YIELDS,
|
||||
QN_EXTERN: :L_EXTERN,
|
||||
QN_FRAGMENT: L_PREPROC:L_FRAGMENT,
|
||||
QN_FRAGMENTS: L_PREPROC:L_FRAGMENTS,
|
||||
QN_FROM: L_PREPROC:L_FROM,
|
||||
QN_GENERATED: L_PREPROC:L_GENERATED,
|
||||
QN_ID: :L_ID,
|
||||
QN_ISOVERRIDE: :L_ISOVERRIDE,
|
||||
QN_LV_PACKAGE: L_LV:L_PACKAGE,
|
||||
QN_L_DEP: L_L:L_DEP,
|
||||
QN_L_EXEC: L_L:L_EXEC,
|
||||
QN_L_FROM: L_L:L_FROM,
|
||||
QN_L_MAP_EXEC: L_L:L_MAP_EXEC,
|
||||
QN_L_MAP_FROM: L_L:L_MAP_FROM,
|
||||
QN_L_RETMAP_EXEC: L_L:L_RETMAP_EXEC,
|
||||
QN_L_STATIC: L_L:L_STATIC,
|
||||
QN_NAME: :L_NAME,
|
||||
QN_PACKAGE: :L_PACKAGE,
|
||||
QN_PARENT: :L_PARENT,
|
||||
QN_PROGRAM: :L_PROGRAM,
|
||||
QN_P_SYM: L_PREPROC:L_SYM,
|
||||
QN_SRC: :L_SRC,
|
||||
QN_SYM: L_PREPROC:L_SYM,
|
||||
QN_SYMTABLE: L_PREPROC:L_SYMTABLE,
|
||||
QN_SYM_DEP: L_PREPROC:L_SYM_DEP,
|
||||
QN_SYM_DEPS: L_PREPROC:L_SYM_DEPS,
|
||||
QN_SYM_REF: L_PREPROC:L_SYM_REF,
|
||||
QN_TITLE: :L_TITLE,
|
||||
QN_TYPE: :L_TYPE,
|
||||
QN_UUROOTPATH: :L_UUROOTPATH,
|
||||
QN_VIRTUAL: :L_VIRTUAL,
|
||||
QN_XMLNS: :L_XMLNS,
|
||||
QN_XMLNS_L: L_XMLNS:L_L,
|
||||
QN_XMLNS_PREPROC: L_XMLNS:L_PREPROC,
|
||||
QN_YIELDS: :L_YIELDS,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue