Skip to content

Commit

Permalink
Merge pull request #561 from MatthewFluet/line-directive-fix
Browse files Browse the repository at this point in the history
Fix regression in `#line` directives
  • Loading branch information
MatthewFluet authored May 13, 2024
2 parents 3c08771 + 584a1d2 commit b20e542
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 162 deletions.
15 changes: 10 additions & 5 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Here are the changes from version 20210117 to YYYYMMDD.

=== Details

* 2024-05-13
** Fix bug in `#line` directives that fails to acceptable
`(*#line line *"file" )`, which should be accepted with a default
column of 1. Thanks to Norman Ramsey for the bug report.

* 2023-08-31
** Fix bug in x86 and amd64 native codegens leading to an internal
compiler error
Expand Down Expand Up @@ -994,7 +999,7 @@ Here are the changes from version 20100608 to version 20130715.
* Runtime.
** Bug fixes: see changelog
* Language.
** Interpret `(*#line line:col "file" *)` directives as relative
** Interpret `(*#line line.col "file" *)` directives as relative
file names.
** ML Basis annotations.
*** Added: `resolveScope`
Expand All @@ -1011,10 +1016,10 @@ Here are the changes from version 20100608 to version 20130715.
*** Added: MLLPT library
* Tools.
** mllex
*** Generate `(*#line line:col "file.lex" *)` directives with simple
*** Generate `(*#line line.col "file.lex" *)` directives with simple
(relative) file names, rather than absolute paths.
** mlyacc
*** Generate `(*#line line:col "file.grm" *)` directives with simple
*** Generate `(*#line line.col "file.grm" *)` directives with simple
(relative) file names, rather than absolute paths.
*** Fixed bug in comment-handling in lexer.

Expand Down Expand Up @@ -1182,7 +1187,7 @@ Here are the changes from version 20070826 to version 20100608.
* Tools.
** `mllex`
*** Eliminated top-level `type int = Int.int` in output.
*** Include `(*#line line:col "file.lex" *)` directives in output.
*** Include `(*#line line.col "file.lex" *)` directives in output.
*** Added `%posint` command, to set the `yypos` type and allow the lexing of
multi-gigabyte files.
** `mlnlffigen`
Expand All @@ -1191,7 +1196,7 @@ Here are the changes from version 20070826 to version 20100608.
*** Added support for ia64 and hppa targets.
** `mlyacc`
*** Eliminated top-level `type int = Int.int` in output.
*** Include `(*#line line:col "file.grm" *)` directives in output.
*** Include `(*#line line.col "file.grm" *)` directives in output.

=== Details

Expand Down
26 changes: 19 additions & 7 deletions mlton/front-end/ml.lex
Original file line number Diff line number Diff line change
Expand Up @@ -532,13 +532,25 @@ real=(~?)(({decnum}{frac}?{exp})|({decnum}{frac}{exp}?));
(addCommentError "Illegal line directive"
; YYBEGIN BLOCK_COMMENT)
in
case String.split (yytext, #".") of
[line, col] =>
(YYBEGIN LINE_DIR2
; addLineDirLineCol (valOf (Int.fromString line), valOf (Int.fromString col))
handle Overflow => err () | Option => err ()
; continue ())
| _ => (err (); continue ())
case String.split (yytext, #".") of
[line, col] => (YYBEGIN LINE_DIR2
; addLineDirLineCol (valOf (Int.fromString line), valOf (Int.fromString col))
handle Overflow => err () | Option => err ()
; continue ())
| _ => (err (); continue ())
end);
<LINE_DIR1>{decDigit}+ =>
(let
fun err () =
(addCommentError "Illegal line directive"
; YYBEGIN BLOCK_COMMENT)
val line = yytext
val col = 1
in
YYBEGIN LINE_DIR2
; addLineDirLineCol (valOf (Int.fromString line), col)
handle Overflow => err () | Option => err ()
; continue ()
end);
<LINE_DIR2>{ws}+"\"" =>
(YYBEGIN LINE_DIR3
Expand Down
Loading

0 comments on commit b20e542

Please sign in to comment.