Sha256: 3df93d510c5d2e977b2c9d3fe1a47f70e06710d5637dce907b1a311164cd25b3

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

module Fonte
  module Parsers
    grammar Number
      include Word

      rule number
        coordinates / float / integer
      end

      rule float
        (
        # Scientific notation (eg 5e7, 2.2E-4)
        [+-]? ([0-9]* '.')? [0-9]+ [eE] [+-]? [0-9]+
        /
        # Standard float (eg -43.21, .05)
        [+-]? [0-9]* '.' [0-9]+
        ) {
          def value
            Float(text_value)
          end
        }
      end

      rule integer
        (
        # Binary (eg 0b101, -0B0010)
        [+-]? '0' [bB] [01]+
        /
        # Hex (eg 0xfff, +0XA30)
        [+-]? '0' [xX] [0-9a-fA-F]+
        /
        # Decimal (eg 27, -421)
        [+-]? [0-9]+
        ) {
          def value
            Integer(text_value)
          end
        }
      end

      rule coordinates
        x:coordinate SPACE y:coordinate SPACE z:coordinate {
          def value
            [x.value, y.value, z.value]
          end
        }
      end

      rule coordinate
        float / integer
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fonte-0.2.0 lib/fonte/parsers/number.treetop