Hello all,
I'am a little disturbed with a reader-macro i use to realize an infix
parsing atop of the infix package. The following code is ok :
-- code --
(defun bracket-reader (stream char)
(declare (ignore char))
(let ((*readtable* infix::*infix-readtable*))
(myread-infix stream)))
(defun myread-infix (stream)
(let* ((result (infix::gather-superiors '\] stream)) ; %infix-end-token%
(next-token (infix::read-token stream)))
(unless (infix::same-token-p next-token '\]) ; %infix-end-token%
(infix::infix-error "Infix expression ends with ~A." next-token))
result))
(set-macro-character #\[ #'bracket-reader)
(set-macro-character #\] (get-macro-character #\)))
-- end code --
> [1+1]
--> 2
But the following produce an stream reading error :
-- code
(defun bracket-reader (stream char)
(declare (ignore char))
(let ((*readtable* infix::*infix-readtable*))
(myread-infix stream)))
(defun myread-infix (stream)
(let* ((result (infix::gather-superiors '\} stream)) ; %infix-end-token%
(next-token (infix::read-token stream)))
(unless (infix::same-token-p next-token '\}) ; %infix-end-token%
(infix::infix-error "Infix expression ends with ~A." next-token))
result))
(set-macro-character #\{ #'bracket-reader)
(set-macro-character #\} (get-macro-character #\)))
-- end code --
> {1+1}
--> End-of-File on #<String-Input Stream>
As i have just changed the []s with {}s i dont understand the error.
Fred
Fred Nicolier <··········@gmail.com> writes:
> Hello all,
>
> I'am a little disturbed with a reader-macro i use to realize an infix
> parsing atop of the infix package. The following code is ok :
>
> -- code --
>
> (defun bracket-reader (stream char)
> (declare (ignore char))
> (let ((*readtable* infix::*infix-readtable*))
> (myread-infix stream)))
>
> (defun myread-infix (stream)
> (let* ((result (infix::gather-superiors '\] stream)) ; %infix-end-token%
> (next-token (infix::read-token stream)))
> (unless (infix::same-token-p next-token '\]) ; %infix-end-token%
> (infix::infix-error "Infix expression ends with ~A." next-token))
> result))
>
> (set-macro-character #\[ #'bracket-reader)
> (set-macro-character #\] (get-macro-character #\)))
>
> -- end code --
>
>> [1+1]
> --> 2
>
> But the following produce an stream reading error :
>
> -- code
>
> (defun bracket-reader (stream char)
> (declare (ignore char))
> (let ((*readtable* infix::*infix-readtable*))
> (myread-infix stream)))
>
> (defun myread-infix (stream)
> (let* ((result (infix::gather-superiors '\} stream)) ; %infix-end-token%
> (next-token (infix::read-token stream)))
> (unless (infix::same-token-p next-token '\}) ; %infix-end-token%
> (infix::infix-error "Infix expression ends with ~A." next-token))
> result))
>
> (set-macro-character #\{ #'bracket-reader)
> (set-macro-character #\} (get-macro-character #\)))
>
> -- end code --
>
>> {1+1}
> --> End-of-File on #<String-Input Stream>
>
> As i have just changed the []s with {}s i dont understand the error.
What is it that gives the symbol named ] a meaning in:
(infix::gather-superiors '\] stream)
(infix::same-token-p next-token '\])
It's possible that whatever does that doesn't provide a similar
meaning for a symbol named }.
-Peter
--
Peter Seibel * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp * http://www.gigamonkeys.com/book/
Fred Nicolier <··········@gmail.com> writes:
> Hello all,
>
> I'am a little disturbed with a reader-macro i use to realize an infix
> parsing atop of the infix package. The following code is ok :
> [...]
> (set-macro-character #\[ #'bracket-reader)
> (set-macro-character #\] (get-macro-character #\)))
> [...]
> (set-macro-character #\{ #'bracket-reader)
> (set-macro-character #\} (get-macro-character #\)))
> [...]
>> {1+1}
> --> End-of-File on #<String-Input Stream>
>
> As i have just changed the []s with {}s i dont understand the error.
Try:
{ 1+1 } ;-)
In addition to the macro character, you need to adjust also the syntax
of the character:
(SET-SYNTAX-FROM-CHAR #\[ #\()
(SET-SYNTAX-FROM-CHAR #\] #\))
(SET-SYNTAX-FROM-CHAR #\{ #\()
(SET-SYNTAX-FROM-CHAR #\} #\))
Note that the macro of the character #\) does nothing else but report
an error. It is not used when reading a correct s-exp.
[18]> )
*** - READ from
#<INPUT CONCATENATED-STREAM #<INPUT STRING-INPUT-STREAM>
#<IO TERMINAL-STREAM>>
: an object cannot start with #\)
The following restarts are available:
ABORT :R1 ABORT
Break 1 [19]> :q
[20]> ]
*** - EVAL: variable ] has no value
The following restarts are available:
USE-VALUE :R1 You may input a value to be used instead of ].
STORE-VALUE :R2 You may input a new value for ].
ABORT :R3 ABORT
Break 1 [21]> :q
[22]> ']
]
[23]> (set-macro-character #\] (get-macro-character #\)))
T
[24]> ]
*** - READ from
#<INPUT CONCATENATED-STREAM #<INPUT STRING-INPUT-STREAM>
#<IO TERMINAL-STREAM>>
: an object cannot start with #\]
The following restarts are available:
ABORT :R1 ABORT
Break 1 [25]> :q
[26]> ']
*** - READ from
#<INPUT CONCATENATED-STREAM #<INPUT STRING-INPUT-STREAM>
#<IO TERMINAL-STREAM>>
: an object cannot start with #\]
The following restarts are available:
ABORT :R1 ABORT
Break 1 [27]> :q
[28]>
--
__Pascal Bourguignon__ http://www.informatimago.com/
Litter box not here.
You must have moved it again.
I'll poop in the sink.
On 08-02-2006, Pascal Bourguignon <······@informatimago.com> wrote:
> In addition to the macro character, you need to adjust also the syntax
> of the character:
>
> (SET-SYNTAX-FROM-CHAR #\[ #\()
> (SET-SYNTAX-FROM-CHAR #\] #\))
> (SET-SYNTAX-FROM-CHAR #\{ #\()
> (SET-SYNTAX-FROM-CHAR #\} #\))
>
This doesn't change anything.
>
> Note that the macro of the character #\) does nothing else but report
> an error. It is not used when reading a correct s-exp.
>
Thanks for this.
The backtrace of the error is :
0: (SWANK::DEBUG-IN-EMACS #<END-OF-FILE @ #x1069903a>)
1: ((FLET SWANK:SWANK-DEBUGGER-HOOK SWANK::DEBUG-IT))
2: (SWANK:SWANK-DEBUGGER-HOOK #<END-OF-FILE @ #x1069903a> #<Function SWANK-DEBUGGER-HOOK>)
3: (ERROR END-OF-FILE :STREAM #1=#<EXCL:STRING-INPUT-SIMPLE-STREAM "{1+1}
" pos 6 @ #x103f95ba> :FORMAT-CONTROL "~
·@<eof encountered on stream ···@[ starting at position ~d.~]··@>" :FORMAT-ARGUMENTS (#1# NIL))
4: (READ-DELIMITED-LIST #\] #<EXCL:STRING-INPUT-SIMPLE-STREAM "{1+1}
" pos 6 @ #x103f95ba> T)
5: (MATH-SYNTAX::LIST-READER #<EXCL:STRING-INPUT-SIMPLE-STREAM "{1+1}
" pos 6 @ #x103f95ba> #\{)
The fact that READ-DELIMITED-LIST is called with #\] is strange. I
tried to replace the {}s with <>s and there's no errors !!!
Fred
Fred Nicolier <··········@gmail.com> writes:
> On 08-02-2006, Pascal Bourguignon <······@informatimago.com> wrote:
>> In addition to the macro character, you need to adjust also the syntax
>> of the character:
>>
>> (SET-SYNTAX-FROM-CHAR #\[ #\()
>> (SET-SYNTAX-FROM-CHAR #\] #\))
>> (SET-SYNTAX-FROM-CHAR #\{ #\()
>> (SET-SYNTAX-FROM-CHAR #\} #\))
>>
>
> This doesn't change anything.
>
>>
>> Note that the macro of the character #\) does nothing else but report
>> an error. It is not used when reading a correct s-exp.
>>
>
> Thanks for this.
>
> The backtrace of the error is :
>
> 0: (SWANK::DEBUG-IN-EMACS #<END-OF-FILE @ #x1069903a>)
> 1: ((FLET SWANK:SWANK-DEBUGGER-HOOK SWANK::DEBUG-IT))
> 2: (SWANK:SWANK-DEBUGGER-HOOK #<END-OF-FILE @ #x1069903a> #<Function SWANK-DEBUGGER-HOOK>)
> 3: (ERROR END-OF-FILE :STREAM #1=#<EXCL:STRING-INPUT-SIMPLE-STREAM "{1+1}
> " pos 6 @ #x103f95ba> :FORMAT-CONTROL "~
> ·@<eof encountered on stream ···@[ starting at position ~d.~]··@>" :FORMAT-ARGUMENTS (#1# NIL))
> 4: (READ-DELIMITED-LIST #\] #<EXCL:STRING-INPUT-SIMPLE-STREAM "{1+1}
> " pos 6 @ #x103f95ba> T)
> 5: (MATH-SYNTAX::LIST-READER #<EXCL:STRING-INPUT-SIMPLE-STREAM "{1+1}
> " pos 6 @ #x103f95ba> #\{)
>
> The fact that READ-DELIMITED-LIST is called with #\] is strange. I
> tried to replace the {}s with <>s and there's no errors !!!
Indeed. Check the source of MATH-SYNTAX...
--
__Pascal Bourguignon__ http://www.informatimago.com/
ADVISORY: There is an extremely small but nonzero chance that,
through a process known as "tunneling," this product may
spontaneously disappear from its present location and reappear at
any random place in the universe, including your neighbor's
domicile. The manufacturer will not be responsible for any damages
or inconveniences that may result.
On 08-02-2006, Pascal Bourguignon <······@informatimago.com> wrote:
> Fred Nicolier <··········@gmail.com> writes:
>
>> On 08-02-2006, Pascal Bourguignon <······@informatimago.com> wrote:
>>> In addition to the macro character, you need to adjust also the syntax
>>> of the character:
>>>
>>> (SET-SYNTAX-FROM-CHAR #\[ #\()
>>> (SET-SYNTAX-FROM-CHAR #\] #\))
>>> (SET-SYNTAX-FROM-CHAR #\{ #\()
>>> (SET-SYNTAX-FROM-CHAR #\} #\))
>>>
>>
>> This doesn't change anything.
>>
>>>
>>> Note that the macro of the character #\) does nothing else but report
>>> an error. It is not used when reading a correct s-exp.
>>>
>>
>> Thanks for this.
>>
>> The backtrace of the error is :
>>
>> 0: (SWANK::DEBUG-IN-EMACS #<END-OF-FILE @ #x1069903a>)
>> 1: ((FLET SWANK:SWANK-DEBUGGER-HOOK SWANK::DEBUG-IT))
>> 2: (SWANK:SWANK-DEBUGGER-HOOK #<END-OF-FILE @ #x1069903a> #<Function SWANK-DEBUGGER-HOOK>)
>> 3: (ERROR END-OF-FILE :STREAM #1=#<EXCL:STRING-INPUT-SIMPLE-STREAM "{1+1}
>> " pos 6 @ #x103f95ba> :FORMAT-CONTROL "~
>> ·@<eof encountered on stream ···@[ starting at position ~d.~]··@>" :FORMAT-ARGUMENTS (#1# NIL))
>> 4: (READ-DELIMITED-LIST #\] #<EXCL:STRING-INPUT-SIMPLE-STREAM "{1+1}
>> " pos 6 @ #x103f95ba> T)
>> 5: (MATH-SYNTAX::LIST-READER #<EXCL:STRING-INPUT-SIMPLE-STREAM "{1+1}
>> " pos 6 @ #x103f95ba> #\{)
>>
>> The fact that READ-DELIMITED-LIST is called with #\] is strange. I
>> tried to replace the {}s with <>s and there's no errors !!!
>
> Indeed. Check the source of MATH-SYNTAX...
>
>
Fred Nicolier wrote:
> As i have just changed the []s with {}s i dont understand the error.
Such a difference could be attributed to one being a terminating macro
character and the other being a non-terminating one.
In your test case, there is no whitespace between the closing bracket
and the preceding identifier. If the closing bracket is a
non-terminating character, then it can actually be part of an
identifier token.
The standard CL # character behaves this way:
;;; vector
#( )
;;; symbol named "AAA#"
aaa#
Non-terminating means that if the character occurs in the middle of an
identifier, it won't terminate that token, but will be incorporated
into it as a constituent.
On 09-02-2006, Kaz Kylheku <········@gmail.com> wrote:
> Fred Nicolier wrote:
>> As i have just changed the []s with {}s i dont understand the error.
>
> Such a difference could be attributed to one being a terminating macro
> character and the other being a non-terminating one.
>
> In your test case, there is no whitespace between the closing bracket
> and the preceding identifier. If the closing bracket is a
> non-terminating character, then it can actually be part of an
> identifier token.
>
> The standard CL # character behaves this way:
>
> ;;; vector
> #( )
>
> ;;; symbol named "AAA#"
> aaa#
>
> Non-terminating means that if the character occurs in the middle of an
> identifier, it won't terminate that token, but will be incorporated
> into it as a constituent.
Nice ! Now i understand the behaviour: typing { 1+1 } works now. But
this raise two questions for me :
1. Why \] is a terminating macro character and \} not.
2. Is there a way to set \} as a terminating macro character ?
Fred
Fred Nicolier wrote:
> On 09-02-2006, Kaz Kylheku <········@gmail.com> wrote:
> > Non-terminating means that if the character occurs in the middle of an
> > identifier, it won't terminate that token, but will be incorporated
> > into it as a constituent.
>
> Nice ! Now i understand the behaviour: typing { 1+1 } works now. But
> this raise two questions for me :
>
> 1. Why \] is a terminating macro character and \} not.
Because someone set that up. You are doing work over an existing infix
package, aren't you?
Take a look at the standard syntax assignments in CLHS 2.1.4. Both ]
and } are token constituents.
> 2. Is there a way to set \} as a terminating macro character ?
Not directly. The syntax type property assigned to a character by a
readtable isn't an object in CL. All you can do is copy the category of
one character to another. They can be in different readtables. See
SET-SYNTAX-FROM-CHAR.
;; make } behave like ]
;; assuming that something already set up ] the way we want
(set-syntax-from-char #\} #\])
Fred Nicolier <··········@gmail.com> writes:
> 1. Why \] is a terminating macro character and \} not.
Both are constituents, by default.
Section 2.1.4 Character Syntax Types, at the very beginning of CLHS.
You aren't reading it, are you!
http://www.lispworks.com/documentation/HyperSpec/Body/02_ad.htm
> 2. Is there a way to set \} as a terminating macro character ?
(set-syntax-from-char #\} #\)) ; does this ring a bell?
--
__Pascal Bourguignon__ http://www.informatimago.com/
In a World without Walls and Fences,
who needs Windows and Gates?