ride.py 4.9 KB

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