Tencent/matrix · error

Can't find the parser driver template file

Error message

Can't find the parser driver template file "%s".

What it means

Lemon locates its parser driver template (lempar.c) by checking -T paths, the current directory, or via pathsearch against argv0. If no readable copy is found, it prints 'Can't find the parser driver template file "lempar.c".', increments errorcnt and aborts generation.

Solutions

  1. Pass the template explicitly: lemon -T /path/to/lempar.c grammar.y
  2. Copy lempar.c into the directory where you invoke lemon
  3. Ensure lempar.c sits in the same directory as the lemon binary (pathsearch target)
  4. Fix the -T argument spelling/permissions (file must be readable, access(004))

Example fix

// before
lemon parser.y
// after
lemon -T src/lemon-gen/lempar.c parser.y
Defensive patterns

Strategy: validation

Validate before calling

#!/bin/sh
TPL=${LEMON_TEMPLATE:-$(dirname "$0")/lempar.c}
if [ ! -r "$TPL" ]; then echo "template missing: $TPL"; exit 1; fi
lemon -T "$TPL" parser.y

Prevention

When it happens

Trigger: Running lemon without a -T flag where lempar.c is not in the current directory nor next to the lemon executable; the -T argument names a template that fails the access(READ) check; lempar.c deleted from the installed toolchain directory.

Common situations: Installing/copying the lemon binary without shipping lempar.c alongside; running lemon from a different working directory (relative lookup fails); packaging matrix-sqlite-lint's build in a container without the lemon-gen template files; misspelled -T path.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08). Data as JSON: /api/errors/30e3a084f88db760. Report an issue: GitHub.

Appendix: source

Thrown at matrix/matrix-android/matrix-sqlite-lint/src/lemon/lemon-gen/lemon.c:3003

  FILE *in;
  char *tpltname;
  char *cp;

  cp = strrchr(lemp->filename,'.');
  if( cp ){
    sprintf(buf,"%.*s.lt",(int)(cp-lemp->filename),lemp->filename);
  }else{
    sprintf(buf,"%s.lt",lemp->filename);
  }
  if( access(buf,004)==0 ){
    tpltname = buf;
  }else if( access(templatename,004)==0 ){
    tpltname = templatename;
  }else{
    tpltname = pathsearch(lemp->argv0,templatename,0);
  }
  if( tpltname==0 ){
    fprintf(stderr,"Can't find the parser driver template file \"%s\".\n",
    templatename);
    lemp->errorcnt++;
    return 0;
  }
  in = fopen(tpltname,"rb");
  if( in==0 ){
    fprintf(stderr,"Can't open the template file \"%s\".\n",templatename);
    lemp->errorcnt++;
    return 0;
  }
  return in;
}

/* Print a #line directive line to the output file. */
PRIVATE void tplt_linedir(out,lineno,filename)
FILE *out;
int lineno;
char *filename;

View on GitHub (pinned to 3b8293bd65)