Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
Need to fix some things
Browse files Browse the repository at this point in the history
  • Loading branch information
Arghnews committed Feb 13, 2017
1 parent 4385429 commit 347965b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
33 changes: 28 additions & 5 deletions baba.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
Token = collections.namedtuple('Token', ['type', 'value', 'line', 'column'])

def tokenize(code):
code = code.replace("\t"," ")
code = code.replace(" "," ")
keywords = ["and","break","do","else","elseif","end","false",
"for","function","if","in","local","nil","not","or",
"repeat","return","then","true","until","while"]
Expand Down Expand Up @@ -89,6 +91,13 @@ def tokenize(code):

firstSets = dict()

errors_switch = True

def error(err):
global errors_switch
if errors_switch:
print(err)

def parse(fname):

firstSets["binop"] = [('+',MATCH_VALUE), ('-',MATCH_VALUE), ('*',MATCH_VALUE), ('/',MATCH_VALUE), ('^',MATCH_VALUE), ('%',MATCH_VALUE), '..', ('<',MATCH_VALUE), '<=', ('>',MATCH_VALUE), '>=', '==', '~=', 'and', 'or']
Expand Down Expand Up @@ -126,10 +135,16 @@ def parse(fname):
print(i,t)
print("Now the program starts fo real")
i = 0



i_b = i
i, tokens = doIt(i, tokens)
print("Output:",[str(t.type)+": "+str(t.value) for t in tokens[i_b:i]])


def doIt(i, tokens):
i, tokens = chunk(i, tokens)
print("I at:",i)
i, tokens = matchTypeNow(i, tokens, "EOF")
return i, tokens

def exp_p(i, tokens):
i, tokens = optional(i, tokens, [(binop,MATCH_FUNCTION),(exp,MATCH_FUNCTION),(exp_p,MATCH_FUNCTION)], 1)
Expand Down Expand Up @@ -196,8 +211,11 @@ def stat(i, tokens):
i, tokens = optional(i, tokens, [("else",MATCH_VALUE),(block,MATCH_FUNCTION)], 1)
i, tokens = matchValueNow(i, tokens, "end")
elif contains(i, tokens, [("for",MATCH_VALUE)]):
print("Start of for:",tokens[i],i)
i, tokens = matchValueNow(i, tokens, "for")
i, tokens = stat_for(i, tokens)
print("End of for:",tokens[i],i)
error("Ahhhh")
elif contains(i, tokens, [("function",MATCH_VALUE)]):
i, tokens = matchValueNow(i, tokens, "function")
i, tokens = funcname(i, tokens)
Expand Down Expand Up @@ -226,10 +244,13 @@ def block(i, tokens):
return i, tokens

def chunk(i, tokens):
my_i = i
print("Chunk called with i as",i,"(",my_i,")")
i, tokens = star(i, tokens, [(stat,MATCH_FUNCTION),
(optional_curry([(";",MATCH_VALUE)],1),MATCH_FUNCTION)], 1)
i, tokens = optional(i, tokens, [(laststat,MATCH_FUNCTION),
(optional_curry([(";",MATCH_VALUE)],1),MATCH_FUNCTION)], 1)
print("Chunk finishing with i as",i,"(",my_i,")")
return i, tokens

def laststat(i, tokens):
Expand Down Expand Up @@ -400,8 +421,6 @@ def parlist(i, tokens):
elif contains(i, tokens, [("Name",MATCH_TYPE)]):
i, tokens = namelist(i, tokens)
i, tokens = optional(i, tokens, [(",",MATCH_VALUE),("...",MATCH_VALUE)], 2)
else:
print("This is not the parlist you've been looking for")

return i, tokens

Expand Down Expand Up @@ -474,6 +493,8 @@ def f(i, tokens):

# lookahead function right here
def lookahead(i, tokens, func_tuples, lookahead_n):
global errors_switch
errors_switch = False
for j in range(0, min(len(func_tuples),lookahead_n)):
b = False
if func_tuples[j][1] == MATCH_VALUE:
Expand All @@ -483,7 +504,9 @@ def lookahead(i, tokens, func_tuples, lookahead_n):
elif func_tuples[j][1] == MATCH_FUNCTION:
b = i_changed(i+j, tokens, func_tuples[j][0])
if not b:
errors_switch = True
return False
errors_switch = True
return True

def i_changed(i, tokens, f):
Expand Down
25 changes: 24 additions & 1 deletion example.lua
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
print ("Hello World!")
local cookie = {}
local remy = require "remy"

function cookie.set(r, key, value, path)
path = path or "/"
if remy.detect(r) == remy.MODE_CGILUA then
local ck = require "cgilua.cookies"
return ck.set(key,value,{path=path})
end
r.headers_out['Set-Cookie'] = ("%s=%s;Path=%s;"):format(key, value, path)
end

function cookie.get(r, key)
local remy_mode = remy.detect(r)
if remy_mode == remy.MODE_CGILUA then
local ck = require "cgilua.cookies"
return ck.get(key)
elseif remy_mode == remy.MODE_LWAN then
return r.native_request:cookie(key)
end
return (r.headers_in['Cookie'] or ""):match(key .. "=([^;]+)") or ""
end

return cookie

0 comments on commit 347965b

Please sign in to comment.