@@ -71,13 +71,13 @@ fileprivate extension NinjaParser {
71
71
typealias Rule = NinjaBuildFile . Rule
72
72
typealias BuildEdge = NinjaBuildFile . BuildEdge
73
73
74
- struct ParsedAttribute : Hashable {
74
+ struct ParsedBinding : Hashable {
75
75
var key : String
76
76
var value : String
77
77
}
78
78
79
79
enum Lexeme : Hashable {
80
- case attribute ( ParsedAttribute )
80
+ case binding ( ParsedBinding )
81
81
case element( String )
82
82
case rule
83
83
case build
@@ -166,15 +166,15 @@ extension NinjaParser.Lexer {
166
166
} )
167
167
}
168
168
169
- private mutating func tryConsumeAttribute ( key: String ) -> Lexeme ? {
169
+ private mutating func tryConsumeBinding ( key: String ) -> Lexeme ? {
170
170
input. tryEating { input in
171
171
input. skip ( while: \. isSpaceOrTab)
172
172
guard input. tryEat ( " = " ) else { return nil }
173
173
input. skip ( while: \. isSpaceOrTab)
174
174
guard let value = input. consumeUnescaped ( while: { !$0. isNewline } ) else {
175
175
return nil
176
176
}
177
- return . attribute ( . init( key: key, value: value) )
177
+ return . binding ( . init( key: key, value: value) )
178
178
}
179
179
}
180
180
@@ -216,7 +216,7 @@ extension NinjaParser.Lexer {
216
216
217
217
// If we're on a newline, check to see if we can lex an attribute.
218
218
if isAtStartOfLine {
219
- if let attr = tryConsumeAttribute ( key: element) {
219
+ if let attr = tryConsumeBinding ( key: element) {
220
220
return attr
221
221
}
222
222
}
@@ -238,8 +238,8 @@ fileprivate extension NinjaParser {
238
238
while let lexeme = eat ( ) , lexeme != . newline { }
239
239
}
240
240
241
- mutating func parseAttribute ( ) throws -> ParsedAttribute ? {
242
- guard case let . attribute ( attr) = peek else { return nil }
241
+ mutating func parseBinding ( ) throws -> ParsedBinding ? {
242
+ guard case let . binding ( attr) = peek else { return nil }
243
243
eat ( )
244
244
tryEat ( . newline)
245
245
return attr
@@ -262,7 +262,7 @@ fileprivate extension NinjaParser {
262
262
}
263
263
264
264
var bindings : [ String : String ] = [ : ]
265
- while indent < lexer. leadingTriviaCount, let binding = try parseAttribute ( ) {
265
+ while indent < lexer. leadingTriviaCount, let binding = try parseBinding ( ) {
266
266
bindings [ binding. key] = binding. value
267
267
}
268
268
@@ -322,7 +322,7 @@ fileprivate extension NinjaParser {
322
322
skipLine ( )
323
323
324
324
var bindings : [ String : String ] = [ : ]
325
- while indent < lexer. leadingTriviaCount, let binding = try parseAttribute ( ) {
325
+ while indent < lexer. leadingTriviaCount, let binding = try parseBinding ( ) {
326
326
bindings [ binding. key] = binding. value
327
327
}
328
328
@@ -345,7 +345,7 @@ fileprivate extension NinjaParser {
345
345
throw NinjaParseError . expected ( . element( " <path> " ) )
346
346
}
347
347
348
- let baseDirectory = self . filePath. removingLastComponent ( )
348
+ let baseDirectory = self . filePath. parentDir!
349
349
let path = AnyPath ( fileName) . absolute ( in: baseDirectory)
350
350
return try NinjaParser . parse ( filePath: path, input: path. read ( ) )
351
351
}
@@ -363,14 +363,15 @@ fileprivate extension NinjaParser {
363
363
buildEdges. append ( edge)
364
364
continue
365
365
}
366
- if let binding = try parseAttribute ( ) {
366
+ if let binding = try parseBinding ( ) {
367
367
bindings [ binding. key] = binding. value
368
368
continue
369
369
}
370
370
if let included = try parseInclude ( ) {
371
371
bindings. merge ( included. bindings. values, uniquingKeysWith: { _, other in other } )
372
372
rules. merge ( included. rules, uniquingKeysWith: { _, other in other } )
373
373
buildEdges. append ( contentsOf: included. buildEdges)
374
+ continue
374
375
}
375
376
// Ignore unknown bits of syntax like 'subninja' for now.
376
377
eat ( )
0 commit comments