From: Kevin Howe Date: 2005-02-13T11:34:59+09:00 Subject: [ANN] LXL (Like Excel) 0.3.0 LXL (Like Excel) is a mini-language that mimics Microsoft Excel formulas. Easily extended with new constants and functions. Version 0.3.0 supports the following features: =Namespaces [NEW] Extending the language is now as easy as defining new constants and methods on an LXL::Namespace class, for immediate use in formulas. class MyLXLNamespace < LXL::Namespace NAME = 'John Doe' def upper(text) text.to_s.upcase end end class MyLXL < LXL::Parser def self.namespace_class() MyLXLNamespace end end MyLXL.eval('=UPPER(NAME)') # => JOHN DOE =Ranges [NEW] B3:D5 => LXL::Range.new("B3","D5") LXL::Range is a subclass of Range which overrides the #each method to return Excel-style ranges. # Ruby Range Range.new("B3", "D5").collect # => ["B3", "B4", "B5", "B6", "B7", "B8", "B9", "C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "D0", "D1", "D2", "D3", "D4", "D5"] # LXL Range LXL::Range.new("B3", "D5").collect # => ["B3", "B4", "B5", "C3", "C4", "C5", "D3", "D4", "D5"] =Percentages [NEW] 25% => .25 =Deferred function calls [NEW] Snapshots the symbol/arguments of a function call for later use. class MyNamespace < LXL::Namespace register_deferred :foo end LXL.new(MyNamespace.new).eval('=FOO(1, "two", 3)').inspect # => =Symbol registration Register uppercase constants of the same name and value. class MyNamespace < LXL::Namespace register_symbols :foo, :bar end LXL.new(MyNamespace.new).eval('=LIST(FOO, BAR)').inspect # => [:FOO, :BAR] =Operators a + b # Add a - b # Subtract a * b # Multiply a / b # Divide a = b # Equal to a <> b # Not equal to a < b # Less than a > b # Greater than a <= b # Less than or equal to a >= b # Greater than or equal to a & b # String concentation [NEW] n ^ n # Exponential [NEW] =Constants TRUE # true FALSE # false NULL # nil =Functions Logical Functions AND (a,b) OR (a,b) IF (cond,true,false) Date/Time Functions TODAY () # current date value NOW () # current date/time value DATE (y,m,d) # date value TIME (h,m,s) # time value DATETIME (value) # convert a date/time string into a date/time value List Functions LIST (a,b,..) # Variable length list IN (find,list) # True if find value is in the given list (works on strings too) =Notes * The number zero is interpereted as FALSE * Return multiple results in an array by separating formulas with a semi-colon (;) * Constant and Function names are case-insensitive * Values prefixed with = are formulas, anything else is assumed to be text: LXL.eval("5+5") # => '5+5' LXL.eval("=5+5") # => 10 Regards, Kevin