Skip to content

Fix braceless functions #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Fix braceless functions #62

wants to merge 2 commits into from

Conversation

RblSb
Copy link
Member

@RblSb RblSb commented Mar 30, 2025

This makes tree more flat, there is no more method scope and method return typehint is handled in global, since there is no a good way to catch function():Hint body, i think. Needs some testing.

Closes #60
Closes #46
Closes #19
Closes #3

name: meta.method.hx
patterns:
- include: '#macro-reification'
- include: '#method-name'
- include: '#method-name-post'
- include: '#method-block'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#method-block is no longer referenced anywhere. somehow restoring this line doesn't change output.

it doesn't feel right that #method-block seems to no longer be needed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there much sense for syntax highlighter to separate method blocks from other blocks? As example dart has very flat scope system. TS has very descriptive, but regex logic for it is kinda insane.
Although this change can be too radical, so maybe there is better and less breaking fix for current problem, I'm just not good enough at this format to find it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently it adds meta.method.block.hx to the list of scope names. searching all of github, I could find mostly Haxe repos having that name. I didn't find any themes (unless I missed them). so there might not be any themes out there that would have different colors for "method blocks" as opposed to "regular blocks".

so we might get away with dropping #method-block without messing up anyone's colors.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we can merge this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the diffs remove a lot of meta.method.hx from baselines and that doesn't seem correct, because usually scopes are added going deeper. meaning everything carries all their outer scopes plus their new / specific ones.

I've looked at e.g. typescript baseline files and they have meta.function.ts for everything from function signature to all things inside it's body. just like what we had with meta.method.hx.

so I'm not sure if it's a good idea to remove those.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that TS requires brackets for anon functions, but in Haxe we cannot detect end of meta.method.hx group to close it.

function f() {
    final v = function() foo();
}
123; // stays in unclosed meta.method.hx
abstract Callback<T>(CallbackData<T>) from CallbackData<T> {} // same

// or this case:
class Hello {
	function main(args: String)
		println("Hello, world")
	function main2(args: String) // still in prev meta.method.hx
		println("Hello, world")
}

I found that Scala has such braceless functions, and it has flat structure too.

object Hello {
    def main(args: Array[String]) =
        println("Hello, world") // just source.scala scope
    def main2(args: Array[String]) =
        println("Hello, world") // so no problem
}

Tested if i can find some matching workaround again, but still don't see other solutions that drop method scope here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants