{"record":{"id":"c3c87507773392fa","repo":"PRQL/prql","slug":"currently-lex-only-works-with-a-single-source-b","errorCode":null,"errorMessage":"Currently `lex` only works with a single source, but found multiple sources","messagePattern":"Currently `lex` only works with a single source, but found multiple sources","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"prqlc/prqlc/src/cli/mod.rs","lineNumber":414,"sourceCode":"    fn execute<'a>(&self, sources: &'a mut SourceTree, main_path: &'a str) -> Result<Vec<u8>> {\n        let main_path = main_path\n            .split('.')\n            .filter(|x| !x.is_empty())\n            .map(str::to_string)\n            .collect_vec();\n\n        Ok(match self {\n            Command::Parse { format, .. } => {\n                let ast = prql_to_pl_tree(sources)?;\n                match format {\n                    Format::Json => serde_json::to_string_pretty(&ast)?.into_bytes(),\n                    Format::Yaml => serde_yaml::to_string(&ast)?.into_bytes(),\n                }\n            }\n            Command::Lex { format, .. } => {\n                let s = sources.sources.values().exactly_one().or_else(|_| {\n                    // TODO: allow multiple sources\n                    bail!(\"Currently `lex` only works with a single source, but found multiple sources\")\n                })?;\n                let tokens = prql_to_tokens(s)?;\n                match format {\n                    Format::Json => serde_json::to_string_pretty(&tokens)?.into_bytes(),\n                    Format::Yaml => serde_yaml::to_string(&tokens)?.into_bytes(),\n                }\n            }\n            Command::Collect(_) => {\n                let mut root_module_def = prql_to_pl_tree(sources)?;\n\n                drop_module_def(&mut root_module_def.stmts, \"std\");\n\n                pl_to_prql(&root_module_def)?.into_bytes()\n            }\n            Command::Debug(DebugCommand::Annotate(_)) => {\n                let (_, source) = sources.sources.clone().into_iter().exactly_one().or_else(\n                    |_| bail!(\n                        \"Currently `annotate` only works with a single source, but found multiple sources: {:?}\",","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/PRQL/prql/blob/e164e249b99485890036eb60f57c37520379b240/prqlc/prqlc/src/cli/mod.rs#L396-L432","documentation":"The `prqlc lex` CLI command lexes a PRQL source into tokens, but the lexer input model assumes a single source file. When the command receives multiple sources (e.g. main query plus includes via --include or stdin+files), execute() bails with this anyhow error instead of lexing each in turn.","triggerScenarios":"Running `prqlc lex` with more than one source — multiple input files, a main file plus --include files, or a project directory resolved to several sources.","commonSituations":"Pointing lex at a project dir containing stdlib/includes; passing several .prql files on the command line; CI scripts feeding both a file and stdin.","solutions":["Run lex on exactly one .prql file at a time","Remove --include arguments (or merge includes into one file temporarily) before lexing","Use `prqlc format` or `prqlc compile` (which do handle multiple sources) if multi-file processing is needed","Split a project into per-file lex invocations in your script"],"exampleFix":"# before\nprqlc lex main.prql --include helpers.prql\n# after\nprqlc lex main.prql","handlingStrategy":"validation","validationCode":"# Ensure a single input before lexing\nif [ \"$(ls *.prql | wc -l)\" -ne 1 ]; then echo \"pass exactly one file\"; exit 1; fi\nprqlc lex main.prql","typeGuard":null,"tryCatchPattern":"# Shell guard\nprqlc lex \"$1\" || echo \"lex failed: pass exactly one source file\"","preventionTips":["Never pass --include to lex/highlight/annotate","Run per-file in a loop for multi-file projects","Use compile/format for multi-source operations"],"tags":["cli","prql","lexer"],"backgroundTag":"unsupported-operation","analyzedSha":"e164e249b99485890036eb60f57c37520379b240","analyzedAt":"2026-09-09T12:18:38.727Z","contentChangedAt":"2026-09-09T12:18:38.727Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}