comparison src/compiler.sml @ 1331:a6427d1eda6f

Comments in .urp files
author Adam Chlipala <adam@chlipala.net>
date Sat, 11 Dec 2010 13:42:54 -0500
parents e12cef71aa1a
children 4dd5d23bace2
comparison
equal deleted inserted replaced
1330:452b14d88a10 1331:a6427d1eda6f
308 Option.app Settings.setProtocol (#protocol job); 308 Option.app Settings.setProtocol (#protocol job);
309 Option.app Settings.setDbms (#dbms job); 309 Option.app Settings.setDbms (#dbms job);
310 Settings.setSafeGets (#safeGets job); 310 Settings.setSafeGets (#safeGets job);
311 Settings.setOnError (#onError job)) 311 Settings.setOnError (#onError job))
312 312
313 fun inputCommentableLine inf =
314 Option.map (fn s =>
315 let
316 val s = #1 (Substring.splitl (fn ch => ch <> #"#") (Substring.full s))
317 in
318 Substring.string (#1 (Substring.splitr (not o Char.isSpace) s))
319 end) (TextIO.inputLine inf)
320
313 fun parseUrp' accLibs fname = 321 fun parseUrp' accLibs fname =
314 if not (Posix.FileSys.access (fname ^ ".urp", []) orelse Posix.FileSys.access (fname ^ "/lib.urp", [])) 322 if not (Posix.FileSys.access (fname ^ ".urp", []) orelse Posix.FileSys.access (fname ^ "/lib.urp", []))
315 andalso Posix.FileSys.access (fname ^ ".ur", []) then 323 andalso Posix.FileSys.access (fname ^ ".ur", []) then
316 let 324 let
317 val job = {prefix = "/", 325 val job = {prefix = "/",
357 fun opener () = TextIO.openIn (OS.Path.joinBaseExt {base = filename, ext = SOME "urp"}) 365 fun opener () = TextIO.openIn (OS.Path.joinBaseExt {base = filename, ext = SOME "urp"})
358 366
359 val inf = opener () 367 val inf = opener ()
360 368
361 fun hasSpaceLine () = 369 fun hasSpaceLine () =
362 case TextIO.inputLine inf of 370 case inputCommentableLine inf of
363 NONE => false 371 NONE => false
364 | SOME s => s = "debug\n" orelse s = "profile\n" 372 | SOME s => s = "debug" orelse s = "profile"
365 orelse CharVector.exists (fn ch => ch = #" " orelse ch = #"\t") s orelse hasSpaceLine () 373 orelse CharVector.exists (fn ch => ch = #" " orelse ch = #"\t") s orelse hasSpaceLine ()
366 374
367 val hasBlankLine = hasSpaceLine () 375 val hasBlankLine = hasSpaceLine ()
368 376
369 val inf = (TextIO.closeIn inf; opener ()) 377 val inf = (TextIO.closeIn inf; opener ())
410 418
411 fun relifyA fname = 419 fun relifyA fname =
412 OS.Path.mkAbsolute {path = pathify fname, relativeTo = absDir} 420 OS.Path.mkAbsolute {path = pathify fname, relativeTo = absDir}
413 421
414 fun readSources acc = 422 fun readSources acc =
415 case TextIO.inputLine inf of 423 case inputCommentableLine inf of
416 NONE => rev acc 424 NONE => rev acc
417 | SOME line => 425 | SOME line =>
418 let 426 let
419 val acc = if CharVector.all Char.isSpace line then 427 val acc = if CharVector.all Char.isSpace line then
420 acc 428 acc
571 (Settings.Prefix, String.substring (s, 0, size s - 1)) 579 (Settings.Prefix, String.substring (s, 0, size s - 1))
572 else 580 else
573 (Settings.Exact, s) 581 (Settings.Exact, s)
574 582
575 fun read () = 583 fun read () =
576 case TextIO.inputLine inf of 584 case inputCommentableLine inf of
577 NONE => finish [] 585 NONE => finish []
578 | SOME "\n" => finish (readSources []) 586 | SOME "" => finish (readSources [])
579 | SOME line => 587 | SOME line =>
580 let 588 let
581 val (cmd, arg) = Substring.splitl (fn x => not (Char.isSpace x)) (Substring.full line) 589 val (cmd, arg) = Substring.splitl (fn x => not (Char.isSpace x)) (Substring.full line)
582 val cmd = Substring.string (trim cmd) 590 val cmd = Substring.string (trim cmd)
583 val arg = Substring.string (trim arg) 591 val arg = Substring.string (trim arg)