1 (* Copyright (C) 2015 Matthew Fluet.
2 * Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
3 * Jagannathan, and Stephen Weeks.
4 * Copyright (C) 1997-2000 NEC Research Institute.
6 * MLton is released under a BSD-style license.
7 * See the file MLton-LICENSE for details.
10 functor FrontEnd (S: FRONT_END_STRUCTS): FRONT_END =
15 structure LrVals = MLLrValsFun (structure Token = LrParser.Token
17 structure Lex = MLLexFun (structure Tokens = LrVals.Tokens)
18 structure Parse = JoinWithArg (structure ParserData = LrVals.ParserData
20 structure LrParser = LrParser)
22 fun lexAndParse (source: Source.t, ins: In.t): Ast.Program.t =
25 Parse.makeLexer (fn n => In.inputN (ins, n))
29 (#1 (Parse.parse (lookahead, stream, fn (s, left, right) =>
30 Control.errorStr (Region.make {left = left,
36 val i = Source.lineStart source
38 Control.errorStr (Region.make {left = i, right = i},
43 val () = Ast.Program.checkSyntax result
45 (* Outputs AST to a file if Control.keepAST is true *)
49 (concat [!Control.inputFile, ".ast"], fn outputStream =>
50 (Out.outputl (outputStream, concat ["File: ", Source.name source]);
51 Layout.output (Ast.Program.layout result, outputStream);
52 Out.newline outputStream;
53 Out.newline outputStream))
59 fun lexAndParseFile (f: File.t) =
61 (f, fn ins => lexAndParse (Source.new f, ins))
64 Trace.trace ("FrontEnd.lexAndParseFile", File.layout, Ast.Program.layout)