Skip to content

[Feature Request] Support nonstandardSymbol for Lambda-Style Functions #2515

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

Closed
bavalpey opened this issue Feb 7, 2024 · 2 comments · Fixed by #2720
Closed

[Feature Request] Support nonstandardSymbol for Lambda-Style Functions #2515

bavalpey opened this issue Feb 7, 2024 · 2 comments · Fixed by #2720

Comments

@bavalpey
Copy link
Contributor

bavalpey commented Feb 7, 2024

I've been working on writing a definition file for Tabletop Simulator's Lua API.

The lua runtime used by Tabletop Simulator is a subset of Moonsharp (currently version 2.0.0.0).
While it would be great if we could get support for Moonsharp as a runtime option, I realize the amount of effort that would require.

For the most part, it's straightforward to write definition files for the functionality added by Moonsharp.
However, Moonsharp adds additional syntax: the use of || for lambda style functions (aka closures).
It looks like this:

|[,args]| expression

Which is shorthand for

function(args) return expression end

Unfortunately, || is already used for the "or" nonstandard symbol, so I'm not sure how to mark this.

@bavalpey bavalpey changed the title Feature Request: Support nonstandardSymbol for Lambda-Style Functions [Feature Request] Support nonstandardSymbol for Lambda-Style Functions Feb 7, 2024
@4P5
Copy link

4P5 commented Feb 25, 2024

I'm working with a similar syntax, a,b -> expr.

I was able to disable warnings for the lines my expression is used on with a plugin, though this doesn't properly integrate with the language server. You might be able to transform your syntax into the regular Lua syntax, which the language server would work with.

function OnSetText(uri, text)
    local diffs = {}

    for line in text:gmatch("->[^\n]*()") do
	    diffs[#diffs+1] = {
		    start = line - 1,
		    finish = line - 1,
		    text = "--[[@diagnostic disable-line: undefined-global, unknown-symbol, redundant-parameter]]"
	    }
    end
    
    return diffs
end

@bavalpey
Copy link
Contributor Author

I'm working with a similar syntax, a,b -> expr.

I was able to disable warnings for the lines my expression is used on with a plugin, though this doesn't properly integrate with the language server. You might be able to transform your syntax into the regular Lua syntax, which the language server would work with.

function OnSetText(uri, text)
    local diffs = {}

    for line in text:gmatch("->[^\n]*()") do
	    diffs[#diffs+1] = {
		    start = line - 1,
		    finish = line - 1,
		    text = "--[[@diagnostic disable-line: undefined-global, unknown-symbol, redundant-parameter]]"
	    }
    end
    
    return diffs
end

Yeah so I looked into this and realized it was the route I would have to take until this is supported. However, your precise solution is brittle from my perspective as it doesn't respect the precise syntax of lua expressions. (Stopping at a newline?). Also wouldn't support nested lambda expressions.
I would need to hook into something like LPEG. From my point of view, if I can't give it full and proper support, it's better to give no support.

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

Successfully merging a pull request may close this issue.

2 participants