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/cm/parse/parse.sml
ViewVC logotype

Diff of /sml/trunk/src/cm/parse/parse.sml

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

revision 297, Thu May 27 08:29:19 1999 UTC revision 309, Wed Jun 2 03:21:57 1999 UTC
# Line 6  Line 6 
6   * Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)   * Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)
7   *)   *)
8  signature CMPARSE = sig  signature CMPARSE = sig
9      val parse : Primitive.configuration -> AbsPath.t -> CMSemant.group option      val parse :
10            GeneralParams.param -> AbsPath.t
11            -> (CMSemant.group * GeneralParams.info) option
12  end  end
13    
14  structure CMParse :> CMPARSE = struct  structure CMParse :> CMPARSE = struct
# Line 16  Line 18 
18      structure S = GenericVC.Source      structure S = GenericVC.Source
19      structure EM = GenericVC.ErrorMsg      structure EM = GenericVC.ErrorMsg
20      structure SM = GenericVC.SourceMap      structure SM = GenericVC.SourceMap
     structure P = GenericVC.Control.Print  
21    
22      structure CMLrVals = CMLrValsFun (structure Token = LrParser.Token)      structure CMLrVals = CMLrValsFun (structure Token = LrParser.Token)
23      structure CMLex = CMLexFun (structure Tokens = CMLrVals.Tokens)      structure CMLex = CMLexFun (structure Tokens = CMLrVals.Tokens)
# Line 25  Line 26 
26                       structure Lex = CMLex                       structure Lex = CMLex
27                       structure LrParser = LrParser)                       structure LrParser = LrParser)
28    
29      fun parse primconf group = let      fun parse param group = let
30    
31          val groupreg = GroupReg.new ()          val groupreg = GroupReg.new ()
32          val fnpolicy = FilenamePolicy.default          val errcons = EM.defaultConsumer ()
33          val params = { groupreg = groupreg,          val ginfo = { param = param, groupreg = groupreg, errcons = errcons }
                        fnpolicy = fnpolicy,  
                        primconf = primconf,  
                        keep_going = false }  
34    
35          val gc = ref AbsPathMap.empty   (* the "group cache" *)          (* The "group cache" -- we store "group options";  having
36             * NONE registered for a group means that a previous attempt
37             * to parse it had failed. *)
38            val gc = ref (AbsPathMap.empty: CMSemant.group option AbsPathMap.map)
39    
40          fun mparse (group, groupstack) =          fun mparse (group, groupstack) =
41              case AbsPathMap.find (!gc, group) of              case AbsPathMap.find (!gc, group) of
# Line 82  Line 83 
83                  val filename = AbsPath.name group                  val filename = AbsPath.name group
84                  val _ = Say.vsay (concat ["[scanning ", filename, "]\n"])                  val _ = Say.vsay (concat ["[scanning ", filename, "]\n"])
85                  val stream = TextIO.openIn filename                  val stream = TextIO.openIn filename
                 val errcons = { linewidth = !P.linewidth,  
                                 flush = P.flush,  
                                 consumer = P.say }  
86                  val source = S.newSource (filename, 1, stream, false, errcons)                  val source = S.newSource (filename, 1, stream, false, errcons)
87                  val sourceMap = #sourceMap source                  val sourceMap = #sourceMap source
88                  val _ = GroupReg.register groupreg (group, source)                  val _ = GroupReg.register groupreg (group, source)
# Line 113  Line 111 
111                       CMSemant.emptyGroup group)                       CMSemant.emptyGroup group)
112    
113                  fun doMember (p, p1, p2, c) =                  fun doMember (p, p1, p2, c) =
114                      CMSemant.member (params, recParse (p1, p2))                      CMSemant.member (ginfo, recParse (p1, p2))
115                                      { sourcepath = p, class = c,                                      { sourcepath = p, class = c,
116                                        group = (group, (p1, p2)) }                                        group = (group, (p1, p2)) }
117    
118                    (* Build the argument for the lexer; the lexer's local
119                     * state is encapsulated here to make sure the parser
120                     * is re-entrant. *)
121                  val lexarg = let                  val lexarg = let
122                      (* local state *)                      (* local state *)
123                      val depth = ref 0                      val depth = ref 0
# Line 185  Line 186 
186                      CMParse.parse (lookAhead, tokenStream,                      CMParse.parse (lookAhead, tokenStream,
187                                     fn (s,p1,p2) => error (p1, p2) s,                                     fn (s,p1,p2) => error (p1, p2) s,
188                                     (group, context, error, recParse,                                     (group, context, error, recParse,
189                                      doMember, params))                                      doMember, ginfo))
190              in              in
191                  TextIO.closeIn stream;                  TextIO.closeIn stream;
192                  if !(#anyErrors source) then NONE                  if !(#anyErrors source) then NONE
# Line 197  Line 198 
198                  h :: t => (report (h, t); NONE)                  h :: t => (report (h, t); NONE)
199                | [] => normal_processing ()                | [] => normal_processing ()
200          end          end
   
201      in      in
202          mparse (group, [])          case mparse (group, []) of
203                NONE => NONE
204              | SOME g =>
205                    if CheckSharing.check (g, ginfo) then
206                        (SmlInfo.forgetAllBut (Reachable.reachable g);
207                         SOME (g, ginfo))
208                    else NONE
209      end      end
210  end  end

Legend:
Removed from v.297  
changed lines
  Added in v.309

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