@@ -18,6 +18,9 @@ use unicode_segmentation::UnicodeSegmentation;
18
18
19
19
use crate :: { ast:: PlaceholderOp , ArraySwizzle , Inputs , Primitive , StackSwizzle , WILDCARD_CHAR } ;
20
20
21
+ /// Subscript digit characters
22
+ pub const SUBSCRIPT_NUMS : [ char ; 10 ] = [ '₀' , '₁' , '₂' , '₃' , '₄' , '₅' , '₆' , '₇' , '₈' , '₉' ] ;
23
+
21
24
/// Lex a Uiua source file
22
25
pub fn lex (
23
26
input : & str ,
@@ -793,7 +796,7 @@ impl<'a> Lexer<'a> {
793
796
"]" => self . end ( CloseBracket , start) ,
794
797
"⟨" => self . end ( OpenAngle , start) ,
795
798
"⟩" => self . end ( CloseAngle , start) ,
796
- "_" => self . end ( Underscore , start) ,
799
+ "_" if self . peek_char ( ) != Some ( "_" ) => self . end ( Underscore , start) ,
797
800
"|" => self . end ( Bar , start) ,
798
801
";" => self . end ( Semicolon , start) ,
799
802
"-" if self . next_chars_exact ( [ "-" , "-" ] ) => self . end ( TripleMinus , start) ,
@@ -1002,12 +1005,28 @@ impl<'a> Lexer<'a> {
1002
1005
}
1003
1006
}
1004
1007
// Identifiers and unformatted glyphs
1005
- c if is_custom_glyph ( c) || c. chars ( ) . all ( is_ident_char) || c == "&" => {
1008
+ c if is_custom_glyph ( c) || c. chars ( ) . all ( is_ident_char) || c == "&" || c == "_" => {
1006
1009
let mut ident = c. to_string ( ) ;
1007
1010
// Collect characters
1008
1011
if !is_custom_glyph ( c) {
1009
- while let Some ( c) = self . next_char_if_all ( is_ident_char) {
1010
- ident. push_str ( c) ;
1012
+ // Handle identifiers beginning with __
1013
+ if c == "_" && self . next_char_exact ( "_" ) {
1014
+ ident. push_str ( "__" ) ;
1015
+ while let Some ( dc) = self . next_char_if_all ( |c| c. is_ascii_digit ( ) ) {
1016
+ ident. push_str ( dc) ;
1017
+ }
1018
+ }
1019
+ loop {
1020
+ if let Some ( c) = self . next_char_if_all ( is_ident_char) {
1021
+ ident. push_str ( c) ;
1022
+ } else if self . next_chars_exact ( [ "_" ; 2 ] ) {
1023
+ ident. push_str ( "__" ) ;
1024
+ while let Some ( dc) = self . next_char_if_all ( |c| c. is_ascii_digit ( ) ) {
1025
+ ident. push_str ( dc) ;
1026
+ }
1027
+ } else {
1028
+ break ;
1029
+ }
1011
1030
}
1012
1031
}
1013
1032
let mut exclam_count = 0 ;
@@ -1376,7 +1395,7 @@ fn parse_format_fragments(s: &str) -> Vec<String> {
1376
1395
1377
1396
/// Whether a character can be part of a Uiua identifier
1378
1397
pub fn is_ident_char ( c : char ) -> bool {
1379
- c. is_alphabetic ( ) && !"ⁿₙπτηℂλ" . contains ( c)
1398
+ c. is_alphabetic ( ) && !"ⁿₙπτηℂλ" . contains ( c) || SUBSCRIPT_NUMS . contains ( & c )
1380
1399
}
1381
1400
1382
1401
/// Whether a string is a custom glyph
0 commit comments