Skip to content

Add interval literal syntax #51

Description

@Seddryck

Summary

Add first-class interval literals to the Expressif grammar and syntax model.

Intervals should use an explicit I prefix and mathematical bound notation, while accepting both common bracket conventions.

Proposed syntax

Bounded intervals

I[1, 10]    // inclusive lower, inclusive upper
I[1, 10)    // inclusive lower, exclusive upper
I(1, 10]    // exclusive lower, inclusive upper
I(1, 10)    // exclusive lower, exclusive upper

Also accept the continental-European notation using reversed square brackets:

I[1, 10[    // inclusive lower, exclusive upper
I]1, 10]    // exclusive lower, inclusive upper
I]1, 10[    // exclusive lower, exclusive upper

The two notations are aliases and must produce the same syntax/AST semantics.

Infinite bounds

Expressif already uses +INF and -INF. They should be valid interval bounds:

I[-INF, +INF]
I[0, +INF]
I]0, +INF]
I[-INF, 0]
I[-INF, 0[

Existing sign-oriented shorthands

Preserve the established interval forms and map them to the corresponding first-class interval semantics:

I(0+)   // zero or positive
I(+)    // positive
I(0-)   // zero or negative
I(-)    // negative

Equivalent semantics:

I(0+)  == [0, +INF]
I(+)   == ]0, +INF]
I(0-)  == [-INF, 0]
I(-)   == [-INF, 0[

Dates and temporal values

Interval bounds should use the canonical Expressif literal syntax. Dates must therefore remain explicit typed literals:

I[#"2022-12-10", #"2022-12-31"[

Do not accept bare date-looking tokens such as:

I[2022-12-10, 2022-12-31]

because 2022-12-10 is otherwise lexically indistinguishable from arithmetic subtraction. The canonical date literal is #"2022-12-10".

Syntax model

The syntax/AST representation should normalize notation differences and expose at least:

  • lower bound value
  • upper bound value
  • lower-bound inclusivity
  • upper-bound inclusivity
  • infinite bounds where applicable

For example, these should have identical semantics:

I[1, 10)
I[1, 10[

Acceptance criteria

  • Parse bounded intervals with inclusive/exclusive endpoints.
  • Accept both parenthesis and European reversed-square-bracket notation.
  • Support +INF and -INF as interval bounds.
  • Support the existing (0+), (+), (0-), and (-) interval concepts through the new interval literal syntax.
  • Require canonical Expressif literals for temporal bounds, e.g. #"2022-12-10".
  • Normalize equivalent spellings to the same syntax/AST semantics.
  • Add grammar tests, syntax-node tests, and C# bindings for interval literals.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions