Last active
          February 29, 2020 16:22 
        
      - 
      
 - 
        
Save kristianmandrup/2b05315477b5d9c836751f34d5346650 to your computer and use it in GitHub Desktop.  
    Nim type/id table display
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | type | |
| TIdTableEntry = object | |
| id: string | |
| genId: string | |
| startIndex: int | |
| endIndex: int | |
| PIdTableEntry = ref TIdTableEntry | |
| TIdLookupTable = object | |
| idMap: TableRef[string, PIdTableEntry] | |
| currentId: string | |
| PIdLookupTable = ref TIdLookupTable | |
| TTypeLookupTable = object | |
| typeMap: TableRef[string, PIdLookupTable] | |
| currentType: string | |
| PTypeLookupTable = ref TTypeLookupTable | |
| proc newIdTableEntry(startIndex: int = 0, id: string = "", genId: string = ""): PIdTableEntry = | |
| new(result) | |
| result.startIndex = startIndex | |
| result.id = id | |
| result.genId = genId | |
| proc newIdLookupTable(): PIdLookupTable = | |
| new(result) | |
| result.idMap = newTable[string, PIdTableEntry]() | |
| proc newTypeLookupTable(): PTypeLookupTable = | |
| new(result) | |
| # I think my problem is bad initialisation of here!? | |
| result.typeMap = newTable[string, PIdLookupTable]() | |
| proc `$`(entry: PIdTableEntry): string = | |
| $(entry.id, entry.genId, entry.startIndex, entry.endIndex) | |
| proc `$`(table: PIdLookupTable): string = | |
| result = "idMap:" | |
| for k, v in table.idMap.pairs: | |
| result.add(k & ": " & v & "\n") | |
| result.add("currentId: " & table.currentId | |
| proc `$`(self: PTypeLookupTable): string = | |
| result = "typeMap:" | |
| for k, v in self.typeMap.pairs: | |
| result.add(k & ":" & v & "\n") | |
| result.add("currentType: " & self.currentType) | |
| var typeTable = newTypeLookupTable() | |
| var idTable = newIdLookupTable() | |
| var entry = newIdTableEntry(startIndex = 1, id = "a", genId = "a123") | |
| idTable["a"] = entry | |
| typeTable["property"] = idTable | |
| # echo idTable | |
| # echo typeTable | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment