react-native-codepad-lang-java 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "CodepadLangJava"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+ s.platforms = { :ios => "17.0" }
13
+ s.source = { :git => "https://github.com/SectionTN/react-native-codepad.git", :tag => "v#{s.version}" }
14
+
15
+ s.source_files = ["ios/*.{h,swift}", "grammar/src/parser.c"]
16
+ s.public_header_files = "ios/*.h"
17
+ s.preserve_paths = "grammar/**/*"
18
+ s.compiler_flags = "-w"
19
+ s.pod_target_xcconfig = {
20
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/grammar/src\"",
21
+ "GCC_OPTIMIZATION_LEVEL" => "1",
22
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
23
+ "SWIFT_OBJC_INTEROP_MODE" => "objcxx",
24
+ "DEFINES_MODULE" => "YES",
25
+ }
26
+
27
+ s.dependency "Codepad"
28
+ end
package/README.md CHANGED
@@ -1,3 +1,55 @@
1
- # Temporary Holding Version
1
+ # react-native-codepad-lang-java
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Generated package. Do not edit by hand; run `yarn gen:languages` in the react-native-codepad repository.
4
+
5
+ Grammar: tree-sitter/tree-sitter-java at e10607b45ff745f5f876bfa3e94fbcc6b44bdc11. Queries: nvim-treesitter at e289100ff98969e118c702199d88b764ce9e7fdf.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ yarn add react-native-codepad react-native-codepad-lang-java
11
+ ```
12
+
13
+ Then pass `language="java"` to `CodeEditor`. Theme token keys this package produces:
14
+
15
+ ### java
16
+
17
+ - `attribute`
18
+ - `boolean`
19
+ - `character`
20
+ - `character.special`
21
+ - `comment`
22
+ - `comment.documentation`
23
+ - `constant`
24
+ - `constant.builtin`
25
+ - `function.builtin`
26
+ - `function.method`
27
+ - `function.method.call`
28
+ - `keyword`
29
+ - `keyword.conditional`
30
+ - `keyword.conditional.ternary`
31
+ - `keyword.exception`
32
+ - `keyword.import`
33
+ - `keyword.modifier`
34
+ - `keyword.operator`
35
+ - `keyword.repeat`
36
+ - `keyword.return`
37
+ - `keyword.type`
38
+ - `label`
39
+ - `number`
40
+ - `number.float`
41
+ - `operator`
42
+ - `punctuation.bracket`
43
+ - `punctuation.delimiter`
44
+ - `punctuation.special`
45
+ - `spell`
46
+ - `string`
47
+ - `string.escape`
48
+ - `type`
49
+ - `type.builtin`
50
+ - `variable`
51
+ - `variable.builtin`
52
+ - `variable.member`
53
+ - `variable.parameter`
54
+
55
+ See the [languages guide](https://sectiontn.github.io/react-native-codepad/guides/languages/) for aliases, injections and themes.
@@ -0,0 +1,14 @@
1
+ cmake_minimum_required(VERSION 3.13)
2
+ project(codepad_lang_java C)
3
+ set(GRAMMAR ${CMAKE_SOURCE_DIR}/../grammar)
4
+
5
+ add_library(codepad_lang_java SHARED
6
+ src/main/cpp/lang.c
7
+ ${GRAMMAR}/src/parser.c
8
+ )
9
+
10
+ target_include_directories(codepad_lang_java PRIVATE ${GRAMMAR}/src)
11
+
12
+ # Parser tables are data. -O1 keeps large grammars from taking minutes to compile.
13
+ set_source_files_properties(${GRAMMAR}/src/parser.c PROPERTIES COMPILE_OPTIONS "-O1")
14
+ target_compile_options(codepad_lang_java PRIVATE -std=c11 -O2 -fvisibility=hidden -w)
@@ -0,0 +1,61 @@
1
+ buildscript {
2
+ repositories {
3
+ google()
4
+ mavenCentral()
5
+ }
6
+ dependencies {
7
+ classpath "com.android.tools.build:gradle:8.7.2"
8
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.21"
9
+ }
10
+ }
11
+
12
+ apply plugin: "com.android.library"
13
+ if (project.extensions.findByName("kotlin") == null) {
14
+ apply plugin: "kotlin-android"
15
+ }
16
+ apply plugin: "com.facebook.react"
17
+
18
+ def safeExtGet(prop, fallback) {
19
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
20
+ }
21
+
22
+ def reactNativeArchitectures() {
23
+ def value = rootProject.getProperties().get("reactNativeArchitectures")
24
+ return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
25
+ }
26
+
27
+ android {
28
+ namespace "me.sectiontn.codepad.lang.java"
29
+ compileSdkVersion safeExtGet("compileSdkVersion", 36)
30
+
31
+ defaultConfig {
32
+ minSdkVersion safeExtGet("minSdkVersion", 24)
33
+ consumerProguardFiles "consumer-rules.pro"
34
+ externalNativeBuild {
35
+ cmake {
36
+ arguments "-DANDROID_STL=none", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
37
+ abiFilters(*reactNativeArchitectures())
38
+ }
39
+ }
40
+ }
41
+
42
+ if (rootProject.ext.has("ndkVersion")) {
43
+ ndkVersion rootProject.ext.ndkVersion
44
+ }
45
+
46
+ externalNativeBuild {
47
+ cmake {
48
+ path "CMakeLists.txt"
49
+ }
50
+ }
51
+
52
+ compileOptions {
53
+ sourceCompatibility JavaVersion.VERSION_17
54
+ targetCompatibility JavaVersion.VERSION_17
55
+ }
56
+ }
57
+
58
+ dependencies {
59
+ implementation "com.facebook.react:react-android"
60
+ implementation project(":react-native-codepad")
61
+ }
@@ -0,0 +1 @@
1
+ -keep class me.sectiontn.codepad.lang.java.JavaLanguage { *; }
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,10 @@
1
+ #include <jni.h>
2
+ #include <stdint.h>
3
+
4
+ const void *tree_sitter_java(void);
5
+
6
+ JNIEXPORT jlong JNICALL Java_me_sectiontn_codepad_lang_java_JavaLanguage_nativeLanguage(JNIEnv *env, jobject thiz) {
7
+ (void) env;
8
+ (void) thiz;
9
+ return (jlong) (intptr_t) tree_sitter_java();
10
+ }
@@ -0,0 +1,13 @@
1
+ package me.sectiontn.codepad.lang.java
2
+
3
+ import com.facebook.react.BaseReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.module.model.ReactModuleInfoProvider
7
+
8
+ // Empty package so React Native autolinking includes this Gradle module.
9
+ class CodepadLangJavaPackage : BaseReactPackage() {
10
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? = null
11
+
12
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = ReactModuleInfoProvider { HashMap() }
13
+ }
@@ -0,0 +1,385 @@
1
+ package me.sectiontn.codepad.lang.java
2
+
3
+ import me.sectiontn.codepad.syntax.LanguageProvider
4
+
5
+ class JavaLanguage : LanguageProvider {
6
+ override val id: String = "java"
7
+ override val languagePointer: Long get() = nativeLanguage()
8
+ override val highlights: String = HIGHLIGHTS
9
+ override val injections: String = INJECTIONS
10
+
11
+ private external fun nativeLanguage(): Long
12
+
13
+ companion object {
14
+ init {
15
+ System.loadLibrary("codepad_lang_java")
16
+ }
17
+
18
+ private val HIGHLIGHTS: String = """; CREDITS @maxbrunsfeld (maxbrunsfeld@gmail.com)
19
+ ; Variables
20
+ (identifier) @variable
21
+
22
+ (underscore_pattern) @character.special
23
+
24
+ ; Methods
25
+ (method_declaration
26
+ name: (identifier) @function.method)
27
+
28
+ (method_invocation
29
+ name: (identifier) @function.method.call)
30
+
31
+ (super) @function.builtin
32
+
33
+ ; Parameters
34
+ (formal_parameter
35
+ name: (identifier) @variable.parameter)
36
+
37
+ (spread_parameter
38
+ (variable_declarator
39
+ name: (identifier) @variable.parameter)) ; int... foo
40
+
41
+ ; Lambda parameter
42
+ (inferred_parameters
43
+ (identifier) @variable.parameter) ; (x,y) -> ...
44
+
45
+ (lambda_expression
46
+ parameters: (identifier) @variable.parameter) ; x -> ...
47
+
48
+ ; Operators
49
+ [
50
+ "+"
51
+ ":"
52
+ "++"
53
+ "-"
54
+ "--"
55
+ "&"
56
+ "&&"
57
+ "|"
58
+ "||"
59
+ "!"
60
+ "!="
61
+ "=="
62
+ "*"
63
+ "/"
64
+ "%"
65
+ "<"
66
+ "<="
67
+ ">"
68
+ ">="
69
+ "="
70
+ "-="
71
+ "+="
72
+ "*="
73
+ "/="
74
+ "%="
75
+ "->"
76
+ "^"
77
+ "^="
78
+ "&="
79
+ "|="
80
+ "~"
81
+ ">>"
82
+ ">>>"
83
+ "<<"
84
+ "::"
85
+ ] @operator
86
+
87
+ ; Types
88
+ (interface_declaration
89
+ name: (identifier) @type)
90
+
91
+ (annotation_type_declaration
92
+ name: (identifier) @type)
93
+
94
+ (class_declaration
95
+ name: (identifier) @type)
96
+
97
+ (record_declaration
98
+ name: (identifier) @type)
99
+
100
+ (enum_declaration
101
+ name: (identifier) @type)
102
+
103
+ (constructor_declaration
104
+ name: (identifier) @type)
105
+
106
+ (compact_constructor_declaration
107
+ name: (identifier) @type)
108
+
109
+ (type_identifier) @type
110
+
111
+ ((type_identifier) @type.builtin
112
+ (#eq? @type.builtin "var"))
113
+
114
+ ((method_invocation
115
+ object: (identifier) @type)
116
+ (#match? @type "^[A-Z]"))
117
+
118
+ ((method_reference
119
+ .
120
+ (identifier) @type)
121
+ (#match? @type "^[A-Z]"))
122
+
123
+ ((field_access
124
+ object: (identifier) @type)
125
+ (#match? @type "^[A-Z]"))
126
+
127
+ (scoped_identifier
128
+ (identifier) @type
129
+ (#match? @type "^[A-Z]"))
130
+
131
+ ; Fields
132
+ (field_declaration
133
+ declarator: (variable_declarator
134
+ name: (identifier) @variable.member))
135
+
136
+ (field_access
137
+ field: (identifier) @variable.member)
138
+
139
+ [
140
+ (boolean_type)
141
+ (integral_type)
142
+ (floating_point_type)
143
+ (void_type)
144
+ ] @type.builtin
145
+
146
+ ; Variables
147
+ ((identifier) @constant
148
+ (#match? @constant "^[A-Z_][A-Z0-9_]+${'$'}"))
149
+
150
+ (this) @variable.builtin
151
+
152
+ ; Annotations
153
+ (annotation
154
+ "@" @attribute
155
+ name: (identifier) @attribute)
156
+
157
+ (marker_annotation
158
+ "@" @attribute
159
+ name: (identifier) @attribute)
160
+
161
+ ; Literals
162
+ (string_literal) @string
163
+
164
+ (escape_sequence) @string.escape
165
+
166
+ (character_literal) @character
167
+
168
+ [
169
+ (hex_integer_literal)
170
+ (decimal_integer_literal)
171
+ (octal_integer_literal)
172
+ (binary_integer_literal)
173
+ ] @number
174
+
175
+ [
176
+ (decimal_floating_point_literal)
177
+ (hex_floating_point_literal)
178
+ ] @number.float
179
+
180
+ [
181
+ (true)
182
+ (false)
183
+ ] @boolean
184
+
185
+ (null_literal) @constant.builtin
186
+
187
+ ; Keywords
188
+ [
189
+ "assert"
190
+ "default"
191
+ "extends"
192
+ "implements"
193
+ "instanceof"
194
+ "@interface"
195
+ "permits"
196
+ "to"
197
+ "with"
198
+ ] @keyword
199
+
200
+ [
201
+ "record"
202
+ "class"
203
+ "enum"
204
+ "interface"
205
+ ] @keyword.type
206
+
207
+ (synchronized_statement
208
+ "synchronized" @keyword)
209
+
210
+ [
211
+ "abstract"
212
+ "final"
213
+ "native"
214
+ "non-sealed"
215
+ "open"
216
+ "private"
217
+ "protected"
218
+ "public"
219
+ "sealed"
220
+ "static"
221
+ "strictfp"
222
+ "transitive"
223
+ ] @keyword.modifier
224
+
225
+ (modifiers
226
+ "synchronized" @keyword.modifier)
227
+
228
+ [
229
+ "transient"
230
+ "volatile"
231
+ ] @keyword.modifier
232
+
233
+ [
234
+ "return"
235
+ "yield"
236
+ ] @keyword.return
237
+
238
+ "new" @keyword.operator
239
+
240
+ ; Conditionals
241
+ [
242
+ "if"
243
+ "else"
244
+ "switch"
245
+ "case"
246
+ "when"
247
+ ] @keyword.conditional
248
+
249
+ (ternary_expression
250
+ [
251
+ "?"
252
+ ":"
253
+ ] @keyword.conditional.ternary)
254
+
255
+ (wildcard
256
+ "?" @character.special)
257
+
258
+ ; Loops
259
+ [
260
+ "for"
261
+ "while"
262
+ "do"
263
+ "continue"
264
+ "break"
265
+ ] @keyword.repeat
266
+
267
+ ; Includes
268
+ [
269
+ "exports"
270
+ "import"
271
+ "module"
272
+ "opens"
273
+ "package"
274
+ "provides"
275
+ "requires"
276
+ "uses"
277
+ ] @keyword.import
278
+
279
+ (import_declaration
280
+ (asterisk
281
+ "*" @character.special))
282
+
283
+ ; Punctuation
284
+ [
285
+ ";"
286
+ "."
287
+ "..."
288
+ ","
289
+ ] @punctuation.delimiter
290
+
291
+ [
292
+ "{"
293
+ "}"
294
+ ] @punctuation.bracket
295
+
296
+ [
297
+ "["
298
+ "]"
299
+ ] @punctuation.bracket
300
+
301
+ [
302
+ "("
303
+ ")"
304
+ ] @punctuation.bracket
305
+
306
+ (type_arguments
307
+ [
308
+ "<"
309
+ ">"
310
+ ] @punctuation.bracket)
311
+
312
+ (type_parameters
313
+ [
314
+ "<"
315
+ ">"
316
+ ] @punctuation.bracket)
317
+
318
+ (string_interpolation
319
+ [
320
+ "\\{"
321
+ "}"
322
+ ] @punctuation.special)
323
+
324
+ ; Exceptions
325
+ [
326
+ "throw"
327
+ "throws"
328
+ "finally"
329
+ "try"
330
+ "catch"
331
+ ] @keyword.exception
332
+
333
+ ; Labels
334
+ (labeled_statement
335
+ (identifier) @label)
336
+
337
+ ; Comments
338
+ [
339
+ (line_comment)
340
+ (block_comment)
341
+ ] @comment @spell
342
+
343
+ ((block_comment) @comment.documentation
344
+ (#match? @comment.documentation "^/[*][*][^*].*[*]/${'$'}"))
345
+
346
+ ((line_comment) @comment.documentation
347
+ (#match? @comment.documentation "^///[^/]"))
348
+
349
+ ((line_comment) @comment.documentation
350
+ (#match? @comment.documentation "^///${'$'}"))
351
+ """
352
+ private val INJECTIONS: String = """([
353
+ (block_comment)
354
+ (line_comment)
355
+ ] @injection.content
356
+ (#set! injection.language "comment"))
357
+
358
+ ((block_comment) @injection.content
359
+ (#match? @injection.content "/[*][*][\\s]")
360
+ (#set! injection.language "javadoc"))
361
+
362
+ ; markdown-style javadocs https://openjdk.org/jeps/467
363
+ ((line_comment) @injection.content
364
+ (#match? @injection.content "^///\\s")
365
+ (#set! injection.language "javadoc"))
366
+
367
+ ((method_invocation
368
+ name: (identifier) @_method
369
+ arguments: (argument_list
370
+ .
371
+ (string_literal
372
+ .
373
+ (_) @injection.content)))
374
+ (#any-of? @_method "format" "printf")
375
+ (#set! injection.language "printf"))
376
+
377
+ ((method_invocation
378
+ object: (string_literal
379
+ (string_fragment) @injection.content)
380
+ name: (identifier) @_method)
381
+ (#eq? @_method "formatted")
382
+ (#set! injection.language "printf"))
383
+ """
384
+ }
385
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Ayman Nadeem
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.