Last active
January 30, 2020 08:06
-
-
Save Oldes/70a8e8c2d9e7e96645ba00c1a754b6ac to your computer and use it in GitHub Desktop.
Just a parse example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [] | |
whitespace: charset reduce [space tab cr lf] | |
ws: [any whitespace] | |
rule-object: [ | |
ws <purchaseObject> [ | |
ws <OKPD2> [ | |
ws <code> copy *cd to "<" </code> | |
ws <name> copy *nm to "<" </name> | |
] | |
ws </OKPD2> | |
ws opt [<currency> thru </currency>] ;- currency is not used | |
ws <price> thru </price> ;- price is not used | |
( append purchases object [code: *cd name: *nm] ) | |
] | |
ws </purchaseObject> ws | |
] | |
rule-lot: [ | |
(purchases: copy []) | |
ws <maxPrice> copy *mp to "<" </maxPrice> | |
ws <purchaseObjects> any rule-object </purchaseObjects> | |
ws | |
] | |
parse-purchases: function[ | |
file [string! file! url!] | |
][ | |
if any [file? file url? file] [ file: read file ] | |
parse file [ | |
(data: none) | |
ws | |
<root> [ | |
ws <id> copy *id to "<" </id> | |
ws <purchaseNumber> copy *pn to "<" </purchaseNumber> | |
ws <lot> rule-lot </lot> | |
( | |
data: object [ | |
id: *id | |
lots: object [ | |
maxPrice: *mp | |
purchaseObjects: purchases | |
] | |
] | |
) | |
] | |
ws | |
</root> | |
] | |
data | |
] | |
file: {<root> | |
<id>19160099</id> | |
<purchaseNumber>0373200101018000262</purchaseNumber> | |
<lot> | |
<maxPrice>8186313.66</maxPrice> | |
<purchaseObjects> | |
<purchaseObject> | |
<OKPD2> | |
<code>11.131.11</code> | |
<name>Foo111</name> | |
</OKPD2> | |
<currency> | |
<code>666</code> | |
</currency> | |
<price>111</price> | |
</purchaseObject> | |
<purchaseObject> | |
<OKPD2> | |
<code>22.12.55</code> | |
<name>Bar222</name> | |
</OKPD2> | |
<price>222</price> | |
</purchaseObject> | |
<purchaseObject> | |
<OKPD2> | |
<code>33.322.41</code> | |
<name>Baz333</name> | |
</OKPD2> | |
<price>333</price> | |
</purchaseObject> | |
</purchaseObjects> | |
</lot> | |
</root>} | |
data: parse-purchases file | |
if data [ | |
print to-json/pretty data " " | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment