hlorenzi / customasm

💻 An assembler for custom, user-defined instruction sets! https://hlorenzi.github.io/customasm/web/
Apache License 2.0
719 stars 56 forks source link

"unknown symbol" error when start of label matches start of ruledef #205

Open PerkyElixir22 opened 5 months ago

PerkyElixir22 commented 5 months ago
#subruledef Foo {
    f{i:u7}    => i`7
}

#ruledef Bar {
    [{f:Foo}]  => 0`1 @ f
    [{i:u7}]   => 1`1 @ i`7
}

foo:
bar:

    [f10]
    [bar]
    [foo]    ; unknown symbol `oo`
hlorenzi commented 4 months ago

This is intended behavior, since we always prioritize matches by the amount of non-parametrized tokens.

[f __ ] wins versus [ __ ] since there's an extra non-parametrized f, and then we naturally only continue the resolution process with the winning match, which is parsed as [f oo] and gets us the symbol error.

Do you have a practical use-case in mind where your behavior would be more appropriate? Otherwise, I think it'd be fine if we leave the current behavior as is.

PerkyElixir22 commented 4 months ago

Sometimes when I write code I make a function or variable with a name that starts with r. My register pattern is r{i:uZ} (I would think I'm not the only one with this pattern). This makes it so I have to either surround the function/variable name in parenthesis any time I want to access it, or change the name, both of which are somewhat inconvenient.

This is something I would otherwise usually expect to work, so it's slightly annoying when it doesn't.

hlorenzi commented 4 months ago

Yeah, that does sound pretty useful. Perhaps I'll have to rethink this behavior, but I'm unsure of its consequences at this point. Let me investigate it further!