# String macro with trailing argument

**URL:** <https://discourse.julialang.org/t/string-macro-with-trailing-argument/121162>\
**Category:** General Usage\
**Tags:** macros\
**Created:** [October 10, 2024, 5:32pm UTC](https://discourse.julialang.org/t/string-macro-with-trailing-argument/121162 "2024-10-10T17:32:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 10, 2024, 5:32pm UTC](https://discourse.julialang.org/t/string-macro-with-trailing-argument/121162/1 "2024-10-10T17:32:08Z")

</div>

I am trying to get the string literal macro example with a trailing argument from the [manual](https://docs.julialang.org/en/v1/manual/metaprogramming/#meta-non-standard-string-literals) to work (end of section linked), with the MWE

```julia
struct Foo
    str::String
    flag::Bool
end

macro foo_str(str, flag)
    _flag = if flag == "true"
        true
    elseif flag == "false"
        false
    else
        error("need a boolean flag, got $(flag)")
    end
    Foo(str, _flag)
end

foo"bar"true

```

which gives me the error

```julia
julia> foo"bar"true
ERROR: LoadError: MethodError: no method matching var"@foo_str"(::LineNumberNode, ::Module, ::String)
The function `@foo_str` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  var"@foo_str"(::LineNumberNode, ::Module, ::Any, ::Any)
   @ Main REPL[10]:1

```

What am I missing?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 10, 2024, 5:39pm UTC](https://discourse.julialang.org/t/string-macro-with-trailing-argument/121162/2 "2024-10-10T17:39:25Z")

</div>

> [@Tamas\_Papp](#):
>
> `foo"bar"true`

The problem is that, since `true` is numeric literal, this is parsed as a multiplication:

```julia
julia> :(foo"bar"true)
:(foo"bar" * true)

```

Just use `t` and `f` as your flags and it should work … normally these string-macro flags are one-character, like in regexes.
