-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.py
More file actions
38 lines (31 loc) · 1007 Bytes
/
Utils.py
File metadata and controls
38 lines (31 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
# Checks if the file has .lwj extension
def checkFile(filepath):
if os.path.isfile(filepath) and os.path.splitext(os.path.basename(filepath))[1] == ".lwj":
return None
else:
raise Exception("Not a Langwej file")
# Stack implementation
class Stack:
def __init__(self, stack = []):
self.stack = stack
self.size = len(stack)
def top(self):
if self.size == 0:
raise Exception("Stack is empty")
return self.stack[0]
def push(self, item):
self.stack.insert(0, item)
self.size += 1
def pop(self):
if self.size == 0:
raise Exception("Stack is empty")
self.size -= 1
return self.stack.pop(0)
def getStack(self, single=True):
if not single:
return self.stack
else:
return [x[0] if isinstance(x, tuple) else x for x in self.stack]
def print(self, single=True):
print(self.getStack(single))