Skip to content
This repository
Browse code

Parse parenthesis in version blocks correctly (hopefully)

  • Loading branch information...
commit ea939311a7cbe223d823328198a720a083f06012 1 parent bcfbe05
Amos Wenger authored

Showing 1 changed file with 41 additions and 12 deletions. Show diff stats Hide diff stats

  1. +41 12 source/rock/middle/UseDef.ooc
53 source/rock/middle/UseDef.ooc
@@ -208,7 +208,7 @@ UseDef: class {
208 208 }
209 209
210 210 parseVersionExpr: func (expr: String, params: BuildParams) -> UseVersion {
211   - "Parsing version: %s" printfln(expr)
  211 + "Parsing version: '%s'" printfln(expr)
212 212
213 213 reader := StringReader new(expr)
214 214 not := false
@@ -218,18 +218,46 @@ UseDef: class {
218 218 not = true
219 219 }
220 220
221   - // read an identifier
222   - value := reader readWhile(|c| c alphaNumeric?())
223   - result := UseVersionValue new(value)
  221 + result: UseVersion
  222 +
  223 + if (reader peek() == '(') {
  224 + reader read()
  225 + level := 1
  226 +
  227 + buff := Buffer new()
  228 + while (reader hasNext?()) {
  229 + c := reader read()
  230 + match c {
  231 + case '(' =>
  232 + level += 1
  233 + buff append(c)
  234 + case ')' =>
  235 + level -= 1
  236 + if (level == 0) {
  237 + break
  238 + }
  239 + buff append(c)
  240 + case =>
  241 + buff append(c)
  242 + }
  243 + }
  244 +
  245 + inner := buff toString()
  246 + result = parseVersionExpr(inner, params)
  247 + } else {
  248 + // read an identifier
  249 + value := reader readWhile(|c| c alphaNumeric?())
  250 + result = UseVersionValue new(value)
  251 + }
224 252
225 253 if (not) {
226 254 result = UseVersionNot new(result)
227 255 }
228 256
229   - if (reader hasNext?()) {
230   - // skip whitespace
231   - reader skipWhile(|c| c whitespace?())
  257 + // skip whitespace
  258 + reader skipWhile(|c| c whitespace?())
232 259
  260 + if (reader hasNext?()) {
233 261 c := reader read()
234 262 match c {
235 263 case '&' =>
@@ -247,7 +275,7 @@ UseDef: class {
247 275 inner := parseVersionExpr(reader readAll(), params)
248 276 result = UseVersionOr new(result, inner)
249 277 case =>
250   - message := "Malformed version expression: %s" format(expr)
  278 + message := "Malformed version expression: %s. Unexpected char %c" format(expr, c)
251 279 params errorHandler onError(UseFormatError new(this, message))
252 280 }
253 281 }
@@ -275,7 +303,8 @@ UseDef: class {
275 303 lineReader := StringReader new(line)
276 304 if (line startsWith?("version")) {
277 305 lineReader readUntil('(')
278   - versionExpr := lineReader readUntil(')')
  306 + lineReader rewind(1)
  307 + versionExpr := lineReader readAll()[0..-2] trim()
279 308
280 309 vb := parseVersionExpr(versionExpr, params)
281 310 "Got vb %s, of type %s, isSatisfied? %d" printfln(vb toString(), vb class name, vb satisfied?(params))
@@ -528,15 +557,15 @@ UseVersionNot: class extends UseVersion {
528 557 }
529 558
530 559 toString: func -> String {
531   - "!%s" format(inner _)
  560 + "!(%s)" format(inner _)
532 561 }
533 562 }
534 563
535   -UseFormatError: class extends InternalError {
  564 +UseFormatError: class extends Error {
536 565 useDef: UseDef
537 566
538 567 init: func (=useDef, .message) {
539   - super(nullToken, "Error while parsing %s: " format(useDef file path, message))
  568 + super(nullToken, "Error while parsing %s: %s" format(useDef file path, message))
540 569 }
541 570 }
542 571

0 comments on commit ea93931

Please sign in to comment.
Something went wrong with that request. Please try again.