[plt-scheme] Syntax Reader and Macros

From: Brian Campbell (lambda at mac.com)
Date: Sat Aug 3 19:34:05 EDT 2002

OK, thanks, your solution for attaching syntax objects to 
lexical contexts works just fine for me. Perhaps there should be 
a built in function that does this. It seems that read-syntax is 
pretty useless without it.

Now about reading directly from the source file. I would 
probably want to create a custom input port, and use read-syntax 
on it for the parts that are expressions, and read-char for the 
parts that are not. Now, I would want it to translate all 
sequences like \n, \12, etc. into single characters, and I can 
do that in the read-string-proc and peek-string-proc-or-false. 
There seems, however, to be no way to influence the current 
position of the port as returned by port-next-location. The only 
way there seems to be to do that is by returning a procedure, 
rather than a character, which will have it's value returned 
without change by the function that is called (read, 
read-syntax, or read-char), rather than being parsed. Is there 
any way to tell a custom port that although only n characters 
have been returned, n+e characters have actually been traversed 
in the input file?

On Saturday, August 3, 2002, at 05:39  PM, Matthew Flatt wrote:

>> Also, when I read characters and expressions from a syntax
>> object converted into a string, I read one character per logical
>> character in the string. In the code, however, a character such
>> as a newline can be represented as a newline directly in the
>> input, \n, \12, \012, \xA, or \x0A. This makes it rather
>> difficult to predict how many characters in the input file
>> correspond to one character in the string, which makes it hard
>> to calculate offsets for highlighting and error reporting in
>> various parts of that string. Is there any way to tell how many
>> characters one character in a string corresponded to originally?
>
> Not currently.
>
>> Would it be possible to attach some table to string syntax
>> objects that tells you which characters in that string
>> correspond to multiple characters in the source?
>
> That's an interesting suggestion, but I wonder where to stop. For
> example, symbols and numbers can have many different concrete
> representations, too. At some point, I wonder whether it isn't best to
> re-read the source to extract additional, special-purpose information.
>
> Matthew
>
>




Posted on the users mailing list.