all repos — min @ acc4d3725fea53776474dae876ebc67472009f50

A small but practical concatenative programming language.

dynparser.nim

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
import strutils
import nre

var
  currentLine = 1
  oldLine = 0
  sourceFile = open("parser2.nim")

for line in lines "parser.ndi":
  let
    fields = line.split('\t')
    (origName, mangledName, path, row, column) = (fields[0], fields[1], fields[2], fields[3].parseInt, fields[4])
  if path == "/home/peter/min/core/parser.nim":
    while currentLine < row:
      currentLine += 1
      discard sourceFile.readLine()
    if currentLine != oldLine:
      let definition = sourceFile.readLine()
      if definition.startsWith("proc"):
        #echo origName & " -> " & mangledName
        echo definition.replace(re""" *= *\".*\"""", ": string").replace(re"""{\..*\.}""","").replace(re""" *= *$""", "").replace("*(","(") & " {.importc, extern:\"" & mangledName & "\".}"
      oldLine = currentLine
      currentLine += 1