@@ -924,20 +924,23 @@ module DynamoDBFilterExpr {
924924
925925 // transform A IN(X,Y) to IN(A,X,Y)
926926 // transform A BETWEEN X AND Y to BETWEEN(A, X, Y)
927- function method ConvertToPrefix (input: seq <Token >) : (res : seq < Token> )
927+ function method ConvertToPrefix (input: seq <Token >, pos : uint64 := 0) : (res : seq < Token> )
928+ requires pos as nat <= |input|
929+ decreases |input| - pos as nat
928930 {
929- if |input| < 5 then
930- input
931- else if IsIN (input, 0) then
932- [input[1], input[2], input[0], Comma] + ConvertToPrefix (input[3..])
931+ SequenceIsSafeBecauseItIsInMemory (input);
932+ if |input| as uint64 < Add (pos, 5) then
933+ input[pos.. ]
934+ else if IsIN (input, pos) then
935+ [input[pos+ 1], input[pos+ 2], input[pos], Comma] + ConvertToPrefix (input, pos+3)
933936 else
934- var between := IsBetween (input, 0 );
937+ var between := IsBetween (input, pos );
935938 if between. Some? then
936939 var b := between. value;
937- [Between, Open] + input[0 .. b. 0] + [Comma] + input[b. 0+ 1.. b. 0+ b. 1+ 1] + [Comma]
938- + input[b. 0+ b. 1+ 2.. b. 0+ b. 1+ b. 2+ 2] + [Close] + ConvertToPrefix (input[ b.0+b.1+b.2+2..] )
940+ [Between, Open] + input[pos .. pos + b. 0] + [Comma] + input[pos + b. 0+ 1.. pos + b. 0+ b. 1+ 1] + [Comma]
941+ + input[pos + b. 0+ b. 1+ 2.. pos + b. 0+ b. 1+ b. 2+ 2] + [Close] + ConvertToPrefix (input, pos+ b.0+b.1+b.2+2)
939942 else
940- [input[0 ]] + ConvertToPrefix (input[1..] )
943+ [input[pos ]] + ConvertToPrefix (input, pos+1 )
941944 }
942945
943946 lemma TestConvertToPrefix3 (input: seq <Token >)
0 commit comments