1// Copyright 2020 Google LLC 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15{ 16 concat_array: [1, 2, 3] + [4], 17 concat_string: '123' + 4, 18 equality1: 1 == '1', 19 equality2: [{}, { x: 3 - 1 }] 20 == [{}, { x: 2 }], 21 ex1: 1 + 2 * 3 / (4 + 5), 22 // Bitwise operations first cast to int. 23 ex2: self.ex1 | 3, 24 // Modulo operator. 25 ex3: self.ex1 % 2, 26 // Boolean logic 27 ex4: (4 > 3) && (1 <= 3) || false, 28 // Mixing objects together 29 obj: { a: 1, b: 2 } + { b: 3, c: 4 }, 30 // Test if a field is in an object 31 obj_member: 'foo' in { foo: 1 }, 32 // String formatting 33 str1: 'The value of self.ex2 is ' 34 + self.ex2 + '.', 35 str2: 'The value of self.ex2 is %g.' 36 % self.ex2, 37 str3: 'ex1=%0.2f, ex2=%0.2f' 38 % [self.ex1, self.ex2], 39 // By passing self, we allow ex1 and ex2 to 40 // be extracted internally. 41 str4: 'ex1=%(ex1)0.2f, ex2=%(ex2)0.2f' 42 % self, 43 // Do textual templating of entire files: 44 str5: ||| 45 ex1=%(ex1)0.2f 46 ex2=%(ex2)0.2f 47 ||| % self, 48} 49