# Parser support for open/closed interval notation?

**URL:** <https://discourse.julialang.org/t/parser-support-for-open-closed-interval-notation/43781>\
**Category:** General Usage\
**Tags:** intervals, parser\
**Created:** [July 27, 2020, 5:40pm UTC](https://discourse.julialang.org/t/parser-support-for-open-closed-interval-notation/43781 "2020-07-27T17:40:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cce](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cce/32/460_2.png) [@cce](https://discourse.julialang.org/u/cce)\
**Post date:** [July 27, 2020, 5:40pm UTC](https://discourse.julialang.org/t/parser-support-for-open-closed-interval-notation/43781/1 "2020-07-27T17:40:21Z")

</div>

I’m working with `Interval{DateTime}` these days, in particular, within a medical data processing application that requires modeling of with closed/open endpoints. It’s inconvenient to write/update intervals due to the permutations of open/closed on each of the right/left endpoints. The `Intervals.jl` library is using more traditional syntax for `show()`, for example, `[1..3)` indicates that the left-most endpoint is closed and the right-most is open. On the other hand, `IntervalSets.jl` eschews this notation, and uses `1..3 (closed-open)` for its representation of the same interval. I’m wondering if this important use case have specialized syntax support in the parser? That is, when you see `..` permit `]` to close a `(` and permit `]` to close a `(`. With this parser change, it might be easier to support custom syntaxes via macros that handle open/closed variants, and also unify what seems to be an unnecessary notation divergence between these two `Interval` implementations.

---

<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:** [July 28, 2020, 8:37am UTC](https://discourse.julialang.org/t/parser-support-for-open-closed-interval-notation/43781/2 "2020-07-28T08:37:21Z")

</div>

I don’t think that extending Julia’s syntax is the best solution here, since the resulting AST is otherwise invalid, and would need to keep track of the parentheses itself, so it is a huge change for a very specialized use case.

Instead, I would recommend a [non-standard literal](https://docs.julialang.org/en/v1/manual/metaprogramming/#Non-Standard-String-Literals-1), eg `iv"[1..3)"` could just parse to the relevant constructor (allowing the endpoints to be expressions, of course).
