Sha256: b7c837fc75b9f9842f36a4ed88eff2964328bdc72063c6d64f620e9b1cfcfd93

Contents?: true

Size: 562 Bytes

Versions: 2

Compression:

Stored size: 562 Bytes

Contents

module Basic101

  class Parser < Parslet::Parser

    rule(:float) do
      (fixed >> exponent.maybe |
       sign.maybe >> decimal >> exponent).as(:float)
    end

    rule(:integer) do
      (sign.maybe >> decimal).as(:integer)
    end

    rule(:decimal) do
      match('[0-9]').repeat(1)
    end

    rule(:sign)  do
      match('[+-]')
    end

    rule(:fixed) do
      sign.maybe >>
        (decimal >> str('.') >> decimal.maybe) |
        (str('.') >> decimal)
    end

    rule(:exponent) do
      str('E') >> sign.maybe >> decimal
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
basic101-0.4.0 lib/basic101/parser/numeric.rb
basic101-0.2.0 lib/basic101/parser/numeric.rb