Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Parse Problem

 [1/7] from: louisaturk::coxinet::net at: 29-Oct-2001 15:21


Friends, Why doesn't the following program work? It should find field/1 in ibidem and replace it with field/2 (see Modify the String in the Parsing section of the Users Guide). Louis REBOL[ Title: "Ibidem2BibTeX" Date: 29-Oct-2001 Version: 0.1 File: %Ibidem2BibTeX.r Author: "Louis A. Turk" Email: [louisaturk--eudoramail--com] Language: 'English Purpose: "Converts NBWin Ibidem files to BibTeX format." Comments: {Be sure to compact your Ibidem data file before using this program.} ] ibidems: parse/all read %turk.bib "¶" fields: [ ["AU:" "author = "] ["ST:" "Short Work Title = "] ["BT:" "Long Work Title = "] ] foreach field fields [ foreach ibidem ibidems [ ;if find ibidem field/1 [print field/1] ; THIS LINE WORKS parse ibidem [any [to field/1 mark: (change mark field/2) skip]] ;WHAT'S WRONG WITH THIS LINE? print ibidem ] ] I get the following error message:
>> do %ibidem2bibtex.r
** Script Error: Invalid argument: field/1 ** Where: halt-view ** Near: parse ibidem [some [to field/1 mark: (change mark field/2) skip]] print ibidem
>>
The file %turk.bib contains data in the following format: R#:9¶ AU:Antonio, Gene¶ BT:AIDS: rage & reality---why silence is deadly¶ BC:Feldschuh, Joseph, M.D. <foreword by>¶ PL:Dallas¶ PR:Anchor Books¶ YR:1992¶ LG:317 pp¶ KW:AIDS; homosexual; gay; sodomy¶ ®PG¯ R#:10¶ AU:Lamont, Corliss¶ BT:The illusion of immortality¶ BC:Dewey, John¶ SR:Half-moon Foundation, Inc.¶ PL:New York¶ PR:The Continuum Publishing Company¶ YR:1990 <1935>¶ LG:303 pp.¶ KW:humanism; ACLU¶ AN:Born in Englewood, New Jersey in 1902, Dr. Lamont graduated first from Phillips Exeter Academy in 1920, then magna cum laude from Harvard University in 1924. He did graduate work at Oxford and at Columbia, where he received his Ph.D. in philosophy in 1932. He was a director of the American Civil Liberties Union from 1932 to 1954, and is currently chairman of the National Emergency Civil Liberties Committee. A leading proponent of the individual’s rights under the Constitution, he has won famous court decisions over Senator Joseph McCarthy, the CIA, and in 1965 a Supreme Court ruling against censorship of incoming mail by the U.S. Postmaster General. Dr. Lamont has long been associated with Humanism, and authored the standard text on the subject, ®MDUL¯The Philosophy of Humanism®MDNM¯, in 1949. He taught at Columbia, Cornell, and Harvard Universities, and at the New School for Social Research. Corliss Lamont is currently honory president of the American Humanist Association.¶ ®PG¯ R#:11¶ AU:Hatcher, William S.; Martin, J. Douglas¶ BT:The Baha¶ ®PG¯ R#:12¶ AU:Hatcher, William S.; Martin, J. Douglas¶ BT:The Baha’i Faith¶ PL:San Francisco¶ PR:Harper & Row¶ YR:1984¶ LG:226 pp¶ KW:Baha’i; humanism¶ ®PG¯ R#:13¶ AU:Storer, Morris B. <ed>¶ BT:Humanist ethics: Dialogue on Basics¶ PL:Buffalo, New York¶ PR:Prometheus Books ¶ YR:1980¶ LG:303 pp¶ KW:humanist, humanism, ¶ ®PG¯ R#:14¶ ST:Kids and guns: a report from America’s classroom killing grounds¶ YR:1992¶ JR:Newsweek¶ DT:March¶ PG:cover¶ KW:violence; school; education; corporal punishment¶ ®PG¯ R#:15¶ ST:Shocking lesson in shame and terror¶ YR:1993¶ JR:National Examiner¶ DT:9 Nov¶ PG:7¶ KW:violence; school; education; guns¶ ®PG¯ R#:16¶ ST:The blackboard jungle---America’s Schoolyards are tragic killing fields where no child is safe¶ YR:1993¶ JR:National Examiner¶ DT:9 Nov¶ PG:7¶ KW:violence; school; education; guns¶ ®PG¯

 [2/7] from: greggirwin:mindspring at: 29-Oct-2001 16:33


Hi Louis, << Why doesn't the following program work? It should find field/1 in ibidem and replace it with field/2 (see Modify the String in the Parsing section of the Users Guide). >> Hopefully someone will correct me if I misinform you, but here's my analysis and a solution. In your call to parse, field/1 is not recognized because while parse can get word values, it doesn't seem to allow a path reference on a word. That's my guess anyway. The part of the code inside parenthesis can be valid REBOL code, not just parse dialect, so it's OK in there. The solution is to set a temporary variable and use that (see below). The other thing I added was to use the /part refinement with change. Since you're substitution is longer than what you're replacing, you'll overwrite other data just using change. foreach field fields [ foreach ibidem ibidems [ f1: field/1 parse ibidem [any [to f1 mark: (change/part mark field/2 length? f1) skip]] ] ] HTH! --Gregg

 [3/7] from: arolls:idatam:au at: 30-Oct-2001 11:02


I can't tell you exactly why it's wrong, but I an say that you are in the parse dialect when you refer to field/1, so maybe it's not handling paths in the manner you expect. In my test I got the same error, and fixed it by setting a new word, f1, outside the parse, then referencing f1 inside the parse: foreach field fields [ f1: field/1 ... parse ibidem [any [to f1 ... ]] ... ] Anton.

 [4/7] from: al:bri:xtra at: 30-Oct-2001 16:52


Louis wrote:
> Why doesn't the following program work? > parse ibidem [any [to field/1 mark: (change mark field/2) skip]]
'parse doesn't understand path! datatypes in it's rules block. As others have mentioned, probably the best solution (for now) is to use a temporary variable, like: f1: field/1 f2: field/2 parse ibidem [any [to f1 mark: (change mark f2) skip]] along with Greg's change/part suggestion. Alternatives are using 'compose, which isn't easy to use if you have actions mixed in the rules, like: parse string compose [] this is better for things like syntax checking. Or you could use 'reduce, which requires quoting all words and prefacing all blocks with reduce: parse string reduce ['any reduce ['to f1 ; and so on. I hope that helps! Andrew Martin ICQ: 26227169 http://valley.150m.com/

 [5/7] from: louisaturk:eudoramail at: 29-Oct-2001 22:35


-- Unable to decode HTML file!! --

 [6/7] from: nitsch-lists:netcologne at: 30-Oct-2001 16:59


RE: [REBOL] Re: Parse Problem [Al--Bri--xtra--co--nz] wrote:

 [7/7] from: greggirwin:mindspring at: 30-Oct-2001 10:47


Hi Louis, Your last message choked. At least I couldn't see any text from it. --Gregg