1"""
2 pygments.lexers.sgf
3 ~~~~~~~~~~~~~~~~~~~
4
5 Lexer for Smart Game Format (sgf) file format.
6
7 :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
9"""
10
11from pygments.lexer import RegexLexer, bygroups
12from pygments.token import Name, Literal, String, Punctuation, Whitespace
13
14__all__ = ["SmartGameFormatLexer"]
15
16
17class SmartGameFormatLexer(RegexLexer):
18 """
19 Lexer for Smart Game Format (sgf) file format.
20
21 The format is used to store game records of board games for two players
22 (mainly Go game).
23 """
24 name = 'SmartGameFormat'
25 url = 'https://www.red-bean.com/sgf/'
26 aliases = ['sgf']
27 filenames = ['*.sgf']
28 version_added = '2.4'
29
30 tokens = {
31 'root': [
32 (r'[():;]+', Punctuation),
33 # tokens:
34 (r'(A[BW]|AE|AN|AP|AR|AS|[BW]L|BM|[BW]R|[BW]S|[BW]T|CA|CH|CP|CR|'
35 r'DD|DM|DO|DT|EL|EV|EX|FF|FG|G[BW]|GC|GM|GN|HA|HO|ID|IP|IT|IY|KM|'
36 r'KO|LB|LN|LT|L|MA|MN|M|N|OB|OM|ON|OP|OT|OV|P[BW]|PC|PL|PM|RE|RG|'
37 r'RO|RU|SO|SC|SE|SI|SL|SO|SQ|ST|SU|SZ|T[BW]|TC|TE|TM|TR|UC|US|VW|'
38 r'V|[BW]|C)',
39 Name.Builtin),
40 # number:
41 (r'(\[)([0-9.]+)(\])',
42 bygroups(Punctuation, Literal.Number, Punctuation)),
43 # date:
44 (r'(\[)([0-9]{4}-[0-9]{2}-[0-9]{2})(\])',
45 bygroups(Punctuation, Literal.Date, Punctuation)),
46 # point:
47 (r'(\[)([a-z]{2})(\])',
48 bygroups(Punctuation, String, Punctuation)),
49 # double points:
50 (r'(\[)([a-z]{2})(:)([a-z]{2})(\])',
51 bygroups(Punctuation, String, Punctuation, String, Punctuation)),
52
53 (r'(\[)([\w\s#()+,\-.:?]+)(\])',
54 bygroups(Punctuation, String, Punctuation)),
55 (r'(\[)(\s.*)(\])',
56 bygroups(Punctuation, Whitespace, Punctuation)),
57 (r'\s+', Whitespace)
58 ],
59 }