1structure AssembleHolfootParser :> AssembleHolfootParser = 2struct 3 4 structure HolfootLrVals = 5 HolfootLrValsFun(structure Token = LrParser.Token) 6 7 structure HolfootLex = 8 HolfootLexFun(structure Tokens = HolfootLrVals.Tokens) 9 10 11 structure DiskFileParser = 12 Join(structure ParserData = HolfootLrVals.ParserData 13 structure Lex = HolfootLex 14 structure LrParser = LrParser) 15 16 17 fun print_parse_error s = 18 let 19 open PPBackEnd; 20 val _ = Parse.print_with_style [FG OrangeRed, Bold, Underline] "Error:"; 21 val _ = Parse.print_with_style [] " "; 22 val _ = Parse.print_with_style [FG OrangeRed] s 23 val _ = Parse.print_with_style [] "\n"; 24 in 25 () 26 end; 27 28 fun invoke lexstream = let 29 open PPBackEnd; 30 val error_count = ref 0; 31 fun print_error (s,(j:int,i:int),_) = 32 ((if (!error_count > 0) then () else print "\n"); 33 (error_count := !error_count + 1); 34 print_parse_error (" "^ 35 " line "^(Int.toString (i+1)) ^ ": " ^ s); 36 (if (!error_count > 15) then Feedback.fail() else ())); 37 38 val r = (#1 (DiskFileParser.parse(15,lexstream,print_error,()))) 39 handle HolfootLex.UserDeclarations.LexicalError (tok, j, i) => 40 let 41 val s = "lex error - ill formed token \""^tok^"\""; 42 val _ = print_error (s, (j, i), (j,i)); 43 in 44 Feedback.fail() 45 end; 46 in 47 (if (!error_count > 0) then Feedback.fail() else r) 48 end 49 50 fun raw_read_stream strm = let 51 val lexer = DiskFileParser.makeLexer (fn _ => Portable.input_line strm) 52 in 53 invoke lexer 54 end 55 56 fun raw_read_file fname = let 57 val strm = TextIO.openIn fname 58 in 59 raw_read_stream strm before TextIO.closeIn strm 60 end 61 62end; 63