fabulator 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/History.txt +30 -1
  2. data/VERSION +1 -1
  3. data/features/functions.feature +7 -0
  4. data/features/primitives.feature +1 -1
  5. data/features/step_definitions/template_steps.rb +40 -3
  6. data/features/step_definitions/xml_steps.rb +3 -2
  7. data/features/templates.feature +49 -22
  8. data/features/types.feature +4 -4
  9. data/lib/fabulator.rb +4 -0
  10. data/lib/fabulator/compiler.rb +27 -0
  11. data/lib/fabulator/core.rb +3 -8
  12. data/lib/fabulator/core/actions/choose.rb +0 -18
  13. data/lib/fabulator/core/actions/for_each.rb +0 -48
  14. data/lib/fabulator/core/{actions.rb → lib.rb} +189 -117
  15. data/lib/fabulator/core/structurals.rb +7 -0
  16. data/lib/fabulator/core/{constraint.rb → structurals/constraint.rb} +2 -0
  17. data/lib/fabulator/core/{filter.rb → structurals/filter.rb} +2 -0
  18. data/lib/fabulator/core/{group.rb → structurals/group.rb} +2 -0
  19. data/lib/fabulator/core/{parameter.rb → structurals/parameter.rb} +2 -0
  20. data/lib/fabulator/core/{state.rb → structurals/state.rb} +2 -0
  21. data/lib/fabulator/core/{state_machine.rb → structurals/state_machine.rb} +2 -0
  22. data/lib/fabulator/core/{transition.rb → structurals/transition.rb} +2 -0
  23. data/lib/fabulator/expr.rb +6 -0
  24. data/lib/fabulator/expr/context.rb +65 -10
  25. data/lib/fabulator/expr/node_logic.rb +3 -2
  26. data/lib/fabulator/expr/parser.rb +787 -638
  27. data/lib/fabulator/expr/statement_list.rb +27 -0
  28. data/lib/fabulator/lib.rb +3 -0
  29. data/lib/fabulator/lib/action.rb +12 -9
  30. data/lib/fabulator/lib/lib.rb +85 -9
  31. data/lib/fabulator/structural.rb +24 -5
  32. data/lib/fabulator/tag_lib.rb +78 -124
  33. data/lib/fabulator/tag_lib/presentations.rb +39 -0
  34. data/lib/fabulator/tag_lib/transformations.rb +66 -0
  35. data/lib/fabulator/tag_lib/type.rb +176 -0
  36. data/lib/fabulator/template/parse_result.rb +125 -62
  37. data/lib/fabulator/template/parser.rb +17 -1
  38. data/xslt/form.xsl +163 -2083
  39. data/xsm_expression_parser.racc +35 -20
  40. metadata +17 -13
  41. data/lib/fabulator/context.rb +0 -39
@@ -16,6 +16,7 @@ rule
16
16
  statement:
17
17
  | expr
18
18
  | let_expr
19
+ | ns_expr { result = nil }
19
20
 
20
21
  expr: or_expr
21
22
  | range_expr
@@ -23,6 +24,9 @@ rule
23
24
  | for_expr
24
25
  | quant_expr
25
26
  | with_expr
27
+ | err_expr
28
+
29
+ err_expr: expr ERR expr { result = Fabulator::Expr::ErrExpr.new(val[0], val[2]) }
26
30
 
27
31
  with_expr: expr WITH expr_set_list { result = Fabulator::Expr::WithExpr.new(val[0], val[2]) }
28
32
 
@@ -41,6 +45,10 @@ rule
41
45
 
42
46
  let_expr: LET DOLLAR_QNAME COLON_EQUAL expr { result = Fabulator::Expr::LetExpr.new(val[1], val[3]) }
43
47
 
48
+ ns_expr: LET XMLNS_COLON_NCNAME COLON_EQUAL LITERAL {
49
+ @context.set_ns(val[1].gsub(/^xmlns:/, ''), val[3])
50
+ }
51
+
44
52
  if_expr: IF LP expr RP THEN expr ELSE expr { result = Fabulator::Expr::IfExpr.new(val[2], val[5], val[7]) }
45
53
  | IF LP expr RP THEN expr { result = Fabulator::Expr::IfExpr.new(val[2], val[5], nil) }
46
54
 
@@ -65,7 +73,7 @@ rule
65
73
  | additive_expr EQ additive_expr { result = Fabulator::Expr::EqExpr.new(val[0], val[2]) }
66
74
  | additive_expr NEQ additive_expr { result = Fabulator::Expr::NeqExpr.new(val[0], val[2]) }
67
75
 
68
- tuple: LP LB args RB RP { result = Fabulator::Expr::Tuple.new(val[2]) }
76
+ tuple: LB args RB { result = Fabulator::Expr::Tuple.new(val[1]) }
69
77
 
70
78
  # | LT args GT { result = Fabulator::Expr::Tuple.new(val[1]) }
71
79
 
@@ -217,7 +225,7 @@ end
217
225
  def parse(text, context)
218
226
  @source = text
219
227
  @curpos = 0
220
- @context = context
228
+ @context = context.merge
221
229
  @line = 0
222
230
  @col = 0
223
231
 
@@ -248,6 +256,7 @@ end
248
256
  @@regex[:axis] = %r{(#{@@regex[:ncname]})\s*(?=::)}
249
257
  @@regex[:name_colon_star] = %r{(#{@@regex[:ncname]}:\*)}
250
258
  @@regex[:qname] = %r{((?:#{@@regex[:ncname]}:)?#{@@regex[:ncname]})}
259
+ @@regex[:xmlns] = %r{((?:xmlns:)#{@@regex[:ncname]})}
251
260
  @@regex[:dollar_qname] = %r{\$#{@@regex[:qname]}}
252
261
  @@regex[:dollar_int] = %r{\$([0-9]+)}
253
262
  @@regex[:function_name] = %r{#{@@regex[:qname]}\??\*?\s*(?=\([^:])}
@@ -290,7 +299,7 @@ end
290
299
  == & && ||
291
300
  }.split(/\s*/), '[', ',', '$' ].each { |t| @@preceding_tokens[t] = true }
292
301
 
293
- @@regex[:general] = Regexp.compile(%{^(?:#{@@regex[:function_name]}|#{@@regex[:axis]}|#{@@regex[:name_colon_star]}|#{@@regex[:qname]}|#{@@regex[:literal]}|#{@@regex[:number]}|#{@@regex[:dollar_qname]}|#{@@regex[:dollar_int]}|(#{@@regex[:simple_tokens]}))})
302
+ @@regex[:general] = Regexp.compile(%{^(?:#{@@regex[:xmlns]}|#{@@regex[:function_name]}|#{@@regex[:axis]}|#{@@regex[:name_colon_star]}|#{@@regex[:qname]}|#{@@regex[:literal]}|#{@@regex[:number]}|#{@@regex[:dollar_qname]}|#{@@regex[:dollar_int]}|(#{@@regex[:simple_tokens]}))})
294
303
 
295
304
  def next_token
296
305
  @token = nil
@@ -393,6 +402,8 @@ end
393
402
  @token = [ :MOD, 'mod' ]
394
403
  when 'div':
395
404
  @token = [ :DIV, 'div' ]
405
+ when 'err':
406
+ @token = [ :ERR, 'err' ]
396
407
  #when '*doh*':
397
408
  # # do nothing
398
409
  # @token = nil
@@ -420,21 +431,23 @@ end
420
431
  raise "Failed to parse '#{@source}' at #{@curpos}': #{@source[@curpos..@source.length-1]}"
421
432
  else
422
433
  if !res[1].nil?
423
- if res[1] == 'if'
434
+ @token = [ :XMLNS_COLON_NCNAME, res[1] ]
435
+ elsif !res[2].nil?
436
+ if res[2] == 'if'
424
437
  @token = [ :IF, 'if' ]
425
438
  else
426
- if @source[@curpos+res[1].length .. @curpos+res[1].length + 1] =~ /^(\??\*?)/
427
- @token = [ :FUNCTION_NAME, res[1]+$1 ]
439
+ if @source[@curpos+res[2].length .. @curpos+res[2].length + 1] =~ /^(\??\*?)/
440
+ @token = [ :FUNCTION_NAME, res[2]+$1 ]
428
441
  else
429
- @token = [ :FUNCTION_NAME, res[1] ]
442
+ @token = [ :FUNCTION_NAME, res[2] ]
430
443
  end
431
444
  end
432
- elsif !res[2].nil?
433
- @token = [ res[2] == 'method' ? :AXIS_METHOD : :AXIS_NAME, res[2] ]
434
445
  elsif !res[3].nil?
435
- @token = [ :NAME_COLON_STAR, res[3] ]
446
+ @token = [ res[3] == 'method' ? :AXIS_METHOD : :AXIS_NAME, res[3] ]
436
447
  elsif !res[4].nil?
437
- qname = res[4]
448
+ @token = [ :NAME_COLON_STAR, res[4] ]
449
+ elsif !res[5].nil?
450
+ qname = res[5]
438
451
  case qname
439
452
  when 'for':
440
453
  @token = [ :FOR, 'for' ]
@@ -460,11 +473,13 @@ end
460
473
  @token = [ :ELSE, 'else' ]
461
474
  when 'with':
462
475
  @token = [ :WITH, 'with' ]
476
+ when 'err':
477
+ @token = [ :ERR, 'err' ]
463
478
  else
464
- @token = [ :QNAME, res[4] ]
479
+ @token = [ :QNAME, qname ]
465
480
  end
466
- elsif !res[5].nil?
467
- s = res[5]
481
+ elsif !res[6].nil?
482
+ s = res[6]
468
483
  s = s[1..s.length-2]
469
484
  @curpos = @curpos + s.length
470
485
  @col = @col + s.length
@@ -474,18 +489,18 @@ end
474
489
  @token = [ :LITERAL, s ]
475
490
  @curpos = @curpos + 2 # the quotes
476
491
  @col = @col + 2
477
- elsif !res[6].nil?
478
- @token = [ :NUMBER, res[6] ]
479
492
  elsif !res[7].nil?
480
- @curpos = @curpos + 1
481
- @col = @col + 1
482
- @token = [ :DOLLAR_QNAME, res[7] ]
493
+ @token = [ :NUMBER, res[7] ]
483
494
  elsif !res[8].nil?
484
495
  @curpos = @curpos + 1
485
496
  @col = @col + 1
486
497
  @token = [ :DOLLAR_QNAME, res[8] ]
487
498
  elsif !res[9].nil?
488
- @token = [ @@ops[res[9]] || res[9], res[9] ]
499
+ @curpos = @curpos + 1
500
+ @col = @col + 1
501
+ @token = [ :DOLLAR_QNAME, res[9] ]
502
+ elsif !res[10].nil?
503
+ @token = [ @@ops[res[10]] || res[10], res[10] ]
489
504
  else
490
505
  raise "Failed to parse '#{@source}' at #{@curpos}: #{@source[@curpos..@source.length-1]}"
491
506
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fabulator
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 8
10
- version: 0.0.8
9
+ - 9
10
+ version: 0.0.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Smith
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-11 00:00:00 +00:00
18
+ date: 2010-10-26 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -130,19 +130,20 @@ files:
130
130
  - init.rb
131
131
  - lib/fabulator.rb
132
132
  - lib/fabulator/action.rb
133
- - lib/fabulator/context.rb
133
+ - lib/fabulator/compiler.rb
134
134
  - lib/fabulator/core.rb
135
- - lib/fabulator/core/actions.rb
136
135
  - lib/fabulator/core/actions/choose.rb
137
136
  - lib/fabulator/core/actions/for_each.rb
138
137
  - lib/fabulator/core/actions/variables.rb
139
- - lib/fabulator/core/constraint.rb
140
- - lib/fabulator/core/filter.rb
141
- - lib/fabulator/core/group.rb
142
- - lib/fabulator/core/parameter.rb
143
- - lib/fabulator/core/state.rb
144
- - lib/fabulator/core/state_machine.rb
145
- - lib/fabulator/core/transition.rb
138
+ - lib/fabulator/core/lib.rb
139
+ - lib/fabulator/core/structurals.rb
140
+ - lib/fabulator/core/structurals/constraint.rb
141
+ - lib/fabulator/core/structurals/filter.rb
142
+ - lib/fabulator/core/structurals/group.rb
143
+ - lib/fabulator/core/structurals/parameter.rb
144
+ - lib/fabulator/core/structurals/state.rb
145
+ - lib/fabulator/core/structurals/state_machine.rb
146
+ - lib/fabulator/core/structurals/transition.rb
146
147
  - lib/fabulator/expr.rb
147
148
  - lib/fabulator/expr/axis.rb
148
149
  - lib/fabulator/expr/axis_descendent_or_self.rb
@@ -171,6 +172,9 @@ files:
171
172
  - lib/fabulator/lib/structural.rb
172
173
  - lib/fabulator/structural.rb
173
174
  - lib/fabulator/tag_lib.rb
175
+ - lib/fabulator/tag_lib/presentations.rb
176
+ - lib/fabulator/tag_lib/transformations.rb
177
+ - lib/fabulator/tag_lib/type.rb
174
178
  - lib/fabulator/template.rb
175
179
  - lib/fabulator/template/context.rb
176
180
  - lib/fabulator/template/parse_result.rb
@@ -1,39 +0,0 @@
1
- module Fabulator
2
- class Context
3
- attr_accessor :data, :state
4
-
5
- def initialize
6
- @state = 'start'
7
- @data = nil
8
- end
9
-
10
- def empty?
11
- @state = 'start' if @state.nil?
12
- (@data.nil? || @data.empty?) && @state == 'start'
13
- end
14
-
15
- def merge!(d, path=nil)
16
- return if @data.nil?
17
- return @data.merge_data(d,path)
18
- end
19
-
20
- def clear(path = nil)
21
- return if @data.nil?
22
- return @data.clear(path)
23
- end
24
-
25
- def context
26
- { :state => @state, :data => @data }
27
- end
28
-
29
- def context=(c)
30
- @state = c[:state]
31
- @data = c[:data]
32
- end
33
-
34
- def get(p = nil)
35
- return if @data.nil?
36
- return @data.get(p)
37
- end
38
- end
39
- end