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

java.lua (7774B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- Java LPeg lexer.
  3. -- Modified by Brian Schott.
  4. local lexer = require('lexer')
  5. local P, S = lpeg.P, lpeg.S
  6. local lex = lexer.new(...)
  7. -- Classes.
  8. lex:add_rule('classdef', lex:tag(lexer.KEYWORD, 'class') * lex:get_rule('whitespace') *
  9. lex:tag(lexer.CLASS, lexer.word))
  10. -- Keywords.
  11. lex:add_rule('keyword', lex:tag(lexer.KEYWORD, lex:word_match(lexer.KEYWORD)))
  12. -- Functions.
  13. local builtin_func = lex:tag(lexer.FUNCTION_BUILTIN, lex:word_match(lexer.FUNCTION_BUILTIN))
  14. local func = lex:tag(lexer.FUNCTION, lexer.word)
  15. local method = lpeg.B('.') * lex:tag(lexer.FUNCTION_METHOD, lexer.word)
  16. lex:add_rule('function', (builtin_func + method + func) * #(lexer.space^0 * '('))
  17. -- Constants.
  18. lex:add_rule('constant', lex:tag(lexer.CONSTANT_BUILTIN, lex:word_match(lexer.CONSTANT_BUILTIN) +
  19. 'System.' * lexer.word_match('err in out')))
  20. -- Types.
  21. lex:add_rule('type', lex:tag(lexer.TYPE, lex:word_match(lexer.TYPE)))
  22. -- Identifiers.
  23. lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, lexer.word))
  24. -- Strings.
  25. local sq_str = lexer.range("'", true)
  26. local dq_str = lexer.range('"', true)
  27. lex:add_rule('string', lex:tag(lexer.STRING, sq_str + dq_str))
  28. -- Comments.
  29. local line_comment = lexer.to_eol('//', true)
  30. local block_comment = lexer.range('/*', '*/')
  31. lex:add_rule('comment', lex:tag(lexer.COMMENT, line_comment + block_comment))
  32. -- Numbers.
  33. lex:add_rule('number', lex:tag(lexer.NUMBER, lexer.number * S('LlFfDd')^-1))
  34. -- Annotations.
  35. lex:add_rule('annotation', lex:tag(lexer.ANNOTATION, '@' * lexer.word))
  36. -- Operators.
  37. lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('+-/*%<>!=^&|?~:;.()[]{}')))
  38. -- Fold points.
  39. lex:add_fold_point(lexer.OPERATOR, '{', '}')
  40. lex:add_fold_point(lexer.COMMENT, '/*', '*/')
  41. -- Word lists.
  42. lex:set_word_list(lexer.KEYWORD, {
  43. 'abstract', 'assert', 'break', 'case', 'catch', 'class', 'const', 'continue', 'default', 'do',
  44. 'else', 'enum', 'extends', 'final', 'finally', 'for', 'goto', 'if', 'implements', 'import',
  45. 'instanceof', 'interface', 'native', 'new', 'package', 'private', 'protected', 'public', 'return',
  46. 'static', 'strictfp', 'super', 'switch', 'synchronized', 'this', 'throw', 'throws', 'transient',
  47. 'try', 'while', 'volatile', --
  48. 'true', 'false', 'null' -- literals
  49. })
  50. lex:set_word_list(lexer.FUNCTION_BUILTIN, {
  51. 'clone', 'equals', 'finalize', 'getClass', 'hashCode', 'notify', 'notifyAll', 'toString', 'wait', --
  52. 'Boolean.compare', 'Boolean.getBoolean', 'Boolean.parseBoolean', 'Boolean.valueOf', --
  53. 'Byte.compare', 'Byte.decode', 'Byte.parseByte', 'Byte.valueOf', --
  54. 'Character.charCount', 'Character.codePointAt', 'Character.codePointBefore',
  55. 'Character.codePointCount', 'Character.compare', 'Character.digit', 'Character.forDigit',
  56. 'Character.getName', 'Character.getNumericValue', 'Character.getType', 'Character.isAlphabetic',
  57. 'Character.isDefined', 'Character.isDigit', 'Character.isIdentifierIgnorable',
  58. 'Character.isIdeographic', 'Character.isISOControl', 'Character.isJavaIdentifierPart',
  59. 'Character.isJavaIdentifierStart', 'Character.isLetter', 'Character.isLetterOrDigit',
  60. 'Character.isLowerCase', 'Character.isMirrored', 'Character.isSpaceChar',
  61. 'Character.isSupplementaryCodePoint', 'Character.isSurrogate', 'Character.isSurrogatePair',
  62. 'Character.isTitleCase', 'Character.isUnicodeIdentifierPart',
  63. 'Character.isUnicodeIdentifierStart', 'Character.isUpperCase', 'Character.isValidCodePoint',
  64. 'Character.isWhitespace', 'Character.offsetByCodePoints', 'Character.reverseBytes',
  65. 'Character.toChars', 'Character.toCodePoint', 'Character.toLowerCase', 'Character.toTitleCase',
  66. 'Character.toUpperCase', 'Character.valueOf', --
  67. 'Double.compare', 'Double.doubleToLongBits', 'Double.doubleToRawLongBits', 'Double.isInfinite',
  68. 'Double.longBitsToDouble', 'Double.parseDouble', 'Double.toHexString', 'Double.valueOf', --
  69. 'Integer.bitCount', 'Integer.compare', 'Integer.decode', 'Integer.getInteger',
  70. 'Integer.highestOneBit', 'Integer.lowestOneBit', 'Integer.numberOfLeadingZeros',
  71. 'Integer.numberOfTrailingZeros', 'Integer.parseInt', 'Integer.reverse', 'Integer.reverseBytes',
  72. 'Integer.rotateLeft', 'Integer.rotateRight', 'Integer.signum', 'Integer.toBinaryString',
  73. 'Integer.toHexString', 'Integer.toOctalString', 'Integer.valueOf', --
  74. 'Math.abs', 'Math.acos', 'Math.asin', 'Math.atan', 'Math.atan2', 'Math.cbrt', 'Math.ceil',
  75. 'Math.copySign', 'Math.cos', 'Math.cosh', 'Math.exp', 'Math.expm1', 'Math.floor',
  76. 'Math.getExponent', 'Math.hypot', 'Math.IEEEremainder', 'Math.log', 'Math.log10', 'Math.log1p',
  77. 'Math.max', 'Math.min', 'Math.nextAfter', 'Math.nextUp', 'Math.pow', 'Math.random', 'Math.rint',
  78. 'Math.round', 'Math.scalb', 'Math.signum', 'Math.sin', 'Math.sinh', 'Math.sqrt', 'Math.tan',
  79. 'Math.tanh', 'Math.toDegrees', 'Math.toRadians', 'Math.ulp', --
  80. 'Runtime.getRuntime', --
  81. 'String.copyValueOf', 'String.format', 'String.valueOf', --
  82. 'System.arraycopy', 'System.clearProperty', 'System.console', 'System.currentTimeMillis',
  83. 'System.exit', 'System.gc', 'System.getenv', 'System.getProperties', 'System.getProperty',
  84. 'System.getSecurityManager', 'System.identityHashCode', 'System.inheritedChannel',
  85. 'System.lineSeparator', 'System.load', 'System.loadLibrary', 'System.mapLibraryName',
  86. 'System.nanoTime', 'System.runFinalization', 'System.setErr', 'System.setIn', 'System.setOut',
  87. 'System.setProperties', 'System.setProperty', 'System.setSecurityManager', --
  88. 'Thread.activeCount', 'Thread.currentThread', 'Thread.dumpStack', 'Thread.enumerate',
  89. 'Thread.getAllStackTraces', 'Thread.getDefaultUncaughtExceptionHandler', 'Thread.holdsLock',
  90. 'Thread.interrupted', 'Thread.setDefaultUncaughtExceptionHandler', 'Thread.sleep', 'Thread.yield' --
  91. })
  92. lex:set_word_list(lexer.CONSTANT_BUILTIN, {
  93. 'Double.MAX_EXPONENT', 'Double.MAX_VALUE', 'Double.MIN_EXPONENT', 'Double.MIN_NORMAL',
  94. 'Double.MIN_VALUE', 'Double.NaN', 'Double.NEGATIVE_INFINITY', 'Double.POSITIVE_INFINITY', --
  95. 'Integer.MAX_VALUE', 'Integer.MIN_VALUE', --
  96. 'Math.E', 'Math.PI', --
  97. 'Thread.MAX_PRIORITY', 'Thread.MIN_PRIORITY', 'Thread.NORM_PRIORITY'
  98. })
  99. lex:set_word_list(lexer.TYPE, {
  100. 'boolean', 'byte', 'char', 'double', 'float', 'int', 'long', 'short', 'void', 'Boolean', 'Byte',
  101. 'Character', 'Class', 'Double', 'Enum', 'Float', 'Integer', 'Long', 'Object', 'Process',
  102. 'Runtime', 'Short', 'String', 'StringBuffer', 'StringBuilder', 'Thread', 'Throwable', 'Void',
  103. -- Exceptions.
  104. 'ArithmeticException', 'ArrayIndexOutOfBoundsException', 'ArrayStoreException',
  105. 'ClassCastException', 'ClassNotFoundException', 'CloneNotSupportedException',
  106. 'EnumConstantNotPresentException', 'Exception', 'IllegalAccessException',
  107. 'IllegalArgumentException', 'IllegalMonitorStateException', 'IllegalStateException',
  108. 'IllegalThreadStateException', 'IndexOutOfBoundsException', 'InstantiationException',
  109. 'InterruptedException', 'NegativeArraySizeException', 'NoSuchFieldException',
  110. 'NoSuchMethodException', 'NullPointerException', 'NumberFormatException',
  111. 'ReflectiveOperationException', 'RuntimeException', 'SecurityException',
  112. 'StringIndexOutOfBoundsException', 'TypeNotPresentException', 'UnsupportedOperationException',
  113. -- Errors.
  114. 'AbstractMethodError', 'AssertionError', 'BootstrapMethodError', 'ClassCircularityError',
  115. 'ClassFormatError', 'Error', 'ExceptionInInitializerError', 'IllegalAccessError',
  116. 'IncompatibleClassChangeError', 'InstantiationError', 'InternalError', 'LinkageError',
  117. 'NoClassDefFoundError', 'NoSuchFieldError', 'NoSuchMethodError', 'OutOfMemoryError',
  118. 'StackOverflowError', 'ThreadDeath', 'UnknownError', 'UnsatisfiedLinkError',
  119. 'UnsupportedClassVersionError', 'VerifyError', 'VirtualMachineError'
  120. })
  121. lexer.property['scintillua.comment'] = '//'
  122. return lex