import { BudgieFile } from "../Tokenization/BudgieFile" ; import { CommandNode } from "../Tokenization/Nodes/CommandNode" ; import { TextNode } from "../Tokenization/Nodes/TextNode" ; import { CaseStyleConverterBag } from "./Casing/CaseStyleConverterBag" ; import { NameSplitter } from "./Casing/NameSplitter" ; import { CommandsBagFactory } from "./Commands/CommandsBagFactory" ; import { FileMetadata } from "./FileMetadata" ; import { BudgieNodeRenderer } from "./BudgieNodeRenderer" ; import { ImportsPrinter } from "./Imports/ImportsPrinter" ; import { ImportsStore } from "./Imports/ImportsStore" ; import { CaseStyle } from "./Languages/Casing/CaseStyle" ; import { Language } from "./Languages/Language" ; import { LineResults } from "./LineResults" ; import { LineResultsGenerator } from "./LineResultsGenerator" ; /**
 * Backing command context for converting Budgie nodes to text.
 */ export class RenderContext { /**
     * Holds case style converters, keyed by their case style.
     */ private caseStyleConverterBag : CaseStyleConverterBag ; /**
     * Name and path for the rendering file.
     */ private fileMetadata : FileMetadata ; /**
     * The language this context is converting Budgie code into.
     */ private language : Language ; /**
     * Generates line results from Budgie nodes.
     */ private lineResultsGenerator : LineResultsGenerator ; /**
     * Splits name strings into words.
     */ private nameSplitter : NameSplitter ; /**
     * Renders Budgie nodes into line results.
     */ private nodeRenderer : BudgieNodeRenderer ; param language public constructor ( language ) { this . language = language ; this . caseStyleConverterBag = new CaseStyleConverterBag ( ) ; this . fileMetadata = FileMetadata . defaultFileMetadata ; this . nameSplitter = new NameSplitter ( ) ; this . nodeRenderer = new BudgieNodeRenderer ( CommandsBagFactory . forContext ( this ) ) ; this . lineResultsGenerator = new LineResultsGenerator ( this . language . syntax . files , new ImportsPrinter ( this . language , this . caseStyleConverterBag . getConverter ( this . language . syntax . imports . case ) , this . caseStyleConverterBag . getConverter ( this . language . general . fileCase ) , this . nameSplitter ) ) ; } param budgieFile returns public convert ( budgieFile ) { const allLineResults = [ ] ; const importsStore = new ImportsStore ( ) ; for ( const node of budgieFile . getNodes ( ) ) { const lineResults = this . nodeRenderer . renderNode ( node ) ; allLineResults . push ( lineResults ) ; importsStore . addImports ( lineResults . addedImports ) ; } return this . lineResultsGenerator . generateLineResults ( allLineResults , importsStore , this . fileMetadata . getPackagePath ( ) . length !== 0 ) ; } param lineParsed returns public convertParsed ( parametersRaw ) { const args = [ ] ; for ( let i = 1 ; i < parametersRaw . length ; i += 1 ) { args . push ( new TextNode ( parametersRaw [ i ] ) ) ; } const commandNode = new CommandNode ( parametersRaw [ 0 ] , args ) ; return this . nodeRenderer . renderNode ( commandNode ) ; } param words param casingStyle returns public convertArrayToCase ( words , casingStyle ) { return this . caseStyleConverterBag . getConverter ( casingStyle ) . convert ( words ) ; } param name param casingStyle returns public convertStringToCase ( name , casingStyle ) { return this . convertArrayToCase ( this . nameSplitter . split ( name ) , casingStyle ) ; } returns public getFileMetadata ( ) { return this . fileMetadata ; } returns public getLanguage ( ) { return this . language ; } param fileDirectory public setFileMetadata ( fileMetadata ) { this . fileMetadata = fileMetadata ; } }