Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pygments/lexers/gleam.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

13 statements  

1""" 

2 pygments.lexers.gleam 

3 ~~~~~~~~~~~~~~~~~~~~~ 

4 

5 Lexer for the Gleam programming language. 

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, words, bygroups 

12from pygments.token import Comment, Operator, Keyword, Name, String, \ 

13 Number, Punctuation, Whitespace 

14 

15__all__ = ['GleamLexer'] 

16 

17 

18class GleamLexer(RegexLexer): 

19 """ 

20 Lexer for the Gleam programming language (version 1.0.0). 

21 """ 

22 

23 name = 'Gleam' 

24 url = 'https://gleam.run/' 

25 filenames = ['*.gleam'] 

26 aliases = ['gleam'] 

27 mimetypes = ['text/x-gleam'] 

28 version_added = '2.19' 

29 

30 keywords = words(( 

31 'as', 'assert', 'auto', 'case', 'const', 'delegate', 'derive', 'echo', 

32 'else', 'fn', 'if', 'implement', 'import', 'let', 'macro', 'opaque', 

33 'panic', 'pub', 'test', 'todo', 'type', 'use', 

34 ), suffix=r'\b') 

35 

36 tokens = { 

37 'root': [ 

38 # Comments 

39 (r'(///.*?)(\n)', bygroups(String.Doc, Whitespace)), 

40 (r'(//.*?)(\n)', bygroups(Comment.Single, Whitespace)), 

41 

42 # Keywords 

43 (keywords, Keyword), 

44 (r'([a-zA-Z_]+)(\.)', bygroups(Keyword, Punctuation)), 

45 

46 # Punctuation 

47 (r'[()\[\]{}:;,@]+', Punctuation), 

48 (r'(#|!=|!|==|\|>|\|\||\||\->|<\-|&&|<<|>>|\.\.|\.|=)', Punctuation), 

49 

50 # Operators 

51 (r'(<>|\+\.?|\-\.?|\*\.?|/\.?|%\.?|<=\.?|>=\.?|<\.?|>\.?|=)', Operator), 

52 

53 # Strings 

54 (r'"(\\"|[^"])*"', String), 

55 

56 # Identifiers 

57 (r'\b(let)(\s+)(\w+)', bygroups(Keyword, Whitespace, Name.Variable)), 

58 (r'\b(fn)(\s+)(\w+)', bygroups(Keyword, Whitespace, Name.Function)), 

59 (r'[a-zA-Z_/]\w*', Name), 

60 

61 # numbers 

62 (r'(\d+(_\d+)*\.(?!\.)(\d+(_\d+)*)?|\.\d+(_\d+)*)([eEf][+-]?[0-9]+)?', Number.Float), 

63 (r'\d+(_\d+)*[eEf][+-]?[0-9]+', Number.Float), 

64 (r'0[xX][a-fA-F0-9]+(_[a-fA-F0-9]+)*(\.([a-fA-F0-9]+(_[a-fA-F0-9]+)*)?)?p[+-]?\d+', Number.Float), 

65 (r'0[bB][01]+(_[01]+)*', Number.Bin), 

66 (r'0[oO][0-7]+(_[0-7]+)*', Number.Oct), 

67 (r'0[xX][a-fA-F0-9]+(_[a-fA-F0-9]+)*', Number.Hex), 

68 (r'\d+(_\d+)*', Number.Integer), 

69 

70 # Whitespace 

71 (r'\s+', Whitespace), 

72 

73 ], 

74 }