私は、PLY や OBJ などの 3D ファイル形式用の単純なインポーターをいくつか作成しました。これらは、非常に状態ベースの行ごとの構造を持ち、解析を非常に簡単にしているようです。私の友人は、Python を使用して mirai からファイル タイプの単純なインポーターを実装するように求めていました。私は以前に使用した単純な行ごとの形式とは異なり、階層的に表現されたデータがたくさんあることに気付きました。
Python ライブラリ、複雑な正規表現を使用して、このための完全な文法を作成する必要があるのか 、それとも文字列置換を使用してソリューションをハックする必要があるのか 疑問に思っていました。このタイプのファイルを解析するための良い提案を誰かが提供できますか? この特定の例は、エクスポートされたキューブです。
filetype gx;
GrammarVersion 2.1.0.0;
TemplateVersion 2.1.0.0;
HostName "ZOO-HP";
UserName "Phil";
TimeStamp "Mon 20-Aug-12, 9:48 pm";
OSName "Windows NT 6.01.7601";
ApplicationName "Mirai";
ApplicationVersion "1.1.0.1 5629";
include "gbf-2-1-0-0.tpl";
include "cube_mirai.gmf";
body Polyhedron-31 (
vertices[] < (
coord -0.500000 -0.500000 0.500000 ;
)
(
coord -0.500000 0.500000 0.500000 ;
)
(
coord 0.500000 0.500000 0.500000 ;
)
(
coord 0.500000 -0.500000 0.500000 ;
)
(
coord 0.500000 -0.500000 -0.500000 ;
)
(
coord 0.500000 0.500000 -0.500000 ;
)
(
coord -0.500000 0.500000 -0.500000 ;
)
(
coord -0.500000 -0.500000 -0.500000 ;
)
>
faces[] < (
normal 0.000000 0.000000 1.00000 ;
vertex-indices[] <0;1;2;3;>
vertex-normal-indices[] <0;1;2;3;> )
(
normal 0.000000 0.000000 -1.00000 ;
vertex-indices[] <4;5;6;7;>
vertex-normal-indices[] <4;5;6;7;> )
(
normal 0.000000 1.00000 0.000000 ;
vertex-indices[] <1;6;5;2;>
vertex-normal-indices[] <1;6;5;2;> )
(
normal 0.000000 -1.00000 0.000000 ;
vertex-indices[] <7;0;3;4;>
vertex-normal-indices[] <7;0;3;4;> )
(
normal 1.00000 0.000000 0.000000 ;
vertex-indices[] <3;2;5;4;>
vertex-normal-indices[] <3;2;5;4;> )
(
normal -1.00000 0.000000 0.000000 ;
vertex-indices[] <7;6;1;0;>
vertex-normal-indices[] <7;6;1;0;> )
>
normals[] <-0.577350 -0.577350 0.577350 ;
-0.577350 0.577350 0.577350 ;
0.577350 0.577350 0.577350 ;
0.577350 -0.577350 0.577350 ;
0.577350 -0.577350 -0.577350 ;
0.577350 0.577350 -0.577350 ;
-0.577350 0.577350 -0.577350 ;
-0.577350 -0.577350 -0.577350 ;
>
)