3

私は、パーサージェネレーターとしてANTLRを選択したかなり標準的なコンパイラプロジェクトに取り組んでいます。既存の文法をv2からv3に更新しているときに、ANTLRの公式IDEであるANTLRWorksがファイル内の拡張ASCII文字を正しく表示していないことに気付きました。Notepad ++を使用してファイルをASCIIからUTF8に変換した後でも、それらの文字は正方形として表示されました。Notepad ++では、正常に表示されます。

このグリッチは、保存時にANTLRWorksがファイルを破損することを意味するため、エディターとして使用できなくなり、かなり面倒です。ここにいる他の誰かがこの問題に遭遇し、おそらくそれを解決しましたか?とても感謝しております。

[編集]:特定の問題は、最新バージョンのANTLRWorks(昨日ダウンロード)およびhttp://www.antlr.org/grammar/1086696923011/vhdlams/index.htmlから取得したvams.g文法ファイルで発生します。

4

1 に答える 1

2

I cannot reproduce this with ANTLRWorks 1.4.3.

If I create a dummy grammar:

grammar T;
parse : . ;
Any   : . ;

and paste the complete extended ASCII set in a multi-line comment:

grammar T;

/*
€

‚
ƒ

...

ÿ
*/

parse : . ;
Any   : . ;

there's no problem. It doesn't matter if I copy the chars with ANTLRWorks, or with a normal editor and then edit the existing grammar with ANTLRWorks: the characters all stay the same after saving inside ANTLRWorks.

On a related note: the versions ANTLR 3.0 to 3.3 still have some dependencies with ANTLR 2.7 classes which might cause the org.antlr.Tool to trip over certain characters outside the ASCII set. Use ANTLR 3.4 in that case, which doesn't have these old dependencies anymore.

EDIT

I suspect there's some odd byte in the original grammar somewhere that is causing all the mayhem. I quickly copied only the rules from the original grammar, changed all v2.7 syntax to v3 syntax (changed double quoted literals to single quoted ones, protected became fragment and commented some custom code) and saved it in a new file. This file could be opened (and saved) by ANTLRWorks or a plain text editor without causing it to mangle the extended ASCII chars.

Here is the ANTLR v3 version of said grammar: http://pastebin.com/zU4xcvXt (the grammar is too big to post on SO...)

EDIT II

Is the grammar name useful for anything beyond just giving it a label?

No, it's not. It's, as you mentioned, only used to give a parser or lexer a name.

There are 4 types of grammars in ANTLR:

  • combined grammar, which looks like grammar T;, generating TLexer.java and TParser.java source files;
  • parser grammar, looking like parser grammar TP;, generating a TP.java source file;
  • lexer grammar, looking like lexer grammar TL;, generating a TL.java source file;
  • tree grammar, looking like tree grammar TWalker, generating a TWalker.java source file.
于 2011-12-04T09:16:36.860 に答える