Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kotlin: parser based on peg grammar #2866

Merged
merged 6 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions Units/parser-kotlin.r/kotlin-comments.d/input.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ var c = 3
*/

/* comment */ var f = 6 /* another comment */

/*
comment
/* nested comment */
var g = 7
*/
11 changes: 8 additions & 3 deletions Units/parser-kotlin.r/kotlin-generics.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Bar input.kt /^class Bar<T, U>(val a: T, val b: U): Foo<T>$/;" c
Baz input.kt /^class Baz <T, U: Pair<String,Pair<T, Double>>>(val c: T, val d: U): Foo<T>$/;" c
Foo input.kt /^interface Foo<T> {$/;" i
a input.kt /^class Bar<T, U>(val a: T, val b: U): Foo<T>$/;" C
b input.kt /^class Bar<T, U>(val a: T, val b: U): Foo<T>$/;" C
genericFunction input.kt /^ fun<T: Any> genericFunction() = 42$/;" m
a input.kt /^class Bar<T, U>(val a: T, val b: U): Foo<T>$/;" C class:Bar
b input.kt /^class Bar<T, U>(val a: T, val b: U): Foo<T>$/;" C class:Bar
c input.kt /^class Baz <T, U: Pair<String,Pair<T, Double>>>(val c: T, val d: U): Foo<T>$/;" C class:Baz
d input.kt /^class Baz <T, U: Pair<String,Pair<T, Double>>>(val c: T, val d: U): Foo<T>$/;" C class:Baz
genericFunction1 input.kt /^ fun<T: Any> genericFunction1() = 41$/;" m interface:Foo
genericFunction2 input.kt /^ fun<T: Pair<String,Pair<Int, T>>> genericFunction2() = 42$/;" m interface:Foo
genericFunction3 input.kt /^ fun <T> genericFunction3() = 43$/;" m interface:Foo
5 changes: 4 additions & 1 deletion Units/parser-kotlin.r/kotlin-generics.d/input.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
interface Foo<T> {
fun<T: Any> genericFunction() = 42
fun<T: Any> genericFunction1() = 41
fun<T: Pair<String,Pair<Int, T>>> genericFunction2() = 42
fun <T> genericFunction3() = 43
}

class Bar<T, U>(val a: T, val b: U): Foo<T>
class Baz <T, U: Pair<String,Pair<T, Double>>>(val c: T, val d: U): Foo<T>
3 changes: 3 additions & 0 deletions Units/parser-kotlin.r/kotlin-invalid-input.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A input.kt /^val A=1$/;" C
B input.kt /^val B=2$/;" C
C input.kt /^val C=3$/;" C
7 changes: 7 additions & 0 deletions Units/parser-kotlin.r/kotlin-invalid-input.d/input.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// this is not valid Kotlin code, but the parser should recover and continue parsing
val A=1
...
...
val B=2
...
val C=3
3 changes: 0 additions & 3 deletions Units/parser-kotlin.r/kotlin-multilinestrings.d/expected.tags

This file was deleted.

5 changes: 0 additions & 5 deletions Units/parser-kotlin.r/kotlin-multilinestrings.d/input.kt

This file was deleted.

7 changes: 7 additions & 0 deletions Units/parser-kotlin.r/kotlin-rawstrings.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
used1 input.kt /^var used1 = """var unused1 = 1"""$/;" v
used2 input.kt /^var used2 = """$/;" v
used3 input.kt /^var used3 = """var unused3a = 3""" + """var unused3b = 3"""$/;" v
used4 input.kt /^var used4 = """..."val unused4"..."""$/;" v
used5 input.kt /^var used5 = """${process("""var unused5 = 5""")}"""$/;" v
used6 input.kt /^var used6 = """"val unused6=6""""$/;" v
used7 input.kt /^var used7 = """""var unused6=6"""""$/;" v
9 changes: 9 additions & 0 deletions Units/parser-kotlin.r/kotlin-rawstrings.d/input.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var used1 = """var unused1 = 1"""
var used2 = """
var unused2 = 2
"""
var used3 = """var unused3a = 3""" + """var unused3b = 3"""
var used4 = """..."val unused4"..."""
var used5 = """${process("""var unused5 = 5""")}"""
var used6 = """"val unused6=6""""
var used7 = """""var unused6=6"""""
1 change: 1 addition & 0 deletions Units/parser-kotlin.r/kotlin-scope.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sort=no
20 changes: 20 additions & 0 deletions Units/parser-kotlin.r/kotlin-scope.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
com.example.test input.kt /^package com.example.test$/;" p
TestObject input.kt /^object TestObject {$/;" o package:com.example.test
a input.kt /^ val a = 1$/;" C object:com.example.test.TestObject
f1 input.kt /^ fun f1(): String {$/;" m object:com.example.test.TestObject
b input.kt /^ val b = "hi"$/;" C method:com.example.test.TestObject.f1
TestClass input.kt /^class TestClass(val c: String, var d: Int) {$/;" c package:com.example.test
c input.kt /^class TestClass(val c: String, var d: Int) {$/;" C class:com.example.test.TestClass
d input.kt /^class TestClass(val c: String, var d: Int) {$/;" v class:com.example.test.TestClass
e input.kt /^ val e = 2$/;" C class:com.example.test.TestClass
f2 input.kt /^ fun f2(): String {$/;" m class:com.example.test.TestClass
f input.kt /^ var f = 42 * 12$/;" v method:com.example.test.TestClass.f2
TestInterface input.kt /^interface TestInterface {$/;" i package:com.example.test
g input.kt /^ abstract val g: Int$/;" C interface:com.example.test.TestInterface
f3 input.kt /^ fun f3(): String {$/;" m interface:com.example.test.TestInterface
lmbd input.kt /^ val lmbd: () -> String = {$/;" C method:com.example.test.TestInterface.f3
<lambda> input.kt /^ val lmbd: () -> String = {$/;" m method:com.example.test.TestInterface.f3
h input.kt /^ val h = "B".toLowerCase()$/;" C method:com.example.test.TestInterface.f3.<lambda>
anonymousFunction input.kt /^val anonymousFunction = fun(x: Int, y: Int): Int {$/;" C package:com.example.test
<anonymous> input.kt /^val anonymousFunction = fun(x: Int, y: Int): Int {$/;" m package:com.example.test
sum input.kt /^ val sum = x + y$/;" C method:com.example.test.<anonymous>
33 changes: 33 additions & 0 deletions Units/parser-kotlin.r/kotlin-scope.d/input.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.example.test

object TestObject {
val a = 1
fun f1(): String {
val b = "hi"
return b
}
}

class TestClass(val c: String, var d: Int) {
val e = 2
fun f2(): String {
var f = 42 * 12
return f.toString()
}
}

interface TestInterface {
abstract val g: Int
fun f3(): String {
val lmbd: () -> String = {
val h = "B".toLowerCase()
h
}
return lmbd()
}
}

val anonymousFunction = fun(x: Int, y: Int): Int {
val sum = x + y
return sum
}
3 changes: 3 additions & 0 deletions Units/parser-kotlin.r/kotlin-strings.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
used1 input.kt /^var used1 = "var unused1 = 1"$/;" v
used2 input.kt /^var used2 = "\\"var\\" unused2 = 2"$/;" v
used3 input.kt /^var used3 = ""$/;" v
used4 input.kt /^var used4 = "${process("var unused4 = 4")}"$/;" v
used5 input.kt /^var used5 = '\\"'$/;" v
4 changes: 4 additions & 0 deletions Units/parser-kotlin.r/kotlin-strings.d/input.kt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
var used1 = "var unused1 = 1"
var used2 = "\"var\" unused2 = 2"
var used3 = ""
var used4 = "${process("var unused4 = 4")}"
// quote in character literal must not break parser
var used5 = '\"'
20 changes: 10 additions & 10 deletions Units/parser-kotlin.r/kotlin-syntax.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
com.example.helloworld input.kt /^package com.example.helloworld$/;" p
AbstractWorker input.kt /^interface AbstractWorker {$/;" i
process input.kt /^ abstract fun process(): String$/;" m
Worker input.kt /^class Worker<T>(val name: T): AbstractWorker {$/;" c
name input.kt /^class Worker<T>(val name: T): AbstractWorker {$/;" C
process input.kt /^ override fun process(): String = name.toString()$/;" m
Global input.kt /^object Global {$/;" o
greeting input.kt /^ const val greeting = "Hello"$/;" C
StringWorker input.kt /^typealias StringWorker = Worker<String>$/;" T
main input.kt /^fun main() {$/;" m
result input.kt /^ var result: String = Global.greeting$/;" v
AbstractWorker input.kt /^interface AbstractWorker {$/;" i package:com.example.helloworld
process input.kt /^ abstract fun process(): String$/;" m interface:com.example.helloworld.AbstractWorker
Worker input.kt /^class Worker<T>(val name: T): AbstractWorker {$/;" c package:com.example.helloworld
name input.kt /^class Worker<T>(val name: T): AbstractWorker {$/;" C class:com.example.helloworld.Worker
process input.kt /^ override fun process(): String = name.toString()$/;" m class:com.example.helloworld.Worker
Global input.kt /^object Global {$/;" o package:com.example.helloworld
greeting input.kt /^ const val greeting = "Hello"$/;" C object:com.example.helloworld.Global
StringWorker input.kt /^typealias StringWorker = Worker<String>$/;" T package:com.example.helloworld
main input.kt /^fun main() {$/;" m package:com.example.helloworld
result input.kt /^ var result: String = Global.greeting$/;" v method:com.example.helloworld.main
2 changes: 1 addition & 1 deletion docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ The following parsers have been added:
* JSON
* Julia
* Kconfig *optlib*
* Kotlin *optlib*
* Kotlin *peg/packcc*
* GNU linker script(LdScript)
* Man page *optlib*
* Markdown *optlib*
Expand Down
4 changes: 2 additions & 2 deletions main/parsers_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@

#ifdef HAVE_PACKCC
#define PEG_PARSER_LIST \
VarlinkParser
VarlinkParser, \
KotlinParser
#else
#define PEG_PARSER_LIST
#endif
Expand Down Expand Up @@ -98,7 +99,6 @@
JsonParser, \
JuliaParser, \
KconfigParser, \
KotlinParser, \
LdScriptParser, \
LispParser, \
LiterateHaskellParser, \
Expand Down
1 change: 0 additions & 1 deletion makefiles/optlib2c_input.mak
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ OPTLIB2C_INPUT = \
optlib/gdbinit.ctags \
optlib/inko.ctags \
optlib/kconfig.ctags \
optlib/kotlin.ctags \
optlib/man.ctags \
optlib/markdown.ctags \
optlib/meson.ctags \
Expand Down
1 change: 1 addition & 0 deletions makefiles/peg_input.mak
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- makefile -*-
PEG_INPUT = \
peg/varlink.peg \
peg/kotlin.peg \
\
$(NULL)
1 change: 1 addition & 0 deletions mk_mvc.mak
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ $(PACKCC): $(PACKCC_OBJS)
main\repoinfo.obj: main\repoinfo.c main\repoinfo.h

peg\varlink.c peg\varlink.h: peg\varlink.peg $(PACKCC)
peg\kotlin.c peg\kotlin.h: peg\kotlin.peg $(PACKCC)

$(RES_OBJ): win32/ctags.rc win32/ctags.exe.manifest win32/resource.h
$(RC) /nologo /l 0x409 /Fo$@ $*.rc
Expand Down
171 changes: 0 additions & 171 deletions optlib/kotlin.c

This file was deleted.