Repository navigation
Conversation
Add `Position.parseLan` to parse moves in Long Algebraic Notation (e.g. `e2-e4`, `Ng1-f3`, `e5xd6`, `e7-e8=Q`, `O-O`, `N@f3`) and return a legal `Move`, or `null` if the input is invalid or illegal. - The origin square, destination square and separator (`-` or `x`) are required, so UCI-style input like `e2e4` is rejected. - The optional piece letter must match the piece on the origin square. - The separator must agree with the position: `x` only for captures (including en passant), `-` otherwise. - Promotion is accepted with or without `=` and is required when a pawn reaches the last rank. - Trailing `+`, `#`, `!` and `?` and surrounding whitespace are ignored. - Castling (`O-O`, `0-0`, `O-O-O`, `0-0-0`) and Crazyhouse drops are delegated to `parseSan`. Written-out castling (`e1-g1`) is normalized to the king-to-rook form, consistent with `parseSan`.
JavaScript regex literal and kept its closing `/` delimiter, so the draw token only matched `1/2-1/2/`. A normal `1/2-1/2` was skipped and `Result` was not set from the movetext. Remove the trailing `/` (and the unneeded `\/` escapes). Add unit tests for `parseLan` and for the draw result in movetext.
veloce
requested changes
Nov 3, 2026
veloce
left a comment
Collaborator
There was a problem hiding this comment.
I'll review asap when the formatting is back to normal. Thanks.
Collaborator
|
@gd-evil I reformatted the code on |
Author
|
@veloce thank you, apologies for not replying earlier, I'll do it as soon as possible |
# Conflicts: # lib/src/pgn.dart
gd-evil
force-pushed
the
feature/LanParsing
branch
from
November 13, 2026 17:06
d8526c3 to
ca4c49a
Compare
Author
|
@veloce I'mn having trouble with the formatting, am I doing something wrong? I only formatted position.dart and pgn.dart files. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs lichess-org/mobile#3855
Summary
Adds
Position.parseLan(String), which parses a move in Long AlgebraicNotation (LAN) and returns a legal
Move, ornullif the input isinvalid or illegal in the position. It is a separate method from
parseSan, so SAN behavior is unchanged.Accepted input
e2-e4,Ng1-f3Nf3xe5,d5xc6h7-h8=Q,h7-h8Q=O-O,0-0,O-O-O,0-0-0e1-g1e1h1)N@f3,@e4Validation rules
-orx) are required,so UCI-style input such as
e2e4returnsnull.xonly for captures(including en passant),
-otherwise.+,#,!,?and surrounding whitespace are ignored.parseSan, and the result goes throughisLegal, so pins, checks and castling rights are enforced.Related fix: PGN draw result
While reviewing the PGN tokenizer I found that the regex was ported from a
JavaScript regex literal and kept its closing
/. In Dart the draw tokentherefore only matched
1/2-1/2/, so a normal1/2-1/2in the movetext wasskipped and
headers['Result']was not updated. This PR removes the trailing/(and the unneeded\/escapes). It is a separate fix and can be split intoits own PR if you prefer.
Tests
LAN parsinggroup intest/position_test.dartcovering normal moves,captures, en passant, promotions, castling (including Chess960), suffixes,
whitespace, pins, a full game, Crazyhouse drops, Antichess king promotion,
and malformed input.
1/2-1/2result token intest/pgn_test.dart.Design decisions to review
-vsxis enforced because that is what LANspecifies. If lenient input is preferred, it is a small change to the regex
and the separator check.
parseLanso each parserhas one clear format.
parseSanreturns, socallers can treat both methods the same way.
Checklist
dart testpassesAI assistance
Tool: Claude Sonnet 5.5.
What the AI did:
parseLanimplementation and theSquare.parsehelper,and proposed a stricter version (piece-letter check,
-/xseparator check,mandatory promotion, annotation and whitespace handling, delegation of
castling and drops to
parseSan,normalizeMoveon the result).pgn.dartand spotted the stray/in the draw token oftokenRegex(a leftover from the JavaScript regex literal).What I did myself:
parseLanand the original tests, and chose to implementLAN as a separate method.
failures that appeared (for example the
e1-g1castling normalization).Prompts used (summarized):
parseLanandSquare.parseare correct and cover allchess scenarios.
parseLanmethod.parseLancode and the tests step by step.pgn.dartis correct, especially the token regex.