diff options
Diffstat (limited to 'rod/pas2nim/pas2nim.nim')
-rwxr-xr-x | rod/pas2nim/pas2nim.nim | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/rod/pas2nim/pas2nim.nim b/rod/pas2nim/pas2nim.nim new file mode 100755 index 000000000..54e4784c8 --- /dev/null +++ b/rod/pas2nim/pas2nim.nim @@ -0,0 +1,67 @@ +# +# +# Pas2nim - Pascal to Nimrod source converter +# (c) Copyright 2010 Andreas Rumpf +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + +# + +import + llstream, strutils, os, ast, rnimsyn, options, msgs, + paslex, pasparse + +proc exSymbols(n: PNode) = + case n.kind + of nkEmpty..nkNilLit: nil + of nkProcDef..nkIteratorDef: exSymbol(n.sons[namePos]) + of nkWhenStmt, nkStmtList: + for i in countup(0, sonsLen(n) - 1): exSymbols(n.sons[i]) + of nkVarSection, nkConstSection: + for i in countup(0, sonsLen(n) - 1): exSymbol(n.sons[i].sons[0]) + of nkTypeSection: + for i in countup(0, sonsLen(n) - 1): + exSymbol(n.sons[i].sons[0]) + if (n.sons[i].sons[2] != nil) and + (n.sons[i].sons[2].kind == nkObjectTy): + fixRecordDef(n.sons[i].sons[2]) + else: nil + +proc CommandExportSymbols(filename: string) = + # now unused! + var module = parseFile(addFileExt(filename, NimExt)) + if module != nil: + exSymbols(module) + renderModule(module, getOutFile(filename, "pretty." & NimExt)) + +proc CommandLexPas(filename: string) = + var f = addFileExt(filename, "pas") + var stream = LLStreamOpen(f, fmRead) + if stream != nil: + var + L: TPasLex + tok: TPasTok + OpenLexer(L, f, stream) + getPasTok(L, tok) + while tok.xkind != pxEof: + printPasTok(tok) + getPasTok(L, tok) + closeLexer(L) + else: rawMessage(errCannotOpenFile, f) + +proc CommandPas(filename: string) = + var f = addFileExt(filename, "pas") + var stream = LLStreamOpen(f, fmRead) + if stream != nil: + var p: TPasParser + OpenPasParser(p, f, stream) + var module = parseUnit(p) + closePasParser(p) + renderModule(module, getOutFile(filename, NimExt)) + else: + rawMessage(errCannotOpenFile, f) + + + |