From 6f81dc9ed113f550da724a4a3a09754142619211 Mon Sep 17 00:00:00 2001 From: coke Date: Wed, 16 Dec 2009 12:08:14 -0500 Subject: [PATCH] Allow expr's == to fallback to string comparision. --- TODO | 6 ------ build/Makefile.in | 4 ++++ src/Partcl.pir | 1 + src/Partcl/Grammar.pm | 2 +- src/Partcl/Operators.pm | 13 +++++++++++++ 5 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 src/Partcl/Operators.pm diff --git a/TODO b/TODO index f01fb21..71acb0c 100644 --- a/TODO +++ b/TODO @@ -4,12 +4,6 @@ Big Goals Tasks/Bugs: -2. This should not print anything, but prints "yes", presumably due to - numeric coercion - tcl allows strings to be matched in this way, if - numeric coercion fails {library/init.tcl} - - if {[set a not-empty] == ""} {puts yes} - 3. [unknown] - invoking a non-existant command should result in a tcl error, not a parrot error. {t/tcl_misc.t; t/tcl_catch.t} diff --git a/build/Makefile.in b/build/Makefile.in index 8b39110..0d68f92 100644 --- a/build/Makefile.in +++ b/build/Makefile.in @@ -39,6 +39,7 @@ NQP_LANG_DIR = $(PARROT_LIB_DIR)/languages/nqp PARTCL_EXE = partcl$(EXE) PARTCL_G_PIR = src/gen/partcl-grammar.pir +PARTCL_O_PIR = src/gen/partcl-operators.pir PARTCL_A_PIR = src/gen/partcl-actions.pir PARTCL_C_PIR = src/gen/partcl-compiler.pir PARTCL_B_PIR = src/gen/partcl-commands-main.pir @@ -57,6 +58,7 @@ INIT_PIR = src/gen/init.pir PARTCL_SOURCES = \ src/Partcl.pir \ $(PARTCL_G_PIR) \ + $(PARTCL_O_PIR) \ $(PARTCL_A_PIR) \ $(PARTCL_C_PIR) \ $(PARTCL_B_PIR) \ @@ -90,6 +92,8 @@ $(PARTCL_EXE) : $(PARTCL_SOURCES) $(PARROT) -o partcl.pbc src/Partcl.pir $(PBC_TO_EXE) partcl.pbc +$(PARTCL_O_PIR): src/Partcl/Operators.pm + $(PARROT_NQP) --target=pir -o $(PARTCL_O_PIR) src/Partcl/Operators.pm $(PARTCL_G_PIR): src/Partcl/Grammar.pm $(PARROT_NQP) --target=pir -o $(PARTCL_G_PIR) src/Partcl/Grammar.pm $(PARTCL_A_PIR): src/Partcl/Actions.pm diff --git a/src/Partcl.pir b/src/Partcl.pir index 604940f..ae24058 100644 --- a/src/Partcl.pir +++ b/src/Partcl.pir @@ -18,6 +18,7 @@ .include 'src/gen/partcl-grammar.pir' .include 'src/gen/partcl-actions.pir' .include 'src/gen/partcl-compiler.pir' +.include 'src/gen/partcl-operators.pir' .include 'src/gen/partcl-commands-main.pir' .include 'src/gen/partcl-commands-file.pir' .include 'src/gen/partcl-commands-info.pir' diff --git a/src/Partcl/Grammar.pm b/src/Partcl/Grammar.pm index 516199e..c2de6a1 100644 --- a/src/Partcl/Grammar.pm +++ b/src/Partcl/Grammar.pm @@ -139,7 +139,7 @@ token infix:sym«<=» { ')> } token infix:sym«>» { ')> } token infix:sym«>=» { ')> } -token infix:sym<==> { ')> } +token infix:sym<==> { } token infix:sym { ')> } token infix:sym { ')> } diff --git a/src/Partcl/Operators.pm b/src/Partcl/Operators.pm new file mode 100644 index 0000000..73a16fe --- /dev/null +++ b/src/Partcl/Operators.pm @@ -0,0 +1,13 @@ +sub &infix:<==>($a, $b) { + # Try to do a numeric compare first (XXX this is integer for now) + try { + return pir::set__iP($a) == pir::set__iP($b); + CATCH { + # Not numeric. Try as string... + return $a eq $b; + } + } + +} + +# vim: filetype=perl6: