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

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

10 statements  

1# This file is part of the Python aiocoap library project. 

2# 

3# Copyright (c) 2012-2014 Maciej Wasilak <http://sixpinetrees.blogspot.com/>, 

4# 2013-2014 Christian Amsüss <c.amsuess@energyharvesting.at> 

5# 

6# aiocoap is free software, this file is published under the MIT license as 

7# described in the accompanying LICENSE file. 

8 

9from pygments import token, lexers 

10from pygments.lexer import RegexLexer, bygroups 

11 

12__all__ = ['LinkFormatLexer'] 

13 

14class LinkFormatLexer(RegexLexer): 

15 name = "LinkFormatLexer" 

16 mimetypes = ['application/link-format'] 

17 

18 tokens = { 

19 'root': [ 

20 ('(<)([^>]*)(>)', bygroups(token.Punctuation, token.Name.Label, token.Punctuation), 'maybe-end') 

21 ], 

22 'maybe-end': [ 

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

24 (';\\s*', token.Punctuation, 'attribute'), 

25 (',\\s*', token.Punctuation, 'root'), 

26 ], 

27 'attribute': [ 

28 ('([^,;=]+)((=)("[^"]*"|[^,;"]+))?', bygroups(token.Name.Attribute, None, token.Operator, token.String.Symbol), 'maybe-end'), 

29 ], 

30 } 

31 

32def _register(): 

33 if 'LinkFormatLexer' not in lexers.LEXERS: 

34 lexers.LEXERS['LinkFormatLexer'] = ( 

35 'aiocoap.util.linkformat_pygments', 

36 'LinkFormatLexer', 

37 (), 

38 (), 

39 LinkFormatLexer.mimetypes, 

40 )