@@ -64,6 +64,10 @@ abstract type AbstractMsg end
64
64
abstract type AbstractSrv end
65
65
abstract type AbstractService end
66
66
67
+ _is_tuple_expr (input) = input isa Expr && input. head == :tuple
68
+ _is_colon_expr (input) = input isa Expr && input. head == :call && input. args[1 ] == :(:)
69
+ _is_dot_expr (input) = input isa Expr && input. head == :(.)
70
+
67
71
"""
68
72
@rosimport
69
73
@@ -81,13 +85,11 @@ macro rosimport(input)
81
85
# Rearranges the expression into a RobotOS._rosimport call. Input comes in as a single package
82
86
# qualified expression, or as a tuple expression where the first element is the same as the
83
87
# single expression case. Most of the code is just error checking that the input takes that form.
84
- @assert input. head in [:tuple , :(.), :(:)] " Improper @rosimport input"
85
- if input. head == :tuple
86
- @assert isa (input. args[1 ], Expr) " Improper @rosimport input"
87
- @assert input. args[1 ]. head == :(:) " First argument needs ':' following"
88
- types = String[]
88
+ @assert _is_tuple_expr (input) || _is_colon_expr (input) || _is_dot_expr (input) " Improper @rosimport input"
89
+ if _is_tuple_expr (input)
90
+ @assert _is_colon_expr (input. args[1 ]) " Improper @rosimport input, first argument needs ':' following"
89
91
pkg, ismsg, typ = _pkgtype_import (input. args[1 ])
90
- push! ( types, typ)
92
+ types = String[ typ]
91
93
for t in input. args[2 : end ]
92
94
@assert isa (t, Symbol) " Type name ($(string (t)) ) not a symbol"
93
95
push! (types, string (t))
@@ -98,32 +100,29 @@ macro rosimport(input)
98
100
return :(_rosimport ($ pkg, $ ismsg, $ typ))
99
101
end
100
102
end
101
-
102
- _get_quote_value (input:: QuoteNode ) = input. value
103
- _get_quote_value (input:: Expr ) = (@assert input. head == :quote ; input. args[1 ])
104
-
105
103
# Return the pkg and types strings for a single expression of form:
106
104
# pkg.[msg|srv].type or pkg.[msg|srv]:type
107
105
function _pkgtype_import (input:: Expr )
108
- @assert input. head in (:(.), :(:) ) " Improper @rosimport input"
109
- @assert isa (input. args[1 ], Expr) " Improper @rosimport input"
110
- @assert input . args[ 1 ] . head == :(. ) " Improper @rosimport input"
111
- p = input . args[ 1 ] . args[1 ]
106
+ @assert _is_colon_expr ( input) || _is_dot_expr (input ) " Improper @rosimport input"
107
+ p_ms, t = _is_colon_expr (input) ? (input . args[2 ], input . args[ 3 ]) : (input . args[ 1 ], input. args[ 2 ])
108
+ @assert _is_dot_expr (p_ms ) " Improper @rosimport input"
109
+ p = p_ms . args[1 ]
112
110
@assert isa (p, Symbol) " Package name ($(string (p)) ) not a symbol"
113
- m_or_s = _get_quote_value (input. args[1 ]. args[2 ])
111
+ @assert isa (p_ms. args[2 ], QuoteNode) " Improper @rosimport input"
112
+ m_or_s = p_ms. args[2 ]. value
114
113
@assert m_or_s in (:msg ,:srv ) " Improper @rosimport input"
115
114
ps = string (p)
116
115
msb = m_or_s == :msg
117
116
ts = " "
118
- if isa (input . args[ 2 ] , Symbol)
119
- ts = string (input . args[ 2 ] )
120
- elseif isa (input . args[ 2 ] , Expr)
121
- @assert length (input . args[ 2 ] . args ) == 1 " Type name not a symbol"
122
- tsym = input . args[ 2 ] . args[1 ]
117
+ if isa (t , Symbol)
118
+ ts = string (t )
119
+ elseif isa (t , Expr)
120
+ @assert length (t . args) == 1 " Type name ( $(t) ) not a symbol"
121
+ tsym = t . args[1 ]
123
122
@assert isa (tsym, Symbol) " Type name ($(string (tsym)) ) not a symbol"
124
123
ts = string (tsym)
125
- elseif isa (input . args[ 2 ] , QuoteNode)
126
- tsym = input . args[ 2 ] . value
124
+ elseif isa (t , QuoteNode)
125
+ tsym = t . value
127
126
@assert isa (tsym, Symbol) " Type name ($(string (tsym)) ) not a symbol"
128
127
ts = string (tsym)
129
128
end
@@ -179,8 +178,8 @@ function addtype!(mod::ROSMsgModule, typ::String)
179
178
if ! (typ in mod. members)
180
179
@debug (" Message type import: " , _fullname (mod), " ." , typ)
181
180
if _nameconflicts (typ)
182
- warn (" Message type '$typ ' conflicts with Julia builtin, " ,
183
- " will be imported as '$(_jl_safe_name (typ," Msg" )) '" )
181
+ @ warn (" Message type '$typ ' conflicts with Julia builtin, " *
182
+ " will be imported as '$(_jl_safe_name (typ," Msg" )) '" )
184
183
end
185
184
pymod, pyobj = _pyvars (_fullname (mod), typ)
186
185
@@ -350,19 +349,19 @@ end
350
349
351
350
# The imports specific to each module, including dependant packages
352
351
function _importexprs (mod:: ROSMsgModule , rosrootmod:: Module )
353
- imports = Expr[Expr ( : import, : RobotOS, : AbstractMsg )]
352
+ imports = Expr[:( import RobotOS. AbstractMsg)]
354
353
othermods = filter (d -> d != _name (mod), mod. deps)
355
- append! (imports, [Expr (:using ,fullname (rosrootmod)... ,Symbol (m),:msg ) for m in othermods])
354
+ append! (imports, [Expr (:using , Expr (:., fullname (rosrootmod)... , Symbol (m), :msg ) ) for m in othermods])
356
355
imports
357
356
end
358
357
function _importexprs (mod:: ROSSrvModule , rosrootmod:: Module )
359
358
imports = Expr[
360
- Expr ( : import, : RobotOS, : AbstractSrv ),
361
- Expr ( : import, : RobotOS, : AbstractService ),
362
- Expr ( : import, : RobotOS, : _srv_reqtype ),
363
- Expr ( : import, : RobotOS, : _srv_resptype ),
359
+ :( import RobotOS. AbstractSrv),
360
+ :( import RobotOS. AbstractService),
361
+ :( import RobotOS. _srv_reqtype),
362
+ :( import RobotOS. _srv_resptype)
364
363
]
365
- append! (imports, [Expr (:using ,fullname (rosrootmod)... ,Symbol (m),:msg ) for m in mod. deps])
364
+ append! (imports, [Expr (:using , Expr (:., fullname (rosrootmod)... , Symbol (m), :msg ) ) for m in mod. deps])
366
365
imports
367
366
end
368
367
@@ -513,8 +512,8 @@ function _addtypemember!(exprs, namestr, typestr)
513
512
jlconargs = exprs[4 ]. args[2 ]. args
514
513
515
514
if typestr == " char" || typestr == " byte"
516
- warn (" Use of type '$typestr ' is deprecated in message definitions, " ,
517
- " use '$(lowercase (string (_ros_builtin_types[typestr]))) ' instead." )
515
+ @ warn (" Use of type '$typestr ' is deprecated in message definitions, " *
516
+ " use '$(lowercase (string (_ros_builtin_types[typestr]))) ' instead." )
518
517
end
519
518
520
519
typestr, arraylen = _check_array_type (typestr)
@@ -609,7 +608,7 @@ function _splittypestr(typestr::String)
609
608
end
610
609
# Valid ROS type string is all word chars split by a single forward slash, with
611
610
# optional square brackets for array types
612
- _isrostype (s:: String ) = ismatch (r" ^\w +/\w +(?:\[\d *\] )?$" , s)
611
+ _isrostype (s:: String ) = occursin (r" ^\w +/\w +(?:\[\d *\] )?$" , s)
613
612
614
613
# Sanitize a string by checking for and removing brackets if they are present
615
614
# Return the sanitized type and the number inside the brackets if it is a fixed
0 commit comments