Skip to content

Commit 31f9d12

Browse files
committed
[assembler] Support superscript and subscript solidus (slash).
1 parent e9e9767 commit 31f9d12

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

assembler/src/asmlib/lexer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub(crate) enum Token {
123123

124124
/// Solidus is often called "slash" but people often confuse slash
125125
/// and backslash. So we don't call it either.
126-
Solidus,
126+
Solidus(Script),
127127

128128
// @plus@ is actually not the correct glyph name, following sub.py.
129129
Plus(Script),
@@ -191,7 +191,7 @@ impl Display for Token {
191191
Token::GreaterThan => f.write_char('>'),
192192
Token::Intersection => f.write_char('∩'),
193193
Token::Union => f.write_char('∪'),
194-
Token::Solidus => f.write_char('/'),
194+
Token::Solidus(script) => write_elevated(script, "/"),
195195
Token::Plus(script) => write_elevated(script, "+"),
196196
Token::Minus(script) => write_elevated(script, "-"),
197197
Token::Times => f.write_char('×'),
@@ -495,7 +495,7 @@ mod lexer_impl_new {
495495
GlyphShape::DoublePipe => {
496496
todo!("double-pipe (which is a symex terminator) does not yet have a token")
497497
}
498-
GlyphShape::Solidus => only_normal(Token::Solidus),
498+
GlyphShape::Solidus => Some(Token::Solidus(script)),
499499
GlyphShape::Times => only_normal(Token::Times),
500500
GlyphShape::Hash => Some(Token::Hash(script)),
501501
GlyphShape::Arrow => Some(match script {

assembler/src/asmlib/lexer/tests.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,22 @@ fn test_union() {
922922

923923
#[test]
924924
fn test_solidus() {
925-
assert_eq!(scan_tokens_only("/"), Ok(vec![Token::Solidus,]));
925+
assert_eq!(
926+
scan_tokens_only("/"),
927+
Ok(vec![Token::Solidus(Script::Normal)])
928+
);
929+
assert_eq!(
930+
scan_tokens_only("@solidus@"),
931+
Ok(vec![Token::Solidus(Script::Normal)])
932+
);
933+
assert_eq!(
934+
scan_tokens_only("@sup_solidus@"),
935+
Ok(vec![Token::Solidus(Script::Super)])
936+
);
937+
assert_eq!(
938+
scan_tokens_only("@sub_solidus@"),
939+
Ok(vec![Token::Solidus(Script::Sub)])
940+
);
926941
}
927942

928943
#[test]

assembler/src/asmlib/parser.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ where
201201
select! {
202202
// Solidus ("/") is used for divide. See section 6-2.7
203203
// "Word Assembly" for details.
204-
// TODO: support subscript/superscript for '/'
205-
Tok::Solidus if script_required == Script::Normal => Operator::Divide,
204+
Tok::Solidus(script) if script_required == script => Operator::Divide,
206205
Tok::Plus(Script::Normal) => Operator::Add,
207206
// TODO: support subscript/superscript for times
208207
Tok::Times if script_required == Script::Normal => Operator::Multiply,
@@ -324,7 +323,7 @@ where
324323
just(Tok::GreaterThan).to('>'),
325324
just(Tok::Intersection).to('∩'),
326325
just(Tok::Union).to('∪'),
327-
just(Tok::Solidus).to('/'),
326+
just(Tok::Solidus(Script::Normal)).to('/'),
328327
just(Tok::Times).to('×'),
329328
just(Tok::LogicalOr(Script::Normal)).to('∨'),
330329
just(Tok::LogicalAnd(Script::Normal)).to('∧'),

0 commit comments

Comments
 (0)