[ANN] LXL (Like Excel) 0.3.0

Discussion in 'Ruby' started by Kevin Howe, Feb 13, 2005.

  1. Kevin Howe

    Kevin Howe Guest

    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
    # => <LXL::Deferred @args=[1, "two", 3] @symbol=:foo>

    =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
    Kevin Howe, Feb 13, 2005
    #1
    1. Advertising

  2. Kevin Howe

    Kevin Howe Guest

    =Download

    http://rubyforge.org/projects/lxl

    =Install

    GEM file

    gem install lxl (remote)
    gem install lxl-x.x.x.gem (local)

    Tarball (setup.rb)

    De-Compress archive and enter its top directory.
    Then type:

    $ ruby setup.rb config
    $ ruby setup.rb setup
    ($ su)
    # ruby setup.rb install

    =License

    LXL incorporates John Carter's LittleLexer for parsing.
    Distributes under the same terms as LittleLexer.
    http://www.rubyforge.org/projects/littlelexer/
    Kevin Howe, Feb 13, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmltIEhlYXZleQ==?=

    Excel _WorkBook vs. Excel.Workbook

    =?Utf-8?B?SmltIEhlYXZleQ==?=, Sep 29, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    3,616
    Steve C. Orr [MVP, MCSD]
    Sep 29, 2004
  2. Luis Esteban Valencia
    Replies:
    1
    Views:
    1,363
    Carl Prothman [MVP]
    Jan 12, 2005
  3. Patrick Kowalzick
    Replies:
    5
    Views:
    455
    Patrick Kowalzick
    Mar 14, 2006
  4. =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=

    Problem with Excel reports ::::Excel 2003 Migration To Excel 2007

    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=, Oct 5, 2007, in forum: ASP .Net
    Replies:
    15
    Views:
    1,478
    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=
    Oct 24, 2007
  5. Kevin Howe
    Replies:
    6
    Views:
    210
    Kevin Howe
    Feb 6, 2005
Loading...

Share This Page