11use anyhow:: Result ;
2- use vim9_lexer:: { Token , TokenKind } ;
2+ use vim9_lexer:: TokenKind ;
33
44use crate :: { Literal , Parser , TokenMeta } ;
55
6+ pub struct TypeOpts {
7+ pub bool : Type ,
8+ }
9+
610#[ derive( Debug , PartialEq , Clone ) ]
711pub enum Type {
812 Any ,
13+
14+ // TODO: Decide what to do with these.
15+ // It's possible we can just dismiss
16+ // BoolOrNumber, but i'm not 100% sure.
17+ //
18+ // The way we could do that would be to
19+ // just "not not" everything that comes from
20+ // vimland... but I feel like BoolOrNumber makes
21+ // that better by only doing it when we see a BoolOrNumber
922 Bool ,
23+ BoolOrNumber ,
24+
1025 Number ,
1126 Float ,
1227 String ,
@@ -41,7 +56,11 @@ impl Type {
4156 matches ! ( k, TokenKind :: GreaterThan | TokenKind :: AngleRight )
4257 }
4358
44- fn parse_inner ( parser : & Parser , consume : bool ) -> Result < Type > {
59+ fn parse_inner (
60+ parser : & Parser ,
61+ consume : bool ,
62+ opts : & TypeOpts ,
63+ ) -> Result < Type > {
4564 match parser. front_kind ( ) {
4665 TokenKind :: Identifier => {
4766 let literal: Literal = match consume {
@@ -52,7 +71,8 @@ impl Type {
5271
5372 Ok ( match literal. token . text . as_str ( ) {
5473 "any" => Type :: Any ,
55- "bool" => Type :: Bool ,
74+ // "bool" => Type::BoolOrNumber,
75+ "bool" => opts. bool . clone ( ) ,
5676 "number" => Type :: Number ,
5777 "void" => Type :: Void ,
5878 "string" => Type :: String ,
@@ -64,7 +84,8 @@ impl Type {
6484
6585 Type :: List {
6686 open : parser. expect_fn ( Self :: open, true ) ?. into ( ) ,
67- inner : Type :: parse_inner ( parser, true ) ?. into ( ) ,
87+ inner : Type :: parse_inner ( parser, true , & opts) ?
88+ . into ( ) ,
6889 close : parser
6990 . expect_fn ( Self :: close, consume) ?
7091 . into ( ) ,
@@ -77,7 +98,8 @@ impl Type {
7798
7899 Type :: Dict {
79100 open : parser. expect_fn ( Self :: open, true ) ?. into ( ) ,
80- inner : Type :: parse_inner ( parser, true ) ?. into ( ) ,
101+ inner : Type :: parse_inner ( parser, true , & opts) ?
102+ . into ( ) ,
81103 close : parser
82104 . expect_fn ( Self :: close, consume) ?
83105 . into ( ) ,
@@ -93,13 +115,16 @@ impl Type {
93115 }
94116 }
95117
96- pub fn parse_in_expression ( parser : & Parser ) -> Result < Type > {
118+ pub fn parse_in_expression (
119+ parser : & Parser ,
120+ opts : & TypeOpts ,
121+ ) -> Result < Type > {
97122 parser. expect_token ( TokenKind :: SpacedColon ) ?;
98- Self :: parse_inner ( parser, false )
123+ Self :: parse_inner ( parser, false , opts )
99124 }
100125
101- pub fn parse ( parser : & Parser ) -> Result < Type > {
126+ pub fn parse ( parser : & Parser , opts : & TypeOpts ) -> Result < Type > {
102127 parser. expect_token ( TokenKind :: SpacedColon ) ?;
103- Self :: parse_inner ( parser, true )
128+ Self :: parse_inner ( parser, true , opts )
104129 }
105130}
0 commit comments