miking-lang / miking

Miking - the meta viking: a meta-language system for creating embedded languages
Other
51 stars 31 forks source link

Add support for negative numbers #818

Closed br4sco closed 10 months ago

br4sco commented 10 months ago

This PR adds support for negative numbers (ints and floats) in the boot parser. The motivation for this addition follows.

  1. We can then match on negative integers (right now we can only match on positive integers).
  2. We do not have to re-discover negative numbers after transformations, such as constant folding or partial evaluation, and translate these to applications of negi or negf on positive numbers before, e.g., pretty printing.
  3. There is no ambiguity between negative number literals and applications of negation operations negi and negf.

An effect of this change is that it is allowed to project from records with, e.g., t.-1, which is well typed if t : all a. { #label"-1" : a, ... }.

This PR solves https://github.com/miking-lang/miking/issues/796, except that it does not make any changes to mexpr/parser.mc.