Parsing Project and Package files using Gold Parser --help needed with 'IdList'

痴心易碎 提交于 2019-12-06 02:38:57

I haven't used the Gold package myself yet, but I have used Yacc quite a bit; that has a slightly different grammar layout but the principle is the same.

For starters I would try modifying the Delphi grammar as follows:

Change

<UsesClause>        ::= USES <IdList> ';'
              | SynError

to

<UsesClause>        ::= USES <UnitList> ';'
              | SynError

and add

<UnitList>      ::= <UnitList> ',' <UnitRef>
              | <UnitRef>

<UnitRef>       ::= <RefID>
              | <RefID> IN <StringLiteral>
!                 | <RefID> in <StringLiteral> Comment Start <RefID> Comment End

The line which I've commented out using the exclamation mark was initially intended to handle this construct in your example:

  UnitDemoMain in 'UnitDemoMain.pas' {Form1},

However, it seems that Gold's Builder treats the open- and close-curly-brace characters, { }, as a special case which seems to prevent them being used as anything other than to surround comments; I've been unable to find a way of using them as part of a grammar rule. The result of this change should hopefully be that '{Form1}' is simply ignored as a comment, and the example construct matches the previous variant ("<RefID> IN StringLiteral") instead.

Fwiw, Gold looks quite a nice package, except for a few problems including

  • the restriction mentioned in the ReadMe that it can only handle characters 0..127 and

  • its Parser Builder (v.5.2) complains when running using the D7 sample grammar that comes with it (before my suggested changes) about an invalid start symbol and a lexical error on line/state 82. Maybe I've missed something ...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!