SQLite Forum

Lemon SQL output omition
Looking at using the sql output of lemon to generate the railroad diagram from the parser I noticed that lemon is omitting info from the rhs side of rules that have '|' like this rule from sqlite3/src/parse.y:

cmd ::= COMMIT|END(X) trans_opt. 

The lemon SQL output:
INSERT INTO rule(ruleid,lhs,txt)VALUES(8,189,'cmd ::= COMMIT|END trans_opt');
INSERT INTO rulerhs(ruleid,pos,sym)VALUES(8,0,10);
-- here somehow the '|' should be present
INSERT INTO rulerhs(ruleid,pos,sym)VALUES(8,0,11);
INSERT INTO rulerhs(ruleid,pos,sym)VALUES(8,1,191);

I noticed it when trying this query over the lemon SQL output for sqlite3/src/parse.y:

select name || ' ::= ' || group_concat(rhs, '
from (
	select id, name, group_concat(ifnull(rhs_name, '/* empty */'), ' ') as rhs
	from (
		select symbol.id, symbol.name, rule.ruleid, rulerhs.pos, rulerhs.sym, s2.name as rhs_name
		from symbol
			left join rule on symbol.id=rule.lhs
			left join rulerhs on rule.ruleid=rulerhs.ruleid
			left join symbol as s2 on rulerhs.sym=s2.id
		where symbol.isTerminal=0
		order by symbol.id, rule.ruleid, rulerhs.pos
	) as tbl
	group by id, ruleid
) as tbl2
group by id

Partial query output:
input ::= cmdlist
cmdlist ::= cmdlist ecmd
ecmd ::= SEMI
	|cmdx SEMI
	|explain cmdx SEMI
cmdx ::= cmd
explain ::= EXPLAIN
cmd ::= BEGIN transtype trans_opt
	|COMMIT END trans_opt //!! here the '|' is missing
	|ROLLBACK trans_opt