Skip to content

Commit

Permalink
Everything
Browse files Browse the repository at this point in the history
  • Loading branch information
hg0428 committed Oct 25, 2020
1 parent c8f7a40 commit 056a2d7
Show file tree
Hide file tree
Showing 54 changed files with 1,218 additions and 749 deletions.
91 changes: 87 additions & 4 deletions Aardvark.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
import language
import sys
import re
global blocks, statements, keywords
Aardvark = language.Lang()
Aardvark.Aardvark=Aardvark
def makevar(defvar):
gt = Aardvark.gettype(defvar[1], Aardvark.line_num)
Aardvark.variables[defvar[0]] = language.Variable(defvar[0], gt)
for i in Aardvark.attributes[gt[0]]:
Aardvark.variables[defvar[0] + "." + i[0]] = language.Variable(
defvar[0] + "." + i[0], Aardvark.gettype(i[1](gt[1]), Aardvark.line_num))
def setupadk():
adk = Aardvark.things
global blocks, statements, keywords
blocks = {
"isif": adk['isif'],
"iswhile": adk['iswhile'],
"isforeach": adk['isforeach'],
"isforin": adk['isforin'],
"isfunctiondefinition": adk['isfunctiondefinition'],
"istryexcept":adk["istryexcept"]
}

statements = {
"isinclude": adk['isinclude'],
"isape": adk['isape'],
"ismaxmem": adk['ismaxmem']
}

keywords = {
"iscontinue": adk['iscontinue'],
"isdelete": adk['isdelete'],
}


colors = {
"red": "31",
"green": "32",
Expand All @@ -13,6 +46,20 @@
}


class AardvarkError(Exception):
def __init__(self, etype, code, line, specific):
self.error=etype
self.line=line
self.code=code
self.specific=specific
super().__init__(error)
def printtext(self):
cp(f"Error on line {self.line}:\n{self.code}\n{self.error}: {self.specific}", "red")
sys.exit()




def gcolor(color="white", style=0, back=0):
a = colors[color]
style = str(style) + ";"
Expand All @@ -22,10 +69,46 @@ def gcolor(color="white", style=0, back=0):
return "\x1b[" + style + a + back + "m"


def cp(text, color="white", style=0, back=0, end="\n"):
print(gcolor(color, style, back) + text + "\x1b[0m", end=end)
def cp(text, color="white", style=0, back=0):
print(gcolor(color, style, back) + text + "\x1b[0m")


def error(etype, line, code, specific):
cp(f"Error on line {line}:\n{code}\n{etype}: {specific}", "red")
sys.exit()

raise Aardvark.AardvarkError(etype, code, line, specific)
return Aardvark.AardvarkError(etype, code, line, specific)

Aardvark.error = error
Aardvark.AardvarkError=AardvarkError
regex = {
"ismethod":
re.compile("[\t ]*(.+)\.([A-Za-z_][a-zA-Z0-9_]*[\t ]*\(.*?\))"),
"isfunction":
re.compile("[\t ]*([A-Za-z_][a-zA-Z0-9_]*[\t ]*\(.*?\)?)"),
"defvar":
re.compile("[\t ]*([A-Za-z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*(.+?)[\t ]*"),
"isif":
re.compile("[\t ]*if [\t ]*(.+?)[\t ]*{[\t ]*"),
"iswhile":
re.compile("[\t ]*while [\t ]*(.+?)[\t ]*{[\t ]*"),
"isforin":
re.compile("[\t ]*for [\t ]*(.+) [\t ]*in [\t ]*(.+)[\t ]*{"),
"isinclude":
re.compile("[\t ]*#include [\t ]*(.+)"),
"isape":
re.compile("[\t ]*#ape [\t ]*(.+)"),
"isfunctiondefinition":
re.compile("[\t ]*funct [\t ]*(.+)\((.*)\)[\t ]*{[\t ]*"),
"ismaxmem":
re.compile("#max-memory[\t ]* (.+)"),
"isforeach":
re.compile("[\t ]*for [\t ]*each [\t ]*(.+?) [\t ]*in [\t ]*(.+?)[\t ]*{"),
"isreturn":
re.compile("[\t ]*return [\t ]*(.+?)[\t ]*"),
"iscontinue":
re.compile("[\t ]*continue [\t ]*(.+?)[\t ]*"),
"isdelete":
re.compile("[\t ]*delete [\t ]*(.+?)[\t ]*"),
"istryexcept":re.compile("[\t ]*try {"),
"iscatch":re.compile("[\t ]*catch[\t ]* [\t ]*(.+?)[\t ]*{[\t ]*")
}
2 changes: 2 additions & 0 deletions File.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ def read_file(name, file):
return file.read()
except:
error("FileOperationError", 0,f"{name}()", f"File with mode '{file.mode}' is not readable.")
def getname(file):
return file.name
8 changes: 0 additions & 8 deletions README.md

This file was deleted.

8 changes: 0 additions & 8 deletions Regex.py

This file was deleted.

Binary file modified __pycache__/Aardvark.cpython-38.pyc
Binary file not shown.
Binary file modified __pycache__/File.cpython-38.pyc
Binary file not shown.
Binary file modified __pycache__/boolean.cpython-38.pyc
Binary file not shown.
Binary file modified __pycache__/dictionaries.cpython-38.pyc
Binary file not shown.
Binary file added __pycache__/fix.cpython-38.pyc
Binary file not shown.
Binary file added __pycache__/functions.cpython-38.pyc
Binary file not shown.
Binary file modified __pycache__/list.cpython-38.pyc
Binary file not shown.
Binary file modified __pycache__/none.cpython-38.pyc
Binary file not shown.
Binary file modified __pycache__/number.cpython-38.pyc
Binary file not shown.
Binary file modified __pycache__/server.cpython-38.pyc
Binary file not shown.
Binary file modified __pycache__/stringtype.cpython-38.pyc
Binary file not shown.
Binary file modified __pycache__/timer.cpython-38.pyc
Binary file not shown.
18 changes: 0 additions & 18 deletions ape.adk

This file was deleted.

5 changes: 4 additions & 1 deletion boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ def Boolean(what, line_num):
except:
pass
number += 1
#print("END",eval(newtext))
#print(newtext,eval(newtext))
return True, eval(newtext)


@Aardvark.method("bool", "not")
def notmethod(name, boolean):
return not boolean
Empty file removed db.json
Empty file.
10 changes: 8 additions & 2 deletions dictionaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

@Aardvark.type("dictionary")
def dictionary_type(what, line_num):
what = str(what)
isdict = re.fullmatch("\{.+\}", what)
if type(what)==dict:
return True, what
what=str(what)
isdict = re.fullmatch("\{.*\}", what)
if not isdict:
return False, what
what = Aardvark.gettokens(what[1:-1], [",", ":"])
Expand Down Expand Up @@ -39,3 +41,7 @@ def dict_length_attribute(thelist):


Aardvark.addattribute("dictionary", "length", dict_length_attribute)

@Aardvark.function("makedict")
def makeDict(name):
return {}
2 changes: 0 additions & 2 deletions docs/genindex.rst

This file was deleted.

1 change: 1 addition & 0 deletions examples/chat.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Test</h1>
10 changes: 10 additions & 0 deletions examples/d.adk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include anr
#include server


message = input('> ')
message_ = input('> ')

render_string(message)
render_string(message_, '9')
run_server()
32 changes: 32 additions & 0 deletions examples/example.adk
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class NewString { /This is a recreation of the string type (with no methods)\
~reference() {
this.refcount++
}
~init(string) {
string=string.fromtoindex(1, -1)
this.length = string.length
this.refcount = 0
}
~identifier(item) {
if item.startswith("\"") and item.endwith("\""){
return True
}
if item.startswith("'") and item.endwith("'"){
return True
}
else {
return False
}
}
}

define do_this times:var "times" code:block { /This defines a new item, this one is a loop\
i=0
while i<times {
exec(code)
i=i+1
}
}
do_this 5 times {/ this is using the loop that was defined earlier \
output("it has looped")
}
8 changes: 8 additions & 0 deletions examples/f.adk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
output("start")
#include anr
funct foo() {
if 1==1 {
output('hi')
}
}
foo()
19 changes: 19 additions & 0 deletions examples/fib.adk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include anr

funct Fib(n) {
output(n)
if number(n) < 0 {
return 1
}
if number(n) == 1 {
return 2
}

n = number(n)
x = Fib(n-1)
a = Fib(n-2)
return a + x

}
a = Fib(input("enter num: "))
output(a)
7 changes: 0 additions & 7 deletions f.adk

This file was deleted.

24 changes: 0 additions & 24 deletions fib.adk

This file was deleted.

13 changes: 0 additions & 13 deletions filesystem.py

This file was deleted.

0 comments on commit 056a2d7

Please sign in to comment.