@@ -64,6 +64,10 @@ abstract type AbstractMsg end
6464abstract type AbstractSrv end
6565abstract type AbstractService end
6666
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+
6771"""
6872 @rosimport
6973
@@ -81,13 +85,11 @@ macro rosimport(input)
8185 # Rearranges the expression into a RobotOS._rosimport call. Input comes in as a single package
8286 # qualified expression, or as a tuple expression where the first element is the same as the
8387 # 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"
8991 pkg, ismsg, typ = _pkgtype_import (input. args[1 ])
90- push! ( types, typ)
92+ types = String[ typ]
9193 for t in input. args[2 : end ]
9294 @assert isa (t, Symbol) " Type name ($(string (t)) ) not a symbol"
9395 push! (types, string (t))
@@ -98,32 +100,29 @@ macro rosimport(input)
98100 return :(_rosimport ($ pkg, $ ismsg, $ typ))
99101 end
100102end
101-
102- _get_quote_value (input:: QuoteNode ) = input. value
103- _get_quote_value (input:: Expr ) = (@assert input. head == :quote ; input. args[1 ])
104-
105103# Return the pkg and types strings for a single expression of form:
106104# pkg.[msg|srv].type or pkg.[msg|srv]:type
107105function _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 ]
112110 @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
114113 @assert m_or_s in (:msg ,:srv ) " Improper @rosimport input"
115114 ps = string (p)
116115 msb = m_or_s == :msg
117116 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 ]
123122 @assert isa (tsym, Symbol) " Type name ($(string (tsym)) ) not a symbol"
124123 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
127126 @assert isa (tsym, Symbol) " Type name ($(string (tsym)) ) not a symbol"
128127 ts = string (tsym)
129128 end
@@ -179,8 +178,8 @@ function addtype!(mod::ROSMsgModule, typ::String)
179178 if ! (typ in mod. members)
180179 @debug (" Message type import: " , _fullname (mod), " ." , typ)
181180 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" )) '" )
184183 end
185184 pymod, pyobj = _pyvars (_fullname (mod), typ)
186185
@@ -350,19 +349,19 @@ end
350349
351350# The imports specific to each module, including dependant packages
352351function _importexprs (mod:: ROSMsgModule , rosrootmod:: Module )
353- imports = Expr[Expr ( : import, : RobotOS, : AbstractMsg )]
352+ imports = Expr[:( import RobotOS. AbstractMsg)]
354353 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])
356355 imports
357356end
358357function _importexprs (mod:: ROSSrvModule , rosrootmod:: Module )
359358 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)
364363 ]
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])
366365 imports
367366end
368367
@@ -513,8 +512,8 @@ function _addtypemember!(exprs, namestr, typestr)
513512 jlconargs = exprs[4 ]. args[2 ]. args
514513
515514 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." )
518517 end
519518
520519 typestr, arraylen = _check_array_type (typestr)
@@ -609,7 +608,7 @@ function _splittypestr(typestr::String)
609608end
610609# Valid ROS type string is all word chars split by a single forward slash, with
611610# 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)
613612
614613# Sanitize a string by checking for and removing brackets if they are present
615614# Return the sanitized type and the number inside the brackets if it is a fixed
0 commit comments