diff --git a/site/primitives.json b/site/primitives.json index 1bb29bab..b3fd18e2 100644 --- a/site/primitives.json +++ b/site/primitives.json @@ -391,7 +391,6 @@ }, "both": { "glyph": "∩", - "args": 2, "outputs": 1, "modifier_args": 1, "class": "Planet", diff --git a/src/compile/mod.rs b/src/compile/mod.rs index ba28c406..1920e0bf 100644 --- a/src/compile/mod.rs +++ b/src/compile/mod.rs @@ -2049,10 +2049,12 @@ code: } #[allow(clippy::match_single_binding)] fn subscript(&mut self, sub: Subscript, span: CodeSpan, call: bool) -> UiuaResult { - self.experimental_error(&span, || { - "Subscripts are experimental. To use them, add \ - `# Experimental!` to the top of the file." - }); + if !matches!(sub.word.value, Word::Primitive(Primitive::Utf8)) { + self.experimental_error(&span, || { + "Subscripts are experimental. To use them, add \ + `# Experimental!` to the top of the file." + }); + } let n = sub.n.value; match sub.word.value { Word::Modified(m) => match m.modifier.value { @@ -2106,6 +2108,12 @@ code: self.primitive(Primitive::Mul, span.clone(), call)?; self.primitive(Primitive::Floor, span, call)?; } + Primitive::Utf8 => { + if n != 8 { + self.add_error(span.clone(), "Only UTF-8 is supported"); + } + self.primitive(Primitive::Utf8, span, call)? + } _ => { self.add_error( span.clone(), diff --git a/src/format.rs b/src/format.rs index 5cbee84f..1a91534d 100644 --- a/src/format.rs +++ b/src/format.rs @@ -1060,7 +1060,7 @@ impl<'a> Formatter<'a> { } self.output.push(')'); } - Word::Primitive(prim) => self.push(&word.span, &prim.to_string()), + Word::Primitive(prim) => self.format_primitive(*prim, &word.span), Word::Modified(m) => { self.format_modifier(&m.modifier); self.format_words(&m.operands, true, depth); @@ -1216,6 +1216,12 @@ impl<'a> Formatter<'a> { } } } + fn format_primitive(&mut self, prim: Primitive, span: &CodeSpan) { + match prim { + Primitive::Utf8 => self.push(span, "utf"), + _ => self.push(span, &prim.to_string()), + } + } fn format_multiline_words( &mut self, mut lines: &[Vec>], diff --git a/src/lex.rs b/src/lex.rs index 79aeacbf..9a2f650d 100644 --- a/src/lex.rs +++ b/src/lex.rs @@ -1119,7 +1119,7 @@ impl<'a> Lexer<'a> { // Try to parse as primitives let lowercase_end = ident .char_indices() - .find(|(_, c)| !c.is_ascii_lowercase()) + .find(|(_, c)| !c.is_ascii_lowercase() && *c != '&') .map_or(ident.len(), |(i, _)| i); let lowercase = &ident[..lowercase_end]; if let Some(prims) = Primitive::from_format_name_multi(lowercase) {