This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: BRL reader problem.


On 08/25/2009 09:17 AM, Dan Stanger wrote:
I have reproduced the problem with the following line:
[(brl ]lorem[)]
 From the command line, the value lorem is returned from BRLReaderString
as the token.  However in the servlet, the read loop sees 10 (newline),
and then -1, returning the newline as the token. I have determined that
when line 79 in BRLReaderString, saveReadState='\n' is commented out,
the reader does not see the newline.  This variable is used to set
readState in the finally block.  Is the purpose of readState, and how
the reader works normally documented somewhere?

The readState is primarily used for the prompt string in a REPL, to give a visual clue when starting a continuation line that you're nested inside something.

I think it's probably used for some error detection/reporting,
but I don't remember for sure.  It is obviously also used by the
BRL reader.

Changing saveReadState in line 79 does seem strange.  It seems to be
needed for REPL mode; without it you get some bad behavior:

$ bin/kawa --brl
<!--BRL:1-->[(+ 3 4)]
<!--BRL:2-->
(+ 3 4)]
<!--BRL:3-->

Note that (+ 3 4) is not evaluated.

When what we want is:

$ bin/kawa --brl
<!--BRL:1-->[(+ 3 4)]
7
<!--BRL:2-->

Perhaps we can fix the BRL reader so that the default/initial state
is '\n' (which is the default for Scheme) rather than ']'.   I did a
quick experiment - see the attached patch.  However, that doesn't
work either, but it might be worth exploring.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/
Index: gnu/kawa/brl/BRLReaderString.java
===================================================================
--- gnu/kawa/brl/BRLReaderString.java	(revision 6341)
+++ gnu/kawa/brl/BRLReaderString.java	(working copy)
@@ -76,7 +76,7 @@
 				else
 				  {
 				    inString = false;
-				    saveReadState = '\n';
+				    //saveReadState = '\n';
 				    if (in instanceof BRLRead)
 				      ((BRLRead) in).saveExpressionStartPosition();
 				  }
Index: gnu/kawa/brl/BRLRead.java
===================================================================
--- gnu/kawa/brl/BRLRead.java	(revision 6341)
+++ gnu/kawa/brl/BRLRead.java	(working copy)
@@ -14,12 +14,12 @@
   /** True if in literal text (even if nested inside an escaped expression). */
   public boolean inLiteral ()
   {
-    return ((InPort) port).readState == ']';
+    return port.readState == '\n';
   }
 
   void init()
   {
-    ((InPort) port).readState = ']';
+    // ((InPort) port).readState = ']';
   }
 
   public BRLRead(InPort port)
@@ -47,13 +47,13 @@
 	    int ch = port.read();
 	    if (ch < 0)
 	      {
-		if (port.readState != ']' && ! isInteractive())
+		if (! inLiteral() && ! isInteractive())
 		  error('e', expressionStartFile,
 			expressionStartLine + 1, expressionStartColumn,
 			"an unmatched '[' was read");
 		  return Sequence.eofValue; // FIXME;
 	      }
-	    if (port.readState == ']')
+	    if (inLiteral())
 	      {
 		port.unread();
 		Object value = BRL.brlReader.read(this, ']', 1);
@@ -64,7 +64,7 @@
 	    else
 	      {
 		if (ch == ']')
-		  port.readState = ']';
+		  port.readState = '\n';
 		else
 		  {
 		    nesting++;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]