@@ -18,7 +18,7 @@ class Parser {
18
18
func parseType( ) -> Type {
19
19
var type : Type = . Unknown
20
20
let token = self . lexer. lexNextToken ( )
21
- type_switch : switch token. type {
21
+ typeSwitch : switch token. type {
22
22
case . Punctuator( . LeftSquare) :
23
23
let key = self . parseType ( )
24
24
var value : Type ? = nil
@@ -31,18 +31,18 @@ class Parser {
31
31
self . diagnose ( " Expected ], found \( after. content) " )
32
32
break
33
33
}
34
- if let actual_value = value {
35
- type = . DictionaryType( key, actual_value )
34
+ if let actualValue = value {
35
+ type = . DictionaryType( key, actualValue )
36
36
} else {
37
37
type = . ArrayType( key)
38
38
}
39
39
case . Punctuator( . LeftParenthesis) :
40
40
var after : Token
41
- var tuple_args = [ Type] ( )
41
+ var tupleArgs = [ Type] ( )
42
42
repeat {
43
43
let inner = self . parseType ( )
44
44
after = self . lexer. lexNextToken ( )
45
- tuple_args . append ( inner)
45
+ tupleArgs . append ( inner)
46
46
} while after. type == . Punctuator( . Comma)
47
47
guard after. type == . Punctuator( . RightParenthesis) else {
48
48
self . diagnose ( " Expected ), found \( after. content) " )
@@ -51,24 +51,24 @@ class Parser {
51
51
after = self . lexer. peekNextToken ( )
52
52
if after. type == . Punctuator( . Arrow) {
53
53
_ = self . lexer. lexNextToken ( )
54
- let return_type = self . parseType ( )
55
- type = . FunctionType( tuple_args , return_type )
54
+ let returnType = self . parseType ( )
55
+ type = . FunctionType( tupleArgs , returnType )
56
56
} else {
57
- type = . TupleType( tuple_args )
57
+ type = . TupleType( tupleArgs )
58
58
}
59
59
case . Identifier( _) :
60
- var parts = [ ( ( Identifier, [ Type] ) ) ] ( )
61
- var ident_token = token
62
- identifier_loop : repeat {
63
- let identifier = Identifier ( ident_token . content)
60
+ var parts = [ ( Identifier, [ Type] ) ] ( )
61
+ var identToken = token
62
+ identifierLoop : repeat {
63
+ let identifier = Identifier ( identToken . content)
64
64
switch self . lexer. peekNextToken ( ) . type {
65
65
case . Punctuator( . Period) :
66
66
parts. append ( ( identifier, [ ] ) )
67
67
let dot = self . lexer. lexNextToken ( )
68
- ident_token = self . lexer. lexNextToken ( )
69
- if ident_token . type == . Identifier( false ) && ( ident_token . content == " Type " || ident_token . content == " Protocol " ) {
68
+ identToken = self . lexer. lexNextToken ( )
69
+ if identToken . type == . Identifier( false ) && ( identToken . content == " Type " || identToken . content == " Protocol " ) {
70
70
self . lexer. resetToBeginning ( of: dot)
71
- break identifier_loop
71
+ break identifierLoop
72
72
}
73
73
case . BinaryOperator( " < " ) :
74
74
var generics = [ Type] ( )
@@ -79,22 +79,22 @@ class Parser {
79
79
let after = self . lexer. lexNextToken ( )
80
80
if case let . PostfixOperator( op) = after. type, op. hasPrefix ( " > " ) {
81
81
if op != " > " {
82
- let next_index = self . lexer. getIndex ( after: after. range. range. lowerBound)
83
- self . lexer. resetIndex ( to: next_index )
82
+ let nextIndex = self . lexer. getIndex ( after: after. range. range. lowerBound)
83
+ self . lexer. resetIndex ( to: nextIndex )
84
84
}
85
85
} else {
86
86
self . diagnose ( " Expected >, found \( after. content) " )
87
- break type_switch
87
+ break typeSwitch
88
88
}
89
89
parts. append ( ( identifier, generics) )
90
90
guard self . lexer. peekNextToken ( ) . type == . Punctuator( . Period) else {
91
- break identifier_loop
91
+ break identifierLoop
92
92
}
93
93
_ = self . lexer. lexNextToken ( )
94
- ident_token = self . lexer. lexNextToken ( )
94
+ identToken = self . lexer. lexNextToken ( )
95
95
default :
96
96
parts. append ( ( identifier, [ ] ) )
97
- break identifier_loop
97
+ break identifierLoop
98
98
}
99
99
} while true
100
100
type = . TypeIdentifier( parts)
@@ -104,7 +104,7 @@ class Parser {
104
104
print ( " Error: " + String( describing: token) )
105
105
}
106
106
107
- postfix_loop : while true {
107
+ postfixLoop : while true {
108
108
let nextToken = self . lexer. peekNextToken ( )
109
109
switch nextToken. type {
110
110
case . Punctuator( . PostfixExclaimationMark) :
@@ -124,11 +124,11 @@ class Parser {
124
124
type = . MetaProtocol( type)
125
125
default :
126
126
self . lexer. resetToBeginning ( of: nextToken)
127
- break postfix_loop
127
+ break postfixLoop
128
128
}
129
129
}
130
130
default :
131
- break postfix_loop
131
+ break postfixLoop
132
132
}
133
133
}
134
134
@@ -144,18 +144,18 @@ class Parser {
144
144
guard kwtoken. type == . DeclarationKeyword( . PrecedenceGroup) else {
145
145
preconditionFailure ( " Should only parsePrecedenceGroup at the beginning of a precedencegroup declaration " )
146
146
}
147
- let ident_token = lexer. lexNextToken ( )
148
- guard case . Identifier( _) = ident_token . type else {
147
+ let identToken = lexer. lexNextToken ( )
148
+ guard case . Identifier( _) = identToken . type else {
149
149
let error = self . diagnose ( " Expected identifier after 'precedencegroup' " )
150
- if ident_token . type == . Punctuator( . LeftBrace) || lexer. peekNextToken ( ) . type == . Punctuator( . LeftBrace) {
150
+ if identToken . type == . Punctuator( . LeftBrace) || lexer. peekNextToken ( ) . type == . Punctuator( . LeftBrace) {
151
151
skipWhile { $0. type != . Punctuator( . RightBrace) }
152
152
}
153
153
consumeIf ( type: . Punctuator( . RightBrace) )
154
154
throw error
155
155
}
156
156
157
157
var valid = true
158
- let name = ident_token . content
158
+ let name = identToken . content
159
159
var higherThan : [ Identifier ] ? = nil
160
160
var lowerThan : [ Identifier ] ? = nil
161
161
var associativity : Associativity ? = nil
@@ -167,13 +167,13 @@ class Parser {
167
167
consumeIf ( type: . Punctuator( . RightBrace) )
168
168
}
169
169
170
- let open_brace = lexer. lexNextToken ( )
171
- guard open_brace . type == . Punctuator( . LeftBrace) else {
170
+ let openBrace = lexer. lexNextToken ( )
171
+ guard openBrace . type == . Punctuator( . LeftBrace) else {
172
172
throw self . diagnose ( " Expected '{' after name of precedence group " )
173
173
}
174
- var attribute_name_token : Token = lexer. lexNextToken ( )
175
- while attribute_name_token . type == . Identifier( false ) {
176
- let name = attribute_name_token . content
174
+ var attributeNameToken : Token = lexer. lexNextToken ( )
175
+ while attributeNameToken . type == . Identifier( false ) {
176
+ let name = attributeNameToken . content
177
177
let colon = lexer. lexNextToken ( )
178
178
if colon. type != . Punctuator( . Colon) {
179
179
self . diagnose ( " Expected colon after attribute name in precedence group " )
@@ -222,20 +222,20 @@ class Parser {
222
222
throw error
223
223
}
224
224
groups. append ( group. content)
225
- } while ( consumeIf ( type: . Punctuator( . Comma) ) )
225
+ } while consumeIf ( type: . Punctuator( . Comma) )
226
226
if name == " higherThan " {
227
227
higherThan = groups. map { Identifier ( $0) }
228
228
} else {
229
229
lowerThan = groups. map { Identifier ( $0) }
230
230
}
231
231
default :
232
- let error = self . diagnose ( " ' \( name) ' is not a valid precedence group attribute " , at: attribute_name_token )
232
+ let error = self . diagnose ( " ' \( name) ' is not a valid precedence group attribute " , at: attributeNameToken )
233
233
abortBlock ( )
234
234
throw error
235
235
}
236
- attribute_name_token = lexer. lexNextToken ( )
236
+ attributeNameToken = lexer. lexNextToken ( )
237
237
}
238
- guard attribute_name_token . type == . Punctuator( . RightBrace) else {
238
+ guard attributeNameToken . type == . Punctuator( . RightBrace) else {
239
239
throw self . diagnose ( " Expected operator attribute identifier in precedence group body " )
240
240
}
241
241
return PrecedenceGroupDeclaration (
@@ -298,4 +298,5 @@ class Parser {
298
298
diagnoses. append ( diag)
299
299
return diag
300
300
}
301
+
301
302
}
0 commit comments