keyword-fn.sml

来自「这是我们参加06年全国开源软件的竞赛作品」· SML 代码 · 共 51 行

SML
51
字号
(* keyword-fn.sml * * COPYRIGHT (c) 1997 AT&T Labs Research. * * This functor is meant to be used as part of a scanner, where identifiers * and keywords are scanned using the same lexical rules and are then * further analyzed. *)functor KeywordFn (KW : sig    type token    type pos    val ident : (Atom.atom * pos * pos) -> token    val keywords : (string * ((pos * pos) -> token)) list  end) : sig    type token    type pos    val keyword : (string * pos * pos) -> token  end = struct    structure A = Atom    structure Tbl = AtomTable    type token = KW.token    type pos = KW.pos  (* the keyword hash table *)    exception Keyword    val kwTbl : ((pos * pos) -> token) Tbl.hash_table =	  Tbl.mkTable(List.length KW.keywords, Keyword)  (* insert the reserved words into the keyword hash table *)    val _ = let	  val insert = Tbl.insert kwTbl	  fun ins (s, item) = insert (A.atom s, item)	  in	    app ins KW.keywords	  end    fun keyword (s, p1, p2) = let	  val name = A.atom s	  in	    case (Tbl.find kwTbl name)	     of (SOME tokFn) => tokFn(p1, p2)	      | NONE => KW.ident(name, p1, p2)	    (* end case *)	  end  end; 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?