Skip to content

Wrong operator ordering in FST for operators of equal precedence #162

@EmilyBourne

Description

@EmilyBourne

When a modulo operator is combined with a multiplication baron does not interpret the code in the same way as python.

E.g:

a % 2 * 4

In python this is equivalent to:

(a % 2) * 4

however baron reads it as:

a % (2 * 4)

as shown here:

>from baron import parse

> fst = parse("a % 2 * 4")

> fst[0]

{'first': {'type': 'name', 'value': 'a'},
 'first_formatting': [{'type': 'space', 'value': ' '}],
 'second': {'first': {'section': 'number', 'type': 'int', 'value': '2'},
  'first_formatting': [{'type': 'space', 'value': ' '}],
  'second': {'section': 'number', 'type': 'int', 'value': '4'},
  'second_formatting': [{'type': 'space', 'value': ' '}],
  'type': 'binary_operator',
  'value': '*'},
 'second_formatting': [{'type': 'space', 'value': ' '}],
 'type': 'binary_operator',
 'value': '%'}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions