# Why does Meta.parse ignores comments?

**URL:** <https://discourse.julialang.org/t/why-does-meta-parse-ignores-comments/109523>\
**Category:** General Usage\
**Tags:** metaprogramming\
**Created:** [January 31, 2024, 3:50pm UTC](https://discourse.julialang.org/t/why-does-meta-parse-ignores-comments/109523 "2024-01-31T15:50:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [January 31, 2024, 3:50pm UTC](https://discourse.julialang.org/t/why-does-meta-parse-ignores-comments/109523/1 "2024-01-31T15:50:12Z")

</div>

I am really surprised that `Meta.parse` seems to actively kick out some information

```julia
julia> Meta.parse("""
       function hi()
       # comment
       end
       """)
:(function hi()
      #= none:1 =#
      #= none:1 =#
  end)

```

The comment is missing apparently…

EDIT: using Julia 1.10.0

---

<div class="post-metadata">

**Author:** ![vchuravy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vchuravy/32/8_2.png) [@vchuravy](https://discourse.julialang.org/u/vchuravy)\
**Post date:** [January 31, 2024, 4:01pm UTC](https://discourse.julialang.org/t/why-does-meta-parse-ignores-comments/109523/2 "2024-01-31T16:01:17Z")

</div>

Comments have no semantic meanings, I think JuliaParser.jl keeps track of them.

---

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [January 31, 2024, 4:03pm UTC](https://discourse.julialang.org/t/why-does-meta-parse-ignores-comments/109523/3 "2024-01-31T16:03:23Z")

</div>

JuliaParser is no longer maintained. This is not an option

---

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [January 31, 2024, 4:04pm UTC](https://discourse.julialang.org/t/why-does-meta-parse-ignores-comments/109523/4 "2024-01-31T16:04:26Z")

</div>

also I think comments can indeed have semantic meaning. especially as julia has macros, it may make sense to but semantic information inside comments, why not?

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [January 31, 2024, 4:11pm UTC](https://discourse.julialang.org/t/why-does-meta-parse-ignores-comments/109523/5 "2024-01-31T16:11:09Z")

</div>

> [@schlichtanders](#):
>
> it may make sense to but semantic information inside comments, why not?

It’s almost the definition of a comment, something that appears in the raw source code but has no semantic meaning?

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [January 31, 2024, 4:12pm UTC](https://discourse.julialang.org/t/why-does-meta-parse-ignores-comments/109523/6 "2024-01-31T16:12:11Z")

</div>

Semantic meaning for code. Comments by design don’t affect code at all, so they were always ignored in expressions in any language. Hypothetically I suppose it could be incorporated into expressions and then ignored later, but there’s no real reason to do that because we’re supposed to read source code. In fact it would bloat the size of expressions only to allow a secondary place to read comments.

---

<div class="post-metadata">

**Author:** ![vchuravy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vchuravy/32/8_2.png) [@vchuravy](https://discourse.julialang.org/u/vchuravy)\
**Post date:** [January 31, 2024, 4:46pm UTC](https://discourse.julialang.org/t/why-does-meta-parse-ignores-comments/109523/7 "2024-01-31T16:46:02Z")

</div>

> [@schlichtanders](#):
>
> JuliaParser is no longer maintained. This is not an option

Sorry freudian slip. JuliaSyntax.jl or CSTParser.jl

> [@schlichtanders](#):
>
> also I think comments can indeed have semantic meaning. especially as julia has macros, it may make sense to but semantic information inside comments, why not?

It sounds like you want to implement something like a pragma?  
You can just add an argument to the macro to pass in additional information rather than depend on comments.

If you need to perform custom parsing you can use string macros [Metaprogramming · The Julia Language](https://docs.julialang.org/en/v1/manual/metaprogramming/#meta-non-standard-string-literals)

Comments not having semantic meaning comes from Julia’s LISP heritage.

From [Comments (GNU Emacs Lisp Reference Manual)](https://www.gnu.org/software/emacs/manual/html_node/elisp/Comments.html)

> The Lisp reader discards comments; they do not become part of the Lisp objects which represent the program within the Lisp system.
