IllustratorのOMVをパースする

なんだかんだともう2月も半ばにかかろうとしていますが、ふりーらんすの皆様におかれましては確定申告のご準備は順調に進んでおられますでしょうか???
後回しにすると結構たいへんだと思いますのでお気をつけください。
本日お届けするのはExtendScriptのIllustrator(ver.26)のOMVデータをパースしてInDesignに自動的に処理させたものを翻訳しようとして力尽きたものです。パーサー自体は見直しを進めている途中ではありますが垂れ流しておきます。
var dc = app.activeDocument;
var st = dc.stories[0];
var sty = dc.paragraphStyles;
var f = File.openDialog("");
var tx = "";
var rt = "";
f.open("r");
while (true) if (f.readln().indexOf("package")>-1) break;
while (!f.eof)
{
tx = f.readln();
if (tx.indexOf("<classdef")>0) headderAdd(tx);
else if (tx.indexOf("<elements")>0) elementsAdd(tx);
else if (tx.indexOf("/classdef")>0) st.insertionPoints[-1].contents = "\r";
}
function headderAdd(str)
{
str.match(/"(.+?)"/);
st.insertionPoints[-1].contents = RegExp.$1 + "\r";
var tg = app.activeDocument.stories[0].paragraphs.lastItem();
tg.appliedParagraphStyle = sty.itemByName("headder1");
tx = f.readln();
if (tx.indexOf("shortdesc")>0)
{
tx.match(/>(.+?)</);
st.insertionPoints[-1].contents = " " + RegExp.$1 + "\r";
tg = app.activeDocument.stories[0].paragraphs.lastItem();
tg.appliedParagraphStyle = sty.itemByName("description");
}
}
function elementsAdd(str)
{
var pf = mf = true;
str.match(/"(.+?)"/);
st.insertionPoints[-1].contents = RegExp.$1 + "\r";
var tg = app.activeDocument.stories[0].paragraphs.lastItem();
tg.appliedParagraphStyle = sty.itemByName("cori");
while (true)
{
tx = f.readln();
if (tx.indexOf("/elements")>0) return;
if (tx.indexOf("<property")>0)
{
if (pf)
{
st.insertionPoints[-1].contents = "Properties\r";
tg = app.activeDocument.stories[0].paragraphs.lastItem();
tg.appliedParagraphStyle = sty.itemByName("pandm");
st.insertionPoints[-1].contents = "Name\tDescription\tType\tValue\r";
tg = app.activeDocument.stories[0].paragraphs.lastItem();
tg.appliedParagraphStyle = sty.itemByName("table");
pf = false;
}
parseProp(tx);
}
else if (tx.indexOf("<method")>0)
{
st.insertionPoints[-1].contents = "\r";
tg = app.activeDocument.stories[0].paragraphs.lastItem();
tg.appliedParagraphStyle = sty.itemByName("body");
if (mf)
{
st.insertionPoints[-1].contents = "Methods\r";
tg = app.activeDocument.stories[0].paragraphs.lastItem();
tg.appliedParagraphStyle = sty.itemByName("pandm");
mf = false;
}
parseMethod(tx);
}
}
}
function parseProp(str)
{
var txt = ""
if (str.match(/"(.+?)".+"(.+?)"/)!=null) txt = " " + RegExp.$1 + "(r/o)\t";
else if (str.match(/"(.+?)"/)!=null) txt = " " + RegExp.$1 + "\t";
while (true)
{
tx = f.readln();
if (tx.indexOf("/property")>0) break;
else if (tx.indexOf("shortdesc")>0)
{
tx.match(/>(.+?)</);
txt += RegExp.$1 + "\t";
}
else if (tx.indexOf("<type>")>0)
{
tx.match(/>(.+?)</);
txt += RegExp.$1 + "\t";
}
else if (tx.indexOf("<value>")>0)
{
tx.match(/>(.+?)</);
txt += RegExp.$1;
}
}
st.insertionPoints[-1].contents = " ";
tg = app.activeDocument.stories[0].paragraphs.lastItem();
tg.appliedParagraphStyle = sty.itemByName("table");
tg.contents = txt + "\r";
return;
}
function parseMethod(str)
{
var txt = "", tg;
str.match(/"(.+?)"/)
st.insertionPoints[-1].contents = " " + RegExp.$1 + "\r";
tg = app.activeDocument.stories[0].paragraphs.lastItem();
tg.appliedParagraphStyle = sty.itemByName("bold");
while (true)
{
tx = f.readln();
if (tx.indexOf("/method")>0) return;
else if (tx.indexOf("shortdesc")>0)
{
tx.match(/>(.+?)</);
st.insertionPoints[-1].contents = RegExp.$1 + "\r";
tg = app.activeDocument.stories[0].paragraphs.lastItem();
g.appliedParagraphStyle = sty.itemByName("s-description");
}
else if (tx.indexOf("<parameters>")>0)
{
getParams();
}
else if (tx.indexOf("<datatype>")>0)
{
tx = f.readln();
tx.match(/<type>(.+?)</);
st.insertionPoints[-1].contents = " ■Result/" + RegExp.$1 + "\r";
tg = app.activeDocument.stories[0].paragraphs.lastItem();
tg.appliedParagraphStyle = sty.itemByName("body");
}
}
}
function getParams()
{
st.insertionPoints[-1].contents = " Parameters\r";
tg = app.activeDocument.stories[0].paragraphs.lastItem();
tg.appliedParagraphStyle = sty.itemByName("pandm");
while (true)
{
tx = f.readln();
if (tx.indexOf("</parameter>")>0) continue;
if (tx.indexOf("</parameters>")>0) return;
if (tx.indexOf("<parameter")>0)
{
tx.match(/"(.+?)"/);
st.insertionPoints[-1].contents = RegExp.$1 + "\r";
tg = app.activeDocument.stories[0].paragraphs.lastItem();
tg.appliedParagraphStyle = sty.itemByName("methodname");
}
if (tx.indexOf("<shortdesc>")>0)
{
tx.match(/>(.+?)</);
st.insertionPoints[-1].contents = RegExp.$1 + "\r";
tg = app.activeDocument.stories[0].paragraphs.lastItem();
tg.appliedParagraphStyle = sty.itemByName("s-description");
}
if (tx.indexOf("<type>")>0)
{
tx.match(/>(.+?)</);
st.insertionPoints[-1].contents = " Type : " + RegExp.$1 + "\r";
tg = app.activeDocument.stories[0].paragraphs.lastItem();
tg.appliedParagraphStyle = sty.itemByName("body");
}
}
return;
}
と、まあ、こんな感じなのですが、諸般の都合でXMLをパースせずに頭から順番にファイルを読み込んで判断している代物です。ですから、コロコロ細かい変更を常に続けるかと思います。
そうして出来上がったのがこちら。
https://shared-assets.adobe.com/link/da8c0cf2-3ab5-451a-5163-f4f7de1ca15c
macOSではOMV Viewerが既にありませんので、こうして参照可能になるのも意味がある事かと思います。