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

SCM Repository

[smlnj] View of /smlnj-lib/trunk/JSON/json-tokens.sml
ViewVC logotype

View of /smlnj-lib/trunk/JSON/json-tokens.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3001 - (download) (annotate)
Tue Apr 22 14:27:15 2008 UTC (11 years, 3 months ago) by jhr
File size: 1188 byte(s)
  Added lexer specification
(* json-tokens.sml
 *
 * COPYRIGHT (c) 2008 The Fellowship of SML/NJ (http://www.smlnj.org)
 * All rights reserved.
 *
 * The tokens returned by the JSON lexer.
 *)

structure JSONTokens =
  struct

    datatype token
      = EOF		(* end-of-file *)
      | LB | RB		(* "[" "]" *)
      | LCB | RCB	(* "{" "}" *)
      | COMMA		(* "," *)
      | COLON		(* ":" *)
      | KW_null		(* "null" *)
      | KW_true		(* "true" *)
      | KW_false	(* "false" *)
      | INT of IntInf.int
      | FLOAT of real
      | STRING of string

    fun toString EOF = "<eof>"
      | toString LB = "["
      | toString RB = "]"
      | toString LCB = "{"
      | toString RCB = "}"
      | toString COMMA = ","
      | toString COLON = ":"
      | toString KW_null = "null"
      | toString KW_true = "true"
      | toString KW_false = "false"
      | toString (INT i) =
	  if (i < 0) then "-" ^ IntInf.toString(~i)
	  else IntInf.toString i
      | toString (FLOAT f) =
	  if (f < 0.0) then "-" ^ Real.toString(~f)
	  else Real.toString f
      | toString (STRING s) = let
	  fun f (wchr, l) = UTF8.toString wchr :: l
	  in
	    String.concat("\"" :: (List.foldr f ["\""] (UTF8.explode s)))
	  end

  end

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