small medium large xlarge

Brooks_0037_head_pragsmall
14 Dec 2011, 16:21
Brooks Boyd (2 posts)

The “phonebook.io” example of writing a parser for a different sort of language structure works if the whole structure is imported as a string and acted upon:

phoneNumbers := doString(s) # Works
phoneNumbers := doString("{ 
    \"Bob Smith\": \"5195551212\",
    \"Mary Walsh\": \"4162223434\"
}") # Works

But I can’t seem to get it to work just as embedded code in the same page:

phoneNumbers := { 
    "Bob Smith": "5195551212",
    "Mary Walsh": "4162223434"
}        

The above fails out with a “Sequence does not respond to ‘:’” exception, like the ‘:’ is not viewed as an Operator after the “Bob Smith” Sequence.

Later, the “builder.io” script is able to create a new language structure using the “forward” method override, which allows for adding the generating code right in the same script. Is that possible to be done with the “phonebook.io” method?

Generic-user-small
11 Feb 2018, 19:24
D.R. (1 post)

Probably way too late, but for people reading the book nowadays and stumbling upon the same problem: https://www.ybrikman.com/writing/2012/02/07/seven-languages-in-seven-weeks-io-day-3/ has the answer: you have to put the operator-table-change into a separate file. The operator table is only loaded once at the beginning of the file, changing it will only affect further files, never the current file.

You must be logged in to comment