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 /smlnj-lib/trunk/RegExp/BackEnd/dfa-engine.sml
ViewVC logotype

Diff of /smlnj-lib/trunk/RegExp/BackEnd/dfa-engine.sml

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

revision 2957, Thu Mar 6 03:17:28 2008 UTC revision 2958, Tue Mar 18 16:08:01 2008 UTC
# Line 1  Line 1 
1  (* dfa-engine.sml  (* dfa-engine.sml
2   *   *
3   * COPYRIGHT (c) 1998 Bell Labs, Lucent Technologies.   * COPYRIGHT (c) 2008 The Fellowship of SML/NJ (http://www.smlnj.org)
4     * All rights reserved.
5   *   *
6   * Implements a matcher engine based on deterministic finite   * Implements a matcher engine based on deterministic finite
7   * automata.   * automata.
# Line 14  Line 15 
15    
16          type regexp = D.dfa          type regexp = D.dfa
17    
18          fun compile r = D.build r    (* a match specifies the position (as a stream) and the length of the match *)
19                          handle _ => raise RegExpSyntax.CannotCompile      type 'a match = {pos : 'a, len : int} MatchTree.match_tree
20    
21        fun compile r = D.build r handle _ => raise RegExpSyntax.CannotCompile
22    
23          (* scan looks at a stream and attempts to match the dfa.          (* scan looks at a stream and attempts to match the dfa.
24           * it returns NONE if it fails           * it returns NONE if it fails
# Line 41  Line 44 
44                  fun try0 stream = (                  fun try0 stream = (
45                        case (accepting 0)                        case (accepting 0)
46                         of (SOME n) =>                         of (SOME n) =>
47                              SOME(n, M.Match(SOME{pos=stream,len=0},[]), stream)                          SOME(n, M.Match({pos=stream,len=0},[]), stream)
48                          | NONE => NONE                          | NONE => NONE
49                        (* end case *))                        (* end case *))
50              in              in
# Line 51  Line 54 
54                        case loop (0, p, stream, NONE)                        case loop (0, p, stream, NONE)
55                         of NONE => try0 stream                         of NONE => try0 stream
56                          | SOME(last, cs, n) =>                          | SOME(last, cs, n) =>
57                              SOME(n, M.Match(SOME{pos=stream,len=last-p},[]), cs)                          SOME(n, M.Match({pos=stream,len=last-p},[]), cs)
58                        (* end case *))                        (* end case *))
59                  (* end case *)                  (* end case *)
60              end              end
# Line 73  Line 76 
76          fun match [] = (fn getc => fn stream => NONE)          fun match [] = (fn getc => fn stream => NONE)
77            | match l =            | match l =
78              let val dfa = D.buildPattern (map #1 l)              let val dfa = D.buildPattern (map #1 l)
79                  val a = Array.fromList (map (fn (a,b) => b) l)              val a = Vector.fromList (map (fn (a,b) => b) l)
80              in              in
81                  fn getc => fn stream => case (scan (dfa,getc,0,stream))                  fn getc => fn stream => case (scan (dfa,getc,0,stream))
82                                            of NONE => NONE                                            of NONE => NONE
83                                             | SOME (n,m,cs) => SOME ((Array.sub (a,n)) m,cs)                                         | SOME(n,m,cs) => SOME((Vector.sub (a,n)) m,cs)
84              end              end
85    
86      end      end

Legend:
Removed from v.2957  
changed lines
  Added in v.2958

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