This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: a basic visual programming linter
- Loading branch information
1 parent
cf58c65
commit 3574486
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Lunarbox.Data.Dataflow.Expression.Lint where | ||
|
||
import Prelude | ||
import Data.Array as Array | ||
import Lunarbox.Data.Dataflow.Expression (Expression(..), VarName, foldExpression) | ||
|
||
data LintError l | ||
= UnusedDeclaration VarName l | ||
|
||
-- | Collect linting errors inside an expression | ||
lint :: forall l. Expression l -> Array (LintError l) | ||
lint = foldExpression go | ||
where | ||
go (Let location name _ body) | ||
| Array.null (references name body) = | ||
[ UnusedDeclaration name location | ||
] | ||
|
||
go a = [] | ||
|
||
-- | Get all the places a variable is referenced in | ||
references :: forall l. VarName -> Expression l -> Array l | ||
references target = foldExpression go | ||
where | ||
go (Variable location name) | ||
| target == name = [ location ] | ||
|
||
go _ = [] |