logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

dmd.lua (6583B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- D LPeg lexer.
  3. -- Heavily modified by Brian Schott (@Hackerpilot on Github).
  4. local lexer = lexer
  5. local P, S = lpeg.P, lpeg.S
  6. local lex = lexer.new(...)
  7. -- Class names.
  8. local ws = lex:get_rule('whitespace')
  9. lex:add_rule('class',
  10. lex:tag(lexer.TYPE, P('class') + 'struct') * ws^-1 * lex:tag(lexer.CLASS, lexer.word))
  11. -- Versions.
  12. local open_paren = lex:tag(lexer.OPERATOR, '(')
  13. lex:add_rule('version', lex:tag(lexer.KEYWORD, 'version') * ws^-1 * open_paren * ws^-1 *
  14. lex:tag(lexer.CONSTANT_BUILTIN .. '.version', lex:word_match('version')))
  15. -- Scopes.
  16. lex:add_rule('scope', lex:tag(lexer.KEYWORD, 'scope') * ws^-1 * open_paren * ws^-1 *
  17. lex:tag(lexer.CONSTANT_BUILTIN .. '.scope', lexer.word_match('exit success failure')))
  18. -- Traits.
  19. lex:add_rule('trait', lex:tag(lexer.KEYWORD, '__traits') * ws^-1 * open_paren * ws^-1 *
  20. lex:tag(lexer.VARIABLE_BUILTIN .. '.traits', lex:word_match('trait')))
  21. -- Function names.
  22. local func = lex:tag(lexer.FUNCTION, lexer.word)
  23. local method = lpeg.B('.') * lex:tag(lexer.FUNCTION_METHOD, lexer.word)
  24. lex:add_rule('function', (method + func) * #(ws^-1 * ('!' * lexer.word^-1 * ws^-1)^-1 * '('))
  25. -- Keywords.
  26. lex:add_rule('keyword', lex:tag(lexer.KEYWORD, lex:word_match(lexer.KEYWORD)))
  27. -- Types.
  28. lex:add_rule('type', lex:tag(lexer.TYPE, lex:word_match(lexer.TYPE)))
  29. -- Constants.
  30. lex:add_rule('constant', lex:tag(lexer.CONSTANT_BUILTIN, lex:word_match(lexer.CONSTANT_BUILTIN)))
  31. -- Properties.
  32. local dot = lex:tag(lexer.OPERATOR, '.')
  33. lex:add_rule('property', lpeg.B(lexer.alnum + ')') * dot *
  34. lex:tag(lexer.VARIABLE_BUILTIN, lex:word_match('property')))
  35. -- Strings.
  36. local sq_str = lexer.range("'", true) * S('cwd')^-1
  37. local dq_str = lexer.range('"') * S('cwd')^-1
  38. local lit_str = 'r' * lexer.range('"', false, false) * S('cwd')^-1
  39. local bt_str = lexer.range('`', false, false) * S('cwd')^-1
  40. local hex_str = 'x' * lexer.range('"') * S('cwd')^-1
  41. local other_hex_str = '\\x' * (lexer.xdigit * lexer.xdigit)^1
  42. local str = sq_str + dq_str + lit_str + bt_str + hex_str + other_hex_str
  43. for left, right in pairs{['['] = ']', ['('] = ')', ['{'] = '}', ['<'] = '>'} do
  44. str = str + lexer.range('q"' .. left, right .. '"', false, false, true) * S('cwd')^-1
  45. end
  46. lex:add_rule('string', lex:tag(lexer.STRING, str))
  47. -- Identifiers.
  48. lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, lexer.word))
  49. -- Comments.
  50. local line_comment = lexer.to_eol('//', true)
  51. local block_comment = lexer.range('/*', '*/')
  52. local nested_comment = lexer.range('/+', '+/', false, false, true)
  53. lex:add_rule('comment', lex:tag(lexer.COMMENT, line_comment + block_comment + nested_comment))
  54. -- Numbers.
  55. lex:add_rule('number', lex:tag(lexer.NUMBER, lexer.number_('_') * S('uULdDfFi')^-1))
  56. -- Preprocessor.
  57. lex:add_rule('annotation', lex:tag(lexer.ANNOTATION, '@' * lexer.word^1))
  58. lex:add_rule('preprocessor', lex:tag(lexer.PREPROCESSOR, lexer.to_eol('#')))
  59. -- Operators.
  60. lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('?=!<>+-*$/%&|^~.,;:()[]{}')))
  61. -- Fold points.
  62. lex:add_fold_point(lexer.OPERATOR, '{', '}')
  63. lex:add_fold_point(lexer.COMMENT, '/*', '*/')
  64. lex:add_fold_point(lexer.COMMENT, '/+', '+/')
  65. -- Word lists.
  66. lex:set_word_list('version', {
  67. 'AArch64', 'AIX', 'all', 'Alpha', 'Alpha_HardFloat', 'Alpha_SoftFloat', 'Android', 'ARM',
  68. 'ARM_HardFloat', 'ARM_SoftFloat', 'ARM_SoftFP', 'ARM_Thumb', 'assert', 'BigEndian', 'BSD',
  69. 'Cygwin', 'D_Coverage', 'D_Ddoc', 'D_HardFloat', 'DigitalMars', 'D_InlineAsm_X86',
  70. 'D_InlineAsm_X86_64', 'D_LP64', 'D_NoBoundsChecks', 'D_PIC', 'DragonFlyBSD', 'D_SIMD',
  71. 'D_SoftFloat', 'D_Version2', 'D_X32', 'FreeBSD', 'GNU', 'Haiku', 'HPPA', 'HPPA64', 'Hurd', 'IA64',
  72. 'LDC', 'linux', 'LittleEndian', 'MIPS32', 'MIPS64', 'MIPS_EABI', 'MIPS_HardFloat', 'MIPS_N32',
  73. 'MIPS_N64', 'MIPS_O32', 'MIPS_O64', 'MIPS_SoftFloat', 'NetBSD', 'none', 'OpenBSD', 'OSX', 'Posix',
  74. 'PPC', 'PPC64', 'PPC_HardFloat', 'PPC_SoftFloat', 'S390', 'S390X', 'SDC', 'SH', 'SH64', 'SkyOS',
  75. 'Solaris', 'SPARC', 'SPARC64', 'SPARC_HardFloat', 'SPARC_SoftFloat', 'SPARC_V8Plus', 'SysV3',
  76. 'SysV4', 'unittest', 'Win32', 'Win64', 'Windows', 'X86', 'X86_64'
  77. })
  78. lex:set_word_list('trait', {
  79. 'allMembers', 'classInstanceSize', 'compiles', 'derivedMembers', 'getAttributes', 'getMember',
  80. 'getOverloads', 'getProtection', 'getUnitTests', 'getVirtualFunctions', 'getVirtualIndex',
  81. 'getVirtualMethods', 'hasMember', 'identifier', 'isAbstractClass', 'isAbstractFunction',
  82. 'isArithmetic', 'isAssociativeArray', 'isFinalClass', 'isFinalFunction', 'isFloating',
  83. 'isIntegral', 'isLazy', 'isNested', 'isOut', 'isOverrideFunction', 'isPOD', 'isRef', 'isSame',
  84. 'isScalar', 'isStaticArray', 'isStaticFunction', 'isUnsigned', 'isVirtualFunction',
  85. 'isVirtualMethod', 'parent'
  86. })
  87. lex:set_word_list(lexer.KEYWORD, {
  88. 'abstract', 'align', 'asm', 'assert', 'auto', 'body', 'break', 'case', 'cast', 'catch', 'const',
  89. 'continue', 'debug', 'default', 'delete', 'deprecated', 'do', 'else', 'extern', 'export', 'false',
  90. 'final', 'finally', 'for', 'foreach', 'foreach_reverse', 'goto', 'if', 'import', 'immutable',
  91. 'in', 'inout', 'invariant', 'is', 'lazy', 'macro', 'mixin', 'new', 'nothrow', 'null', 'out',
  92. 'override', 'pragma', 'private', 'protected', 'public', 'pure', 'ref', 'return', 'scope',
  93. 'shared', 'static', 'super', 'switch', 'synchronized', 'this', 'throwtrue', 'try', 'typeid',
  94. 'typeof', 'unittest', 'version', 'virtual', 'volatile', 'while', 'with', '__gshared', '__thread',
  95. '__traits', '__vector', '__parameters'
  96. })
  97. lex:set_word_list(lexer.TYPE, {
  98. 'alias', 'bool', 'byte', 'cdouble', 'cent', 'cfloat', 'char', 'class', 'creal', 'dchar',
  99. 'delegate', 'double', 'enum', 'float', 'function', 'idouble', 'ifloat', 'int', 'interface',
  100. 'ireal', 'long', 'module', 'package', 'ptrdiff_t', 'real', 'short', 'size_t', 'struct',
  101. 'template', 'typedef', 'ubyte', 'ucent', 'uint', 'ulong', 'union', 'ushort', 'void', 'wchar',
  102. 'string', 'wstring', 'dstring', 'hash_t', 'equals_t'
  103. })
  104. lex:set_word_list(lexer.CONSTANT_BUILTIN, {
  105. '__FILE__', '__LINE__', '__DATE__', '__EOF__', '__TIME__', '__TIMESTAMP__', '__VENDOR__',
  106. '__VERSION__', '__FUNCTION__', '__PRETTY_FUNCTION__', '__MODULE__'
  107. })
  108. lex:set_word_list('property', {
  109. 'alignof', 'dig', 'dup', 'epsilon', 'idup', 'im', 'init', 'infinity', 'keys', 'length',
  110. 'mangleof', 'mant_dig', 'max', 'max_10_exp', 'max_exp', 'min', 'min_normal', 'min_10_exp',
  111. 'min_exp', 'nan', 'offsetof', 'ptr', 're', 'rehash', 'reverse', 'sizeof', 'sort', 'stringof',
  112. 'tupleof', 'values'
  113. })
  114. lexer.property['scintillua.comment'] = '//'
  115. return lex