{"record":{"id":"3ac0b96b1ffee0c3","repo":"rust-lang/rust-analyzer","slug":"unexpected-r-only-unix-style-line-endings-allo","errorCode":null,"errorMessage":"unexpected `\\r`, only Unix-style line endings allowed","messagePattern":"unexpected `\\\\r`, only Unix-style line endings allowed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/ungrammar/src/lexer.rs","lineNumber":113,"sourceCode":"                }\n            }\n            TokenKind::Token(buf)\n        }\n        c if is_ident_char(c) => {\n            let mut buf = String::new();\n            buf.push(c);\n            loop {\n                match chars.clone().next() {\n                    Some(c) if is_ident_char(c) => {\n                        chars.next();\n                        buf.push(c);\n                    }\n                    _ => break,\n                }\n            }\n            TokenKind::Node(buf)\n        }\n        '\\r' => bail!(\"unexpected `\\\\r`, only Unix-style line endings allowed\"),\n        c => bail!(\"unexpected character: `{}`\", c),\n    };\n\n    *input = chars.as_str();\n    Ok(res)\n}\n\nfn is_escapable(c: char) -> bool {\n    matches!(c, '\\\\' | '\\'')\n}\nfn is_whitespace(c: char) -> bool {\n    matches!(c, ' ' | '\\t' | '\\n')\n}\nfn is_ident_char(c: char) -> bool {\n    matches!(c, 'a'..='z' | 'A'..='Z' | '_')\n}\n","sourceCodeStart":95,"sourceCodeEnd":130,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/lib/ungrammar/src/lexer.rs#L95-L130","documentation":"The ungrammar lexer rejects carriage-return characters outright: any `\\r` in the input bails, because grammar files are expected to use Unix (LF) line endings only. This keeps position tracking and the parser simple and deterministic.","triggerScenarios":"Loading a `.ungrammar` file saved with CRLF (Windows) line endings; a tool or editor converting line endings; a git checkout with `core.autocrlf=true` on Windows.","commonSituations":"Cloning the repo on Windows with autocrlf enabled; editing grammar files in an editor configured for CRLF; committing files reformatted on Windows.","solutions":["Convert the file to LF line endings (dos2unix or editor setting)","Add/update `.gitattributes` to force `*.ungrammar text eol=lf`","Set git `core.autocrlf=input` for this repo","Configure your editor to save LF for .ungrammar files"],"exampleFix":"# before (CRLF bytes)\r\nExpr = 'foo'\r\n# after (LF)\nExpr = 'foo'","handlingStrategy":"validation","validationCode":"// normalize CRLF before parsing\nlet src = if src.contains('\\r') {\n    src.replace(\"\\r\\n\", \"\\n\").replace('\\r', \"\\n\")\n} else { src.to_string() };","typeGuard":null,"tryCatchPattern":"match ungrammar::Grammar::parse(&src) {\n    Err(e) if e.to_string().contains('\\\\r') => {\n        eprintln!(\"convert the grammar file to LF line endings: {e}\")\n    }\n    r => r?,\n}","preventionTips":["Add `*.ungrammar text eol=lf` to .gitattributes","Set editor default to LF for grammar files","Avoid core.autocrlf=true when working on this repo"],"tags":["lexer","ungrammar","line-endings","windows"],"backgroundTag":"crlf-line-endings","analyzedSha":"e8f7e90aa3e7b26aa9a000200f606c1078da99ec","analyzedAt":"2026-09-03T21:08:06.959Z","contentChangedAt":"2026-09-03T21:08:06.959Z","schemaVersion":2},"datasetVersion":"2026-09-11T07:07:21.782Z"}