WingedSeal / jmc

A compiler for JMC (JavaScript-like Minecraft Function), a mcfunction extension language for making Minecraft Datapack
https://jmc.wingedseal.com
MIT License
64 stars 10 forks source link

[BUG] `EVAL` throws errors in macro factories #110

Open Nico314159 opened 4 months ago

Nico314159 commented 4 months ago

Describe the bug [A clear and concise description of what the bug is.]

When using #define, defining another macro factory in terms of EVAL expressions results in a parsing error.

To Reproduce [Steps to reproduce the behavior]

  1. Write the following code in a .hjmc file:
    #define SCALE 480
    #bind EVAL
    #define Units(x) EVAL((x * SCALE) \ 1)
  2. Use jmc compile
  3. Read the error message that appears in console.

Expected behavior [A clear and concise description of what you expected to happen.]

I expect that the code would compile without error, and that if something like Units(1.5) appeared in the main code, it would be automatically replaced with 720

Actual behavior

I get the following error.

EvaluationException
Unable to evaluate expression '(x * 480)\1'`

Desktop

WingedSeal commented 4 months ago

This is a problem in __parse_header which it tries to parse line #define Units(x) EVAL((x * SCALE) \ 1) then tries to evaluate EVAL((x * SCALE) \ 1) first which obviously fails. Parsing header depends on the tokenizer which completely parse out the replacement tokens for define first. A possible solution is to hoist binding EVAL to the last stage of parsing header somehow, then apply it back again somehow. I'll look into this later.