A fix for : syntax error here: ...

103 views
Skip to first unread message

Boring Coder

unread,
Oct 11, 2025, 8:33:23 AMOct 11
to Shen
First : sorry if I am polluting the group with my questions.

Right now, when there is a syntax error like a parenthesis missing, shen will report 
syntax error here:
...

it can be annoying when the file is long enough, and you don't know where the error is?
This happens because the global variable *residue* is not set anywhere, it is always empty.
one solution to the problem is to create a new compile function for bytes in reader.shen
I tested and it works, but of course maybe there is a better solution: 

(define read-file
  File -> (let Bytelist (read-file-as-bytelist File)
               S-exprs (compileBytes (/. X (<s-exprs> X)) Bytelist)
               Process (process-sexprs S-exprs)
               Process))

(define compileBytes
  F L -> (let Compile (F L)
              (cases (parse-failure? Compile) (error "parse failure~%")
                     (cons? (in-> Compile))   (print-residue (in-> Compile))
                     true (<-out Compile))))

dr.mt...@gmail.com

unread,
Oct 16, 2025, 5:28:49 AMOct 16
to Shen
Hi,

I've been away for a bit.   Yes, the syntax error report needs looking at.  It works of course, but the info
is not always helpful.

M.

dr.mt...@gmail.com

unread,
Oct 17, 2025, 5:48:52 PMOct 17
to Shen
It would be good if you could supply a list of files where you feel the 
error messages are unhelpful so that I can assess what needs to be done.

M.

Boring Coder

unread,
Oct 27, 2025, 3:44:40 PM (12 days ago) Oct 27
to Shen
So the issue I was talking about applies to any file to be honest, the parser does not print back the residue

(1-) (load "simulator.shen")
syntax error here:
 ...
(2-)

with the fix I applied it prints out the residue 
(0-) (load "simulator.shen")
syntax error here:
(define gcd-machine ->
    (make-machine
    gcd ...
(1-)

it does not point out the exact place of the error which is a missing bracket from a list, but at least 
I can just go to the function and check.

as for improving the messages, there is this project called ohmjs (Ohm: a user-friendly parsing toolkit for JavaScript and Typescript)
it is similar in many ways to shen yacc, but it works on strings not lists, and by default the parser will points out the line and column of the error
and also the message expected "something" the something is taken from the grammar.
example taken from the editor Ohm Editor
(3 + 2
Expected ")""-""+""^""/", or "*"

ohmjs by the way started by alan kay in Viewpoints Research Institute  as  ometa (alexwarth/ometa-js: OMeta for JavaScript)
a next version of the meta ii paper. 

in shen yacc, I am not sure if introducing this extra information should be in the reader itself just for the s-expr grammar
or in the yacc file itself for any grammar.
Reply all
Reply to author
Forward
0 new messages