nendo 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/init.nndc CHANGED
@@ -16186,7 +16186,7 @@ trampCall(
16186
16186
  rescue => __e ; __e.set_backtrace( ["./lib/init.nnd:1070"] + __e.backtrace ) ; raise __e
16187
16187
  end ,
16188
16188
  [
16189
- Regexp.new( "^([.]/|[.][.]/|/)") ,
16189
+ Regexp.new( "^([.]\\/|[.][.]\\/|\\/)") ,
16190
16190
  begin
16191
16191
  trampCall(_path)
16192
16192
  rescue => __e ; __e.set_backtrace( ["./lib/init.nnd:1067"] + __e.backtrace ) ; raise __e
data/lib/nendo.rb CHANGED
@@ -157,6 +157,9 @@ module Nendo
157
157
  @exp = str[ 1 ... str.size ]
158
158
  @ignoreCase = (str[0] == 'i')
159
159
  end
160
+ def to_s
161
+ sprintf( "|%s|", @exp ) + (@ignoreCase ? "i" : "")
162
+ end
160
163
  def escape
161
164
  @exp.gsub( /\\/, "\\\\\\\\" )
162
165
  end
@@ -429,12 +432,7 @@ module Nendo
429
432
  if ch.chr == "\\" #escape
430
433
  ch2 = @chReader.getc
431
434
  #printf( " readRegexp2: [%s]\n", ch2 )
432
- if ch2.chr == '/'
433
- ret += ch2.chr # drop escape "\\" char
434
- else
435
- ret += ch.chr
436
- ret += ch2.chr
437
- end
435
+ ret += "\\" + ch2.chr
438
436
  elsif ch.chr == '/'
439
437
  break
440
438
  else
@@ -1199,9 +1197,8 @@ module Nendo
1199
1197
  end
1200
1198
 
1201
1199
  def _hash_MIMARKtable_MIMARKget( h, key, *args )
1202
- val = h[key]
1203
- if val
1204
- val
1200
+ if h.has_key?(key)
1201
+ h[key]
1205
1202
  else
1206
1203
  arr = args[0].to_arr
1207
1204
  if 0 < arr.length
@@ -1303,6 +1300,7 @@ module Nendo
1303
1300
 
1304
1301
  # call depth counter
1305
1302
  @call_depth = 0
1303
+ @call_counters = Hash.new
1306
1304
 
1307
1305
  # init optimize level
1308
1306
  @optimize_level = 1
@@ -1488,7 +1486,17 @@ module Nendo
1488
1486
  end
1489
1487
 
1490
1488
  def callProcedure( origname, pred, args )
1491
- pred.call( *toRubyArgument( origname, pred, args ))
1489
+ if @call_counters.has_key?( origname )
1490
+ @call_counters[ origname ] += 1
1491
+ else
1492
+ @call_counters[ origname ] = 1
1493
+ end
1494
+
1495
+ result = pred.call( *toRubyArgument( origname, pred, args ))
1496
+
1497
+ @call_counters[ origname ] -= 1
1498
+
1499
+ result
1492
1500
  end
1493
1501
 
1494
1502
  # for code generation of Ruby's argument values
@@ -1980,41 +1988,59 @@ module Nendo
1980
1988
  }
1981
1989
  end
1982
1990
 
1991
+ def displayTopOfCalls( exception )
1992
+ STDERR.puts( "\n <<< Top of calls >>>" )
1993
+ strs = []
1994
+ @call_counters.each_key { |funcname|
1995
+ if 0 < @call_counters[ funcname ]
1996
+ strs << sprintf( " %7d : %-20s", @call_counters[ funcname ], funcname )
1997
+ end
1998
+ }
1999
+ strs.sort.reverse.each { |str|
2000
+ STDERR.puts( str )
2001
+ }
2002
+ end
2003
+
1983
2004
  def lispEval( sexp, sourcefile, lineno )
1984
- sourceInfo = SourceInfo.new
1985
- @lastSourcefile = sourcefile
1986
- @lastLineno = lineno
1987
- sourceInfo.setSource( sourcefile, lineno, sexp )
1988
- sexp = macroExpandPhase( sexp )
1989
- sexp = quotingPhase( sexp )
1990
- if @debug
1991
- printf( "\n quoting=<<< %s >>>\n", (Printer.new())._print(sexp))
1992
- end
1993
- # compiling phase written in Nendo
1994
- sym = toRubySymbol( "%compile-phase" )
1995
- if ( eval( sprintf( "(defined? @%s and Proc == @%s.class)", sym,sym ), @binding ))
1996
- eval( sprintf( "@___tmp = @%s", sym ), @binding )
1997
- sexp = trampCall( callProcedure( sym, @___tmp, [ sexp ]))
2005
+ begin
2006
+ sourceInfo = SourceInfo.new
2007
+ @lastSourcefile = sourcefile
2008
+ @lastLineno = lineno
2009
+ sourceInfo.setSource( sourcefile, lineno, sexp )
2010
+ sexp = macroExpandPhase( sexp )
2011
+ sexp = quotingPhase( sexp )
1998
2012
  if @debug
1999
- printf( "\n compiled=<<< %s >>>\n", (Printer.new())._print(sexp))
2013
+ printf( "\n quoting=<<< %s >>>\n", (Printer.new())._print(sexp))
2000
2014
  end
2015
+ # compiling phase written in Nendo
2016
+ sym = toRubySymbol( "%compile-phase" )
2017
+ if ( eval( sprintf( "(defined? @%s and Proc == @%s.class)", sym,sym ), @binding ))
2018
+ eval( sprintf( "@___tmp = @%s", sym ), @binding )
2019
+ sexp = trampCall( callProcedure( sym, @___tmp, [ sexp ]))
2020
+ if @debug
2021
+ printf( "\n compiled=<<< %s >>>\n", (Printer.new())._print(sexp))
2022
+ end
2023
+ end
2024
+ sourceInfo.setExpanded( sexp )
2025
+
2026
+ arr = [ "trampCall( ", translate( sexp, [], sourceInfo ), " )" ]
2027
+ rubyExp = ppRubyExp( 0, arr ).flatten.join
2028
+ sourceInfo.setCompiled( rubyExp )
2029
+ if not @compiled_code.has_key?( sourcefile )
2030
+ @compiled_code[ sourcefile ] = Array.new
2031
+ end
2032
+ @compiled_code[ sourcefile ] << rubyExp
2033
+ if sourceInfo.varname
2034
+ @source_info_hash[ sourceInfo.varname ] = sourceInfo
2035
+ end
2036
+ printf( " rubyExp=<<<\n%s\n>>>\n", rubyExp ) if @debug
2037
+ eval( rubyExp, @binding, @lastSourcefile, @lastLineno )
2038
+ rescue SystemStackError => e
2039
+ displayTopOfCalls( e )
2040
+ raise e
2001
2041
  end
2002
- sourceInfo.setExpanded( sexp )
2003
-
2004
- arr = [ "trampCall( ", translate( sexp, [], sourceInfo ), " )" ]
2005
- rubyExp = ppRubyExp( 0, arr ).flatten.join
2006
- sourceInfo.setCompiled( rubyExp )
2007
- if not @compiled_code.has_key?( sourcefile )
2008
- @compiled_code[ sourcefile ] = Array.new
2009
- end
2010
- @compiled_code[ sourcefile ] << rubyExp
2011
- if sourceInfo.varname
2012
- @source_info_hash[ sourceInfo.varname ] = sourceInfo
2013
- end
2014
- printf( " rubyExp=<<<\n%s\n>>>\n", rubyExp ) if @debug
2015
- eval( rubyExp, @binding, @lastSourcefile, @lastLineno )
2016
2042
  end
2017
-
2043
+
2018
2044
  def __PAMARKload( filename )
2019
2045
  printer = Printer.new( @debug )
2020
2046
  open( filename, "r:utf-8" ) {|f|
@@ -2208,7 +2234,7 @@ module Nendo
2208
2234
  end
2209
2235
 
2210
2236
  def self.version
2211
- "0.4.0" ##NENDO-VERSION
2237
+ "0.4.1" ##NENDO-VERSION
2212
2238
  end
2213
2239
 
2214
2240
  def loadInitFile( use_compiled = true )
data/lib/rfc/json.nnd ADDED
@@ -0,0 +1,106 @@
1
+ ;;-*- mode: nendo; syntax: scheme -*-;;
2
+ ;;;
3
+ ;;; json.nnd - JSON parser and constructor
4
+ ;;;
5
+ ;;; Copyright (c) 2011 Kiyoka Nishiyama <kiyoka@sumibi.org>
6
+ ;;;
7
+ ;;; Redistribution and use in source and binary forms, with or without
8
+ ;;; modification, are permitted provided that the following conditions
9
+ ;;; are met:
10
+ ;;;
11
+ ;;; 1. Redistributions of source code must retain the above copyright
12
+ ;;; notice, this list of conditions and the following disclaimer.
13
+ ;;;
14
+ ;;; 2. Redistributions in binary form must reproduce the above copyright
15
+ ;;; notice, this list of conditions and the following disclaimer in the
16
+ ;;; documentation and/or other materials provided with the distribution.
17
+ ;;;
18
+ ;;; 3. Neither the name of the authors nor the names of its contributors
19
+ ;;; may be used to endorse or promote products derived from this
20
+ ;;; software without specific prior written permission.
21
+ ;;;
22
+ ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
+ ;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
+ ;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25
+ ;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26
+ ;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27
+ ;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
28
+ ;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29
+ ;;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30
+ ;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31
+ ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32
+ ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
+ ;;;
34
+ ;;; $Id:
35
+ ;;;
36
+
37
+ (require "json")
38
+
39
+
40
+ ;; ------------------------------
41
+ (define (%json:hash-table->alist obj)
42
+ (cond
43
+ ((null? obj)
44
+ obj)
45
+ ((vector? obj)
46
+ (list->vector
47
+ (map
48
+ (lambda (x)
49
+ (%json:hash-table->alist x))
50
+ (vector->list obj))))
51
+ ((hash-table? obj)
52
+ (map
53
+ (lambda (entry)
54
+ (cons (car entry)
55
+ (%json:hash-table->alist (cdr entry))))
56
+ (hash-table->alist obj)))
57
+ (else
58
+ obj)))
59
+
60
+ (define (%json:alist->hash-table obj)
61
+ (cond
62
+ ((null? obj)
63
+ (make-hash-table))
64
+ ((vector? obj)
65
+ (list->vector
66
+ (map
67
+ (lambda (x)
68
+ (%json:alist->hash-table x))
69
+ (vector->list obj))))
70
+ ((pair? obj)
71
+ (alist->hash-table
72
+ (map
73
+ (lambda (entry)
74
+ (cons (car entry)
75
+ (%json:alist->hash-table (cdr entry))))
76
+ obj)))
77
+ (else
78
+ obj)))
79
+
80
+
81
+ ;; ------------------------------
82
+ ;; parser
83
+ ;; ------------------------------
84
+ (define (parse-json-string str)
85
+ (%json:hash-table->alist
86
+ (JSON.parse str)))
87
+
88
+ (define (parse-json . io)
89
+ (let* ((_ (get-optional io STDIN))
90
+ (str (_.read)))
91
+ (parse-json-string str)))
92
+
93
+
94
+ ;; ------------------------------
95
+ ;; writer
96
+ (define (construct-json-string obj)
97
+ (JSON.dump
98
+ (%json:alist->hash-table obj)))
99
+
100
+ (define (construct-json obj . io)
101
+ (let1 _ (get-optional io STDOUT)
102
+ (_.print
103
+ (construct-json-string obj))))
104
+
105
+
106
+ ;;[EOS]
data/lib/rfc/json.nndc ADDED
@@ -0,0 +1,688 @@
1
+ #
2
+ # This file is nendo's compiled library file.
3
+ # generated "nendo -c src" command.
4
+ #
5
+
6
+ trampCall(
7
+ delayCall( '_require', 'require',
8
+ begin
9
+ if @global_lisp_binding.has_key?('_require') then
10
+ trampCall(@_require)
11
+ else raise NameError.new( "Error: undefined variable _require", "_require" ) end
12
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:37"] + __e.backtrace ) ; raise __e
13
+ end ,
14
+ [
15
+ "json"
16
+ ]
17
+ )
18
+ )
19
+ #--------------------
20
+
21
+ trampCall(
22
+ begin
23
+ def self.__PAMARKjson_COMARKhash_MIMARKtable_MIMARK_GTMARKalist_METHOD( origname, pred, args ) lispMethodEntry( origname, true ) ; ret = callProcedure( origname, pred, args ) ; lispMethodExit( origname, true ) ; return ret end
24
+ @global_lisp_binding['__PAMARKjson_COMARKhash_MIMARKtable_MIMARK_GTMARKalist'] = self.method( :__PAMARKjson_COMARKhash_MIMARKtable_MIMARK_GTMARKalist_METHOD )
25
+ @__PAMARKjson_COMARKhash_MIMARKtable_MIMARK_GTMARKalist =
26
+ trampCall(
27
+ Proc.new { |_obj|
28
+ if (
29
+ trampCall( self._null_QUMARK_METHOD( 'null?',
30
+ begin
31
+ if @global_lisp_binding.has_key?('_null_QUMARK') then
32
+ trampCall(@_null_QUMARK)
33
+ else raise NameError.new( "Error: undefined variable _null_QUMARK", "_null_QUMARK" ) end
34
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:43"] + __e.backtrace ) ; raise __e
35
+ end ,
36
+ [
37
+ begin
38
+ trampCall(_obj)
39
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:58"] + __e.backtrace ) ; raise __e
40
+ end
41
+ ]
42
+ ))
43
+ ) then
44
+ begin
45
+ begin
46
+ trampCall(_obj)
47
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:58"] + __e.backtrace ) ; raise __e
48
+ end
49
+ end
50
+ else
51
+ if (
52
+ trampCall( self._vector_QUMARK_METHOD( 'vector?',
53
+ begin
54
+ if @global_lisp_binding.has_key?('_vector_QUMARK') then
55
+ trampCall(@_vector_QUMARK)
56
+ else raise NameError.new( "Error: undefined variable _vector_QUMARK", "_vector_QUMARK" ) end
57
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:45"] + __e.backtrace ) ; raise __e
58
+ end ,
59
+ [
60
+ begin
61
+ trampCall(_obj)
62
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:58"] + __e.backtrace ) ; raise __e
63
+ end
64
+ ]
65
+ ))
66
+ ) then
67
+ begin
68
+ delayCall( '_list_MIMARK_GTMARKvector', 'list->vector',
69
+ begin
70
+ if @global_lisp_binding.has_key?('_list_MIMARK_GTMARKvector') then
71
+ trampCall(@_list_MIMARK_GTMARKvector)
72
+ else raise NameError.new( "Error: undefined variable _list_MIMARK_GTMARKvector", "_list_MIMARK_GTMARKvector" ) end
73
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:46"] + __e.backtrace ) ; raise __e
74
+ end ,
75
+ [
76
+ trampCall( self._map_METHOD( 'map',
77
+ begin
78
+ if @global_lisp_binding.has_key?('_map') then
79
+ trampCall(@_map)
80
+ else raise NameError.new( "Error: undefined variable _map", "_map" ) end
81
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:52"] + __e.backtrace ) ; raise __e
82
+ end ,
83
+ [
84
+ Proc.new { |_x|
85
+ trampCall( self.__PAMARKjson_COMARKhash_MIMARKtable_MIMARK_GTMARKalist_METHOD( '%json:hash-table->alist',
86
+ begin
87
+ if @global_lisp_binding.has_key?('__PAMARKjson_COMARKhash_MIMARKtable_MIMARK_GTMARKalist') then
88
+ trampCall(@__PAMARKjson_COMARKhash_MIMARKtable_MIMARK_GTMARKalist)
89
+ else raise NameError.new( "Error: undefined variable __PAMARKjson_COMARKhash_MIMARKtable_MIMARK_GTMARKalist", "__PAMARKjson_COMARKhash_MIMARKtable_MIMARK_GTMARKalist" ) end
90
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:55"] + __e.backtrace ) ; raise __e
91
+ end ,
92
+ [
93
+ begin
94
+ trampCall(_x)
95
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:49"] + __e.backtrace ) ; raise __e
96
+ end
97
+ ]
98
+ ))
99
+ } ,
100
+ trampCall( self._vector_MIMARK_GTMARKlist_METHOD( 'vector->list',
101
+ begin
102
+ if @global_lisp_binding.has_key?('_vector_MIMARK_GTMARKlist') then
103
+ trampCall(@_vector_MIMARK_GTMARKlist)
104
+ else raise NameError.new( "Error: undefined variable _vector_MIMARK_GTMARKlist", "_vector_MIMARK_GTMARKlist" ) end
105
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:50"] + __e.backtrace ) ; raise __e
106
+ end ,
107
+ [
108
+ begin
109
+ trampCall(_obj)
110
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:58"] + __e.backtrace ) ; raise __e
111
+ end
112
+ ]
113
+ ))
114
+ ]
115
+ ))
116
+ ]
117
+ )
118
+ end
119
+ else
120
+ if (
121
+ trampCall( self._hash_MIMARKtable_QUMARK_METHOD( 'hash-table?',
122
+ begin
123
+ if @global_lisp_binding.has_key?('_hash_MIMARKtable_QUMARK') then
124
+ trampCall(@_hash_MIMARKtable_QUMARK)
125
+ else raise NameError.new( "Error: undefined variable _hash_MIMARKtable_QUMARK", "_hash_MIMARKtable_QUMARK" ) end
126
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:51"] + __e.backtrace ) ; raise __e
127
+ end ,
128
+ [
129
+ begin
130
+ trampCall(_obj)
131
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:58"] + __e.backtrace ) ; raise __e
132
+ end
133
+ ]
134
+ ))
135
+ ) then
136
+ begin
137
+ delayCall( '_map', 'map',
138
+ begin
139
+ if @global_lisp_binding.has_key?('_map') then
140
+ trampCall(@_map)
141
+ else raise NameError.new( "Error: undefined variable _map", "_map" ) end
142
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:52"] + __e.backtrace ) ; raise __e
143
+ end ,
144
+ [
145
+ Proc.new { |_entry|
146
+ trampCall( self._cons_METHOD( 'cons',
147
+ begin
148
+ if @global_lisp_binding.has_key?('_cons') then
149
+ trampCall(@_cons)
150
+ else raise NameError.new( "Error: undefined variable _cons", "_cons" ) end
151
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:54"] + __e.backtrace ) ; raise __e
152
+ end ,
153
+ [
154
+ trampCall( self._car_METHOD( 'car',
155
+ begin
156
+ if @global_lisp_binding.has_key?('_car') then
157
+ trampCall(@_car)
158
+ else raise NameError.new( "Error: undefined variable _car", "_car" ) end
159
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:54"] + __e.backtrace ) ; raise __e
160
+ end ,
161
+ [
162
+ begin
163
+ trampCall(_entry)
164
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:55"] + __e.backtrace ) ; raise __e
165
+ end
166
+ ]
167
+ )) ,
168
+ trampCall( self.__PAMARKjson_COMARKhash_MIMARKtable_MIMARK_GTMARKalist_METHOD( '%json:hash-table->alist',
169
+ begin
170
+ if @global_lisp_binding.has_key?('__PAMARKjson_COMARKhash_MIMARKtable_MIMARK_GTMARKalist') then
171
+ trampCall(@__PAMARKjson_COMARKhash_MIMARKtable_MIMARK_GTMARKalist)
172
+ else raise NameError.new( "Error: undefined variable __PAMARKjson_COMARKhash_MIMARKtable_MIMARK_GTMARKalist", "__PAMARKjson_COMARKhash_MIMARKtable_MIMARK_GTMARKalist" ) end
173
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:55"] + __e.backtrace ) ; raise __e
174
+ end ,
175
+ [
176
+ trampCall( self._cdr_METHOD( 'cdr',
177
+ begin
178
+ if @global_lisp_binding.has_key?('_cdr') then
179
+ trampCall(@_cdr)
180
+ else raise NameError.new( "Error: undefined variable _cdr", "_cdr" ) end
181
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:55"] + __e.backtrace ) ; raise __e
182
+ end ,
183
+ [
184
+ begin
185
+ trampCall(_entry)
186
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:55"] + __e.backtrace ) ; raise __e
187
+ end
188
+ ]
189
+ ))
190
+ ]
191
+ ))
192
+ ]
193
+ ))
194
+ } ,
195
+ trampCall( self._hash_MIMARKtable_MIMARK_GTMARKalist_METHOD( 'hash-table->alist',
196
+ begin
197
+ if @global_lisp_binding.has_key?('_hash_MIMARKtable_MIMARK_GTMARKalist') then
198
+ trampCall(@_hash_MIMARKtable_MIMARK_GTMARKalist)
199
+ else raise NameError.new( "Error: undefined variable _hash_MIMARKtable_MIMARK_GTMARKalist", "_hash_MIMARKtable_MIMARK_GTMARKalist" ) end
200
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:56"] + __e.backtrace ) ; raise __e
201
+ end ,
202
+ [
203
+ begin
204
+ trampCall(_obj)
205
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:58"] + __e.backtrace ) ; raise __e
206
+ end
207
+ ]
208
+ ))
209
+ ]
210
+ )
211
+ end
212
+ else
213
+ if (
214
+ true
215
+ ) then
216
+ begin
217
+ begin
218
+ trampCall(_obj)
219
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:58"] + __e.backtrace ) ; raise __e
220
+ end
221
+ end
222
+ else
223
+ Cell.new()
224
+ end
225
+ end
226
+ end
227
+ end
228
+ }
229
+ )
230
+ end
231
+ )
232
+ #--------------------
233
+
234
+ trampCall(
235
+ begin
236
+ def self.__PAMARKjson_COMARKalist_MIMARK_GTMARKhash_MIMARKtable_METHOD( origname, pred, args ) lispMethodEntry( origname, true ) ; ret = callProcedure( origname, pred, args ) ; lispMethodExit( origname, true ) ; return ret end
237
+ @global_lisp_binding['__PAMARKjson_COMARKalist_MIMARK_GTMARKhash_MIMARKtable'] = self.method( :__PAMARKjson_COMARKalist_MIMARK_GTMARKhash_MIMARKtable_METHOD )
238
+ @__PAMARKjson_COMARKalist_MIMARK_GTMARKhash_MIMARKtable =
239
+ trampCall(
240
+ Proc.new { |_obj|
241
+ if (
242
+ trampCall( self._null_QUMARK_METHOD( 'null?',
243
+ begin
244
+ if @global_lisp_binding.has_key?('_null_QUMARK') then
245
+ trampCall(@_null_QUMARK)
246
+ else raise NameError.new( "Error: undefined variable _null_QUMARK", "_null_QUMARK" ) end
247
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:62"] + __e.backtrace ) ; raise __e
248
+ end ,
249
+ [
250
+ begin
251
+ trampCall(_obj)
252
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:78"] + __e.backtrace ) ; raise __e
253
+ end
254
+ ]
255
+ ))
256
+ ) then
257
+ begin
258
+ delayCall( '_make_MIMARKhash_MIMARKtable', 'make-hash-table',
259
+ begin
260
+ if @global_lisp_binding.has_key?('_make_MIMARKhash_MIMARKtable') then
261
+ trampCall(@_make_MIMARKhash_MIMARKtable)
262
+ else raise NameError.new( "Error: undefined variable _make_MIMARKhash_MIMARKtable", "_make_MIMARKhash_MIMARKtable" ) end
263
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:63"] + __e.backtrace ) ; raise __e
264
+ end ,
265
+ [
266
+ ]
267
+ )
268
+ end
269
+ else
270
+ if (
271
+ trampCall( self._vector_QUMARK_METHOD( 'vector?',
272
+ begin
273
+ if @global_lisp_binding.has_key?('_vector_QUMARK') then
274
+ trampCall(@_vector_QUMARK)
275
+ else raise NameError.new( "Error: undefined variable _vector_QUMARK", "_vector_QUMARK" ) end
276
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:64"] + __e.backtrace ) ; raise __e
277
+ end ,
278
+ [
279
+ begin
280
+ trampCall(_obj)
281
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:78"] + __e.backtrace ) ; raise __e
282
+ end
283
+ ]
284
+ ))
285
+ ) then
286
+ begin
287
+ delayCall( '_list_MIMARK_GTMARKvector', 'list->vector',
288
+ begin
289
+ if @global_lisp_binding.has_key?('_list_MIMARK_GTMARKvector') then
290
+ trampCall(@_list_MIMARK_GTMARKvector)
291
+ else raise NameError.new( "Error: undefined variable _list_MIMARK_GTMARKvector", "_list_MIMARK_GTMARKvector" ) end
292
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:65"] + __e.backtrace ) ; raise __e
293
+ end ,
294
+ [
295
+ trampCall( self._map_METHOD( 'map',
296
+ begin
297
+ if @global_lisp_binding.has_key?('_map') then
298
+ trampCall(@_map)
299
+ else raise NameError.new( "Error: undefined variable _map", "_map" ) end
300
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:72"] + __e.backtrace ) ; raise __e
301
+ end ,
302
+ [
303
+ Proc.new { |_x|
304
+ trampCall( self.__PAMARKjson_COMARKalist_MIMARK_GTMARKhash_MIMARKtable_METHOD( '%json:alist->hash-table',
305
+ begin
306
+ if @global_lisp_binding.has_key?('__PAMARKjson_COMARKalist_MIMARK_GTMARKhash_MIMARKtable') then
307
+ trampCall(@__PAMARKjson_COMARKalist_MIMARK_GTMARKhash_MIMARKtable)
308
+ else raise NameError.new( "Error: undefined variable __PAMARKjson_COMARKalist_MIMARK_GTMARKhash_MIMARKtable", "__PAMARKjson_COMARKalist_MIMARK_GTMARKhash_MIMARKtable" ) end
309
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:75"] + __e.backtrace ) ; raise __e
310
+ end ,
311
+ [
312
+ begin
313
+ trampCall(_x)
314
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:68"] + __e.backtrace ) ; raise __e
315
+ end
316
+ ]
317
+ ))
318
+ } ,
319
+ trampCall( self._vector_MIMARK_GTMARKlist_METHOD( 'vector->list',
320
+ begin
321
+ if @global_lisp_binding.has_key?('_vector_MIMARK_GTMARKlist') then
322
+ trampCall(@_vector_MIMARK_GTMARKlist)
323
+ else raise NameError.new( "Error: undefined variable _vector_MIMARK_GTMARKlist", "_vector_MIMARK_GTMARKlist" ) end
324
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:69"] + __e.backtrace ) ; raise __e
325
+ end ,
326
+ [
327
+ begin
328
+ trampCall(_obj)
329
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:78"] + __e.backtrace ) ; raise __e
330
+ end
331
+ ]
332
+ ))
333
+ ]
334
+ ))
335
+ ]
336
+ )
337
+ end
338
+ else
339
+ if (
340
+ trampCall( self._pair_QUMARK_METHOD( 'pair?',
341
+ begin
342
+ if @global_lisp_binding.has_key?('_pair_QUMARK') then
343
+ trampCall(@_pair_QUMARK)
344
+ else raise NameError.new( "Error: undefined variable _pair_QUMARK", "_pair_QUMARK" ) end
345
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:70"] + __e.backtrace ) ; raise __e
346
+ end ,
347
+ [
348
+ begin
349
+ trampCall(_obj)
350
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:78"] + __e.backtrace ) ; raise __e
351
+ end
352
+ ]
353
+ ))
354
+ ) then
355
+ begin
356
+ delayCall( '_alist_MIMARK_GTMARKhash_MIMARKtable', 'alist->hash-table',
357
+ begin
358
+ if @global_lisp_binding.has_key?('_alist_MIMARK_GTMARKhash_MIMARKtable') then
359
+ trampCall(@_alist_MIMARK_GTMARKhash_MIMARKtable)
360
+ else raise NameError.new( "Error: undefined variable _alist_MIMARK_GTMARKhash_MIMARKtable", "_alist_MIMARK_GTMARKhash_MIMARKtable" ) end
361
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:71"] + __e.backtrace ) ; raise __e
362
+ end ,
363
+ [
364
+ trampCall( self._map_METHOD( 'map',
365
+ begin
366
+ if @global_lisp_binding.has_key?('_map') then
367
+ trampCall(@_map)
368
+ else raise NameError.new( "Error: undefined variable _map", "_map" ) end
369
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:72"] + __e.backtrace ) ; raise __e
370
+ end ,
371
+ [
372
+ Proc.new { |_entry|
373
+ trampCall( self._cons_METHOD( 'cons',
374
+ begin
375
+ if @global_lisp_binding.has_key?('_cons') then
376
+ trampCall(@_cons)
377
+ else raise NameError.new( "Error: undefined variable _cons", "_cons" ) end
378
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:74"] + __e.backtrace ) ; raise __e
379
+ end ,
380
+ [
381
+ trampCall( self._car_METHOD( 'car',
382
+ begin
383
+ if @global_lisp_binding.has_key?('_car') then
384
+ trampCall(@_car)
385
+ else raise NameError.new( "Error: undefined variable _car", "_car" ) end
386
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:74"] + __e.backtrace ) ; raise __e
387
+ end ,
388
+ [
389
+ begin
390
+ trampCall(_entry)
391
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:75"] + __e.backtrace ) ; raise __e
392
+ end
393
+ ]
394
+ )) ,
395
+ trampCall( self.__PAMARKjson_COMARKalist_MIMARK_GTMARKhash_MIMARKtable_METHOD( '%json:alist->hash-table',
396
+ begin
397
+ if @global_lisp_binding.has_key?('__PAMARKjson_COMARKalist_MIMARK_GTMARKhash_MIMARKtable') then
398
+ trampCall(@__PAMARKjson_COMARKalist_MIMARK_GTMARKhash_MIMARKtable)
399
+ else raise NameError.new( "Error: undefined variable __PAMARKjson_COMARKalist_MIMARK_GTMARKhash_MIMARKtable", "__PAMARKjson_COMARKalist_MIMARK_GTMARKhash_MIMARKtable" ) end
400
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:75"] + __e.backtrace ) ; raise __e
401
+ end ,
402
+ [
403
+ trampCall( self._cdr_METHOD( 'cdr',
404
+ begin
405
+ if @global_lisp_binding.has_key?('_cdr') then
406
+ trampCall(@_cdr)
407
+ else raise NameError.new( "Error: undefined variable _cdr", "_cdr" ) end
408
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:75"] + __e.backtrace ) ; raise __e
409
+ end ,
410
+ [
411
+ begin
412
+ trampCall(_entry)
413
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:75"] + __e.backtrace ) ; raise __e
414
+ end
415
+ ]
416
+ ))
417
+ ]
418
+ ))
419
+ ]
420
+ ))
421
+ } ,
422
+ begin
423
+ trampCall(_obj)
424
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:78"] + __e.backtrace ) ; raise __e
425
+ end
426
+ ]
427
+ ))
428
+ ]
429
+ )
430
+ end
431
+ else
432
+ if (
433
+ true
434
+ ) then
435
+ begin
436
+ begin
437
+ trampCall(_obj)
438
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:78"] + __e.backtrace ) ; raise __e
439
+ end
440
+ end
441
+ else
442
+ Cell.new()
443
+ end
444
+ end
445
+ end
446
+ end
447
+ }
448
+ )
449
+ end
450
+ )
451
+ #--------------------
452
+
453
+ trampCall(
454
+ begin
455
+ def self._parse_MIMARKjson_MIMARKstring_METHOD( origname, pred, args ) lispMethodEntry( origname, true ) ; ret = callProcedure( origname, pred, args ) ; lispMethodExit( origname, true ) ; return ret end
456
+ @global_lisp_binding['_parse_MIMARKjson_MIMARKstring'] = self.method( :_parse_MIMARKjson_MIMARKstring_METHOD )
457
+ @_parse_MIMARKjson_MIMARKstring =
458
+ trampCall(
459
+ Proc.new { |_str|
460
+ delayCall( '__PAMARKjson_COMARKhash_MIMARKtable_MIMARK_GTMARKalist', '%json:hash-table->alist',
461
+ begin
462
+ if @global_lisp_binding.has_key?('__PAMARKjson_COMARKhash_MIMARKtable_MIMARK_GTMARKalist') then
463
+ trampCall(@__PAMARKjson_COMARKhash_MIMARKtable_MIMARK_GTMARKalist)
464
+ else raise NameError.new( "Error: undefined variable __PAMARKjson_COMARKhash_MIMARKtable_MIMARK_GTMARKalist", "__PAMARKjson_COMARKhash_MIMARKtable_MIMARK_GTMARKalist" ) end
465
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:85"] + __e.backtrace ) ; raise __e
466
+ end ,
467
+ [
468
+ begin
469
+ trampCall(JSON).parse(
470
+ begin
471
+ trampCall(_str)
472
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:86"] + __e.backtrace ) ; raise __e
473
+ end
474
+ )
475
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:86"] + __e.backtrace ) ; raise __e
476
+ end
477
+ ]
478
+ )
479
+ }
480
+ )
481
+ end
482
+ )
483
+ #--------------------
484
+
485
+ trampCall(
486
+ begin
487
+ def self._parse_MIMARKjson_METHOD( origname, pred, args ) lispMethodEntry( origname, true ) ; ret = callProcedure( origname, pred, args ) ; lispMethodExit( origname, true ) ; return ret end
488
+ @global_lisp_binding['_parse_MIMARKjson'] = self.method( :_parse_MIMARKjson_METHOD )
489
+ @_parse_MIMARKjson =
490
+ trampCall(
491
+ Proc.new { |*__rest__| _io = __rest__[0] ;
492
+ begin
493
+ ___lambda = lambda { |__|
494
+ begin
495
+ ___lambda = lambda { |_str|
496
+ delayCall( '_parse_MIMARKjson_MIMARKstring', 'parse-json-string',
497
+ begin
498
+ if @global_lisp_binding.has_key?('_parse_MIMARKjson_MIMARKstring') then
499
+ trampCall(@_parse_MIMARKjson_MIMARKstring)
500
+ else raise NameError.new( "Error: undefined variable _parse_MIMARKjson_MIMARKstring", "_parse_MIMARKjson_MIMARKstring" ) end
501
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:91"] + __e.backtrace ) ; raise __e
502
+ end ,
503
+ [
504
+ begin
505
+ trampCall(_str)
506
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:91"] + __e.backtrace ) ; raise __e
507
+ end
508
+ ]
509
+ )
510
+ } ; ___lambda.call(
511
+ begin
512
+ trampCall(__).read(
513
+ )
514
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:90"] + __e.backtrace ) ; raise __e
515
+ end
516
+ )
517
+ end
518
+ } ; ___lambda.call(
519
+ begin
520
+ ___lambda = lambda { |___gensym__6e1da08b054bbf0469585c6330e1b00b59b91d4c_20019|
521
+ if (
522
+ trampCall( self._null_QUMARK_METHOD( 'null?',
523
+ begin
524
+ if @global_lisp_binding.has_key?('_null_QUMARK') then
525
+ trampCall(@_null_QUMARK)
526
+ else raise NameError.new( "Error: undefined variable _null_QUMARK", "_null_QUMARK" ) end
527
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:62"] + __e.backtrace ) ; raise __e
528
+ end ,
529
+ [
530
+ begin
531
+ trampCall(___gensym__6e1da08b054bbf0469585c6330e1b00b59b91d4c_20019)
532
+ rescue => __e ; __e.set_backtrace( [":1"] + __e.backtrace ) ; raise __e
533
+ end
534
+ ]
535
+ ))
536
+ ) then
537
+ begin
538
+ trampCall(STDIN)
539
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:89"] + __e.backtrace ) ; raise __e
540
+ end
541
+ else
542
+ delayCall( '_car', 'car',
543
+ begin
544
+ if @global_lisp_binding.has_key?('_car') then
545
+ trampCall(@_car)
546
+ else raise NameError.new( "Error: undefined variable _car", "_car" ) end
547
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:74"] + __e.backtrace ) ; raise __e
548
+ end ,
549
+ [
550
+ begin
551
+ trampCall(___gensym__6e1da08b054bbf0469585c6330e1b00b59b91d4c_20019)
552
+ rescue => __e ; __e.set_backtrace( [":1"] + __e.backtrace ) ; raise __e
553
+ end
554
+ ]
555
+ )
556
+ end
557
+ } ; ___lambda.call(
558
+ begin
559
+ trampCall(_io)
560
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:89"] + __e.backtrace ) ; raise __e
561
+ end
562
+ )
563
+ end
564
+ )
565
+ end
566
+ }
567
+ )
568
+ end
569
+ )
570
+ #--------------------
571
+
572
+ trampCall(
573
+ begin
574
+ def self._construct_MIMARKjson_MIMARKstring_METHOD( origname, pred, args ) lispMethodEntry( origname, true ) ; ret = callProcedure( origname, pred, args ) ; lispMethodExit( origname, true ) ; return ret end
575
+ @global_lisp_binding['_construct_MIMARKjson_MIMARKstring'] = self.method( :_construct_MIMARKjson_MIMARKstring_METHOD )
576
+ @_construct_MIMARKjson_MIMARKstring =
577
+ trampCall(
578
+ Proc.new { |_obj|
579
+ begin
580
+ trampCall(JSON).dump(
581
+ trampCall( self.__PAMARKjson_COMARKalist_MIMARK_GTMARKhash_MIMARKtable_METHOD( '%json:alist->hash-table',
582
+ begin
583
+ if @global_lisp_binding.has_key?('__PAMARKjson_COMARKalist_MIMARK_GTMARKhash_MIMARKtable') then
584
+ trampCall(@__PAMARKjson_COMARKalist_MIMARK_GTMARKhash_MIMARKtable)
585
+ else raise NameError.new( "Error: undefined variable __PAMARKjson_COMARKalist_MIMARK_GTMARKhash_MIMARKtable", "__PAMARKjson_COMARKalist_MIMARK_GTMARKhash_MIMARKtable" ) end
586
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:98"] + __e.backtrace ) ; raise __e
587
+ end ,
588
+ [
589
+ begin
590
+ trampCall(_obj)
591
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:98"] + __e.backtrace ) ; raise __e
592
+ end
593
+ ]
594
+ ))
595
+ )
596
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:97"] + __e.backtrace ) ; raise __e
597
+ end
598
+ }
599
+ )
600
+ end
601
+ )
602
+ #--------------------
603
+
604
+ trampCall(
605
+ begin
606
+ def self._construct_MIMARKjson_METHOD( origname, pred, args ) lispMethodEntry( origname, true ) ; ret = callProcedure( origname, pred, args ) ; lispMethodExit( origname, true ) ; return ret end
607
+ @global_lisp_binding['_construct_MIMARKjson'] = self.method( :_construct_MIMARKjson_METHOD )
608
+ @_construct_MIMARKjson =
609
+ trampCall(
610
+ Proc.new { |_obj,*__rest__| _io = __rest__[0] ;
611
+ begin
612
+ ___lambda = lambda { |__|
613
+ begin
614
+ trampCall(__).print(
615
+ trampCall( self._construct_MIMARKjson_MIMARKstring_METHOD( 'construct-json-string',
616
+ begin
617
+ if @global_lisp_binding.has_key?('_construct_MIMARKjson_MIMARKstring') then
618
+ trampCall(@_construct_MIMARKjson_MIMARKstring)
619
+ else raise NameError.new( "Error: undefined variable _construct_MIMARKjson_MIMARKstring", "_construct_MIMARKjson_MIMARKstring" ) end
620
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:103"] + __e.backtrace ) ; raise __e
621
+ end ,
622
+ [
623
+ begin
624
+ trampCall(_obj)
625
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:103"] + __e.backtrace ) ; raise __e
626
+ end
627
+ ]
628
+ ))
629
+ )
630
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:102"] + __e.backtrace ) ; raise __e
631
+ end
632
+ } ; ___lambda.call(
633
+ begin
634
+ ___lambda = lambda { |___gensym__6e1da08b054bbf0469585c6330e1b00b59b91d4c_20020|
635
+ if (
636
+ trampCall( self._null_QUMARK_METHOD( 'null?',
637
+ begin
638
+ if @global_lisp_binding.has_key?('_null_QUMARK') then
639
+ trampCall(@_null_QUMARK)
640
+ else raise NameError.new( "Error: undefined variable _null_QUMARK", "_null_QUMARK" ) end
641
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:62"] + __e.backtrace ) ; raise __e
642
+ end ,
643
+ [
644
+ begin
645
+ trampCall(___gensym__6e1da08b054bbf0469585c6330e1b00b59b91d4c_20020)
646
+ rescue => __e ; __e.set_backtrace( [":1"] + __e.backtrace ) ; raise __e
647
+ end
648
+ ]
649
+ ))
650
+ ) then
651
+ begin
652
+ trampCall(STDOUT)
653
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:101"] + __e.backtrace ) ; raise __e
654
+ end
655
+ else
656
+ delayCall( '_car', 'car',
657
+ begin
658
+ if @global_lisp_binding.has_key?('_car') then
659
+ trampCall(@_car)
660
+ else raise NameError.new( "Error: undefined variable _car", "_car" ) end
661
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:74"] + __e.backtrace ) ; raise __e
662
+ end ,
663
+ [
664
+ begin
665
+ trampCall(___gensym__6e1da08b054bbf0469585c6330e1b00b59b91d4c_20020)
666
+ rescue => __e ; __e.set_backtrace( [":1"] + __e.backtrace ) ; raise __e
667
+ end
668
+ ]
669
+ )
670
+ end
671
+ } ; ___lambda.call(
672
+ begin
673
+ trampCall(_io)
674
+ rescue => __e ; __e.set_backtrace( ["./lib/rfc/json.nnd:101"] + __e.backtrace ) ; raise __e
675
+ end
676
+ )
677
+ end
678
+ )
679
+ end
680
+ }
681
+ )
682
+ end
683
+ )
684
+
685
+
686
+ # -------------------------------------------------------
687
+ # [EOF]
688
+ # -------------------------------------------------------
@@ -0,0 +1,178 @@
1
+ ;;-*- mode: nendo; syntax: scheme -*-
2
+ ;;;
3
+ ;;; json-test.nnd - test of json.nnd
4
+ ;;;
5
+ ;;; Copyright (c) 2011 Kiyoka Nishiyama <kiyoka@sumibi.org>
6
+ ;;;
7
+ ;;; Redistribution and use in source and binary forms, with or without
8
+ ;;; modification, are permitted provided that the following conditions
9
+ ;;; are met:
10
+ ;;;
11
+ ;;; 1. Redistributions of source code must retain the above copyright
12
+ ;;; notice, this list of conditions and the following disclaimer.
13
+ ;;;
14
+ ;;; 2. Redistributions in binary form must reproduce the above copyright
15
+ ;;; notice, this list of conditions and the following disclaimer in the
16
+ ;;; documentation and/or other materials provided with the distribution.
17
+ ;;;
18
+ ;;; 3. Neither the name of the authors nor the names of its contributors
19
+ ;;; may be used to endorse or promote products derived from this
20
+ ;;; software without specific prior written permission.
21
+ ;;;
22
+ ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
+ ;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
+ ;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25
+ ;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26
+ ;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27
+ ;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
28
+ ;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29
+ ;;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30
+ ;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31
+ ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32
+ ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
+ ;;;
34
+ ;;; $Id:
35
+ ;;;
36
+ (use nendo.test)
37
+ (use rfc.json)
38
+
39
+ (test-start "json")
40
+
41
+ ;;===================================================================
42
+
43
+ ;;-------------------------------------------------------------------
44
+ (test-section "json parser")
45
+
46
+ (test* "string (1)"
47
+ '#( "str" )
48
+ (parse-json-string "[\"str\"]"))
49
+
50
+ (test* "string (2)"
51
+ '#( "Ã" )
52
+ (parse-json-string "[\"Ã\"]"))
53
+
54
+ (test* "string (3)"
55
+ '#( "Ã" "€" )
56
+ (parse-json-string "[ \"\\u00c3\", \"\\u20ac\" ]"))
57
+
58
+ (test* "string (4)"
59
+ '#(nil)
60
+ (parse-json-string "[null]"))
61
+
62
+ (test* "string (4)"
63
+ '#(nil)
64
+ (parse-json-string "[null]"))
65
+
66
+ (test* "string (5)"
67
+ '#(#t)
68
+ (parse-json-string "[true]"))
69
+
70
+ (test* "string (6)"
71
+ '#(#f)
72
+ (parse-json-string "[false]"))
73
+
74
+
75
+ (test* "simple object (1)"
76
+ '()
77
+ (parse-json-string "{}"))
78
+ (test* "simple object (2)"
79
+ '()
80
+ (parse-json-string " { } "))
81
+ (test* "simple object (3)"
82
+ '(("a" . 23))
83
+ (parse-json-string "{ \"a\": 23 } "))
84
+ (test* "simple object (4)"
85
+ '(("a" . 23) ("b" . 45))
86
+ (parse-json-string "{ \"a\": 23 , \"b\": 45 } "))
87
+
88
+ (test* "arrays (1)"
89
+ '#(1 2 3)
90
+ (parse-json-string "[1,2,3]"))
91
+ (test* "arrays (2)"
92
+ '#(#() #(#() #()))
93
+ (parse-json-string "[[],[[],[]]]"))
94
+ (test* "arrays (3)"
95
+ '#(#(4)
96
+ #(#(5) #(6)))
97
+ (parse-json-string "[[4],[[5],[6]]]"))
98
+
99
+
100
+ (define testdata-json-string
101
+ (string-join
102
+ '("["
103
+ " { \"a\": 1, "
104
+ " \"b\": 2, "
105
+ " \"c\": { \"c1\": 10,"
106
+ " \"c2\": 20 },"
107
+ " \"d\": [ \"vec1\", \"vec2\", \"vec3\" ]"
108
+ " },"
109
+ " { \"true\" : true , "
110
+ " \"false\" : false , "
111
+ " \"null\" : null "
112
+ " }"
113
+ "]")))
114
+
115
+ (define testdata-lisp-object
116
+ '#(
117
+ (("a" . 1)
118
+ ("b" . 2)
119
+ ("c" . (
120
+ ("c1" . 10)
121
+ ("c2" . 20)))
122
+ ("d" . #("vec1" "vec2" "vec3")))
123
+ (("true" . true)
124
+ ("false" . false)
125
+ ("null" . nil))))
126
+
127
+
128
+ (test* "array and hash (1)"
129
+ (write-to-string testdata-lisp-object)
130
+ (write-to-string (parse-json-string testdata-json-string)))
131
+
132
+
133
+ (let1 sio (StringIO.new "{\"a\":23,\"b\":45}")
134
+ (test* "write to IO"
135
+ '(("a" . 23) ("b" . 45))
136
+ (parse-json sio)))
137
+
138
+
139
+
140
+ ;;-------------------------------------------------------------------
141
+ (test-section "json constructor")
142
+
143
+ (test* "string (1)"
144
+ "[\"str\"]"
145
+ (construct-json-string '#( "str" )))
146
+
147
+ (test* "arrays (1)"
148
+ "[1,2,3]"
149
+ (construct-json-string '#(1 2 3)))
150
+ (test* "arrays (2)"
151
+ "[[],[[],[]]]"
152
+ (construct-json-string '#(#() #(#() #()))))
153
+
154
+ (test* "simple object (1)"
155
+ "{}"
156
+ (construct-json-string '()))
157
+ (test* "simple object (2)"
158
+ "{\"a\":23}"
159
+ (construct-json-string '(("a" . 23))))
160
+ (test* "simple object (3)"
161
+ "{\"a\":23,\"b\":45}"
162
+ (construct-json-string '(("a" . 23) ("b" . 45))))
163
+
164
+ (test* "array and hash (1)"
165
+ (testdata-json-string.gsub #/[ ]/ "")
166
+ (construct-json-string testdata-lisp-object))
167
+
168
+ (let1 sio (StringIO.new)
169
+ (test* "write to IO"
170
+ "{\"a\":23,\"b\":45}"
171
+ (begin
172
+ (construct-json '(("a" . 23) ("b" . 45)) sio)
173
+ (sio.rewind)
174
+ (sio.read))))
175
+
176
+
177
+ ;;===================================================================
178
+ (test-end)
data/test/nendo_spec.rb CHANGED
@@ -998,17 +998,22 @@ describe Nendo, "when use regexp litteral and library functions " do
998
998
  @nendo.evalStr( " #/abc/ " ).should == "#/abc/"
999
999
  @nendo.evalStr( " #/[a-z]/ " ).should == "#/[a-z]/"
1000
1000
  @nendo.evalStr( " #/[a-zA-Z0-9]+/ " ).should == "#/[a-zA-Z0-9]+/"
1001
- @nendo.evalStr( " #/\\d/ " ).should == "#/\\d/"
1002
- @nendo.evalStr( " #/[\\/]/ " ).should == "#/[/]/"
1001
+ @nendo.evalStr( ' #/\d/ ' ).should == '#/\d/'
1002
+ @nendo.evalStr( ' #/[\/]/ ' ).should == '#/[\/]/'
1003
+ @nendo.evalStr( ' #/\]/ ' ).should == '#/\]/'
1004
+ @nendo.evalStr( ' #/^\]/ ' ).should == '#/^\]/'
1005
+ @nendo.evalStr( ' #/\[/ ' ).should == '#/\[/'
1006
+ @nendo.evalStr( ' #/^\[/ ' ).should == '#/^\[/'
1007
+ @nendo.evalStr( ' #/\.\^\$\/\+\-\(\)\|/ ' ).should == '#/\.\^\$\/\+\-\(\)\|/'
1003
1008
  @nendo.evalStr( " #/abc/i " ).should == "#/abc/i"
1004
1009
  @nendo.evalStr( " #/[a-z]/i " ).should == "#/[a-z]/i"
1005
1010
  lambda { @nendo.evalStr( " #/[a-z]/I " ) }.should raise_error(NameError)
1006
1011
  lambda { @nendo.evalStr( " #/[a-z]/a " ) }.should raise_error(NameError)
1007
1012
 
1008
- @nendo.evalStr( " (string->regexp \"abc\") " ).should == "#/abc/"
1009
- @nendo.evalStr( " (string->regexp \"[a-z]\") " ).should == "#/[a-z]/"
1010
- @nendo.evalStr( " (string->regexp \"[a-zA-Z0-9]+\" ) " ).should == "#/[a-zA-Z0-9]+/"
1011
- @nendo.evalStr( " (string->regexp \"\\\\d\" ) " ).should == "#/\\d/"
1013
+ @nendo.evalStr( ' (string->regexp "abc") ' ).should == '#/abc/'
1014
+ @nendo.evalStr( ' (string->regexp "[a-z]") ' ).should == '#/[a-z]/'
1015
+ @nendo.evalStr( ' (string->regexp "[a-zA-Z0-9]+" ) ' ).should == '#/[a-zA-Z0-9]+/'
1016
+ @nendo.evalStr( ' (string->regexp "\\\\d" ) ' ).should == '#/\d/'
1012
1017
  @nendo.evalStr( " (regexp? #/str/ ) " ).should == "#t"
1013
1018
  @nendo.evalStr( " (regexp? #/str/i ) " ).should == "#t"
1014
1019
  @nendo.evalStr( " (regexp? \"str\" ) " ).should == "#f"
@@ -1705,6 +1710,12 @@ describe Nendo, "when use hash-table feature " do
1705
1710
  @nendo.evalStr( " (hash-table-push! h 'a :AAA_2) (hash-table->alist h)" ).should == "((a :AAA_2 :AAA_1))"
1706
1711
  @nendo.evalStr( " (hash-table-push! h 'b :BBB_1) (hash-table->alist h)" ).should == "((a :AAA_2 :AAA_1) (b :BBB_1))"
1707
1712
  @nendo.evalStr( " (hash-table-push! h 'b :BBB_2) (hash-table->alist h)" ).should == "((a :AAA_2 :AAA_1) (b :BBB_2 :BBB_1))"
1713
+ @nendo.evalStr( " (set! h (hash-table '(true . 1) '(false . 2) '(nil . 3))) h" ).should == "{true=>1, false=>2, nil=>3}"
1714
+ @nendo.evalStr( " (hash-table->alist h) " ).should == "((#t . 1) (#f . 2) (nil . 3))"
1715
+ @nendo.evalStr( " (hash-table-keys h) " ).should == "(#t #f nil)"
1716
+ @nendo.evalStr( " (set! h (hash-table '(1 . true) '(2 . false) '(3 . nil))) h" ).should == "{1=>true, 2=>false, 3=>nil}"
1717
+ @nendo.evalStr( " (hash-table->alist h) " ).should == "((1 . #t) (2 . #f) (3 . nil))"
1718
+ @nendo.evalStr( " (hash-table-keys h) " ).should == "(1 2 3)"
1708
1719
  end
1709
1720
  end
1710
1721
 
File without changes
@@ -32,7 +32,7 @@
32
32
  var))
33
33
 
34
34
  (test* "disasm info"
35
- " file: ./test/nendo_util.nnd
35
+ " file: ./test/util-test.nnd
36
36
  lineno: 30
37
37
  source:
38
38
  (define
@@ -69,7 +69,7 @@ trampCall(
69
69
  ___lambda = lambda { |_var|
70
70
  begin
71
71
  trampCall(_var)
72
- rescue => __e ; __e.set_backtrace( [\"./test/nendo_util.nnd:32\"] + __e.backtrace ) ; raise __e
72
+ rescue => __e ; __e.set_backtrace( [\"./test/util-test.nnd:32\"] + __e.backtrace ) ; raise __e
73
73
  end
74
74
  } ; ___lambda.call(
75
75
  trampCall( self.__PLMARK_METHOD( '+',
@@ -77,12 +77,12 @@ trampCall(
77
77
  if @global_lisp_binding.has_key?('__PLMARK') then
78
78
  trampCall(@__PLMARK)
79
79
  else raise NameError.new( \"Error: undefined variable __PLMARK\", \"__PLMARK\" ) end
80
- rescue => __e ; __e.set_backtrace( [\"./test/nendo_util.nnd:31\"] + __e.backtrace ) ; raise __e
80
+ rescue => __e ; __e.set_backtrace( [\"./test/util-test.nnd:31\"] + __e.backtrace ) ; raise __e
81
81
  end ,
82
82
  [
83
83
  begin
84
84
  trampCall(_arg1)
85
- rescue => __e ; __e.set_backtrace( [\"./test/nendo_util.nnd:31\"] + __e.backtrace ) ; raise __e
85
+ rescue => __e ; __e.set_backtrace( [\"./test/util-test.nnd:31\"] + __e.backtrace ) ; raise __e
86
86
  end ,
87
87
  1
88
88
  ]
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nendo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 4
9
- - 0
10
- version: 0.4.0
8
+ - 1
9
+ version: 0.4.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Kiyoka Nishiyama
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-11-12 00:00:00 +09:00
17
+ date: 2011-01-27 00:00:00 +09:00
19
18
  default_executable: nendo
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
31
29
  - 0
32
30
  version: "0"
@@ -71,24 +69,27 @@ files:
71
69
  - lib/nendo.rb
72
70
  - lib/nendo/test.nnd
73
71
  - lib/nendo/test.nndc
72
+ - lib/rfc/json.nnd
73
+ - lib/rfc/json.nndc
74
74
  - lib/srfi-1.nnd
75
75
  - lib/srfi-1.nndc
76
76
  - lib/text/html-lite.nnd
77
77
  - lib/text/html-lite.nndc
78
78
  - lib/text/tree.nnd
79
79
  - lib/text/tree.nndc
80
+ - test/json-test.nnd
80
81
  - test/nendo_spec.rb
81
- - test/nendo_util.nnd
82
82
  - test/srfi-1-test.nnd
83
- - test/textlib.nnd
83
+ - test/textlib-test.nnd
84
+ - test/util-test.nnd
84
85
  - README
85
86
  has_rdoc: true
86
87
  homepage: http://github.com/kiyoka/nendo
87
88
  licenses: []
88
89
 
89
90
  post_install_message:
90
- rdoc_options:
91
- - --charset=UTF-8
91
+ rdoc_options: []
92
+
92
93
  require_paths:
93
94
  - lib
94
95
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -96,7 +97,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
97
  requirements:
97
98
  - - ">="
98
99
  - !ruby/object:Gem::Version
99
- hash: 3
100
100
  segments:
101
101
  - 0
102
102
  version: "0"
@@ -105,7 +105,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - ">="
107
107
  - !ruby/object:Gem::Version
108
- hash: 3
109
108
  segments:
110
109
  - 0
111
110
  version: "0"