@@ -1131,6 +1131,26 @@ const expr_parens = Dict(:tuple=>('(',')'), :vcat=>('[',']'),
1131
1131
1132
1132
is_id_start_char (c:: AbstractChar ) = ccall (:jl_id_start_char , Cint, (UInt32,), c) != 0
1133
1133
is_id_char (c:: AbstractChar ) = ccall (:jl_id_char , Cint, (UInt32,), c) != 0
1134
+
1135
+ """
1136
+ isidentifier(s) -> Bool
1137
+
1138
+ Return whether the symbol or string `s` contains characters that are parsed as
1139
+ a valid identifier in Julia code.
1140
+
1141
+ Internally Julia allows any sequence of characters in a `Symbol` (except `\0 `s),
1142
+ and macros automatically use variable names containing `#` in order to avoid
1143
+ naming collision with the surrounding code. In order for the parser to
1144
+ recognize a variable, it uses a limited set of characters (greatly extended by
1145
+ Unicode). `isidentifier()` makes it possible to query the parser directly
1146
+ whether a symbol contains valid characters.
1147
+
1148
+ # Examples
1149
+ ```jldoctest
1150
+ julia> Meta.isidentifier(:x), Meta.isidentifier("1x")
1151
+ (true, false)
1152
+ ```
1153
+ """
1134
1154
function isidentifier (s:: AbstractString )
1135
1155
isempty (s) && return false
1136
1156
(s == " true" || s == " false" ) && return false
@@ -1151,7 +1171,7 @@ Return `true` if the symbol can be used as an operator, `false` otherwise.
1151
1171
1152
1172
# Examples
1153
1173
```jldoctest
1154
- julia> Base .isoperator(:+), Base .isoperator(:f)
1174
+ julia> Meta .isoperator(:+), Meta .isoperator(:f)
1155
1175
(true, false)
1156
1176
```
1157
1177
"""
@@ -1164,7 +1184,7 @@ Return `true` if the symbol can be used as a unary (prefix) operator, `false` ot
1164
1184
1165
1185
# Examples
1166
1186
```jldoctest
1167
- julia> Base .isunaryoperator(:-), Base .isunaryoperator(:√), Base .isunaryoperator(:f)
1187
+ julia> Meta .isunaryoperator(:-), Meta .isunaryoperator(:√), Meta .isunaryoperator(:f)
1168
1188
(true, true, false)
1169
1189
```
1170
1190
"""
@@ -1178,7 +1198,7 @@ Return `true` if the symbol can be used as a binary (infix) operator, `false` ot
1178
1198
1179
1199
# Examples
1180
1200
```jldoctest
1181
- julia> Base .isbinaryoperator(:-), Base .isbinaryoperator(:√), Base .isbinaryoperator(:f)
1201
+ julia> Meta .isbinaryoperator(:-), Meta .isbinaryoperator(:√), Meta .isbinaryoperator(:f)
1182
1202
(true, false, false)
1183
1203
```
1184
1204
"""
@@ -1194,7 +1214,7 @@ Return `true` if the symbol can be used as a postfix operator, `false` otherwise
1194
1214
1195
1215
# Examples
1196
1216
```jldoctest
1197
- julia> Base .ispostfixoperator(Symbol("'")), Base .ispostfixoperator(Symbol("'ᵀ")), Base .ispostfixoperator(:-)
1217
+ julia> Meta .ispostfixoperator(Symbol("'")), Meta .ispostfixoperator(Symbol("'ᵀ")), Meta .ispostfixoperator(:-)
1198
1218
(true, true, false)
1199
1219
```
1200
1220
"""
0 commit comments