nrkn/hrm-parser

Add optional callback

Closed this issue · 0 comments

nrkn commented

Rather than having to catch errors. Also it could pass metadata as a 3rd arg:

parse( source, ( err, parsed, meta ) => {
  console.log( meta )
})

The meta would be something like:

{
  programComments: {
    //above line 0 of the parsed program (not original source) are two comments
    0: [ 
      '-- HUMAN RESOURCE MACHINE PROGRAM --',
      '-- 41-Sorting-Floor - SIZE 20/34 - SPEED 689/714 --'
    ]
  },
  //above line 10 of the parsed program are two jump destinations, 
  //originally a: and b:
  sourceLabels: {
    10: [
      {
        from: 20,
        name: 'a'
      },
      {
        from: 30,
        name: 'b'
      }
    ]
  },
  floorLabels : {
    0: 'eJ...',
    1: 'eJ...'
  },
  comments: {
    0: [
      'eJ...'
    ],
    20: [
      'eJ...',
      'eJ...'
    ]
  }
}

If a cb isn't being used then we don't bother extracting the metadata, makes the simple use-case faster