Skip to content

Commit

Permalink
0.0.1 manual released.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoxem committed Jul 4, 2021
1 parent 00f487a commit 2806c8e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Clochur/ClochurLexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def styleText(self, start, end):
# pass

'''comment'''
if item["str"] == "%":
if item["str"] == "%" and rainbow_state < 10:
is_comment = True
if is_comment == True:
new_state = self.Comment # end of comment
Expand Down
56 changes: 44 additions & 12 deletions src/Clochur/Interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,16 @@ def interprete_aux(self, sexp):

elif sexp[0]["token"] == "str-append":
if len(sexp) != 3:
raise Exception("Ln %d, Col %d: the argument number of str should be 2" %
raise Exception("Ln %d, Col %d: the argument number of str-append should be 2" %
(sexp[0]["line"], sexp[0]["col"]))
else:
return self.interprete_aux(sexp[1]) + self.interprete_aux(sexp[2])
lhs = self.destring(self.interprete_aux(sexp[1]))
rhs = self.destring(self.interprete_aux(sexp[2]))
if isinstance(lhs, str) and isinstance(rhs, str):
return lhs + rhs
else:
raise Exception("Ln %d, Col %d: the argument of str-append should be string" %
(sexp[0]["line"], sexp[0]["col"]))

elif sexp[0]["token"] == "print":
if len(sexp) != 2:
Expand Down Expand Up @@ -440,42 +446,54 @@ def interprete_aux(self, sexp):

# (car List)
elif sexp[0]["token"] == "car":
ls = self.interprete_aux(sexp[1])
if len(sexp) != 2:
raise Exception("Line %d, Col. %d, the argument length should be 1" % (sexp[0]["line"], sexp[0]["col"]))
elif not isinstance(sexp[1], List):
elif not isinstance(ls, List):
raise Exception("Line %d, Col. %d, the argument is not a list." % (sexp[1]["line"], sexp[1]["col"]))
else:
ls = sexp[1].ls
ls = ls.ls
return ls[0]

# (cdr List)
elif sexp[0]["token"] == "cdr":
ls = self.interprete_aux(sexp[1])
if len(sexp) != 2:
raise Exception("Line %d, Col. %d, the argument length should be 1" % (sexp[0]["line"], sexp[0]["col"]))
elif not isinstance(sexp[1], List):
elif not isinstance(ls, List):
raise Exception("Line %d, Col. %d, the argument is not a list." % (sexp[1]["line"], sexp[1]["col"]))
else:
ls = sexp[1].ls
return ls[1:]
ls = ls.ls
return List(ls[1:])

# (cons any List)
elif sexp[0]["token"] == "cons":
ls = self.interprete_aux(sexp[2])
if len(sexp) != 3:
raise Exception("Line %d, Col. %d, the argument length should be 2" % (sexp[0]["line"], sexp[0]["col"]))
elif not isinstance(sexp[2], List):
elif not isinstance(ls, List):
raise Exception("Line %d, Col. %d, the 2nd argument of cons is not a list." % (sexp[2]["line"], sexp[2]["col"]))
else:
car = sexp[1]
cdr = sexp[2].ls
result_ls = List([sexp[1]]+cdr)
cdr = ls.ls
result_ls = List([sexp[1]["token"]]+cdr)
return result_ls


elif sexp[0]["token"] == "ls-ref":
ls = self.interprete_aux(sexp[1])
index = self.interprete_aux(sexp[2])
if len(sexp) != 3:
raise Exception("Line %d, Col. %d, the argument length should be 1" % (sexp[0]["line"], sexp[0]["col"]))
elif not isinstance(sexp[1], List):
raise Exception("Line %d, Col. %d, the 2nd argument of cons is not a list." % (sexp[2]["line"], sexp[2]["col"]))
elif not isinstance(index, int):
raise Exception("Line %d, Col. %d, the 1st argument of cons is not a integer." % (sexp[2]["line"], sexp[2]["col"]))
elif not isinstance(ls, List):
raise Exception("Line %d, Col. %d, the 2nd argument of cons is not a List." % (ls, sexp[1]["col"]))
elif index >= len(ls.ls):
raise Exception("Line %d, Col. %d, List out of range")
else:
return ls.ls[index]




Expand Down Expand Up @@ -621,6 +639,8 @@ def __str__(self):
class List:
def __init__(self, ls):
self.ls = ls
def __repr__(self):
return (f"&lt;List object of Clochur. list={self.ls}&gt;")

# closure
class Lambda:
Expand All @@ -633,3 +653,15 @@ def __init__(self, vars, body, env):
self.vars = [i["token"] for i in vars]
self.body = body
self.env = env

def __str__(self):
parser = Parser()
body_sexp = parser.generate_printable_sexp(self.body)
return (f"&lt;Clojure object of Clochur. vars={self.vars}, " + \
"env=" + str(self.env) + f", body={body_sexp}&gt;")

def __repr__(self):
parser = Parser()
body_sexp = parser.generate_printable_sexp(self.body)
return (f"&lt;Clojure object of Clochur. vars={self.vars}, " + \
"env=" + str(self.env) + f", body={body_sexp}&gt;")
12 changes: 9 additions & 3 deletions src/Clochur/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,12 @@ def convert_call(self):
with open(sile_xml_path, "w") as xml:
xml.write(result)
xml.close()

subprocess.run([sile_command, sile_xml_path])

try:
subprocess.run([sile_command, sile_xml_path])
except FileNotFoundError as e:
raise Exception("the command \"sile\" is not found. Please check if it's installed.")

pdf_js_webviewer_list = self.findChildren(QtWebEngineWidgets.QWebEngineView)
pdf_js_webviewer = pdf_js_webviewer_list[-1]
pdf_js_webviewer.load_path(sile_pdf_path)
Expand All @@ -325,6 +329,8 @@ def exit_call(self):
if reply == QMessageBox.Yes:
if self.filename != None:
self.save_call()
self.remove_tmp_outputs()
app.exit()
else:

file_path = QFileDialog.getSaveFileName(self, 'Save file as...', self.opened_file_dirname, "CLC typesetting format (*.clc)")
Expand Down Expand Up @@ -386,7 +392,7 @@ def underline_call(self):
def add_font_call(self):
selected_text = self.editor.selectedText()
font_family = self.font_combo_box.currentText()
self.editor.replaceSelectedText(f'[font-family "{font_family}" {selected_text}]')
self.editor.replaceSelectedText(f'[font-family "{font_family}" "{selected_text}"]')

def about_call(self):

Expand Down
Binary file modified src/manual.pdf
Binary file not shown.

0 comments on commit 2806c8e

Please sign in to comment.