/
parse.cr
1115 lines (1043 loc) · 28.2 KB
/
parse.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module XPath2
# An XPath expression token type
enum TokenType
Comma = 0 # ','
Slash # '/'
At # '@'
Dot # '.'
LParens # '('
RParens # ')'
LBracket # '['
RBracket # ']'
Star # '*'
Plus # '+'
Minus # '-'
Eq # '='
Lt # '<'
Gt # '>'
Bang # '!'
Dollar # '$'
Apos # '\''
Quote # '"'
Union # '|'
Ne # '!='
Le # '<='
Ge # '>='
And # '&&'
Or # '||'
DotDot # '..'
SlashSlash # '//'
Name # XML Name
String # Quoted string constant
Number # Number constant
Axe # Axe (like child::)
Eof # END
end
# A Node is an XPath node in the parser tree
private module Node
abstract def type : ParserNodeType
end
private abstract class BaseNodeType
include Node
@node_type : ParserNodeType
def initialize(@node_type)
end
def type : ParserNodeType
@node_type
end
end
enum ParserNodeType
Root = 0
Axis
Filter
Function
Operator
Variable
ConstantOperand
end
# RootNode holds a top-level node of tree
private class RootNode < BaseNodeType
@slash : String
def initialize(@slash)
super(ParserNodeType::Root)
end
def to_s
@slash
end
end
# OperatorNode holds two Nodes operator
private class OperatorNode < BaseNodeType
getter op : String
getter left : Node?
getter right : Node?
def initialize(@op, @left, @right)
super(ParserNodeType::Operator)
end
def to_s(io : IO) : Nil
io << "#{@left}#{@op}#{@right}"
end
end
# AxixNode holds a location step.
private class AxisNode < BaseNodeType
getter input : Node?
getter prop : String # node-test name. [comment|text|processing-instruction|node]
getter axe_type : String # name of the axes.[attribute|ancestor|child|...]
getter local_name : String # local part name of the node
getter prefix : String # prefix name of node
def initialize(@axe_type, @local_name, @prefix, @prop, @input)
super(ParserNodeType::Axis)
end
def to_s(io : IO) : Nil
io << "#{@axe_type}::" unless @axe_type.empty?
io << "#{@prefix}:" unless @prefix.empty?
io << "#{local_name}" unless local_name.empty?
io << "/#{@prop}()" unless @prop.empty?
end
end
# OperandNode holds a constant operand
private class OperandNode < BaseNodeType
getter val : ExprResult
def initialize(@val)
super(ParserNodeType::ConstantOperand)
end
def to_s(io : IO) : Nil
io << @val.to_s
end
end
# FilterNode holds a condition filter
private class FilterNode < BaseNodeType
getter input : Node?
getter condition : Node?
def initialize(@input, @condition)
super(ParserNodeType::Filter)
end
def to_s(io : IO) : Nil
io << "#{@input}[#{@condition}]"
end
end
# VariableNode holds a condition filter
private class VariableNode < BaseNodeType
getter name : String
getter prefix : String
def initialize(@name, @prefix)
super(ParserNodeType::Variable)
end
def to_s(io : IO) : Nil
if prefix.empty?
io << name
return
end
io << "#{@prefix}:#{@name}"
end
end
# FunctionNode holds a function call.
private class FunctionNode < BaseNodeType
getter args : Array(Node)
getter prefix : String
getter funcname : String
def initialize(@args, @prefix, @funcname)
super(ParserNodeType::Function)
end
def to_s(io : IO) : Nil
io << to_s
end
def to_s
String.build do |sb|
sb << @funcname
sb << "("
@args.each_with_index do |a, i|
sb << "," if i > 0
sb << a.to_s
end
sb << ")"
end
end
end
private class Parser
@r : Scanner
@d : Int32
def initialize(@r, @d)
end
# parse the XPath expression string expr and returns a tree node
def self.parse(expr : String)
r = Scanner.new(text: expr)
r.next_char
r.next_item
p = Parser.new(r: r, d: 0)
p.parse_expression(nil)
end
# parse the expression with input node n
protected def parse_expression(n : Node?)
@d += 1
raise XPath2Exception.new("XPath query is too complex (depth > 200)") if @d > 200
n = parse_or_expr(n)
@d -= 1
n
end
# scan next item moving forward
private def next
@r.next_item
end
private def check(typ : TokenType)
raise XPath2Exception.new("#{@r.text} has an invalid token") unless @r.type == typ
end
private def testop(op : String)
@r.type == TokenType::Name && @r.prefix.empty? && @r.name == op
end
private def primary_expr?
case @r.type
when .string?, .number?, .dollar?, .l_parens?
true
when .name?
@r.can_be_func && !node_type?
else
false
end
end
private def node_type?
case @r.name
when "node", "text", "processing-instruction", "comment"
@r.prefix.empty?
else
false
end
end
private def step?(typ : TokenType)
case typ
when .dot?, .dot_dot?, .at?, .axe?, .star?, .name?
true
else
false
end
end
private def skip(typ : TokenType)
check(typ)
self.next
end
# OrExpr ::= AndExpr | OrExpr 'or' AndExpr
private def parse_or_expr(n : Node?)
opnd = parse_and_expr(n)
loop do
break unless testop("or")
self.next
opnd = OperatorNode.new("or", opnd, parse_and_expr(n))
end
opnd
end
# AndExpr ::= EqualityExpr | AndExpr 'and' EqualityExpr
private def parse_and_expr(n : Node?)
opnd = parse_equality_expr(n)
loop do
break unless testop("and")
self.next
opnd = OperatorNode.new("and", opnd, parse_equality_expr(n))
end
opnd
end
# EqualityExpr ::= RelationalExpr | EqualityExpr '=' RelationalExpr | EqualityExpr !=' RelationalExpr
private def parse_equality_expr(n : Node?)
opnd = parse_relational_expr(n)
loop do
case @r.type
when .eq?
op = "="
when .ne?
op = "!="
else
return opnd
end
self.next
opnd = OperatorNode.new(op, opnd, parse_relational_expr(n))
end
opnd
end
# RelationalExpr ::= AdditiveExpr | RelationalExpr '<' AdditiveExpr | RelationalExpr '>' AdditiveExpr
# | RelationalExpr '<=' AdditiveExpr
# | RelationalExpr '>=' AdditiveExpr
private def parse_relational_expr(n : Node?)
opnd = parse_additive_expr(n)
loop do
case @r.type
when .lt?
op = "<"
when .gt?
op = ">"
when .le?
op = "<="
when .ge?
op = ">="
else
return opnd
end
self.next
opnd = OperatorNode.new(op, opnd, parse_additive_expr(n))
end
opnd
end
# AdditiveExpr ::= MultiplicativeExpr | AdditiveExpr '+' MultiplicativeExpr | AdditiveExpr '-' MultiplicativeExpr
private def parse_additive_expr(n : Node?)
opnd = parse_multiplicative_expr(n)
loop do
case @r.type
when .plus?
op = "+"
when .minus?
op = "-"
else
return opnd
end
self.next
opnd = OperatorNode.new(op, opnd, parse_multiplicative_expr(n))
end
opnd
end
# MultiplicativeExpr ::= UnaryExpr | MultiplicativeExpr MultiplyOperator(*) UnaryExpr
# | MultiplicativeExpr 'div' UnaryExpr | MultiplicativeExpr 'mod' UnaryExpr
private def parse_multiplicative_expr(n : Node?)
opnd = parse_unary_expr(n)
loop do
if @r.type == TokenType::Star
op = "*"
elsif testop("div") || testop("mod")
op = @r.name
else
return opnd
end
self.next
opnd = OperatorNode.new(op, opnd, parse_unary_expr(n))
end
opnd
end
# UnaryExpr ::= UnionExpr | '-' UnaryExpr
private def parse_unary_expr(n : Node?)
minus = false
# ignore '-' sequence
while @r.type == TokenType::Minus
self.next
minus = !minus
end
opnd = parse_union_expr(n)
opnd = OperatorNode.new("*", opnd, OperandNode.new(-1_f64)) if minus
opnd
end
# UnionExpr ::= PathExpr | UnionExpr '|' PathExpr
private def parse_union_expr(n : Node?)
opnd = parse_path_expr(n)
loop do
break unless @r.type == TokenType::Union
self.next
opnd2 = parse_path_expr(n)
# Checking the node type that must be is node set type?
opnd = OperatorNode.new("|", opnd, opnd2)
end
opnd
end
# PathExpr ::= LocationPath | FilterExpr | FilterExpr '/' RelativeLocationPath | FilterExpr '//' RelativeLocationPath
private def parse_path_expr(n : Node?)
if primary_expr?
opnd = parse_filter_expr(n)
case @r.type
when .slash?
self.next
opnd = parse_relative_location_path(opnd)
when .slash_slash?
self.next
opnd = parse_relative_location_path(AxisNode.new("descendant-or-self", "", "", "", opnd))
else
#
end
else
opnd = parse_location_path(nil)
end
opnd
end
# FilterExpr ::= PrimaryExpr | FilterExpr Predicate
private def parse_filter_expr(n : Node?)
opnd = parse_primary_expr(n)
return FilterNode.new(opnd, parse_predicate(opnd)) if @r.type == TokenType::LBracket
opnd
end
# Predicate ::= '[' PredicateExpr ']'
private def parse_predicate(n : Node)
skip(TokenType::LBracket)
opnd = parse_expression(n)
skip(TokenType::RBracket)
opnd
end
# LocationPath ::= RelativeLocationPath | AbsoluteLocationPath
private def parse_location_path(n : Node?)
case @r.type
when .slash?
self.next
opnd = RootNode.new("/")
opnd = parse_relative_location_path(opnd) if step?(@r.type)
when .slash_slash?
self.next
opnd = RootNode.new("//")
opnd = parse_relative_location_path(AxisNode.new("descendant-or-self", "", "", "", opnd))
else
opnd = parse_relative_location_path(n)
end
opnd
end
# RelativeLocationPath ::= Step | RelativeLocationPath '/' Step | AbbreviatedRelativeLocationPath
private def parse_relative_location_path(n : Node?)
opnd = n
loop do
opnd = parse_step(opnd)
case @r.type
when .slash_slash?
self.next
opnd = AxisNode.new("descendant-or-self", "", "", "", opnd)
when .slash?
self.next
else
break
end
end
opnd
end
# Step ::= AxisSpecifier NodeTest Predicate* | AbbreviatedStep
private def parse_step(n : Node?)
axe_type = "child" # default axes value
if @r.type == TokenType::Dot || @r.type == TokenType::DotDot
axe_type = @r.type == TokenType::Dot ? "self" : "parent"
self.next
opnd = AxisNode.new(axe_type: axe_type, local_name: "", prefix: "", prop: "", input: n)
return opnd unless @r.type == TokenType::LBracket
else
case @r.type
when .at?
self.next
axe_type = "attribute"
when .axe?
axe_type = @r.name
self.next
when .l_parens?
return parse_sequence(n)
else
#
end
opnd = parse_node_test(n, axe_type)
end
while @r.type == TokenType::LBracket
exc : Exception? = nil
begin
pnode = parse_predicate(opnd)
rescue ex
exc = ex
end
raise exc unless exc.nil?
opnd = FilterNode.new(opnd, pnode)
end
opnd
end
# Expr ::= '(' Step ("," Step)* ')'
private def parse_sequence(n : Node?)
skip(TokenType::LParens)
opnd = parse_step(n)
loop do
break unless @r.type == TokenType::Comma
self.next
opnd2 = parse_step(n)
opnd = OperatorNode.new("|", opnd, opnd2)
end
skip(TokenType::RParens)
opnd
end
# NodeTest ::= NameTest | nodeType '(' ')' | 'processing-instruction' '(' Literal ')'
private def parse_node_test(n, axe_type)
case @r.type
when .name?
if @r.can_be_func && node_type?
prop = ""
prop = @r.name if ["comment", "text", "processing-instruction", "node"].includes?(@r.name)
name = ""
self.next
skip(TokenType::LParens)
if prop == "processing-instruction" && @r.type != TokenType::RParens
check(TokenType::String)
name = @r.strval
self.next
end
skip(TokenType::RParens)
opnd = AxisNode.new(axe_type, name, "", prop, n)
else
prefix = @r.prefix
name = @r.name
self.next
name = "" if @r.name == "*"
opnd = AxisNode.new(axe_type, name, prefix, "", n)
end
when .star?
opnd = AxisNode.new(axe_type, "", "", "", n)
self.next
else
raise XPath2Exception.new("express must evaluate to a node-set")
end
opnd
end
# PrimaryExpr ::= VariableReference | '(' Expr ')' | Literal | Number | FunctionCall
private def parse_primary_expr(n : Node?)
case @r.type
when .string?
opnd = OperandNode.new(@r.strval)
self.next
when .number?
opnd = OperandNode.new(@r.numval)
self.next
when .dollar?
self.next
check(TokenType::Name)
opnd = VariableNode.new(@r.prefix, @r.name)
self.next
when .l_parens?
self.next
opnd = parse_expression(n)
skip(TokenType::RParens)
when .name?
opnd = parse_method(nil) if @r.can_be_func && !node_type?
else
raise XPath2Exception.new("Uknown Token type : #{@r.type}")
end
opnd.not_nil!
end
# FunctionCall ::= FunctionName '(' ( Argument ( ',' Argument )* )? ')'
private def parse_method(n : Node?)
args = Array(Node).new
name = @r.name
prefix = @r.prefix
skip(TokenType::Name)
skip(TokenType::LParens)
unless @r.type == TokenType::RParens
loop do
if (e = parse_expression(n))
args << e
end
break if @r.type == TokenType::RParens
skip(TokenType::Comma)
end
end
skip(TokenType::RParens)
FunctionNode.new(args, prefix, name)
end
end
private class Scanner
getter type : TokenType
getter strval : String # text value at current pos
getter numval : Float64 # number value at current pos
getter can_be_func : Bool
getter name : String
getter prefix : String
getter text : String
def initialize(@text : String, @name = "", @prefix = "")
@pos = 0
@curr = Char::ZERO
@type = TokenType::Eof
@strval = ""
@numval = 0_f64
@can_be_func = false
end
def next_char
if @pos >= @text.size
@curr = Char::ZERO
return false
end
@curr = @text[@pos]
@pos += 1
true
end
def next_item
skip_space
case @curr
when Char::ZERO
@type = TokenType::Eof
return false
when ',', '@', '(', ')', '|', '*', '[', ']', '+', '-', '=', '#', '$'
@type = as_item_type
next_char
when '<'
@type = TokenType::Lt
next_char
if @curr == '='
@type = TokenType::Le
next_char
end
when '>'
@type = TokenType::Gt
next_char
if @curr == '='
@type = TokenType::Ge
next_char
end
when '!'
@type = TokenType::Bang
next_char
if @curr == '='
@type = TokenType::Ne
next_char
end
when '.'
@type = TokenType::Dot
next_char
if @curr == '.'
@type = TokenType::DotDot
next_char
elsif @curr.number?
@type = TokenType::Number
@numval = scan_fraction
end
when '/'
@type = TokenType::Slash
next_char
if @curr == '/'
@type = TokenType::SlashSlash
next_char
end
when '"', '\''
@type = TokenType::String
@strval = scan_string
else
if @curr.number?
@type = TokenType::Number
@numval = scan_number
elsif is_name(@curr)
@type = TokenType::Name
@name = scan_name
@prefix = ""
# "foo:bar" is one item not three because it doesn't allow spaces in between
# we should distinct it from "foo::" and need process "foo ::" as well
if @curr == ':'
next_char
# can be "foo:bar" or "foo::"
if @curr == ':'
# "foo::"
next_char
@type = TokenType::Axe
else # "foo:*", "foo:bar" or "foo: "
@prefix = @name
if @curr == '*'
next_char
@name = "*"
elsif is_name(@curr)
@name = scan_name
else
raise XPath2Exception.new("#{@text} has an invalid qualified name.")
end
end
else
skip_space
if @curr == ':'
next_char
# it can be "foo ::" or just "foo :"
if @curr == ':'
next_char
@type = TokenType::Axe
else
raise XPath2Exception.new("#{@text} has an invalid qualified name.")
end
end
end
skip_space
@can_be_func = @curr == '('
else
raise XPath2Exception.new("#{@text} has an invalid token.")
end
end
true
end
private def skip_space
loop do
break if !@curr.whitespace? || !next_char
end
end
private def scan_fraction
i = @pos - 2
c = 1 # '.'
while @curr.number?
next_char
c += 1
end
if (v = @text[i...i + c].to_f?)
v
else
raise XPath2Exception.new("Invalid float value #{@text[i...i + c]}")
end
end
private def scan_number
i = @pos - 1
c = 0
while @curr.number?
next_char
c += 1
end
if @curr == '.'
next_char
c += 1
while @curr.number?
next_char
c += 1
end
end
if (v = @text[i...i + c].to_f?)
v
else
raise XPath2Exception.new("Invalid float value #{@text[i...i + c]}")
end
end
private def scan_string
c = 0
e = @curr
next_char
i = @pos - 1
while @curr != e
raise XPath2Exception.new("unclosed string") unless next_char
c += 1
end
next_char
@text[i...i + c]
end
private def scan_name
c = 0
i = @pos - 1
while is_name(@curr)
c += 1
break unless next_char
end
@text[i...i + c]
end
private def is_name(c : Char)
c != ':' && c != '/' && (allowed_char(c) || c == '*')
end
private def as_item_type
case @curr
when ',' then TokenType::Comma
when '@' then TokenType::At
when '(' then TokenType::LParens
when ')' then TokenType::RParens
when '|' then TokenType::Union
when '*' then TokenType::Star
when '[' then TokenType::LBracket
when ']' then TokenType::RBracket
when '+' then TokenType::Plus
when '-' then TokenType::Minus
when '=' then TokenType::Eq
when '$' then TokenType::Dollar
else
raise XPath2Exception.new("Uknown Token type: #{@curr}")
end
end
private def allowed_char(ch : Char) : Bool
UNICODE_RANGE.each do |t|
if (t[0].unsafe_chr..t[1].unsafe_chr).includes?(ch)
return true
end
end
false
end
private UNICODE_RANGE = [
{0x003A, 0x003A, 1},
{0x0041, 0x005A, 1},
{0x005F, 0x005F, 1},
{0x0061, 0x007A, 1},
{0x00C0, 0x00D6, 1},
{0x00D8, 0x00F6, 1},
{0x00F8, 0x00FF, 1},
{0x0100, 0x0131, 1},
{0x0134, 0x013E, 1},
{0x0141, 0x0148, 1},
{0x014A, 0x017E, 1},
{0x0180, 0x01C3, 1},
{0x01CD, 0x01F0, 1},
{0x01F4, 0x01F5, 1},
{0x01FA, 0x0217, 1},
{0x0250, 0x02A8, 1},
{0x02BB, 0x02C1, 1},
{0x0386, 0x0386, 1},
{0x0388, 0x038A, 1},
{0x038C, 0x038C, 1},
{0x038E, 0x03A1, 1},
{0x03A3, 0x03CE, 1},
{0x03D0, 0x03D6, 1},
{0x03DA, 0x03E0, 2},
{0x03E2, 0x03F3, 1},
{0x0401, 0x040C, 1},
{0x040E, 0x044F, 1},
{0x0451, 0x045C, 1},
{0x045E, 0x0481, 1},
{0x0490, 0x04C4, 1},
{0x04C7, 0x04C8, 1},
{0x04CB, 0x04CC, 1},
{0x04D0, 0x04EB, 1},
{0x04EE, 0x04F5, 1},
{0x04F8, 0x04F9, 1},
{0x0531, 0x0556, 1},
{0x0559, 0x0559, 1},
{0x0561, 0x0586, 1},
{0x05D0, 0x05EA, 1},
{0x05F0, 0x05F2, 1},
{0x0621, 0x063A, 1},
{0x0641, 0x064A, 1},
{0x0671, 0x06B7, 1},
{0x06BA, 0x06BE, 1},
{0x06C0, 0x06CE, 1},
{0x06D0, 0x06D3, 1},
{0x06D5, 0x06D5, 1},
{0x06E5, 0x06E6, 1},
{0x0905, 0x0939, 1},
{0x093D, 0x093D, 1},
{0x0958, 0x0961, 1},
{0x0985, 0x098C, 1},
{0x098F, 0x0990, 1},
{0x0993, 0x09A8, 1},
{0x09AA, 0x09B0, 1},
{0x09B2, 0x09B2, 1},
{0x09B6, 0x09B9, 1},
{0x09DC, 0x09DD, 1},
{0x09DF, 0x09E1, 1},
{0x09F0, 0x09F1, 1},
{0x0A05, 0x0A0A, 1},
{0x0A0F, 0x0A10, 1},
{0x0A13, 0x0A28, 1},
{0x0A2A, 0x0A30, 1},
{0x0A32, 0x0A33, 1},
{0x0A35, 0x0A36, 1},
{0x0A38, 0x0A39, 1},
{0x0A59, 0x0A5C, 1},
{0x0A5E, 0x0A5E, 1},
{0x0A72, 0x0A74, 1},
{0x0A85, 0x0A8B, 1},
{0x0A8D, 0x0A8D, 1},
{0x0A8F, 0x0A91, 1},
{0x0A93, 0x0AA8, 1},
{0x0AAA, 0x0AB0, 1},
{0x0AB2, 0x0AB3, 1},
{0x0AB5, 0x0AB9, 1},
{0x0ABD, 0x0AE0, 0x23},
{0x0B05, 0x0B0C, 1},
{0x0B0F, 0x0B10, 1},
{0x0B13, 0x0B28, 1},
{0x0B2A, 0x0B30, 1},
{0x0B32, 0x0B33, 1},
{0x0B36, 0x0B39, 1},
{0x0B3D, 0x0B3D, 1},
{0x0B5C, 0x0B5D, 1},
{0x0B5F, 0x0B61, 1},
{0x0B85, 0x0B8A, 1},
{0x0B8E, 0x0B90, 1},
{0x0B92, 0x0B95, 1},
{0x0B99, 0x0B9A, 1},
{0x0B9C, 0x0B9C, 1},
{0x0B9E, 0x0B9F, 1},
{0x0BA3, 0x0BA4, 1},
{0x0BA8, 0x0BAA, 1},
{0x0BAE, 0x0BB5, 1},
{0x0BB7, 0x0BB9, 1},
{0x0C05, 0x0C0C, 1},
{0x0C0E, 0x0C10, 1},
{0x0C12, 0x0C28, 1},
{0x0C2A, 0x0C33, 1},
{0x0C35, 0x0C39, 1},
{0x0C60, 0x0C61, 1},
{0x0C85, 0x0C8C, 1},
{0x0C8E, 0x0C90, 1},
{0x0C92, 0x0CA8, 1},
{0x0CAA, 0x0CB3, 1},
{0x0CB5, 0x0CB9, 1},
{0x0CDE, 0x0CDE, 1},
{0x0CE0, 0x0CE1, 1},
{0x0D05, 0x0D0C, 1},
{0x0D0E, 0x0D10, 1},
{0x0D12, 0x0D28, 1},
{0x0D2A, 0x0D39, 1},
{0x0D60, 0x0D61, 1},
{0x0E01, 0x0E2E, 1},
{0x0E30, 0x0E30, 1},
{0x0E32, 0x0E33, 1},
{0x0E40, 0x0E45, 1},
{0x0E81, 0x0E82, 1},
{0x0E84, 0x0E84, 1},
{0x0E87, 0x0E88, 1},
{0x0E8A, 0x0E8D, 3},
{0x0E94, 0x0E97, 1},
{0x0E99, 0x0E9F, 1},
{0x0EA1, 0x0EA3, 1},
{0x0EA5, 0x0EA7, 2},
{0x0EAA, 0x0EAB, 1},
{0x0EAD, 0x0EAE, 1},
{0x0EB0, 0x0EB0, 1},
{0x0EB2, 0x0EB3, 1},
{0x0EBD, 0x0EBD, 1},
{0x0EC0, 0x0EC4, 1},
{0x0F40, 0x0F47, 1},
{0x0F49, 0x0F69, 1},
{0x10A0, 0x10C5, 1},
{0x10D0, 0x10F6, 1},
{0x1100, 0x1100, 1},
{0x1102, 0x1103, 1},
{0x1105, 0x1107, 1},
{0x1109, 0x1109, 1},
{0x110B, 0x110C, 1},
{0x110E, 0x1112, 1},
{0x113C, 0x1140, 2},
{0x114C, 0x1150, 2},
{0x1154, 0x1155, 1},
{0x1159, 0x1159, 1},
{0x115F, 0x1161, 1},
{0x1163, 0x1169, 2},
{0x116D, 0x116E, 1},
{0x1172, 0x1173, 1},
{0x1175, 0x119E, 0x119E - 0x1175},
{0x11A8, 0x11AB, 0x11AB - 0x11A8},
{0x11AE, 0x11AF, 1},
{0x11B7, 0x11B8, 1},
{0x11BA, 0x11BA, 1},
{0x11BC, 0x11C2, 1},
{0x11EB, 0x11F0, 0x11F0 - 0x11EB},
{0x11F9, 0x11F9, 1},
{0x1E00, 0x1E9B, 1},
{0x1EA0, 0x1EF9, 1},
{0x1F00, 0x1F15, 1},
{0x1F18, 0x1F1D, 1},
{0x1F20, 0x1F45, 1},
{0x1F48, 0x1F4D, 1},
{0x1F50, 0x1F57, 1},
{0x1F59, 0x1F5B, 0x1F5B - 0x1F59},
{0x1F5D, 0x1F5D, 1},
{0x1F5F, 0x1F7D, 1},
{0x1F80, 0x1FB4, 1},
{0x1FB6, 0x1FBC, 1},
{0x1FBE, 0x1FBE, 1},
{0x1FC2, 0x1FC4, 1},
{0x1FC6, 0x1FCC, 1},
{0x1FD0, 0x1FD3, 1},
{0x1FD6, 0x1FDB, 1},
{0x1FE0, 0x1FEC, 1},
{0x1FF2, 0x1FF4, 1},
{0x1FF6, 0x1FFC, 1},
{0x2126, 0x2126, 1},
{0x212A, 0x212B, 1},
{0x212E, 0x212E, 1},
{0x2180, 0x2182, 1},
{0x3007, 0x3007, 1},
{0x3021, 0x3029, 1},
{0x3041, 0x3094, 1},
{0x30A1, 0x30FA, 1},
{0x3105, 0x312C, 1},
{0x4E00, 0x9FA5, 1},
{0xAC00, 0xD7A3, 1},