slatex / RusTeX

A (somewhat experimental) implementation of a TeX engine in rust, used to convert LaTeX documents to xhtml.
22 stars 0 forks source link

listings with otherkeywords which start with `=` break RusTeX #13

Closed stuebinm closed 9 months ago

stuebinm commented 9 months ago

minimal example I could find, working on the current master f166e3ab9357f3b7e80c3cd531a7e0b147fc0fe0:

\documentclass{article}

\usepackage{listings}
\lstdefinelanguage{Bad}{otherkeywords={=>}}

\begin{document}
\begin{lstlisting}[language=Bad]
hello
\end{lstlisting}
\end{document}

produces

File ended unexpectedly

/path/to/repo/RusTeX/rustex/test.tex (10;0)   0: rustex::commands::conditionals::false_loop
   1: core::ops::function::FnOnce::call_once
   2: rustex::commands::PrimitiveTeXCommand::get_expansion
   3: rustex::commands::TeXCommand::expand
   4: rustex::interpreter::Interpreter::do_top
   5: rustex::interpreter::Interpreter::do_vfile
   6: rustex::interpreter::Interpreter::do_file
   7: rustex::run
   8: std::sys_common::backtrace::__rust_begin_short_backtrace
   9: core::ops::function::FnOnce::call_once{{vtable.shim}}
  10: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9
      <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9
      std::sys::unix::thread::Thread::new::thread_start
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys/unix/thread.rs:108:17
  11: start_thread
  12: __clone3

if you exchange the otherkeywords={=>} with e.g. otherkeywords={->} or even otherkeywords={<=} it works as expected (with LaTeX, all three work). Perhaps something got expanded in an unexpected place, where the = caused confusion? Unfortunately, i'm not sure how to figure out where / what RusTeX was doing before it failed, so I can't investigate this further.

(I discovered this since the listings package's definition for Haskell includes this)

Jazzpirate commented 9 months ago

Thanks for the report. The issue was that = is a keyword in certain contexts (e.g. \let\foo=\bar or \count15=125), but only if the = has category code 12 (other). So far, RusTeX didn't check the category code - adding the check fixes the bug. I'll run some tests to see if that breaks something else and push a fix (in the best case ETA 30 minutes)

Jazzpirate commented 9 months ago

fixed in ed4697f

stuebinm commented 9 months ago

thanks, works like a charm!