Skip to content

Multi line object expressions don't work with comments #2491

@dvd101x

Description

@dvd101x

Hi, I'm really enjoying the implementation of multi line expressions, I feel it makes the code more readable for objects and other a bit more complex mathjs expressions like this

car = {
       speed: 10  m/s,
       mass:  1e3 kg,
       lenth: 3   m
      }

A workaround without multiline expressions was to make an empty object first and then assigning the attributes one by one with the added benefit that it's possible to comment each one

car = {};
car.speed  = 10  m/s # speed
car.mass   = 1e3 kg  # mass
car.length = 3   m   # length

One small issue is that it multi line expressions do not work when they are commented in between

car = {
       speed: 10  m/s,  # speed
       mass:  1e3 kg,   # mass
       lenth: 3   m     # length
      }

Yielding

SyntaxError: Syntax error in part "
       mass:  1e3 kg,   # mass
       lenth: 3   m     # length
      }" (char 40)

I understand that this could be fixed by the user by submitting lines without comments to math.parser but please consider the possibility of having comments in between multiline expressions.

Metadata

Metadata

Assignees

Labels

bugcategory:expressionsIssues about the expression parser, variable scoping etc.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions