@@ -44,38 +44,26 @@ instance : Positional Fragment where
44
44
45
45
/- Token -/
46
46
/--
47
- `TokenInfo` is the base structure of all `Token`.
48
- Inherently it describe the semantic info of the token, which can and should be used for semantic syntax
49
- highlighting.
47
+ `SemanticTokenInfo` describe the semantic info of the token, which can and should be used for semantic syntax highlighting.
50
48
-/
51
- structure TokenInfo extends Fragment where
49
+ structure SemanticTokenInfo extends Fragment where
52
50
semanticType: Option String := none
53
51
deriving Inhabited
54
52
55
53
/--
56
54
The `TypeTokenInfo` describes the metadata of a source text token that conforms
57
- to a specific type within our type system.
58
- E.g.: A variable token `p` might conform to type `Nat`
55
+ to a specific type within our type system. It may also describe just a docstring associated with the token.
56
+ We combine both these informatio together, as the docstring is naturally attached to the type.
57
+ E.g.: A variable token `p` might conform to type `Nat` and has the docstring for `Nat`
59
58
-/
60
- structure TypeTokenInfo extends TokenInfo where
61
- type: String
59
+ structure TypeTokenInfo extends Fragment where
60
+ type: Option String
61
+ docString: Option String
62
62
deriving Inhabited
63
63
64
64
instance : Positional TypeTokenInfo where
65
65
headPos := (λ x => x.toFragment.headPos)
66
66
tailPos := (λ x => x.toFragment.tailPos)
67
-
68
- /--
69
- The `DocStringTokenInfo` describes the metadata of an available docstring of a source text token.
70
- In this case a source text token may be a function or structure with a docstring.
71
- -/
72
- structure DocStringTokenInfo extends TokenInfo where
73
- docString: String
74
- deriving Inhabited
75
-
76
- instance : Positional DocStringTokenInfo where
77
- headPos := (λ x => x.toFragment.headPos)
78
- tailPos := (λ x => x.toFragment.tailPos)
79
67
80
68
/--
81
69
A `Token` describes the metadata of a specific range of source text.
@@ -86,25 +74,25 @@ instance : Positional DocStringTokenInfo where
86
74
-/
87
75
inductive Token where
88
76
| type (info: TypeTokenInfo)
89
- | docString (info: DocStringTokenInfo )
77
+ | semantic (info: SemanticTokenInfo )
90
78
deriving Inhabited
91
79
92
- instance : ToString Token where -- TODO: Improve this
80
+ instance : ToString Token where
93
81
toString : Token -> String
94
82
| Token.type _ => "Type"
95
- | Token.docString _ => "DocString "
83
+ | Token.semantic _ => "Semantic "
96
84
97
85
namespace Token
98
86
def toFragment : Token -> Fragment
99
87
| type info => info.toFragment
100
- | docString info => info.toFragment
88
+ | semantic info => info.toFragment
101
89
102
90
def toTypeTokenInfo? : Token -> Option TypeTokenInfo
103
91
| type info => info
104
92
| _ => none
105
93
106
- def toDocStringTokenInfo ? : Token -> Option DocStringTokenInfo
107
- | docString info => info
94
+ def toSemanticTokenInfo ? : Token -> Option SemanticTokenInfo
95
+ | semantic info => info
108
96
| _ => none
109
97
end Token
110
98
@@ -239,25 +227,23 @@ namespace TraversalFragment
239
227
let elabInfo := fragment.info
240
228
return ← findDocString? env elabInfo.elaborator <||> findDocString? env elabInfo.stx.getKind
241
229
242
- def genDocStringTokenInfo? (self : TraversalFragment) : AnalysisM (Option DocStringTokenInfo) := do
243
- match ← runMetaM (genDocString?) self with
244
- | some string => some { headPos := self.headPos, tailPos := self.tailPos, docString := string }
245
- | none => none
246
-
247
230
def genTypeTokenInfo? (self : TraversalFragment) : AnalysisM (Option TypeTokenInfo) := do
248
- match ← runMetaM (inferType?) self with
249
- | some string => some { headPos := self.headPos, tailPos := self.tailPos, type := string }
250
- | none => none
231
+ let mut docString : Option String := none
232
+ let mut type : Option String := none
233
+ let config ← read
234
+ if config.experimentalDocString then
235
+ docString ← runMetaM (genDocString?) self
236
+ if config.experimentalTypeInfo then
237
+ type ← runMetaM (inferType?) self
238
+ if type == none ∧ docString == none then
239
+ return none
240
+ else
241
+ return some { headPos := self.headPos, tailPos := self.tailPos, type := type, docString := docString }
251
242
252
243
def genTokens (self : TraversalFragment) : AnalysisM (List Token) := do
253
244
let mut tokens : List Token := []
254
- let config ← read
255
- if config.experimentalTypeInfo then
256
- if let some typeToken ← self.genTypeTokenInfo? then
257
- tokens := tokens.append [Token.type typeToken]
258
- if config.experimentalDocString then
259
- if let some docStringToken ← self.genDocStringTokenInfo? then
260
- tokens := tokens.append [Token.docString docStringToken]
245
+ if let some typeToken ← self.genTypeTokenInfo? then
246
+ tokens := tokens.append [Token.type typeToken]
261
247
return tokens
262
248
263
249
/- Sentence Generation -/
0 commit comments