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/JSON/json.lex
ViewVC logotype

Diff of /smlnj-lib/trunk/JSON/json.lex

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

revision 3004, Wed Apr 23 21:58:57 2008 UTC revision 3018, Tue May 6 13:41:38 2008 UTC
# Line 4  Line 4 
4   * All rights reserved.   * All rights reserved.
5   *   *
6   * Lexer for JSON files.   * Lexer for JSON files.
7     *
8     * TODO:
9     *      EOF rules for strings
10     *      newlines in strings
11     *      error messages for unknown characters
12   *)   *)
13    
14  %name JSONLexer;  %name JSONLexer;
# Line 24  Line 29 
29          in          in
30            addStr(UTF8.encode w)            addStr(UTF8.encode w)
31          end          end
32    fun finishString () = (String.concat(List.rev(!sbuf)) before sbuf := [])    fun finishString () = (T.STRING(String.concat(List.rev(!sbuf))) before sbuf := [])
33  );  );
34    
35  %let digit1_9 = [1-9];  %let digit1_9 = [1-9];
# Line 37  Line 42 
42    
43  %states S;  %states S;
44    
45  [ \t\n\r]+              => (skip() );  <INITIAL>[\ \t\n\r]+            => ( skip() );
46    
47  "{"                     => ( T.LCB );  <INITIAL>"{"                    => ( T.LCB );
48  "}"                     => ( T.RCB );  <INITIAL>"}"                    => ( T.RCB );
49  "["                     => ( T.LB );  <INITIAL>"["                    => ( T.LB );
50  "]"                     => ( T.RB );  <INITIAL>"]"                    => ( T.RB );
51  ","                     => ( T.COMMA );  <INITIAL>","                    => ( T.COMMA );
52  ":"                     => ( T.COLON );  <INITIAL>":"                    => ( T.COLON );
53  "null"                  => ( T.KW_null );  <INITIAL>"null"                 => ( T.KW_null );
54  "true"                  => ( T.KW_true );  <INITIAL>"true"                 => ( T.KW_true );
55  "false"                 => ( T.KW_false );  <INITIAL>"false"                => ( T.KW_false );
56    
57  {int}                   => ( T.INT(valOf(IntInf.fromString yytext)) );  <INITIAL>{int}                  => ( T.INT(valOf(IntInf.fromString yytext)) );
58    
59  {int}{frac}             => ( float yytext );  <INITIAL>{int}{frac}            => ( float yytext );
60  {int}{exp}              => ( float yytext );  <INITIAL>{int}{exp}             => ( float yytext );
61  {int}{frac}{exp}        => ( float yytext );  <INITIAL>{int}{frac}{exp}       => ( float yytext );
62    
63  "\""                    => ( YYBEGIN S; continue() );  <INITIAL>"\""                   => ( YYBEGIN S; continue() );
64  <S>"\\\""               => ( addStr "\\"; continue() );  <S>"\\\""               => ( addStr "\\"; continue() );
65  <S>"\\/"                => ( addStr "/"; continue() );  <S>"\\/"                => ( addStr "/"; continue() );
66  <S>"\\b"                => ( addStr "\b"; continue() );  <S>"\\b"                => ( addStr "\b"; continue() );
# Line 67  Line 72 
72  <S>[^\\"]+              => ( addStr yytext; continue() );  <S>[^\\"]+              => ( addStr yytext; continue() );
73  <S>"\""                 => ( YYBEGIN INITIAL; finishString() );  <S>"\""                 => ( YYBEGIN INITIAL; finishString() );
74    
75  "/*"~(.*"*/".*)"*/"     => ( skip() );  <INITIAL>"/*"(~(.*"*/".*))"*/"  => ( skip() );
76    
77    (* FIXME: add some error reporting *)
78    <INITIAL>.                      => ( skip() );

Legend:
Removed from v.3004  
changed lines
  Added in v.3018

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