Skip to content
This repository was archived by the owner on Aug 24, 2024. It is now read-only.

Commit 8471b60

Browse files
committed
feat: allow runAnalysis with custom Output
1 parent 4dd8e71 commit 8471b60

File tree

7 files changed

+55
-43
lines changed

7 files changed

+55
-43
lines changed

LeanInk/Analysis/Basic.lean

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import LeanInk.Configuration
22
import LeanInk.FileHelper
3-
import LeanInk.Annotation
3+
import LeanInk.Annotation.DataTypes
4+
import LeanInk.Annotation.Alectryon
45
import LeanInk.Logger
56
import LeanInk.CLI
67

@@ -10,6 +11,7 @@ import Lean.Util.Path
1011

1112
namespace LeanInk.Analysis
1213

14+
open LeanInk.Annotation
1315
open LeanInk.CLI
1416
open Lean
1517
open System
@@ -21,7 +23,6 @@ private def _buildConfiguration (arguments: List ResolvedArgument) (file: FilePa
2123
return {
2224
inputFilePath := file
2325
inputFileContents := contents
24-
outputType := OutputType.alectryonFragments
2526
lakeFile := getLakeFile? arguments
2627
verbose := containsFlag arguments "--verbose"
2728
experimentalTypeInfo := containsFlag arguments "--x-enable-type-info"
@@ -34,24 +35,31 @@ where
3435
| none => none
3536
| some string => some (FilePath.mk string)
3637

37-
def runAnalysis : AnalysisM UInt32 := do
38+
def runAnalysis (output : Output) : AnalysisM UInt32 := do
3839
let config ← read
3940
logInfo s!"Starting process with lean file: {config.inputFileName}"
4041
logInfo "Analyzing..."
4142
let result ← analyzeInput config
4243
logInfo "Annotating..."
4344
let annotation ← Annotation.annotateFile result
4445
logInfo "Outputting..."
45-
returnAnnotation.Alectryon.genOutput annotation
46+
returnoutput.genOutput annotation
4647

4748
-- EXECUTION
49+
def execAuxM : AnalysisM UInt32 := do
50+
return ← runAnalysis {
51+
name := "Alectryon"
52+
genOutput := Alectryon.genOutput
53+
}
54+
4855
def execAux (args: List ResolvedArgument) (file: String) : IO UInt32 := do
4956
if not (_validateInputFile file) then do
5057
Logger.logError s!"Provided file \"{file}\" is not lean file."
5158
else
5259
IO.println s!"Starting Analysis for: \"{file}\""
5360
let config ← _buildConfiguration args file
54-
return ← (runAnalysis.run config)
61+
return ← (execAuxM.run config)
62+
5563

5664
def exec (args: List ResolvedArgument) : List String -> IO UInt32
5765
| [] => do Logger.logError s!"No input files provided"

LeanInk/Analysis/DataTypes.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import LeanInk.ListUtil
2-
import LeanInk.Configuration
32

43
import Lean.Elab
54
import Lean.Data.Lsp

LeanInk/Analysis/SemanticToken.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import LeanInk.Analysis.DataTypes
2+
import LeanInk.Configuration
23
import LeanInk.ListUtil
34

45
import Lean.Elab

LeanInk/Annotation/Basic.lean

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import LeanInk.ListUtil
33
import LeanInk.Logger
44

55
import LeanInk.Annotation.Util
6+
import LeanInk.Annotation.DataTypes
67

78
import LeanInk.Analysis.DataTypes
89
import LeanInk.Analysis.Analysis
@@ -14,10 +15,6 @@ open LeanInk.Analysis
1415
/-
1516
Annotation
1617
-/
17-
structure Annotation where
18-
sentence : Compound Sentence
19-
tokens : List (Compound Token)
20-
2118
def tokensBetween (aux : List (Compound Token)) (head : String.Pos) (tail : Option String.Pos) : List (Compound Token) -> List (Compound Token)
2219
| [] => aux
2320
| x::xs =>

LeanInk/Annotation/DataTypes.lean

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import LeanInk.Analysis.DataTypes
2+
3+
namespace LeanInk.Annotation
4+
5+
open LeanInk.Analysis
6+
7+
universe u
8+
9+
/- COMPOUND -/
10+
structure Compound (β : Type u) where
11+
headPos : String.Pos
12+
fragments : List (Nat × β)
13+
deriving Inhabited
14+
15+
structure Annotation where
16+
sentence : Compound Sentence
17+
tokens : List (Compound Token)
18+
19+
namespace Compound
20+
def getFragments (self : Compound b) : List b := self.fragments.map (λ f => f.2)
21+
22+
def tailPos { x : Type u } [Positional x] (self : Compound x) : Option String.Pos := (self.getFragments.map (λ f => Positional.tailPos f)).maximum?
23+
24+
def empty { x : Type u } (headPos : String.Pos) : Compound x := { headPos := headPos, fragments := [] }
25+
end Compound
26+
27+
instance {a : Type u} [ToString a] : ToString (Compound a) where
28+
toString (self : Compound a) : String := "<COMPOUND head:" ++ toString self.headPos ++ " fragments := " ++ toString self.getFragments ++ ">"

LeanInk/Annotation/Util.lean

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,12 @@ import LeanInk.Configuration
22
import LeanInk.Logger
33

44
import LeanInk.Analysis.Analysis
5+
import LeanInk.Analysis.DataTypes
56

67
namespace LeanInk.Annotation
78

89
open LeanInk.Analysis
910

10-
universe u
11-
12-
/- COMPOUND -/
13-
structure Compound (β : Type u) where
14-
headPos : String.Pos
15-
fragments : List (Nat × β)
16-
deriving Inhabited
17-
18-
namespace Compound
19-
def getFragments (self : Compound b) : List b := self.fragments.map (λ f => f.2)
20-
21-
def tailPos { x : Type u } [Positional x] (self : Compound x) : Option String.Pos := (self.getFragments.map (λ f => Positional.tailPos f)).maximum?
22-
23-
def empty { x : Type u } (headPos : String.Pos) : Compound x := { headPos := headPos, fragments := [] }
24-
end Compound
25-
26-
instance {a : Type u} [ToString a] : ToString (Compound a) where
27-
toString (self : Compound a) : String := "<COMPOUND head:" ++ toString self.headPos ++ " fragments := " ++ toString self.getFragments ++ ">"
28-
2911
/- FRAGMENT INTERVAL -/
3012
inductive FragmentInterval (a : Type u) where
3113
| head (pos: String.Pos) (fragment: a) (idx: Nat)

LeanInk/Configuration.lean

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
1+
import LeanInk.Annotation.DataTypes
2+
13
namespace LeanInk
24

35
open System
6+
open LeanInk.Annotation
47

5-
-- The `OutputType` specifies in which format the result of
6-
-- leanInks analysis gets returned.
7-
inductive OutputType where
8-
-- alectryonFragments describes the format used by Alectryon which basically is a list
9-
-- of fragments. Each fragment is either a `Text` or `Sentence`. TODO: specify further
10-
| alectryonFragments : OutputType
11-
12-
-- The analyze `Configuration` describes all input specifications and infos for
13-
-- the LeanInk analysis execution context. It contains the list of input file paths, etc.
148
structure Configuration where
159
inputFilePath : FilePath
1610
inputFileContents : String
17-
outputType : OutputType
1811
lakeFile : Option FilePath
1912
verbose : Bool
2013
experimentalTypeInfo : Bool
2114
experimentalDocString : Bool
2215
experimentalSemanticType : Bool
2316

2417
namespace Configuration
18+
def inputFileName (self : Configuration) : String :=
19+
self.inputFilePath.toString
20+
end Configuration
2521

26-
def inputFileName (self : Configuration) : String :=
27-
self.inputFilePath.toString
22+
abbrev AnalysisM := ReaderT Configuration $ IO
2823

29-
end Configuration
24+
structure Output where
25+
name : String
26+
genOutput : List Annotation -> AnalysisM UInt32
3027

31-
abbrev AnalysisM := ReaderT Configuration $ IO
28+
abbrev ExecM := ReaderT Configuration $ IO

0 commit comments

Comments
 (0)