M
M
Mariik2020-04-25 23:14:42
JavaScript
Mariik, 2020-04-25 23:14:42

How to parse a string into an object (AST)?

Hello.

I need to parse a line like this

const str="SALARY('@JohnSmith') = {USER.workingHours} * {USER.hourlyRate}";


convert to something close to an AST object like this:

const result = [
  {type: 'function', name: 'SALARY', params: ['@JohnSmith']},
  {type: 'entity', name: 'USER', fields: ['workingHours']},
  {type: 'mathOperation', operator: 'mutliply'},
  {type: 'entity', name: 'USER', fields: ['hourlyRate']} 
]


Perhaps there are already libraries with similar capabilities?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LinuxGod, 2020-04-25
@LinuxGod

Tyk

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question