import {ParseFragment, RegRepository, RegRepositoryToken} from '../interface/index';
import { NumericParseService } from './numeric-parse.service';
import { isNil } from 'lodash';
import { Inject, Injectable} from '@angular/core';

@Injectable()
export class RegParseService {
  constructor(
    @Inject(RegRepositoryToken)
    public readonly regRepo:RegRepository,
    public readonly numericPareService:NumericParseService,
  ) {}

  public parse(operand:ParseFragment,length:number):string {
    if(isNil(this.regRepo.get(operand.code))) {
      return operand.code;
    }
    return this.numericPareService.comp(this.regRepo.get(operand.code),length);
  }
}

{'avg_line_length': 31.571428571428573, 'max_line_length': 84, 'alphanum_fraction': 0.7405731523378583, 'licenses': ['MIT'], 'repository_name': 'lonelyhentai/workspace', 'path': 'compile/minsys-assembler/src/app/minisys-32-assembler/assembler-lib/parser/reg-parse.service.ts', 'size': 663, 'lang': 'TypeScript'}