Mercurial > urweb
comparison src/compiler.sml @ 1603:06958d5a7088
Don't treat comment-only lines as blank, in determining split point of .urp files
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Sun, 20 Nov 2011 18:33:21 -0500 |
parents | 154cfe2eb366 |
children | 48eed6cf2be7 |
comparison
equal
deleted
inserted
replaced
1602:e44be6ece475 | 1603:06958d5a7088 |
---|---|
1 (* Copyright (c) 2008-2010, Adam Chlipala | 1 (* Copyright (c) 2008-2011, Adam Chlipala |
2 * All rights reserved. | 2 * All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are met: | 5 * modification, are permitted provided that the following conditions are met: |
6 * | 6 * |
345 Settings.setSafeGets (#safeGets job); | 345 Settings.setSafeGets (#safeGets job); |
346 Settings.setOnError (#onError job); | 346 Settings.setOnError (#onError job); |
347 Settings.setMinHeap (#minHeap job); | 347 Settings.setMinHeap (#minHeap job); |
348 Settings.setSigFile (#sigFile job)) | 348 Settings.setSigFile (#sigFile job)) |
349 | 349 |
350 datatype commentableLine = | |
351 EndOfFile | |
352 | OnlyComment | |
353 | Content of string | |
354 | |
350 fun inputCommentableLine inf = | 355 fun inputCommentableLine inf = |
351 Option.map (fn s => | 356 case TextIO.inputLine inf of |
352 let | 357 NONE => EndOfFile |
353 val s = #1 (Substring.splitl (fn ch => ch <> #"#") (Substring.full s)) | 358 | SOME s => |
354 val s = #1 (Substring.splitr (not o Char.isSpace) s) | 359 let |
355 in | 360 val (befor, after) = Substring.splitl (fn ch => ch <> #"#") (Substring.full s) |
356 Substring.string (if Substring.size s > 0 andalso Char.isSpace (Substring.sub (s, Substring.size s - 1)) then | 361 in |
357 if Substring.size s > 1 andalso Char.isSpace (Substring.sub (s, Substring.size s - 2)) then | 362 if not (Substring.isEmpty after) |
358 Substring.trimr 2 s | 363 andalso Substring.foldl (fn (ch, b) => b andalso Char.isSpace ch) true befor then |
359 else | 364 OnlyComment |
360 Substring.trimr 1 s | 365 else |
361 else | 366 let |
362 s) | 367 val s = #1 (Substring.splitr (not o Char.isSpace) befor) |
363 end) (TextIO.inputLine inf) | 368 in |
369 Content (Substring.string (if Substring.size s > 0 andalso Char.isSpace (Substring.sub (s, Substring.size s - 1)) then | |
370 if Substring.size s > 1 andalso Char.isSpace (Substring.sub (s, Substring.size s - 2)) then | |
371 Substring.trimr 2 s | |
372 else | |
373 Substring.trimr 1 s | |
374 else | |
375 s)) | |
376 end | |
377 end | |
364 | 378 |
365 fun parseUrp' accLibs fname = | 379 fun parseUrp' accLibs fname = |
366 if not (Posix.FileSys.access (fname ^ ".urp", []) orelse Posix.FileSys.access (fname ^ "/lib.urp", [])) | 380 if not (Posix.FileSys.access (fname ^ ".urp", []) orelse Posix.FileSys.access (fname ^ "/lib.urp", [])) |
367 andalso Posix.FileSys.access (fname ^ ".ur", []) then | 381 andalso Posix.FileSys.access (fname ^ ".ur", []) then |
368 let | 382 let |
415 | 429 |
416 val inf = opener () | 430 val inf = opener () |
417 | 431 |
418 fun hasSpaceLine () = | 432 fun hasSpaceLine () = |
419 case inputCommentableLine inf of | 433 case inputCommentableLine inf of |
420 NONE => false | 434 Content s => s = "debug" orelse s = "profile" |
421 | SOME s => s = "debug" orelse s = "profile" | 435 orelse CharVector.exists (fn ch => ch = #" " orelse ch = #"\t") s orelse hasSpaceLine () |
422 orelse CharVector.exists (fn ch => ch = #" " orelse ch = #"\t") s orelse hasSpaceLine () | 436 | _ => false |
423 | 437 |
424 val hasBlankLine = hasSpaceLine () | 438 val hasBlankLine = hasSpaceLine () |
425 | 439 |
426 val inf = (TextIO.closeIn inf; opener ()) | 440 val inf = (TextIO.closeIn inf; opener ()) |
427 | 441 |
465 fun relifyA fname = | 479 fun relifyA fname = |
466 OS.Path.mkAbsolute {path = pathify fname, relativeTo = absDir} | 480 OS.Path.mkAbsolute {path = pathify fname, relativeTo = absDir} |
467 | 481 |
468 fun readSources acc = | 482 fun readSources acc = |
469 case inputCommentableLine inf of | 483 case inputCommentableLine inf of |
470 NONE => rev acc | 484 Content line => |
471 | SOME line => | |
472 let | 485 let |
473 val acc = if CharVector.all Char.isSpace line then | 486 val acc = if CharVector.all Char.isSpace line then |
474 acc | 487 acc |
475 else | 488 else |
476 let | 489 let |
481 fname :: acc | 494 fname :: acc |
482 end | 495 end |
483 in | 496 in |
484 readSources acc | 497 readSources acc |
485 end | 498 end |
499 | _ => rev acc | |
486 | 500 |
487 val prefix = ref (case Settings.getUrlPrefix () of "/" => NONE | s => SOME s) | 501 val prefix = ref (case Settings.getUrlPrefix () of "/" => NONE | s => SOME s) |
488 val database = ref (Settings.getDbstring ()) | 502 val database = ref (Settings.getDbstring ()) |
489 val exe = ref (Settings.getExe ()) | 503 val exe = ref (Settings.getExe ()) |
490 val sql = ref (Settings.getSql ()) | 504 val sql = ref (Settings.getSql ()) |
637 else | 651 else |
638 (Settings.Exact, s) | 652 (Settings.Exact, s) |
639 | 653 |
640 fun read () = | 654 fun read () = |
641 case inputCommentableLine inf of | 655 case inputCommentableLine inf of |
642 NONE => finish [] | 656 EndOfFile => finish [] |
643 | SOME "" => finish (readSources []) | 657 | OnlyComment => read () |
644 | SOME line => | 658 | Content "" => finish (readSources []) |
659 | Content line => | |
645 let | 660 let |
646 val (cmd, arg) = Substring.splitl (fn x => not (Char.isSpace x)) (Substring.full line) | 661 val (cmd, arg) = Substring.splitl (fn x => not (Char.isSpace x)) (Substring.full line) |
647 val cmd = Substring.string (trim cmd) | 662 val cmd = Substring.string (trim cmd) |
648 val arg = Substring.string (trim arg) | 663 val arg = Substring.string (trim arg) |
649 | 664 |