First of, I prefer functions over everything else. But I am in a situation in which I only know the correct argument AFTER the SQL statement is tokenized. I won’t bother you with the details but just know that I can’t see another solution to this problem then metaprogramming.
this is the example SQL statement:
a ="select column_2, column_3 from Table_X"
This is the Lexer
function Lexer(a::String) G = Tokenize(split_up(replace_all(a,cleaning_up))) End_List = esc(copy(G)) for i in G eval(Meta.parse(i)) end return End_List end
this is the error statement:
ERROR: UndefVarError: End_List not defined Stacktrace:  top-level scope @ none:1
End_List does not refer to
End_List in the function Lexer (as far as I can tell) but to the function that I want to evaluatie which is a string in a Token (which is a
this is what it actually lookslike once I want to evaluate it in the for loop for the first element:
This is the function to which it refers to:
function select(End_List,G, num) if End_List[num+1]== "Nothing" && occursin("comma", G[num+2]) End_List[num+1] = "COLUMN" End_List[num] = "SELECT" end end
How do I let the
eval function know that there is indeed a Vector called
End_List just outside the for-loop it is currenlty in?
I have though long about rewriting my whole code but:
- I am unsure if this is possible.
- as far as I can tell
eval is specifically made to deal with these types of situations. So I now kinda want to know what I am doing wrong.
Thanks in advance.