From 4cf9710bd27fdb5f0720f4d8478ef940e7c4ba59 Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Fri, 26 Sep 2008 23:03:39 +0200 Subject: Add parser for arbitrary expressions The expressions can be used in if 'test' and in the right side of assignements. The expressions can contain any number of sub-expressions combined by either arithmetic operators, comparison operators, or boolean operators. Random Usage Examples: $result = ((( $two + 2) / $one) + 4 * 5.45) - (6 << 7) + (0x800 + -9) or if ($a < 10) and ($a + 10 != 200) { ... } --- test/data/snippets/arithmetic_expression.pp | 8 ++++++++ test/data/snippets/ifexpression.rb | 6 ++++++ 2 files changed, 14 insertions(+) create mode 100644 test/data/snippets/arithmetic_expression.pp create mode 100644 test/data/snippets/ifexpression.rb (limited to 'test/data') diff --git a/test/data/snippets/arithmetic_expression.pp b/test/data/snippets/arithmetic_expression.pp new file mode 100644 index 000000000..aae98a4db --- /dev/null +++ b/test/data/snippets/arithmetic_expression.pp @@ -0,0 +1,8 @@ + +$one = 1.30 +$two = 2.034e-2 + +$result = ((( $two + 2) / $one) + 4 * 5.45) - (6 << 7) + (0x800 + -9) + + +notice("result is $result == 1295.87692307692") \ No newline at end of file diff --git a/test/data/snippets/ifexpression.rb b/test/data/snippets/ifexpression.rb new file mode 100644 index 000000000..eea3b855b --- /dev/null +++ b/test/data/snippets/ifexpression.rb @@ -0,0 +1,6 @@ +$one = 1 +$two = 2 + +if ($one < $two) and (($two < 3) or ($two == 2)) { + notice("True!") +} -- cgit