# All files / src/parsers/math math.js

100% Statements 6/6
100% Branches 4/4
100% Functions 3/3
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33

    19x
    19x
    60x

    19x

    95x

     // @flow

    import P from 'parsimmon'

    import BinaryOperatorParser from '../abstract/binaryOperator'
    import UnaryOperatorParser from './unaryOperator'

    import type { ParserType } from '../../types'

    const processBoolean2 = (x: string): string => x + '='
    const processBoolean3 = (x: string): string =>
      x === 'or' ? '||' : x === 'and' ? '&&' : x

    const operatorPrecedenceTable = [
      ['unary', UnaryOperatorParser],
      ['multiplicative', P.regexp(/[*/%]/)],
      ['additive', P.regexp(/[+-]/)],
      ['boolean1', P.regexp(/[<>]=?/)],
      ['boolean2', P.regexp(/[=!]=/).map(processBoolean2)],
      ['boolean3', P.regexp(/(\|\||&&|or|and)/).map(processBoolean3)]
    ]

    export default operatorPrecedenceTable
      .slice(1)
      .reduce(
        (
          ParentParser: ParserType,
          [parserDecription, Parser]: [string, ParserType]
        ): ParserType =>
          BinaryOperatorParser(ParentParser, Parser, parserDecription),
        operatorPrecedenceTable[0][1]
      )