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