Skip to content

Commit

Permalink
use Vec instead of Box in Accent
Browse files Browse the repository at this point in the history
  • Loading branch information
cbreeden committed Jul 31, 2017
1 parent 9c42fb8 commit 39c1216
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 26 deletions.
5 changes: 3 additions & 2 deletions src/layout/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fn accent(result: &mut Layout, acc: &Accent, config: LayoutSettings) {
// [ ] Bottom accents: vertical placement is directly below nucleus,
// no correction takes place.
// [ ] WideAccent vs Accent: Don't expand Accent types.
let base = layout_node(&acc.nucleus, config.cramped());
let base = layout(&acc.nucleus, config.cramped());
let accent_variant = glyph_metrics(acc.symbol.unicode).horz_variant(base.width);
let accent = accent_variant.as_layout(config);

Expand Down Expand Up @@ -291,7 +291,8 @@ fn scripts(result: &mut Layout, scripts: &Scripts, config: LayoutSettings) {
// For accents, whose base is a simple symbol, we do not take
// the accent into account while positioning the superscript.
if let ParseNode::Accent(ref acc) = **b {
if let Some(sym) = acc.nucleus.is_symbol() {
use parser;
if let Some(sym) = parser::is_symbol(&acc.nucleus) {
height = glyph_metrics(sym.unicode).height().scaled(config);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/parser/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ macro_rules! accent {
ParseNode::Accent(
Accent {
symbol: $sym,
nucleus: Box::new($nucleus)
nucleus: $nucleus
}
)
)
Expand Down
4 changes: 1 addition & 3 deletions src/parser/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,7 @@ pub fn symbol(lex: &mut Lexer, local: Style) -> Result<Option<ParseNode>> {
lex.next();

if sym.atom_type == AtomType::Accent {
let nucleus = math_field(lex, local)
.map_err(|_| Error::AccentMissingArg(cs.into()))?;

let nucleus = required_argument(lex, local)?;
Ok(Some(accent!(sym, nucleus)))
} else {
Ok(Some(ParseNode::Symbol(Symbol {
Expand Down
37 changes: 17 additions & 20 deletions src/parser/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct AtomChange {
#[derive(Clone, Debug, PartialEq)]
pub struct Accent {
pub symbol: Symbol,
pub nucleus: Box<ParseNode>,
pub nucleus: Vec<ParseNode>,
}

#[derive(Copy, Clone, PartialEq, Debug)]
Expand All @@ -66,25 +66,12 @@ pub struct Rule {
//pub depth: Unit,
}

#[derive(Debug, PartialEq, Clone)]
pub enum MathField {
Symbol(Symbol),
Group(Vec<ParseNode>),
}

#[derive(Debug, PartialEq, Clone)]
pub struct Radical {
pub inner: Vec<ParseNode>,
// pub superscript: Vec<ParseNode>,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum MathStyle {
Display,
Text,
NoChange,
}

#[derive(Debug, PartialEq, Clone)]
pub struct GenFraction {
pub numerator: Vec<ParseNode>,
Expand All @@ -95,17 +82,24 @@ pub struct GenFraction {
pub style: MathStyle,
}

#[derive(Debug, Clone, PartialEq)]
pub struct Color {
pub color: RGBA,
pub inner: Vec<ParseNode>,
}

#[derive(Debug, Copy, Clone, PartialEq)]
pub enum BarThickness {
Default,
None,
Unit(Unit),
}

#[derive(Debug, Clone, PartialEq)]
pub struct Color {
pub color: RGBA,
pub inner: Vec<ParseNode>,
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum MathStyle {
Display,
Text,
NoChange,
}

impl ParseNode {
Expand Down Expand Up @@ -152,9 +146,9 @@ impl ParseNode {
pub fn is_symbol(&self) -> Option<Symbol> {
match *self {
ParseNode::Symbol(sym) => Some(sym),
ParseNode::Accent(ref acc) => acc.nucleus.is_symbol(),
ParseNode::Scripts(Scripts { ref base, .. }) =>
base.as_ref().and_then(|b| b.is_symbol()),
ParseNode::Accent(ref acc) => is_symbol(&acc.nucleus),
ParseNode::AtomChange(ref ac) => is_symbol(&ac.inner),
ParseNode::Color(ref clr) => is_symbol(&clr.inner),
_ => None,
Expand All @@ -174,7 +168,10 @@ impl ParseNode {

ParseNode::Rule(_) => AtomType::Alpha,
ParseNode::Kerning(_) => AtomType::Transparent,
ParseNode::Accent(ref acc) => acc.nucleus.atom_type(),
ParseNode::Accent(ref acc) => acc.nucleus.first()
.map(|acc| acc.atom_type())
.unwrap_or(AtomType::Alpha),

ParseNode::Style(_) => AtomType::Transparent,
ParseNode::AtomChange(ref ac) => ac.at,
ParseNode::Color(ref clr) => clr.inner.first()
Expand Down
Binary file modified tests/data/layout.bincode
Binary file not shown.

0 comments on commit 39c1216

Please sign in to comment.