[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Server Side Includes/HTML + scripting



Hi,

Can someone please give me some tips on how I might implement a parser
for a program that processes server side includes (SSI) or a mini
language that can be interspersed throughout an HTML file?

E.g. for SSI:

<!--#exec cmd="/bin/foo"-->
<p>Hi. Document root is: <!--#var name="$DOCUMENT_ROOT"--></p>

<!--#if expr="$foo == $bar" -->
   <h3>My homepage</h3>
<!--#else -->
   <h3>My new homepage</h3>
<!--#endif -->

... or very similar to this.

For something like PHP or ASP:

<%
	statments...
%>

<%= var %>	; Direct output

<% if foo.length() > 0 then %>
	<b>foo's length is greater than 0!</b>
<% endif %>

The programming commands can mix in with the HTML by having the
statments inside special tags the parser picks up.  It would need to
associate the next block of HTML with the tag if it's a conditional,
otherwise it gets sent out after processing the command tag(s).

I'm not exactly sure how I could do this. The nodes that get built after
the parser builds the parse tree might have a link to a node that holds
HTML to output.  It would need to be able to find the extra nodes that
it wants to end if statements and such, so it can skip elseif parts. 
Similar for looping constructs.

Node: <% stuff %>
HTMLNode (just print it out)
Node: <%= varname %>
HTMLNode (just print it out)
Node: <% morestuff %>

Any ideas for a grammar that I can make with SableCC?

Thanks,
James