How to build a new grammer for pg?

Started by jacktbyover 2 years ago6 messages
#1jacktby
jacktby@gmail.com

<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
</head>
<body>
<style>
font{
line-height: 1.6;
}
ul,ol{
padding-left: 20px;
list-style-position: inside;
}
</style>
<div style = 'font-family:Helvetica,Helvetica,微软雅黑, 宋体; line-height:1.6;'>
<div ></div><div>
<div>
<span>
<br>
</span>
</div>
<div>
<span style="font-family: Helvetica, Helvetica, 微软雅黑, 宋体;">Hi, I’m trying to develop a new grammar for pg, can you give me a code example to reference?</span><span>
<br>
</span>
</div>
<div id="ntes-pcmac-signature" style="font-family:'Helvetica','Microsoft Yahei', '微软雅黑'">

<div style="font-size:14px; padding: 0; margin:0;line-height: 14px;">
<div style="padding-bottom:6px;margin-bottom:10px;display:inline-block;">
<a href="https://dashi.163.com/projects/signature-manager/detail/index.html?ftlId=1&amp;amp;name=jacktby&amp;amp;uid=jacktby%40gmail.com&amp;amp;iconUrl=https%3A%2F%2Fmail-online.nosdn.127.net%2Fqiyelogo%2FdefaultAvatar.png&amp;amp;items=%5B%22jacktby%40gmail.com%22%5D&quot; style="display:block;background:#fff; max-width: 400px; _width: 400px;padding:15px 0 10px 0;text-decoration: none; outline:none;-webkit-tap-highlight-color:transparent;-webkit-text-size-adjust:none !important;text-size-adjust:none !important;">
<table cellpadding="0" style="width: 100%; max-width: 100%; table-layout: fixed; border-collapse: collapse;color: #9b9ea1;font-size: 14px;line-height:1.3;-webkit-text-size-adjust:none !important;text-size-adjust:none !important;">
<tbody style="font-family: 'PingFang SC', 'Hiragino Sans GB','WenQuanYi Micro Hei', 'Microsoft Yahei', '微软雅黑', verdana !important; word-wrap:break-word; word-break:break-all;-webkit-text-size-adjust:none !important;text-size-adjust:none !important;">
<tr class="firstRow">
<td width="38" style="padding:0; box-sizing: border-box; width: 38px;">
<img width="38" height="38" style="vertical-align:middle; width: 38px; height: 38px; border-radius:50%;" src="https://mail-online.nosdn.127.net/qiyelogo/defaultAvatar.png&quot;&gt;
</td>
<td style="padding: 0 0 0 10px; color: #31353b;">
<div style="font-size: 16px;font-weight:bold; width:100%; white-space: nowrap; overflow:hidden;text-overflow: ellipsis;">jacktby</div>
</td>
</tr>
<tr width="100%" style="font-size: 14px !important; width: 100%;">
<td colspan="2" style="padding:10px 0 0 0; font-size:14px !important; width: 100%;">
<div style="width: 100%;font-size: 14px !important;word-wrap:break-word;word-break:break-all;">jacktby@gmail.com</div>
</td>
</tr>
</tbody>
</table>
</a>
</div>
</div>
</div>
<br>
</div><!--�-->
</div>
</body>
</html>

#2Julien Rouhaud
rjuju123@gmail.com
In reply to: jacktby (#1)
Re: How to build a new grammer for pg?

Hi,

On Tue, Aug 01, 2023 at 07:36:36PM +0800, jacktby wrote:

<span style="font-family: Helvetica, Helvetica, 微软雅黑, 宋体;">Hi, I’m trying to develop a new grammar for pg, can

+you give me a code example to reference?</span><span>

It's unclear to me whether you want to entirely replace the flex/bison parser
with something else or just add some new bison rule.

If the latter, it really depends on what you change to achieve exactly. I
guess you could just look at the gram.y git history until you find something
close enough to your use case and get inspiration from that.

#3Chapman Flack
chap@anastigmatix.net
In reply to: Julien Rouhaud (#2)
Re: How to build a new grammer for pg?

On 2023-08-01 07:58, Julien Rouhaud wrote:

On Tue, Aug 01, 2023 at 07:36:36PM +0800, jacktby wrote:

Hi, I’m trying to develop a new grammar for pg

It's unclear to me whether you want to entirely replace the flex/bison
parser
with something else or just add some new bison rule.

Or express a grammar matching PG's in some other parser-generator
language, to enable some other tool to parse PG productions?

Regards,
-Chap

#4Andrew Dunstan
andrew@dunslane.net
In reply to: Chapman Flack (#3)
Re: How to build a new grammer for pg?

On 2023-08-01 Tu 12:50, Chapman Flack wrote:

On 2023-08-01 07:58, Julien Rouhaud wrote:

On Tue, Aug 01, 2023 at 07:36:36PM +0800, jacktby wrote:

Hi, I’m trying to develop a new grammar for pg

It's unclear to me whether you want to entirely replace the
flex/bison parser
with something else or just add some new bison rule.

Or express a grammar matching PG's in some other parser-generator
language, to enable some other tool to parse PG productions?

Or to enable some language other than SQL (QUEL anyone?)

cheers

andrew

--
Andrew Dunstan
EDB:https://www.enterprisedb.com

#5Jonah H. Harris
jonah.harris@gmail.com
In reply to: Andrew Dunstan (#4)
Re: How to build a new grammer for pg?

On Tue, Aug 1, 2023 at 3:45 PM Andrew Dunstan <andrew@dunslane.net> wrote:

Or to enable some language other than SQL (QUEL anyone?)

A few years ago, I got a minimal POSTQUEL working again to release as a
patch for April Fools' Day, which I never did. I should dig that up
somewhere :)

Anyway, as far as OP's original question regarding replacing the grammar,
there are a couple of such implementations floating around that have done
that. But, I actually think the pluggable parser patches were good examples
of how to integrate a replacement parser that generates the expected parse
tree nodes for anyone who wants to do their own custom parser. See Julien
Rouhaud's SQLOL in the "Hook for extensible parsing" thread and Jim
Mlodgenski's "Parser Hook" thread.

--
Jonah H. Harris

#6Hannu Krosing
hannuk@google.com
In reply to: Jonah H. Harris (#5)
Re: How to build a new grammer for pg?

I would look at how Babelfish DB did it when adding SQL Server compatibility

https://babelfishpg.org/ and https://github.com/babelfish-for-postgresql/

another source to inspect could be
https://github.com/IvorySQL/IvorySQL for "oracle compatible
PostgreSQL"

Show quoted text

On Tue, Aug 1, 2023 at 10:07 PM Jonah H. Harris <jonah.harris@gmail.com> wrote:

On Tue, Aug 1, 2023 at 3:45 PM Andrew Dunstan <andrew@dunslane.net> wrote:

Or to enable some language other than SQL (QUEL anyone?)

A few years ago, I got a minimal POSTQUEL working again to release as a patch for April Fools' Day, which I never did. I should dig that up somewhere :)

Anyway, as far as OP's original question regarding replacing the grammar, there are a couple of such implementations floating around that have done that. But, I actually think the pluggable parser patches were good examples of how to integrate a replacement parser that generates the expected parse tree nodes for anyone who wants to do their own custom parser. See Julien Rouhaud's SQLOL in the "Hook for extensible parsing" thread and Jim Mlodgenski's "Parser Hook" thread.

--
Jonah H. Harris