Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/trunk/src/MLRISC/Tools/Parser/parser.sml
ViewVC logotype

Diff of /sml/trunk/src/MLRISC/Tools/Parser/parser.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1078, Tue Feb 19 21:26:48 2002 UTC revision 1079, Wed Feb 20 01:16:15 2002 UTC
# Line 5  Line 5 
5     exception ParseError     exception ParseError
6    
7     val parse : string * TextIO.instream -> Ast.decl list     val parse : string * TextIO.instream -> Ast.decl list
8       val parse'       : bool -> string * TextIO.instream -> Ast.decl list
9     val parseString : string -> Ast.decl list     val parseString : string -> Ast.decl list
10       val parseString' : bool -> string -> Ast.decl list
11     val load  : string -> Ast.decl list     val load  : string -> Ast.decl list
12       val load'        : bool -> string -> Ast.decl list
13    
14  end  end
15    
# Line 17  Line 20 
20      ) : MDL_PARSER_DRIVER =      ) : MDL_PARSER_DRIVER =
21  struct  struct
22    
23       val MAX_ERROR = 30
24    
25     structure Ast = AstPP.Ast     structure Ast = AstPP.Ast
26     structure Error = MDLError     structure Error = MDLError
27     structure LrVals = MDLParser(structure Token = LrParser.Token     structure LrVals = MDLParser(structure Token = LrParser.Token
# Line 60  Line 65 
65    
66     exception ParseError     exception ParseError
67    
68     fun parseIt(filename,stream)=     fun parseIt silent (filename,stream)=
69     let val _     = Lex.UserDeclarations.init ()     let val _     = Lex.UserDeclarations.init ()
70         val srcMap = SourceMapping.newmap{srcFile=filename}         val srcMap = SourceMapping.newmap{srcFile=filename}
71           val errCount = ref 0
72         fun err(a,b,msg) =         fun err(a,b,msg) =
73           if silent then raise ParseError
74           else
75         let val loc = SourceMapping.location srcMap (a,b)         let val loc = SourceMapping.location srcMap (a,b)
76         in  Error.setLoc loc; Error.error(msg) end         in  Error.setLoc loc;
77               Error.error(msg);
78               errCount := !errCount + 1;
79               if !errCount > MAX_ERROR then raise ParseError else ()
80           end
81         fun input n = TextIO.inputN(stream,n)         fun input n = TextIO.inputN(stream,n)
82         val lexArg = {srcMap=srcMap, err=err, MDLmode=MDLmode}         val lexArg = {srcMap=srcMap, err=err, MDLmode=MDLmode}
83         val lexer = Parser.Stream.streamify(Lex.makeLexer input lexArg)         val lexer = Parser.Stream.streamify(Lex.makeLexer input lexArg)
84         fun parseError(msg,a,b) = err(a,b,msg)         fun parseError(msg,a,b) = err(a,b,msg)
85           fun errPos msg = if silent then raise ParseError else Error.errorPos msg
86           fun import (loc,filename) = (Error.setLoc loc; loadIt silent filename)
87         val (result,lexer) =         val (result,lexer) =
88               Parser.parse(15,lexer,parseError,               Parser.parse(15,lexer,parseError,
89                 (srcMap,Error.errorPos,import,ref defaultPrec,extraCells))                 (srcMap,errPos,import,ref defaultPrec,extraCells))
90     in  if !Error.errorCount > 0 then raise ParseError else result end     in  if !Error.errorCount > 0 then raise ParseError else result end
91    
92     and loadIt filename =     and loadIt silent filename =
93     let val stream = TextIO.openIn filename     let val stream = TextIO.openIn filename
94     in  parseIt(filename,stream) before TextIO.closeIn stream     in  parseIt silent (filename,stream) before TextIO.closeIn stream
95            handle e => (TextIO.closeIn stream; raise e)            handle e => (TextIO.closeIn stream; raise e)
96     end handle IO.Io{function,name,cause,...} =>     end handle IO.Io{function,name,cause,...} =>
97         (         (
98          Error.error(function^" failed in \""^name^"\" ("^exnName cause^")");          Error.error(function^" failed in \""^name^"\" ("^exnName cause^")");
99          raise ParseError)          raise ParseError)
100    
    and import (loc,filename) = (Error.setLoc loc; loadIt filename)  
   
    fun parse x = (Error.init(); parseIt x)  
    fun load x = (Error.init(); loadIt x)  
    fun parseString s = parse("???",TextIO.openString s)  
101    
102       fun parse' silent x = (Error.init(); parseIt silent x)
103       fun load' silent x = (Error.init(); loadIt silent x)
104       fun parseString' silent s = parse' silent ("???",TextIO.openString s)
105    
106       val parse       = parse' false
107       val load        = load' false
108       val parseString = parseString' false
109  end  end

Legend:
Removed from v.1078  
changed lines
  Added in v.1079

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0