Skip to content

Commit

Permalink
feat: assume <table>.<field> = as function if ---@param is found (#…
Browse files Browse the repository at this point in the history
…50)

Resolves #31
  • Loading branch information
numToStr authored Oct 13, 2022
1 parent 7e46731 commit 3fc909e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
10 changes: 2 additions & 8 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,9 @@ impl Lexer {
kind: Kind::Local,
}),
))),
func.clone()
.ignore_then(dotted)
func.ignore_then(dotted)
.map(|(prefix, kind, name)| TagType::Func { prefix, name, kind }),
choice((
expr.clone()
.then_ignore(func)
.map(|(prefix, kind, name)| TagType::Func { prefix, name, kind }),
expr.map(|(prefix, kind, name)| TagType::Expr { prefix, name, kind }),
)),
expr.map(|(prefix, kind, name)| TagType::Expr { prefix, name, kind }),
keyword("return")
.ignore_then(ident().padded())
.then_ignore(end())
Expand Down
5 changes: 4 additions & 1 deletion src/parser/tags/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ impl_parse!(Func, {
.then(Return::parse().repeated())
.then(See::parse())
.then(Usage::parse().or_not())
.then(select! { TagType::Func { prefix, name, kind } => (prefix, name, kind) })
.then(select! {
TagType::Func { prefix, name, kind } => (prefix, name, kind),
TagType::Expr { prefix, name, kind } => (prefix, name, kind),
})
.map(
|(((((desc, params), returns), see), usage), (prefix, name, kind))| Self {
name,
Expand Down
19 changes: 19 additions & 0 deletions tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,17 @@ fn functions() {
return (U.mul(this, that) / U.sum(that, this)), (U.sum(this, that) * U.sub(that, this))
end
local function wrap(arg1, arg2)
return function(...)
-- Do work
end
end
---Wrapped function
---@param foo string
---@param bar integer
U.exported_fn = wrap('a', 'b')
return U
"#;

Expand Down Expand Up @@ -282,6 +293,14 @@ U.magical({this}, {that}) *U.magical*
|U.sub|
U.exported_fn({foo}, {bar}) *U.exported_fn*
Wrapped function
Parameters: ~
{foo} (string)
{bar} (integer)
"
)
}
Expand Down

0 comments on commit 3fc909e

Please sign in to comment.