Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,6 @@ for UTF-8 characters within strings.

`-allow-sig-withtype [true|false]` (default `false`) controls whether or not
SuccessorML `withtype` in signatures syntax is allowed.

`-allow-line-comments [true|false]` (default `false`) controls whether or not
SuccessorML line comments syntax is allowed.
1 change: 1 addition & 0 deletions src/Main.smlnj.sml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct
, recordPun = false
, orPat = false
, extendedText = false
, lineComment = false
}


Expand Down
4 changes: 4 additions & 0 deletions src/base/AstAllows.sml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ sig
, orPat: bool
, extendedText: bool
, sigWithtype: bool
, lineComment: bool
}
-> t

Expand All @@ -23,6 +24,7 @@ sig
val orPat: t -> bool
val extendedText: t -> bool
val sigWithtype: t -> bool
val lineComment: t -> bool
end =
struct
datatype t =
Expand All @@ -33,6 +35,7 @@ struct
, orPat: bool
, extendedText: bool
, sigWithtype: bool
, lineComment: bool
}

fun make x = T x
Expand All @@ -42,4 +45,5 @@ struct
fun orPat (T x) = #orPat x
fun extendedText (T x) = #extendedText x
fun sigWithtype (T x) = #sigWithtype x
fun lineComment (T x) = #lineComment x
end
1 change: 1 addition & 0 deletions src/lex-mlb/MLBLexer.sml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct
, orPat = false
, extendedText = false
, sigWithtype = false
, lineComment = false
}
in
case Lexer.next smlLexerAllows src of
Expand Down
20 changes: 18 additions & 2 deletions src/lex/Lexer.sml
Original file line number Diff line number Diff line change
Expand Up @@ -632,11 +632,20 @@ struct
if nesting = 0 then
success (mk Token.Comment (commentStart, s))
else if is #"(" at s andalso is #"*" at s + 1 then
loop_inComment (s + 2)
{commentStart = commentStart, nesting = nesting + 1}
if (AstAllows.lineComment allows) andalso is #")" at s + 2 then
(* Nested line comment *)
loop_inLineComment (s + 3)
{commentStart = commentStart, nesting = nesting + 1}
else
loop_inComment (s + 2)
{commentStart = commentStart, nesting = nesting + 1}
else if is #"*" at s andalso is #")" at s + 1 then
loop_inComment (s + 2)
{commentStart = commentStart, nesting = nesting - 1}
else if (AstAllows.lineComment allows) andalso is #")" at commentStart + 2 then
(* Top-level line comment *)
loop_inLineComment (s + 1)
{commentStart = commentStart, nesting = nesting}
else if isEndOfFileAt s then
error
{ pos = slice (commentStart, commentStart + 2)
Expand All @@ -647,6 +656,13 @@ struct
loop_inComment (s + 1)
{commentStart = commentStart, nesting = nesting}

and loop_inLineComment s {commentStart, nesting} =
if is #"\n" at s then
loop_inComment (s)
{commentStart = commentStart, nesting = nesting - 1}
else
loop_inLineComment (s + 1)
{commentStart = commentStart, nesting = nesting}

in
loop_topLevel startOffset
Expand Down
19 changes: 19 additions & 0 deletions src/parse-mlb/ParseAnnotations.sml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct
, orPat = b
, extendedText = b
, sigWithtype = b
, lineComment = b
}


Expand All @@ -33,6 +34,7 @@ struct
, orPat = AstAllows.orPat a
, extendedText = AstAllows.extendedText a
, sigWithtype = AstAllows.sigWithtype a
, lineComment = AstAllows.lineComment a
}


Expand All @@ -44,6 +46,7 @@ struct
, orPat = AstAllows.orPat a
, extendedText = AstAllows.extendedText a
, sigWithtype = AstAllows.sigWithtype a
, lineComment = AstAllows.lineComment a
}


Expand All @@ -55,6 +58,7 @@ struct
, orPat = b
, extendedText = AstAllows.extendedText a
, sigWithtype = AstAllows.sigWithtype a
, lineComment = AstAllows.lineComment a
}


Expand All @@ -66,6 +70,7 @@ struct
, orPat = AstAllows.orPat a
, extendedText = b
, sigWithtype = AstAllows.sigWithtype a
, lineComment = AstAllows.lineComment a
}

fun allowSigWithtype a b =
Expand All @@ -76,6 +81,18 @@ struct
, orPat = AstAllows.orPat a
, extendedText = AstAllows.extendedText a
, sigWithtype = b
, lineComment = AstAllows.lineComment a
}

fun allowLineComments a b =
AstAllows.make
{ optBar = AstAllows.optBar a
, topExp = AstAllows.topExp a
, recordPun = AstAllows.recordPun a
, orPat = AstAllows.orPat a
, extendedText = AstAllows.extendedText a
, sigWithtype = AstAllows.sigWithtype a
, lineComment = b
}


Expand Down Expand Up @@ -111,6 +128,8 @@ struct
allowExtendedTextConsts allows false
| ["allowSigWithtype", "true"] => allowSigWithtype allows true
| ["allowSigWithtype", "false"] => allowSigWithtype allows false
| ["allowLineComments", "true"] => allowLineComments allows true
| ["allowLineComments", "false"] => allowLineComments allows false
| _ => allows


Expand Down
8 changes: 8 additions & 0 deletions src/smlfmt.sml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ val optionalArgDesc =
\ Valid options are: true, false\n\
\ (default 'false')\n\
\\n\
\ [-allow-line-comments B] Enable/disable SuccessorML line comments\n\
\ syntax.\n\
\ Valid options are: true, false\n\
\ (default 'false')\n\
\\n\
\ [--help] print this message\n"


Expand All @@ -105,6 +110,8 @@ val allowExtendedText =
CommandLineArgs.parseBool "allow-extended-text-consts" allowSuccessorML
val allowSigWithtype =
CommandLineArgs.parseBool "allow-sig-withtype" allowSuccessorML
val allowLineComments =
CommandLineArgs.parseBool "allow-line-comments" allowSuccessorML

val doDebug = CommandLineArgs.parseFlag "debug-engine"
val doForce = CommandLineArgs.parseFlag "force"
Expand All @@ -126,6 +133,7 @@ val allows = AstAllows.make
, orPat = allowOrPat
, extendedText = allowExtendedText
, sigWithtype = allowSigWithtype
, lineComment = allowLineComments
}

val _ =
Expand Down
1 change: 1 addition & 0 deletions src/syntax-highlighting/SyntaxHighlighter.sml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ struct
, orPat = true
, extendedText = true
, sigWithtype = true
, lineComment = true
}

val startOffset = Source.absoluteStartOffset src
Expand Down
5 changes: 5 additions & 0 deletions test/succeed/line-comments.mlb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$(SML_LIB)/basis/basis.mlb
ann "allowLineComments true" in
successor-ml/line-comments.sml
star-close-paren-but-not-comment.sml
end
23 changes: 23 additions & 0 deletions test/succeed/successor-ml/line-comments.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
val x =
(*) whole line
case foobar of (*) end of line

(*
(*) nested
*)

(*
(*) nested with closing marker *)
*)

(* with closing ) paren
*)

(* after two (* nested block comments *)
(*) line comment
*)

(* in two (* nested block comments
(*) line comment
*) *)
3 => 2