All files / src/asn1 ASN1ModuleFactory.ts

92.3% Statements 12/13
50% Branches 1/2
100% Functions 1/1
92.3% Lines 12/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 201x 1x 1x     1x   5x 5x 5x 5x 5x     5x 5x 5x      
import {ASN1CstParser} from '../analysis/ASN1CstParser';
import {ASN1Lexer} from '../analysis/ASN1Lexer';
import {ASN1Visitor} from '../analysis/ASN1Visitor';
import {ASN1Module} from './ASN1Module';
 
export class ASN1ModuleFactory {
  static compile(definition: string): ASN1Module {
    const output = ASN1Lexer.tokenize(definition);
    const parserInstance = new ASN1CstParser();
    parserInstance.input = output.tokens;
    const cstOutput = parserInstance.ModuleDefinition();
    Iif (parserInstance.errors.length > 0) {
      throw Error('Syntax error:\n' + parserInstance.errors[0].message);
    }
    const toAstVisitorInstance = new ASN1Visitor();
    const ast = toAstVisitorInstance.visit(cstOutput);
    return ast;
  }
}