Skip to content

Commit

Permalink
fix: fix bug of glob env
Browse files Browse the repository at this point in the history
  • Loading branch information
OrangeX4 committed Apr 24, 2024
1 parent 941fab0 commit 1209f8d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
10 changes: 9 additions & 1 deletion crates/mitex-spec/src/preludes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(missing_docs)]

pub mod command {
use crate::{ArgShape, CommandSpecItem};
use crate::{ArgShape, CommandSpecItem, ContextFeature};

pub fn define_command(len: u8) -> CommandSpecItem {
CommandSpecItem::Cmd(crate::CmdShape {
Expand All @@ -22,6 +22,14 @@ pub mod command {
})
}

pub fn define_glob_env(reg: &str, alias: &str, ctx_feature: ContextFeature) -> CommandSpecItem {
CommandSpecItem::Env(crate::EnvShape {
args: crate::ArgPattern::Glob(reg.into()),
ctx_feature,
alias: Some(alias.to_owned()),
})
}

pub fn define_symbol(alias: &str) -> CommandSpecItem {
CommandSpecItem::Cmd(crate::CmdShape {
args: crate::ArgShape::Right {
Expand Down
21 changes: 18 additions & 3 deletions crates/mitex-spec/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{collections::HashMap, sync::Arc};

use serde::{Deserialize, Serialize};

use crate::{CmdShape, EnvShape};
use crate::{CmdShape, ContextFeature, EnvShape};

/// A package specification.
#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -57,6 +57,16 @@ pub enum CommandSpecItem {
/// A command that takes no argument and is a normal environment.
#[serde(rename = "normal-env")]
EnvNormal,
/// A command that has a glob argument pattern and is an environment.
#[serde(rename = "glob-env")]
EnvGlob {
/// The glob pattern of the command.
pattern: String,
/// The aliasing typst handle of the command.
alias: String,
/// The context feature of the command.
ctx_feature: ContextFeature,
},

/// A command that is aliased to a Typst symbol.
#[serde(rename = "alias-sym")]
Expand All @@ -70,15 +80,15 @@ pub enum CommandSpecItem {
/// The aliasing typst handle of the command.
alias: String,
},
#[serde(rename = "infix-cmd")]
/// A command that is an infix operator and is aliased to a Typst handler.
#[serde(rename = "infix-cmd")]
CmdInfix {
/// The aliasing typst handle of the command.
alias: String,
},
#[serde(rename = "glob-cmd")]
/// A command that has a glob argument pattern and is aliased to a Typst
/// handler.
#[serde(rename = "glob-cmd")]
CmdGlob {
/// The glob pattern of the command.
pattern: String,
Expand All @@ -100,6 +110,11 @@ impl From<CommandSpecItem> for crate::CommandSpecItem {
CommandSpecItem::CmdLeft1 => TEX_LEFT1_OPEARTOR,
CommandSpecItem::EnvMatrix => TEX_MATRIX_ENV,
CommandSpecItem::EnvNormal => TEX_NORMAL_ENV,
CommandSpecItem::EnvGlob {
pattern,
alias,
ctx_feature,
} => define_glob_env(&pattern, &alias, ctx_feature),
CommandSpecItem::SymAlias { alias } => define_symbol(&alias),
CommandSpecItem::CmdGreedy { alias } => define_greedy_command(&alias),
CommandSpecItem::CmdInfix { alias } => crate::CommandSpecItem::Cmd(crate::CmdShape {
Expand Down
4 changes: 2 additions & 2 deletions packages/mitex/specs/latex/standard.typ
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
enumerate: define-env(none, kind: "is-enumerate"),
quote: define-env(none, alias: "quote(block: true)"),
abstract: define-env(none, alias: "quote(block: true)"),
// figure: define-glob-env("{,b}", kind: "is-figure", alias: "figure"), // todo: fix this
// table: define-glob-env("{,b}", kind: "is-figure", alias: "figure"),
figure: define-glob-env("{,b}", kind: "is-figure", alias: "figure"),
table: define-glob-env("{,b}", kind: "is-figure", alias: "figure"),
tabular: define-env(1, kind: "is-table", alias: "table"),
// commands for figure
centering: ignore-sym,
Expand Down
4 changes: 2 additions & 2 deletions packages/mitex/specs/prelude.typ
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@

#let define-glob-env(pat, kind: "none", alias: none, handle: none) = {
((
kind: "env",
args: ( kind: "glob", pattern: pat ),
kind: "glob-env",
pattern: pat,
ctx_feature: ( kind: kind ),
alias: alias,
), if handle != none { (alias: alias, handle: handle) } else { none })
Expand Down

0 comments on commit 1209f8d

Please sign in to comment.