Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hashbang #17

Open
wants to merge 4 commits into
base: Rel-2.10
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion src/compiler/Exec_phr.sig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
val execToplevelPhrase: Asynt.Dec -> unit;
val quietdec : bool ref

val hashbang : bool ref


4 changes: 4 additions & 0 deletions src/compiler/Exec_phr.sml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ open Symtable Rtvals Load_phr;

val quietdec = ref false ;

(* Is enabled if running with -hashbang arg: *)

val hashbang = ref false ;

(* Executing a top-level declaration. *)

local
Expand Down
16 changes: 15 additions & 1 deletion src/compiler/Lexer.lex
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ datatype lexingMode =
NORMALlm
| QUOTElm
| ANTIQUOTElm
| HASHBANGlm

val lexingMode = ref NORMALlm

val parCount = Stack.new() : int Stack.t

fun resetLexerState() =
(
lexingMode := NORMALlm;
Expand Down Expand Up @@ -207,6 +207,10 @@ fun scanString scan lexbuf =
setLexStartPos lexbuf (!savedLexemeStart - getLexAbsPos lexbuf)
)

(* enable support for Shebang/Hashbang *)
fun enableHashbang b = (if b
then lexingMode := HASHBANGlm
else lexingMode := NORMALlm; ());
}

rule Token = parse
Expand All @@ -221,12 +225,16 @@ rule Token = parse
case !lexingMode of
NORMALlm =>
QUOTER (get_stored_string())
| HASHBANGlm =>
QUOTER (get_stored_string())
| ANTIQUOTElm =>
QUOTEM (get_stored_string())
| QUOTElm =>
fatalError "Token")
| ANTIQUOTElm =>
AntiQuotation lexbuf
| HASHBANGlm =>
Hashbang lexbuf
}

and TokenN = parse
Expand Down Expand Up @@ -461,6 +469,12 @@ and AntiQuotation = parse
{
skipString "ill-formed antiquotation" SkipQuotation lexbuf
}
and Hashbang = parse
"#!" [^`\n` `\r`]*
{ lexingMode := NORMALlm; Token lexbuf }
| ""
{ lexingMode := NORMALlm; Token lexbuf }

;


Expand Down
3 changes: 3 additions & 0 deletions src/compiler/Lexer.sig
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
(* Lexer.sig *)

val enableHashbang : bool -> unit;
val quotation : bool ref;
val resetLexerState : unit -> unit;
val Token : Lexing.lexbuf -> Parser.token;
13 changes: 12 additions & 1 deletion src/compiler/Maint.sml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
open List BasicIO Nonstdio;
open Miscsys Memory Fnlib Config Mixture Location Units Smlperv Rtvals Smltop;
open Types (* cvr *);
open Lexer (*to set hashbang*);
val initialFiles = ref ([] : string list);

(* Initial loop *)
Expand Down Expand Up @@ -72,6 +73,13 @@ fun set_value_polymorphism b _ =
fun set_quietdec b _ =
Exec_phr.quietdec := b;

fun set_hashbang b _ =
let in
Lexer.enableHashbang b;
Exec_phr.quietdec := b;
Exec_phr.hashbang := b
end;

fun add_include d =
load_path := !load_path @ [d];

Expand Down Expand Up @@ -117,6 +125,8 @@ fun main () =
("-perv", Arg.String perv_set),
("-imptypes", Arg.Unit (set_value_polymorphism false)),
("-valuepoly", Arg.Unit (set_value_polymorphism true)),
("-hashbang", Arg.Unit (set_hashbang true)),
("-s", Arg.Unit (set_hashbang true)),
("-quietdec", Arg.Unit (set_quietdec true)),
("-msgstyle", Arg.String set_msgstyle),
("-m", Arg.String set_msgstyle),
Expand Down Expand Up @@ -148,7 +158,8 @@ fun main () =
resetTypes();
Miscsys.catch_interrupt true;
input_lexbuf := Compiler.createLexerStream std_in;
(initial_loop() handle EndOfFile => ());
(initial_loop() handle EndOfFile =>
if !Exec_phr.hashbang then BasicIO.exit 0 else ());
main_loop()
end
handle
Expand Down
3 changes: 3 additions & 0 deletions src/launch/mosml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ while : ; do
-quietdec)
options="$options -quietdec"
;;
-s|-hashbang)
options="$options -hashbang"
;;
-valuepoly)
options="$options -valuepoly"
;;
Expand Down