@@ -934,7 +934,25 @@ primitive type Kind 16 end
934
934
# the K_str macro to self-name these kinds with their literal representation,
935
935
# rather than needing to invent a new name for each.
936
936
937
- let kind_int_type = :UInt16 ,
937
+ let kind_int_type = :UInt16
938
+ # Preprocess _kind_names to conflate category markers with the first/last
939
+ # in the category.
940
+ kindstr_to_int = Dict {String,UInt16} ()
941
+ i = 1
942
+ while i <= length (_kind_names)
943
+ kn = _kind_names[i]
944
+ kind_int = i- 1
945
+ if startswith (kn, " BEGIN_" )
946
+ deleteat! (_kind_names, i)
947
+ elseif startswith (kn, " END_" )
948
+ kind_int = i- 2
949
+ deleteat! (_kind_names, i)
950
+ else
951
+ i += 1
952
+ end
953
+ push! (kindstr_to_int, kn=> kind_int)
954
+ end
955
+
938
956
max_kind_int = length (_kind_names)- 1
939
957
940
958
@eval begin
@@ -945,9 +963,9 @@ let kind_int_type = :UInt16,
945
963
return Base. bitcast (Kind, convert ($ kind_int_type, x))
946
964
end
947
965
948
- Base. convert (:: Type{String} , k:: Kind ) = _kind_names[1 + Base . bitcast ($ kind_int_type, k)]
966
+ Base. convert (:: Type{String} , k:: Kind ) = _kind_names[1 + reinterpret ($ kind_int_type, k)]
949
967
950
- let kindstr_to_int = Dict (s => i - 1 for (i,s) in enumerate (_kind_names))
968
+ let kindstr_to_int= $ kindstr_to_int
951
969
function Base. convert (:: Type{Kind} , s:: AbstractString )
952
970
i = get (kindstr_to_int, s) do
953
971
error (" unknown Kind name $(repr (s)) " )
@@ -1078,12 +1096,12 @@ const _token_error_descriptions = Dict{Kind, String}(
1078
1096
1079
1097
# -------------------------------------------------------------------------------
1080
1098
# Predicates
1081
- is_contextual_keyword (k:: Kind ) = K " BEGIN_CONTEXTUAL_KEYWORDS" < k < K " END_CONTEXTUAL_KEYWORDS"
1082
- is_error (k:: Kind ) = K " BEGIN_ERRORS" < k < K " END_ERRORS" || k == K " ErrorInvalidOperator" || k == K " Error**"
1083
- is_keyword (k:: Kind ) = K " BEGIN_KEYWORDS" < k < K " END_KEYWORDS"
1084
- is_block_continuation_keyword (k:: Kind ) = K " BEGIN_BLOCK_CONTINUATION_KEYWORDS" < k < K " END_BLOCK_CONTINUATION_KEYWORDS"
1085
- is_literal (k:: Kind ) = K " BEGIN_LITERAL" < k < K " END_LITERAL"
1086
- is_operator (k:: Kind ) = K " BEGIN_OPS" < k < K " END_OPS"
1099
+ is_contextual_keyword (k:: Kind ) = K " BEGIN_CONTEXTUAL_KEYWORDS" <= k <= K " END_CONTEXTUAL_KEYWORDS"
1100
+ is_error (k:: Kind ) = K " BEGIN_ERRORS" <= k <= K " END_ERRORS" || k == K " ErrorInvalidOperator" || k == K " Error**"
1101
+ is_keyword (k:: Kind ) = K " BEGIN_KEYWORDS" <= k <= K " END_KEYWORDS"
1102
+ is_block_continuation_keyword (k:: Kind ) = K " BEGIN_BLOCK_CONTINUATION_KEYWORDS" <= k <= K " END_BLOCK_CONTINUATION_KEYWORDS"
1103
+ is_literal (k:: Kind ) = K " BEGIN_LITERAL" <= k <= K " END_LITERAL"
1104
+ is_operator (k:: Kind ) = K " BEGIN_OPS" <= k <= K " END_OPS"
1087
1105
is_word_operator (k:: Kind ) = (k == K " in" || k == K " isa" || k == K " where" )
1088
1106
1089
1107
is_contextual_keyword (k) = is_contextual_keyword (kind (k))
@@ -1097,28 +1115,28 @@ is_word_operator(k) = is_word_operator(kind(k))
1097
1115
# Predicates for operator precedence
1098
1116
# FIXME : Review how precedence depends on dottedness, eg
1099
1117
# https://github.com/JuliaLang/julia/pull/36725
1100
- is_prec_assignment (x) = K " BEGIN_ASSIGNMENTS" < kind (x) < K " END_ASSIGNMENTS"
1101
- is_prec_pair (x) = K " BEGIN_PAIRARROW" < kind (x) < K " END_PAIRARROW"
1102
- is_prec_conditional (x) = K " BEGIN_CONDITIONAL" < kind (x) < K " END_CONDITIONAL"
1103
- is_prec_arrow (x) = K " BEGIN_ARROW" < kind (x) < K " END_ARROW"
1104
- is_prec_lazy_or (x) = K " BEGIN_LAZYOR" < kind (x) < K " END_LAZYOR"
1105
- is_prec_lazy_and (x) = K " BEGIN_LAZYAND" < kind (x) < K " END_LAZYAND"
1106
- is_prec_comparison (x) = K " BEGIN_COMPARISON" < kind (x) < K " END_COMPARISON"
1107
- is_prec_pipe (x) = K " BEGIN_PIPE" < kind (x) < K " END_PIPE"
1108
- is_prec_colon (x) = K " BEGIN_COLON" < kind (x) < K " END_COLON"
1109
- is_prec_plus (x) = K " BEGIN_PLUS" < kind (x) < K " END_PLUS"
1110
- is_prec_bitshift (x) = K " BEGIN_BITSHIFTS" < kind (x) < K " END_BITSHIFTS"
1111
- is_prec_times (x) = K " BEGIN_TIMES" < kind (x) < K " END_TIMES"
1112
- is_prec_rational (x) = K " BEGIN_RATIONAL" < kind (x) < K " END_RATIONAL"
1113
- is_prec_power (x) = K " BEGIN_POWER" < kind (x) < K " END_POWER"
1114
- is_prec_decl (x) = K " BEGIN_DECL" < kind (x) < K " END_DECL"
1115
- is_prec_where (x) = K " BEGIN_WHERE" < kind (x) < K " END_WHERE"
1116
- is_prec_dot (x) = K " BEGIN_DOT" < kind (x) < K " END_DOT"
1117
- is_prec_unicode_ops (x) = K " BEGIN_UNICODE_OPS" < kind (x) < K " END_UNICODE_OPS"
1118
+ is_prec_assignment (x) = K " BEGIN_ASSIGNMENTS" <= kind (x) <= K " END_ASSIGNMENTS"
1119
+ is_prec_pair (x) = K " BEGIN_PAIRARROW" <= kind (x) <= K " END_PAIRARROW"
1120
+ is_prec_conditional (x) = K " BEGIN_CONDITIONAL" <= kind (x) <= K " END_CONDITIONAL"
1121
+ is_prec_arrow (x) = K " BEGIN_ARROW" <= kind (x) <= K " END_ARROW"
1122
+ is_prec_lazy_or (x) = K " BEGIN_LAZYOR" <= kind (x) <= K " END_LAZYOR"
1123
+ is_prec_lazy_and (x) = K " BEGIN_LAZYAND" <= kind (x) <= K " END_LAZYAND"
1124
+ is_prec_comparison (x) = K " BEGIN_COMPARISON" <= kind (x) <= K " END_COMPARISON"
1125
+ is_prec_pipe (x) = K " BEGIN_PIPE" <= kind (x) <= K " END_PIPE"
1126
+ is_prec_colon (x) = K " BEGIN_COLON" <= kind (x) <= K " END_COLON"
1127
+ is_prec_plus (x) = K " BEGIN_PLUS" <= kind (x) <= K " END_PLUS"
1128
+ is_prec_bitshift (x) = K " BEGIN_BITSHIFTS" <= kind (x) <= K " END_BITSHIFTS"
1129
+ is_prec_times (x) = K " BEGIN_TIMES" <= kind (x) <= K " END_TIMES"
1130
+ is_prec_rational (x) = K " BEGIN_RATIONAL" <= kind (x) <= K " END_RATIONAL"
1131
+ is_prec_power (x) = K " BEGIN_POWER" <= kind (x) <= K " END_POWER"
1132
+ is_prec_decl (x) = K " BEGIN_DECL" <= kind (x) <= K " END_DECL"
1133
+ is_prec_where (x) = K " BEGIN_WHERE" <= kind (x) <= K " END_WHERE"
1134
+ is_prec_dot (x) = K " BEGIN_DOT" <= kind (x) <= K " END_DOT"
1135
+ is_prec_unicode_ops (x) = K " BEGIN_UNICODE_OPS" <= kind (x) <= K " END_UNICODE_OPS"
1118
1136
is_prec_pipe_lt (x) = kind (x) == K " <|"
1119
1137
is_prec_pipe_gt (x) = kind (x) == K " |>"
1120
- is_syntax_kind (x) = K " BEGIN_SYNTAX_KINDS" < kind (x) < K " END_SYNTAX_KINDS"
1121
- is_macro_name (x) = K " BEGIN_MACRO_NAMES" < kind (x) < K " END_MACRO_NAMES"
1138
+ is_syntax_kind (x) = K " BEGIN_SYNTAX_KINDS" <= kind (x) <= K " END_SYNTAX_KINDS"
1139
+ is_macro_name (x) = K " BEGIN_MACRO_NAMES" <= kind (x) <= K " END_MACRO_NAMES"
1122
1140
1123
1141
function is_number (x)
1124
1142
kind (x) in (K " Integer" , K " BinInt" , K " HexInt" , K " OctInt" , K " Float" , K " Float32" )
0 commit comments