@@ -432,10 +432,12 @@ def end(self) -> "std.map[T, U].iterator[T, U]":
432
432
# // be an inclusive range ([a-z])
433
433
# LLAMA_GRETYPE_CHAR_RNG_UPPER = 5,
434
434
435
-
436
435
# // modifies a preceding LLAMA_GRETYPE_CHAR or
437
436
# // LLAMA_GRETYPE_CHAR_RNG_UPPER to add an alternate char to match ([ab], [a-zA])
438
437
# LLAMA_GRETYPE_CHAR_ALT = 6,
438
+
439
+ # // any character (.)
440
+ # LLAMA_GRETYPE_CHAR_ANY = 7,
439
441
# };
440
442
class llama_gretype (Enum ):
441
443
"""grammar element type"""
@@ -447,6 +449,7 @@ class llama_gretype(Enum):
447
449
LLAMA_GRETYPE_CHAR_NOT = 4 # inverse char(s) ([^a], [^a-b] [^abc])
448
450
LLAMA_GRETYPE_CHAR_RNG_UPPER = 5 # modifies a preceding LLAMA_GRETYPE_CHAR or LLAMA_GRETYPE_CHAR_ALT to be an inclusive range ([a-z])
449
451
LLAMA_GRETYPE_CHAR_ALT = 6 # modifies a preceding LLAMA_GRETYPE_CHAR or LLAMA_GRETYPE_CHAR_RNG_UPPER to add an alternate char to match ([ab], [a-zA])
452
+ LLAMA_GRETYPE_CHAR_ANY = 7 # any character (.)
450
453
451
454
452
455
# struct parse_state {
@@ -830,6 +833,10 @@ def parse_sequence(
830
833
# if (last_sym_start == out_elements.size()) {
831
834
# throw std::runtime_error(std::string("expecting preceeding item to */+/? at ") + pos);
832
835
# }
836
+ elif pos [0 ] == '.' :
837
+ last_sym_start = out_elements .size ()
838
+ out_elements .push_back (LlamaGrammarElement (llama_gretype .LLAMA_GRETYPE_CHAR_ANY , 0 ))
839
+ pos = parse_space (pos + 1 , is_nested )
833
840
elif pos [0 ] in ("*" , "+" , "?" ): # repetition operator
834
841
if last_sym_start == out_elements .size ():
835
842
raise RuntimeError ("expecting preceding item to */+/? at " + str (pos ))
@@ -1039,6 +1046,7 @@ def is_char_element(elem: LlamaGrammarElement) -> bool:
1039
1046
llama_gretype .LLAMA_GRETYPE_CHAR_NOT ,
1040
1047
llama_gretype .LLAMA_GRETYPE_CHAR_ALT ,
1041
1048
llama_gretype .LLAMA_GRETYPE_CHAR_RNG_UPPER ,
1049
+ llama_gretype .LLAMA_GRETYPE_CHAR_ANY ,
1042
1050
)
1043
1051
1044
1052
@@ -1135,6 +1143,8 @@ def print_rule(
1135
1143
+ str (i )
1136
1144
)
1137
1145
print_grammar_char (file , elem .value )
1146
+ elif case is llama_gretype .LLAMA_GRETYPE_CHAR_ANY :
1147
+ print ("." , file = file , end = "" )
1138
1148
# if (is_char_element(elem)) {
1139
1149
# switch (rule[i + 1].type) {
1140
1150
# case LLAMA_GRETYPE_CHAR_ALT:
0 commit comments