shithub: MicroHs

Download patch

ref: da72cf93b9b1baf72bf4a0c227473b5891645b3a
parent: a0250a64c0c22bd1c630f3d0d03abf082b84da37
author: Lennart Augustsson <lennart@augustsson.net>
date: Wed Sep 11 18:41:00 EDT 2024

Parse #line (as generated by cpphs)

--- a/src/MicroHs/Lex.hs
+++ b/src/MicroHs/Lex.hs
@@ -85,6 +85,14 @@
 lex loc cs@(d:_) | isDigit d = number loc cs
 lex loc ('.':cs@(d:_)) | isLower_ d =
   TSpec loc '.' : lex (addCol loc 1) cs
+-- Recognize #line 123 "file/name.hs"
+lex loc ('#':xcs) | (SLoc _ _ 1) <- loc, Just cs <- stripPrefix "line " xcs =
+  case span (/= '\n') cs of
+    (line, rs) ->        -- rs will contain the '\n', so subtract 1 below
+      let ws = words line
+          file = tail $ init $ ws!!1   -- strip the initial and final '"' 
+          loc' = SLoc file (read (ws!!0) - 1) 1
+      in  lex loc' rs
 lex loc (c:cs@(d:_)) | (c == '!' || c == '~') && (d == '(' || d == '[' || isIdentChar d) =  -- XXX hacky way to make ~ a TSpec
   TSpec loc c : lex (addCol loc 1) cs
 lex loc (d:cs) | isOperChar d =
--