@@ -132,6 +132,50 @@ type CallableBodyVisitor(tokens) =
132132 }
133133 |> Specializations
134134
135+ type UnderlyingTypeVistor ( tokens ) =
136+ inherit QSharpParserBaseVisitor< UnderlyingType>()
137+
138+ let typeVisitor = TypeVisitor tokens
139+
140+ override _.DefaultResult = failwith " Unknown underlying type."
141+
142+ override visitor.VisitTupleUnderlyingType context =
143+ context.typeDeclarationTuple () |> visitor.Visit
144+
145+ override _.VisitUnnamedTypeItem context =
146+ context.`` type `` () |> typeVisitor.Visit |> Type
147+
148+ override _.VisitTypeDeclarationTuple context =
149+ let parameters = context._ items |> Seq.map ( TypeTupleItemVistor tokens) .Visit
150+ let commas = context._ commas |> Seq.map ( Node.toTerminal tokens)
151+
152+ {
153+ OpenParen = context.openParen |> Node.toTerminal tokens
154+ Items = Node.tupleItems parameters commas
155+ CloseParen = context.closeParen |> Node.toTerminal tokens
156+ }
157+ |> TypeDeclarationTuple
158+
159+ and TypeTupleItemVistor ( tokens ) =
160+ inherit QSharpParserBaseVisitor< TypeTupleItem>()
161+
162+ let typeVisitor = TypeVisitor tokens
163+ let underlyingTypeVistor = UnderlyingTypeVistor tokens
164+
165+ override _.DefaultResult = failwith " Unknown type tuple item."
166+
167+ override visitor.VisitNamedTypeItem context = context.namedItem () |> visitor.Visit
168+
169+ override _.VisitUnderlyingTypeItem context =
170+ context.underlyingType () |> underlyingTypeVistor.Visit |> UnderlyingType
171+
172+ override _.VisitNamedItem context =
173+ {
174+ Name = context.name |> Node.toTerminal tokens
175+ Type = { Colon = context.colon |> Node.toTerminal tokens; Type = context.itemType |> typeVisitor.Visit }
176+ }
177+ |> TypeBinding
178+
135179/// <summary>
136180/// Creates syntax tree <see cref="NamespaceItem"/> nodes from a parse tree and the list of tokens.
137181/// </summary>
@@ -141,30 +185,56 @@ type NamespaceItemVisitor(tokens) =
141185 let parameterVisitor = ParameterVisitor tokens
142186 let typeVisitor = TypeVisitor tokens
143187 let callableBodyVisitor = CallableBodyVisitor tokens
188+ let underlyingTypeVistor = UnderlyingTypeVistor tokens
144189
145190 override _.DefaultResult = failwith " Unknown namespace element."
146191
147192 override _.VisitChildren node = Node.toUnknown tokens node |> Unknown
148193
149- override _.VisitCallableElement context =
194+ override visitor.VisitOpenElement context =
195+ context.openDirective () |> visitor.Visit
196+
197+ override visitor.VisitTypeElement context =
198+ context.typeDeclaration () |> visitor.Visit
199+
200+ override visitor.VisitCallableElement context =
201+ context.callableDeclaration () |> visitor.Visit
202+
203+ override _.VisitOpenDirective context =
150204 {
151- Attributes =
152- context.callable.prefix._ attributes |> Seq.map ( NamespaceContext.toAttribute tokens) |> Seq.toList
153- Access = context.callable.prefix.access () |> Option.ofObj |> Option.map ( Node.toUnknown tokens)
154- CallableKeyword = context.callable.keyword |> Node.toTerminal tokens
155- Name = context.callable.name |> Node.toTerminal tokens
205+ OpenKeyword = context.`` open `` |> Node.toTerminal tokens
206+ OpenName = context.openName |> Node.toUnknown tokens
207+ AsKeyword = context.`` as `` |> Option.ofObj |> Option.map ( Node.toTerminal tokens)
208+ AsName = context.asName |> Option.ofObj |> Option.map ( Node.toUnknown tokens)
209+ Semicolon = context.semicolon |> Node.toTerminal tokens
210+ }
211+ |> OpenDirective
212+
213+ override _.VisitTypeDeclaration context =
214+ {
215+ Attributes = context.prefix._ attributes |> Seq.map ( NamespaceContext.toAttribute tokens) |> Seq.toList
216+ Access = context.prefix.access () |> Option.ofObj |> Option.map ( Node.toUnknown tokens)
217+ NewtypeKeyword = context.keyword |> Node.toTerminal tokens
218+ DeclaredType = context.declared |> Node.toTerminal tokens
219+ Equals = context.equals |> Node.toTerminal tokens
220+ UnderlyingType = context.underlying |> underlyingTypeVistor.Visit
221+ Semicolon = context.semicolon |> Node.toTerminal tokens
222+ }
223+ |> TypeDeclaration
224+
225+ override _.VisitCallableDeclaration context =
226+ {
227+ Attributes = context.prefix._ attributes |> Seq.map ( NamespaceContext.toAttribute tokens) |> Seq.toList
228+ Access = context.prefix.access () |> Option.ofObj |> Option.map ( Node.toUnknown tokens)
229+ CallableKeyword = context.keyword |> Node.toTerminal tokens
230+ Name = context.name |> Node.toTerminal tokens
156231 TypeParameters =
157- Option.ofObj context.callable.typeParameters
158- |> Option.map ( NamespaceContext.toTypeParameterBinding tokens)
159- Parameters = parameterVisitor.Visit context.callable.tuple
232+ Option.ofObj context.typeParameters |> Option.map ( NamespaceContext.toTypeParameterBinding tokens)
233+ Parameters = parameterVisitor.Visit context.tuple
160234 ReturnType =
161- {
162- Colon = context.callable.colon |> Node.toTerminal tokens
163- Type = typeVisitor.Visit context.callable.returnType
164- }
165- CharacteristicSection =
166- Option.ofObj context.callable.returnChar |> Option.map ( toCharacteristicSection tokens)
167- Body = callableBodyVisitor.Visit context.callable.body
235+ { Colon = context.colon |> Node.toTerminal tokens; Type = typeVisitor.Visit context.returnType }
236+ CharacteristicSection = Option.ofObj context.returnChar |> Option.map ( toCharacteristicSection tokens)
237+ Body = callableBodyVisitor.Visit context.body
168238 }
169239 |> CallableDeclaration
170240
0 commit comments