ride.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. """
  2. pygments.lexers.ride
  3. ~~~~~~~~~~~~~~~~~~~~
  4. Lexer for the Ride programming language.
  5. :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. from pygments.lexer import RegexLexer, words, include
  9. from pygments.token import Comment, Keyword, Name, Number, Punctuation, \
  10. String, Text
  11. __all__ = ['RideLexer']
  12. class RideLexer(RegexLexer):
  13. """
  14. For Ride source code.
  15. """
  16. name = 'Ride'
  17. aliases = ['ride']
  18. filenames = ['*.ride']
  19. mimetypes = ['text/x-ride']
  20. url = 'https://docs.waves.tech/en/ride'
  21. version_added = '2.6'
  22. validName = r'[a-zA-Z_][a-zA-Z0-9_\']*'
  23. builtinOps = (
  24. '||', '|', '>=', '>', '==', '!',
  25. '=', '<=', '<', '::', ':+', ':', '!=', '/',
  26. '.', '=>', '-', '+', '*', '&&', '%', '++',
  27. )
  28. globalVariablesName = (
  29. 'NOALG', 'MD5', 'SHA1', 'SHA224', 'SHA256', 'SHA384', 'SHA512',
  30. 'SHA3224', 'SHA3256', 'SHA3384', 'SHA3512', 'nil', 'this', 'unit',
  31. 'height', 'lastBlock', 'Buy', 'Sell', 'CEILING', 'FLOOR', 'DOWN',
  32. 'HALFDOWN', 'HALFEVEN', 'HALFUP', 'UP',
  33. )
  34. typesName = (
  35. 'Unit', 'Int', 'Boolean', 'ByteVector', 'String', 'Address', 'Alias',
  36. 'Transfer', 'AssetPair', 'DataEntry', 'Order', 'Transaction',
  37. 'GenesisTransaction', 'PaymentTransaction', 'ReissueTransaction',
  38. 'BurnTransaction', 'MassTransferTransaction', 'ExchangeTransaction',
  39. 'TransferTransaction', 'SetAssetScriptTransaction',
  40. 'InvokeScriptTransaction', 'IssueTransaction', 'LeaseTransaction',
  41. 'LeaseCancelTransaction', 'CreateAliasTransaction',
  42. 'SetScriptTransaction', 'SponsorFeeTransaction', 'DataTransaction',
  43. 'WriteSet', 'AttachedPayment', 'ScriptTransfer', 'TransferSet',
  44. 'ScriptResult', 'Invocation', 'Asset', 'BlockInfo', 'Issue', 'Reissue',
  45. 'Burn', 'NoAlg', 'Md5', 'Sha1', 'Sha224', 'Sha256', 'Sha384', 'Sha512',
  46. 'Sha3224', 'Sha3256', 'Sha3384', 'Sha3512', 'BinaryEntry',
  47. 'BooleanEntry', 'IntegerEntry', 'StringEntry', 'List', 'Ceiling',
  48. 'Down', 'Floor', 'HalfDown', 'HalfEven', 'HalfUp', 'Up',
  49. )
  50. functionsName = (
  51. 'fraction', 'size', 'toBytes', 'take', 'drop', 'takeRight', 'dropRight',
  52. 'toString', 'isDefined', 'extract', 'throw', 'getElement', 'value',
  53. 'cons', 'toUtf8String', 'toInt', 'indexOf', 'lastIndexOf', 'split',
  54. 'parseInt', 'parseIntValue', 'keccak256', 'blake2b256', 'sha256',
  55. 'sigVerify', 'toBase58String', 'fromBase58String', 'toBase64String',
  56. 'fromBase64String', 'transactionById', 'transactionHeightById',
  57. 'getInteger', 'getBoolean', 'getBinary', 'getString',
  58. 'addressFromPublicKey', 'addressFromString', 'addressFromRecipient',
  59. 'assetBalance', 'wavesBalance', 'getIntegerValue', 'getBooleanValue',
  60. 'getBinaryValue', 'getStringValue', 'addressFromStringValue',
  61. 'assetInfo', 'rsaVerify', 'checkMerkleProof', 'median',
  62. 'valueOrElse', 'valueOrErrorMessage', 'contains', 'log', 'pow',
  63. 'toBase16String', 'fromBase16String', 'blockInfoByHeight',
  64. 'transferTransactionById',
  65. )
  66. reservedWords = words((
  67. 'match', 'case', 'else', 'func', 'if',
  68. 'let', 'then', '@Callable', '@Verifier',
  69. ), suffix=r'\b')
  70. tokens = {
  71. 'root': [
  72. # Comments
  73. (r'#.*', Comment.Single),
  74. # Whitespace
  75. (r'\s+', Text),
  76. # Strings
  77. (r'"', String, 'doublequote'),
  78. (r'utf8\'', String, 'utf8quote'),
  79. (r'base(58|64|16)\'', String, 'singlequote'),
  80. # Keywords
  81. (reservedWords, Keyword.Reserved),
  82. (r'\{-#.*?#-\}', Keyword.Reserved),
  83. (r'FOLD<\d+>', Keyword.Reserved),
  84. # Types
  85. (words(typesName), Keyword.Type),
  86. # Main
  87. # (specialName, Keyword.Reserved),
  88. # Prefix Operators
  89. (words(builtinOps, prefix=r'\(', suffix=r'\)'), Name.Function),
  90. # Infix Operators
  91. (words(builtinOps), Name.Function),
  92. (words(globalVariablesName), Name.Function),
  93. (words(functionsName), Name.Function),
  94. # Numbers
  95. include('numbers'),
  96. # Variable Names
  97. (validName, Name.Variable),
  98. # Parens
  99. (r'[,()\[\]{}]', Punctuation),
  100. ],
  101. 'doublequote': [
  102. (r'\\u[0-9a-fA-F]{4}', String.Escape),
  103. (r'\\[nrfvb\\"]', String.Escape),
  104. (r'[^"]', String),
  105. (r'"', String, '#pop'),
  106. ],
  107. 'utf8quote': [
  108. (r'\\u[0-9a-fA-F]{4}', String.Escape),
  109. (r'\\[nrfvb\\\']', String.Escape),
  110. (r'[^\']', String),
  111. (r'\'', String, '#pop'),
  112. ],
  113. 'singlequote': [
  114. (r'[^\']', String),
  115. (r'\'', String, '#pop'),
  116. ],
  117. 'numbers': [
  118. (r'_?\d+', Number.Integer),
  119. ],
  120. }