Coverage for aiocoap/util/linkformat_pygments.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.6.3, created at 2024-10-15 22:10 +0000

1# SPDX-FileCopyrightText: Christian Amsüss and the aiocoap contributors 

2# 

3# SPDX-License-Identifier: MIT 

4 

5from pygments import token, lexers 

6from pygments.lexer import RegexLexer, bygroups 

7 

8__all__ = ["LinkFormatLexer"] 

9 

10 

11class LinkFormatLexer(RegexLexer): 

12 name = "LinkFormatLexer" 

13 mimetypes = ["application/link-format"] 

14 

15 tokens = { 

16 "root": [ 

17 ( 

18 "(<)([^>]*)(>)", 

19 bygroups(token.Punctuation, token.Name.Label, token.Punctuation), 

20 "maybe-end", 

21 ) 

22 ], 

23 "maybe-end": [ 

24 # Whitespace is not actually allowed, but produced by the pretty printer 

25 (";\\s*", token.Punctuation, "attribute"), 

26 (",\\s*", token.Punctuation, "root"), 

27 ], 

28 "attribute": [ 

29 ( 

30 '([^,;=]+)((=)("[^"]*"|[^,;"]+))?', 

31 bygroups( 

32 token.Name.Attribute, None, token.Operator, token.String.Symbol 

33 ), 

34 "maybe-end", 

35 ), 

36 ], 

37 } 

38 

39 

40def _register(): 

41 if "LinkFormatLexer" not in lexers.LEXERS: 

42 lexers.LEXERS["LinkFormatLexer"] = ( 

43 "aiocoap.util.linkformat_pygments", 

44 "LinkFormatLexer", 

45 (), 

46 (), 

47 LinkFormatLexer.mimetypes, 

48 )