Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/teal.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:16 +0000

1""" 

2 pygments.lexers.teal 

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

4 

5 Lexer for TEAL. 

6 

7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. 

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11from pygments.lexer import RegexLexer, bygroups, include, words 

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

13 Whitespace 

14 

15__all__ = ['TealLexer'] 

16 

17 

18class TealLexer(RegexLexer): 

19 """ 

20 For the Transaction Execution Approval Language (TEAL) 

21 

22 For more information about the grammar, see: 

23 https://github.com/algorand/go-algorand/blob/master/data/transactions/logic/assembler.go 

24 

25 .. versionadded:: 2.9 

26 """ 

27 name = 'teal' 

28 url = 'https://developer.algorand.org/docs/reference/teal/specification/' 

29 aliases = ['teal'] 

30 filenames = ['*.teal'] 

31 

32 keywords = words({ 

33 'Sender', 'Fee', 'FirstValid', 'FirstValidTime', 'LastValid', 'Note', 

34 'Lease', 'Receiver', 'Amount', 'CloseRemainderTo', 'VotePK', 

35 'SelectionPK', 'VoteFirst', 'VoteLast', 'VoteKeyDilution', 'Type', 

36 'TypeEnum', 'XferAsset', 'AssetAmount', 'AssetSender', 'AssetReceiver', 

37 'AssetCloseTo', 'GroupIndex', 'TxID', 'ApplicationID', 'OnCompletion', 

38 'ApplicationArgs', 'NumAppArgs', 'Accounts', 'NumAccounts', 

39 'ApprovalProgram', 'ClearStateProgram', 'RekeyTo', 'ConfigAsset', 

40 'ConfigAssetTotal', 'ConfigAssetDecimals', 'ConfigAssetDefaultFrozen', 

41 'ConfigAssetUnitName', 'ConfigAssetName', 'ConfigAssetURL', 

42 'ConfigAssetMetadataHash', 'ConfigAssetManager', 'ConfigAssetReserve', 

43 'ConfigAssetFreeze', 'ConfigAssetClawback', 'FreezeAsset', 

44 'FreezeAssetAccount', 'FreezeAssetFrozen', 

45 'NoOp', 'OptIn', 'CloseOut', 'ClearState', 'UpdateApplication', 

46 'DeleteApplication', 

47 'MinTxnFee', 'MinBalance', 'MaxTxnLife', 'ZeroAddress', 'GroupSize', 

48 'LogicSigVersion', 'Round', 'LatestTimestamp', 'CurrentApplicationID', 

49 'AssetBalance', 'AssetFrozen', 

50 'AssetTotal', 'AssetDecimals', 'AssetDefaultFrozen', 'AssetUnitName', 

51 'AssetName', 'AssetURL', 'AssetMetadataHash', 'AssetManager', 

52 'AssetReserve', 'AssetFreeze', 'AssetClawback', 

53 }, suffix=r'\b') 

54 

55 identifier = r'[^ \t\n]+(?=\/\/)|[^ \t\n]+' 

56 newline = r'\r?\n' 

57 tokens = { 

58 'root': [ 

59 include('whitespace'), 

60 # pragmas match specifically on the space character 

61 (r'^#pragma .*' + newline, Comment.Directive), 

62 # labels must be followed by a space, 

63 # but anything after that is ignored 

64 ('(' + identifier + ':' + ')' + '([ \t].*)', 

65 bygroups(Name.Label, Comment.Single)), 

66 (identifier, Name.Function, 'function-args'), 

67 ], 

68 'function-args': [ 

69 include('whitespace'), 

70 (r'"', String, 'string'), 

71 (r'(b(?:ase)?(?:32|64) ?)(\(?[a-zA-Z0-9+/=]+\)?)', 

72 bygroups(String.Affix, String.Other)), 

73 (r'[A-Z2-7]{58}', Number), # address 

74 (r'0x[\da-fA-F]+', Number.Hex), 

75 (r'\d+', Number.Integer), 

76 (keywords, Keyword), 

77 (identifier, Name.Attributes), # branch targets 

78 (newline, Text, '#pop'), 

79 ], 

80 'string': [ 

81 (r'\\(?:["nrt\\]|x\d\d)', String.Escape), 

82 (r'[^\\\"\n]+', String), 

83 (r'"', String, '#pop'), 

84 ], 

85 'whitespace': [ 

86 (r'[ \t]+', Whitespace), 

87 (r'//[^\n]+', Comment.Single), 

88 ], 

89 }