I'm wanting to integrate jison into a wiki parser with both a php and a
javascript parser, one for WYSIWYG editing, and the other for page parsing.
One of the problems I'm having though it that in the wiki page there are
plugins that use this type of syntax:
Example of plugin with body:
{PLUGIN(var1="test" var2="test")}
Plugin body
{PLUGIN}
Example of plugin without body:
{plugin var1="test" var2="test" /}
The problem that I'm having is that in the first example, there can be
nested plugins, how can I tell jison to match the opening plugin syntax with
the closing syntax?
--
Robert Plummer
Here's a draft grammar. The lexer uses a stack to keep track of open
plugin tags:
%lex
PLUGIN_ID [A-Z]+
%%
"{"{PLUGIN_ID}"(".*?")}" %{ if (!yy.pluginStack) yy.pluginStack = [];
yy.pluginStack.push(yytext.match(/^\{([A-Z]+)/)[1])
return 'PLUGIN_START'
%}
"{"{PLUGIN_ID}"}" %{ if (yy.pluginStack &&
yy.pluginStack.length &&
yytext.match(yy.pluginStack[yy.pluginStack.length-1])) {
yy.pluginStack.pop();
return 'PLUGIN_END';
} else {
return 'CONTENT';
}
%}
(.|\n)+?/("{"{PLUGIN_ID}) return 'CONTENT'
(.|\n)+ return 'CONTENT'
<<EOF>> return 'EOF'
/lex
%%
wiki
: wiki_contents EOF
;
wiki_contents
:
| content
| wiki_contents PLUGIN_START wiki_contents PLUGIN_END
| wiki_contents PLUGIN_START wiki_contents PLUGIN_END content
;
content
: CONTENT
| content CONTENT
;
On Thu, Jul 28, 2011 at 11:41 AM, Robert Plummer
<robertleeplummerjr@gmail.com> wrote:
>
> I'm wanting to integrate jison into a wiki parser with both a php and a
javascript parser, one for WYSIWYG editing, and the other for page
parsing. One of the problems I'm having though it that in the wiki page
there are plugins that use this type of syntax:
> Example of plugin with body:
> {PLUGIN(var1="test" var2="test")}
> Plugin body
> {PLUGIN}
>
> Example of plugin without body:
> {plugin var1="test" var2="test" /}
>
>
> The problem that I'm having is that in the first example, there can be
nested plugins, how can I tell jison to match the opening plugin syntax
with the closing syntax?
> --
> Robert Plummer
--
Zach Carter
How do you accept payment? On Sun, Jul 31, 2011 at 12:54 AM, Zachary Carter <zack.carter@gmail.com>wrote: > Here's a draft grammar. The lexer uses a stack to keep track of open > plugin tags: > > > %lex > > PLUGIN_ID [A-Z]+ > > %% > > "{"{PLUGIN_ID}"(".*?")}" %{ if (!yy.pluginStack) yy.pluginStack = > []; > > yy.pluginStack.push(yytext.match(/^\{([A-Z]+)/)[1]) > return 'PLUGIN_START' > %} > "{"{PLUGIN_ID}"}" %{ if (yy.pluginStack && > yy.pluginStack.length && > > yytext.match(yy.pluginStack[yy.pluginStack.length-1])) { > yy.pluginStack.pop(); > return 'PLUGIN_END'; > } else { > return 'CONTENT'; > } > %} > (.|\n)+?/("{"{PLUGIN_ID}) return 'CONTENT' > (.|\n)+ return 'CONTENT' > <<EOF>> return 'EOF' > > /lex > > %% > > wiki > : wiki_contents EOF > ; > > wiki_contents > : > | content > | wiki_contents PLUGIN_START wiki_contents PLUGIN_END > | wiki_contents PLUGIN_START wiki_contents PLUGIN_END content > ; > > content > : CONTENT > | content CONTENT > ; > > > On Thu, Jul 28, 2011 at 11:41 AM, Robert Plummer > <robertleeplummerjr@gmail.com> wrote: > > > > I'm wanting to integrate jison into a wiki parser with both a php and a > javascript parser, one for WYSIWYG editing, and the other for page parsing. > One of the problems I'm having though it that in the wiki page there are > plugins that use this type of syntax: > > Example of plugin with body: > > {PLUGIN(var1="test" var2="test")} > > Plugin body > > {PLUGIN} > > > > Example of plugin without body: > > {plugin var1="test" var2="test" /} > > > > > > The problem that I'm having is that in the first example, there can be > nested plugins, how can I tell jison to match the opening plugin syntax with > the closing syntax? > > -- > > Robert Plummer > > > > -- > Zach Carter > -- Robert Plummer