Previous Entry Share Next Entry
Please Parse the Source
2012
unknownj
See the pun there? Clever, isn't it. OK, so not that clever. Anyhow, the point is this - I've been thinking about my parser thing (Ben's idea, but hey...). A quick warning - this is quite a technical post - most readers of my journal won't understand it (I'm not sure if even I do, and I wrote it).... Hope you get what I mean Ben, and anybody else who cares :o)

The main feature of it is that it would be multi layered. By that, I mean you would have several levels of code, which it would execute one at a time, running from the top of the page to the bottom. It's very hard to explain what I mean, or indeed why I need it, but here's a scenario for you.

I have a context sensitive menu to the right of a page. I want to populate it with links, which are generated by a server-side VBScript, which runs something akin to:

For linkNumber = 1 to totalLinks
%>

General Link Layout Here

<%

Now, I can do this. However, I then want an include file somewhere to name all these links, give the addresses they point to (which may be manipulated by other code first), and also tell the script above how many links to include. So our general link format must be something like:

<A HREF="(link page)(arguments)">(Link Name)</a>

So, we have our (link page) variable, our (arguments) variable, and our (link name) variable. Now, in theory, I'd like to work this with either an array, or just a number of different variables which act in the same way. Since it's simpler, I'll go with the latter. So the links would look something like

<A HREF="(link page 1)(arguments 1)">(Link Name 1)</a>
<A HREF="(link page 2)(arguments 2)">(Link Name 2)</a>
<A HREF="(link page 3)(arguments 3)">(Link Name 3)</a>

However, here's the problem. The thing is that (link page #) is a variable. When the parser reaches it, it'll try to evaluate it. I can't let it work that way, since it'll evaluate the variable as it populates the list of links. What I want is for it to populate the list of links, and to increment the number inside the call to the variable as it does it. Here's an example of what I mean - rather than fiddle with the GT and LT codes, I'll use brackets to denote my tags

<%1

For linkNumber = 1 to totalLinks

%1>

<a href="<%2=linkpage<%1=linkNumber%1>%2><%2=linkargs<%1=linkNumber%1>%2>"> <%2=linkname<%1=linkNumber%1>%2> </a>

<%1
Next
%1>

Now, what this would do is quite complex, yet very simple at the same time. First, it would execute all code within <%1 and %1> tags, to generate an intermediate UJML page. Assuming a totalLinks value of 5, that page would then look like this:

<a href="<%2=linkpage1%2><%2=linkargs1%2>"> <%2=linkname1%2> </a>
<a href="<%2=linkpage2%2><%2=linkargs2%2>"> <%2=linkname2%2> </a>
<a href="<%2=linkpage3%2><%2=linkargs3%2>"> <%2=linkname3%2> </a>
<a href="<%2=linkpage4%2><%2=linkargs4%2>"> <%2=linkname4%2> </a>
<a href="<%2=linkpage5%2><%2=linkargs5%2>"> <%2=linkname5%2> </a>

The page then executes all code within <%2 and %2> tags. It therefore then replaces all the variables above with their values, as predefined in another include file. This is just one example of where this could be used... Another feature of it would be the ability to insert include references into different layers...

At present, ASP (which is what I use, I'm sure other things do it different, but...) will include all the files, and then execute script. This is not what I want it to do. I want it to include all level 1 includes, then execute the script between <%1 and %1>. After that, it would then include all level 2 includes, and run this process through those. After that was done, it'd then move onto the <%2 and %2> code. Basically, the whole process is highly recursive, and as such I can't write about it much. But you get the idea - putting includes to be included at different stages of execution. That way, if you have files include1.inc up to include9.inc, you could in theory have the following code:

<%1
Randomize
intRandNum = 1 + int(9 * Rnd)
%1>

<!--2#include file ="include<%1=intRandNum%1>.inc"-->

The code would then include this level 2 file after determining the random number, and inserting it into the place of the variable call to it. If you see what I mean. Anyhow, that's all for now - tell me what you think.

  • 1
Please odn't let the music be a reflextion of your thoughts
;-)


Righty. If I have understood this correctly, you essentially want to run the code through a parser x times. First time all of i is dealt with, second time all i+1 varibles, etc

If this is what you mean, it's quite complex, but stupidly simple

I think

You're right, I didn't understand a bloody bit of that. Thank you so much for making me feel totally blonde, James. ;-)

I did think 'please parse the source' was pretty witty, though. ;-)

Aww, you're not blonde really, don't worry ;o)

*hug*

*choking with laughter*

*HOOT!*

You're adorable! *chortling*

Now this I won't try to contradict... But I would like to ammend your statement to include yourself as well :o)

*swoon*

Flaming hell, James, can't you clone yourself into a 30ish Canadian bloke? ;-)

Sorry, I only come in the 19 year old British variety, take me or leave me ;o)

*thinks about this*

Well, if you insist....

*POUNCE*

  • 1
?

Log in

No account? Create an account