|
25 | 25 | #If not otherwise stated, any source coe generated by Coco/R (other than
|
26 | 26 | #Coco/R itself) does not fall under the GNU General Public License.
|
27 | 27 | #-------------------------------------------------------------------------*/
|
28 |
| - |
29 |
| -import os.path |
| 28 | +import os |
| 29 | +from pathlib import Path |
30 | 30 | import sys
|
31 | 31 | import copy
|
32 | 32 | from optparse import OptionParser
|
@@ -2326,24 +2326,25 @@ def FillStartTab(startTab):
|
2326 | 2326 | def OpenGen(backUp):
|
2327 | 2327 | assert isinstance(backUp,bool)
|
2328 | 2328 | try:
|
2329 |
| - fn = os.path.join(__class__.outDir, "Scanner.py") # String |
2330 |
| - if backUp and os.path.exists(fn): |
2331 |
| - if os.path.exists(fn + '.old'): |
2332 |
| - os.remove( fn + '.old' ) |
2333 |
| - os.rename( fn, fn + '.old' ) |
2334 |
| - __class__.gen = open( fn, 'wt', encoding="utf-8") |
| 2329 | + fn = __class__.outDir / "Scanner.py" # String |
| 2330 | + if backUp and fn.is_file(): |
| 2331 | + backUpFile = fn.parent / (fn.name + '.old') |
| 2332 | + if backUpFile.is_file(): |
| 2333 | + os.remove(str(backUpFile)) |
| 2334 | + os.rename( str(fn), str(backUpFile)) |
| 2335 | + __class__.gen = fn.open('wt', encoding="utf-8") |
2335 | 2336 | except:
|
2336 | 2337 | raise RuntimeError("-- Compiler Error: Cannot generate scanner file.")
|
2337 | 2338 |
|
2338 | 2339 | @staticmethod
|
2339 | 2340 | def WriteScanner( withNames):
|
2340 | 2341 | assert isinstance(withNames,bool)
|
2341 | 2342 | startTab = [ 0 for i in range(CharClass.charSetSize) ]
|
2342 |
| - fr = os.path.join(__class__.srcDir, "Scanner.frame") # String |
2343 |
| - if not os.path.exists( fr ): |
| 2343 | + fr = __class__.srcDir / "Scanner.frame" # String |
| 2344 | + if not fr.is_file(): |
2344 | 2345 | if Tab.frameDir is not None:
|
2345 |
| - fr = os.path.join( Tab.frameDir.strip(), "Scanner.frame" ) |
2346 |
| - if not os.path.exists(fr): |
| 2346 | + fr = Tab.frameDir / "Scanner.frame" |
| 2347 | + if not fr.is_file(): |
2347 | 2348 | raise RuntimeError("-- Compiler Error: Cannot find Scanner.frame")
|
2348 | 2349 | try:
|
2349 | 2350 | __class__.fram = open( fr, 'rt', encoding="utf-8")
|
@@ -2440,10 +2441,10 @@ def WriteScanner( withNames):
|
2440 | 2441 | __class__.gen.close()
|
2441 | 2442 |
|
2442 | 2443 | @staticmethod
|
2443 |
| - def Init ( file:str, srcDir:str, outDir:str): |
2444 |
| - assert isinstance(file, str) |
2445 |
| - assert isinstance(srcDir, str) |
2446 |
| - assert isinstance(outDir, str) |
| 2444 | + def Init ( file:str, srcDir:Path, outDir:Path): |
| 2445 | + assert isinstance(file, str), repr(str) |
| 2446 | + assert isinstance(srcDir, Path), repr(srcDir) |
| 2447 | + assert isinstance(outDir, Path), repr(outDir) |
2447 | 2448 | __class__.srcName = file
|
2448 | 2449 | __class__.srcDir = srcDir
|
2449 | 2450 | __class__.outDir = outDir
|
|
0 commit comments