Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F18935732
D19637.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D19637.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -296,6 +296,7 @@
'PhutilJSONProtocolChannelTestCase' => 'channel/__tests__/PhutilJSONProtocolChannelTestCase.php',
'PhutilJSONTestCase' => 'parser/__tests__/PhutilJSONTestCase.php',
'PhutilJavaCodeSnippetContextFreeGrammar' => 'grammar/code/PhutilJavaCodeSnippetContextFreeGrammar.php',
+ 'PhutilJavaFragmentLexer' => 'lexer/PhutilJavaFragmentLexer.php',
'PhutilKeyValueCache' => 'cache/PhutilKeyValueCache.php',
'PhutilKeyValueCacheNamespace' => 'cache/PhutilKeyValueCacheNamespace.php',
'PhutilKeyValueCacheProfiler' => 'cache/PhutilKeyValueCacheProfiler.php',
@@ -937,6 +938,7 @@
'PhutilJSONProtocolChannelTestCase' => 'PhutilTestCase',
'PhutilJSONTestCase' => 'PhutilTestCase',
'PhutilJavaCodeSnippetContextFreeGrammar' => 'PhutilCLikeCodeSnippetContextFreeGrammar',
+ 'PhutilJavaFragmentLexer' => 'PhutilLexer',
'PhutilKeyValueCache' => 'Phobject',
'PhutilKeyValueCacheNamespace' => 'PhutilKeyValueCacheProxy',
'PhutilKeyValueCacheProfiler' => 'PhutilKeyValueCacheProxy',
diff --git a/src/lexer/PhutilJavaFragmentLexer.php b/src/lexer/PhutilJavaFragmentLexer.php
new file mode 100644
--- /dev/null
+++ b/src/lexer/PhutilJavaFragmentLexer.php
@@ -0,0 +1,120 @@
+<?php
+
+final class PhutilJavaFragmentLexer extends PhutilLexer {
+
+ protected function getRawRules() {
+ $keywords = array(
+ 'assert',
+ 'break',
+ 'case',
+ 'catch',
+ 'continue',
+ 'default',
+ 'do',
+ 'else',
+ 'finally',
+ 'for',
+ 'if',
+ 'goto',
+ 'instanceof',
+ 'new',
+ 'return',
+ 'switch',
+ 'this',
+ 'throw',
+ 'try',
+ 'while',
+ );
+
+ $declarations = array(
+ 'abstract',
+ 'const',
+ 'enum',
+ 'extends',
+ 'final',
+ 'implements',
+ 'native',
+ 'private',
+ 'protected',
+ 'public',
+ 'static',
+ 'strictfp',
+ 'super',
+ 'synchronized',
+ 'throws',
+ 'transient',
+ 'volatile',
+ );
+
+ $types = array(
+ 'boolean',
+ 'byte',
+ 'char',
+ 'double',
+ 'float',
+ 'int',
+ 'long',
+ 'short',
+ 'void',
+ );
+
+ $constants = array(
+ 'true',
+ 'false',
+ 'null',
+ );
+
+ $nonsemantic_rules = array(
+ array('\s+', null),
+ array('//.*?\\n', 'c'),
+ array('/\\*.*?\\*/', 'c'),
+ );
+
+ return array(
+ 'start' => array_merge(
+ $nonsemantic_rules,
+ array(
+ array('('.implode('|', $keywords).')\\b', 'k'),
+ array('@[^\\W\\d][\\w.]*', 'nd'),
+ array('('.implode('|', $declarations).')\\b', 'k'),
+ array('('.implode('|', $types).')\\b', 't'),
+ array('(package|import\\s+static|import)\\b', 'kn', 'import'),
+ array('('.implode('|', $constants).')\\b', 'kc'),
+ array('(class|interface)\\b', 'kd', 'class'),
+ array('"(\\\\\\\\|\\\\"|[^"\\\\]+)*"', 's'),
+ array("'(\\\\.|[^\\\\]|\\\\u[0-9a-f-A-F]{4})'", 's'),
+ array('([^\\W\\d]|\\$)[\\w$]*:', 'nl'),
+ array('([^\\W\\d]|\\$)[\\w$]*', 'n'),
+ array(
+ '(([0-9][0-9_]*\\.([0-9][0-9_]*)?|'.
+ '\\.[0-9][0-9_]*)([eE][+-]?[0-9][0-9_]*)?[fFdD]?|'.
+ '[0-9][eE][+-]?[0-9][0-9_]*[fFdD]?|'.
+ '[0-9]([eE][+-]?[0-9][0-9_]*)?[fFdD]|'.
+ '0[xX]([0-9a-fA-F][0-9a-fA-F_]*\\.?|'.
+ '([0-9a-fA-F][0-9a-fA-F_]*)?\\.[0-9a-fA-F][0-9a-fA-F_]*)'.
+ '[pP][+-]?[0-9][0-9_]*[fFdD]?)',
+ 'mf',
+ ),
+ array('0[xX][0-9a-fA-F][0-9a-fA-F_]*[lL]?', 'mh'),
+ array('0[bB][01][01_]*[lL]?', 'mb'),
+ array('0[0-7_]+[lL]?', 'mo'),
+ array('(0|[1-9][0-9_]*[lL]?)', 'mi'),
+ array('([~^*!%&\\[\\](){}<>|+=:;,./?-])', 'o'),
+ array('(\S+|\s+)', null),
+ )),
+ 'class' => array_merge(
+ $nonsemantic_rules,
+ array(
+ array('([^\W\d]|\$)[\w$]*', 'nc', '!pop'),
+ array('', null, '!pop'),
+ )),
+ 'import' => array_merge(
+ $nonsemantic_rules,
+ array(
+ array('[\w.]+\*?', 'nn', '!pop'),
+ array('', null, '!pop'),
+ )),
+ );
+ }
+
+}
diff --git a/src/markup/syntax/engine/PhutilDefaultSyntaxHighlighterEngine.php b/src/markup/syntax/engine/PhutilDefaultSyntaxHighlighterEngine.php
--- a/src/markup/syntax/engine/PhutilDefaultSyntaxHighlighterEngine.php
+++ b/src/markup/syntax/engine/PhutilDefaultSyntaxHighlighterEngine.php
@@ -80,6 +80,13 @@
->getHighlightFuture($source);
}
+ if ($language == 'java') {
+ return id(new PhutilLexerSyntaxHighlighter())
+ ->setConfig('lexer', new PhutilJavaFragmentLexer())
+ ->setConfig('language', 'java')
+ ->getHighlightFuture($source);
+ }
+
if ($language == 'json') {
return id(new PhutilLexerSyntaxHighlighter())
->setConfig('lexer', new PhutilJSONFragmentLexer())
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 11, 6:51 PM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
8770015
Default Alt Text
D19637.diff (5 KB)
Attached To
Mode
D19637: Port the Java fragment lexer to PHP
Attached
Detach File
Event Timeline
Log In to Comment