Sha256: eaa67dc1d6fa130308bdee7fbebdaf5d7000ed227317437d817d95823d166f61

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

grammar FormulaGrammar
  rule additive
    head:multiplicative tail:(space* operator:[+-] space* operand:multiplicative)* <Spreadshit::Formula::Nodes::AdditiveNode>
  end

  rule multiplicative
    head:operand tail:(space* operator:[*/] space* operand:operand)* <Spreadshit::Formula::Nodes::MultiplicativeNode>
  end

  rule operand
    reference / signed_number / string / group / function
  end

  rule group
    '(' space* content:additive space* ')' <Spreadshit::Formula::Nodes::GroupNode>
  end

  rule function
    name:[a-zA-Z]+ '(' space* arguments:arguments_list? space* ')' <Spreadshit::Formula::Nodes::FunctionNode>
  end

  rule arguments_list
    head:argument tail:(space* ';' space* arguments:arguments_list)* <Spreadshit::Formula::Nodes::ArgumentListNode>
  end

  rule argument
    range / additive / operand
  end

  rule range
    top:reference ':' bottom:reference <Spreadshit::Formula::Nodes::RangeNode>
  end

  rule reference
    col:[a-zA-Z]+ row:([1-9] [0-9]+ / [1-9]) <Spreadshit::Formula::Nodes::ReferenceNode>
  end

  rule signed_number
    sign? number <Spreadshit::Formula::Nodes::NumberNode>
  end

  rule number
    ([0-9]+ '.')? [0-9]+
  end

  rule sign
    [+-]
  end

  rule string
    quote chars:(!quote .)* quote <Spreadshit::Formula::Nodes::StringNode>
  end

  rule quote
    '"'
  end

  rule space
    ' '
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spreadshit-0.2.0 lib/spreadshit/formula.treetop
spreadshit-0.1.1 lib/spreadshit/formula.treetop
spreadshit-0.1.0 lib/spreadshit/formula.treetop