First fully featured programming language for Stack Overflow Driven Development
fun main() = createCode {
+StackOverflowSnippet(answerNumber = 1077349)
}.buildWith("python3", "script.py")
fun main() = createCode {
+StackOverflowSnippet(answerNumber = 11502683, codeBlockNumber = 2)
}.buildWith("cat", "hello.txt")
fun main() = createCode {
+StackOverflowSnippet(answerNumber = 40427469, codeBlockNumber = 7)
}.buildWith("python2", "script.py")
fun main() = createCode {
+StackOverflowSnippet(answerNumber = 40427469, codeBlockNumber = 7) toLine 7 change ("101" to "51")
}.buildWith("python2", "script.py")
fun main() = createCode {
+StackOverflowSnippet(answerNumber = 50165755) toLine 15 //declare randomdate
+StackOverflowSnippet(answerNumber = 48980683, codeBlockNumber = 2) toLine 1 change ("random.random" to "randomTime") change ("x" to "my_list") //generate list
+StackOverflowSnippet(answerNumber = 902736, codeBlockNumber = 6) fromLine 3 change (">" to ">")//declare bubble and print sorted lits
}.buildWith("python2", "script.py")
fun main() = createCode {
SoLangConfiguration.soLangMode = SoLangConfiguration.SoLangMode.PRINT
+SimpleSnippet("First revision:")
+StackOverflowSnippet(answerNumber = 4362605, codeBlockNumber = 2, revisionNumber = 1)
+SimpleSnippet("Second revision:")
+StackOverflowSnippet(answerNumber = 4362605, codeBlockNumber = 2, revisionNumber = 2)
}.buildWith("python2", "script.py")
To try SoLang you can just clone the repository and build with gradle.
If you want to use SoLang in your own project, add it as a library to your build scripts:
build.gradle
repositories {
maven{ url "https://jitpack.io" }
maven{ url "https://kotlin.bintray.com/kotlinx" }
}
dependencies {
implementation 'com.github.krzysztofsroga.solang:0.1.4-alpha'
}
build.gradle.kts
repositories {
maven(url = "https://jitpack.io")
maven(url = "https://kotlin.bintray.com/kotlinx")
}
dependencies {
implementation(group = "com.github.krzysztofsroga", name = "solang", version = "0.1.4-alpha")
}
You can configure some basic features of SoLang compiler
// SAFE is default mode. You will be prompted if the code and build command are okay
SoLangConfiguration.soLangMode = SoLangConfiguration.SoLangMode.SAFE
// UNSAFE is dangerous. It executes the code without any prompt.
SoLangConfiguration.soLangMode = SoLangConfiguration.SoLangMode.UNSAFE
// PRINT mode just shows you generated code and build command
SoLangConfiguration.soLangMode = SoLangConfiguration.SoLangMode.PRINT
toLine
, change
, the original snippet is modified. If you need the code in more than one place, please write a function.rm -rf ~/
.To get an access token, simply authorize SoLang application with your StackExchange account
Just go to this link and log in to your stack account: SoLang App
This way you'll get a token which will expire after one day. If you need non-expiring token, click HERE
Your access token will be given in url of a page you're being redirected to.
Now you can use it in your application:
SoLangConfiguration.apiToken = "YOUR TOKEN"
The matching key is already embedded in the application. If apiToken
string is set to anything but empty string, it will be used in requests.
Just open an issue and we can talk about it.
Well, it's not recommended, but as long as you fetch specific answer revision, it should work fine.
All of the answers on StackOverflow can be changed. If you want to disable this check Configuration
You can download 300 snippets a day without access token. You can download 10000 with it.
You may want to read: StackApss: Is there a limit of api requests?
You tell me
Documentation is still being created, hence it may be lacking something.
fun main() = createCode {
//Your snippets go here
}.buildWith("command", "filename")
Function createCode
takes a lambda with receiver CodeBuilder
, returns SoCode
fun createCode(block: CodeBuilder.() -> Unit): SoCode
Method buildWith
builds SoCode
saves code to file and complies it using given command. Redirects program output to console.
fun SoCode.buildWith(buildScript: String, targetFile: String)
SimpleSnippet
just stores your code in unchanged form
class SimpleSnippet(code: String) : Snippet()
StackOverflowSnippet
downloads given answer(and caches it in case other snippets would base on the same one), then cuts selected block number from it. In case you specified revision, all revisions are downloaded and then the one selected is used.
In case no revision is specified, the newest one is used.
class StackOverflowSnippet(
answerNumber: Int,
codeBlockNumber: Int,
revisionNumber: Int? = null
) : Snippet()
To add a snippet to code just mark it with +
symbol. You can assign snippet to variable if you want
createCode {
+SimpleSnippet("Hello world!") //this snippet is just appended
val s = SimpleSnippet("Code in SoLang!")
+s
+s
}
This will result in output:
Hello world!
Code in SoLang!
Code in SoLang!
This section is being worked on... Stay tuned!
You can add modifiers to snippets. Modifiers are queued until code compilation and executed all at the same time.
Take care! When you modify a snippet, there isn't created a copy!
This section will be published in near future
toLine
after fromLine
usagefromLine
first then line numeration for toLine
changes. Hence snippet fromLine 4 toLine 8
is the same thing as snippet takeLines 4..11
Snippet
from SurroundingSnippet - not extending CodeBuilder, but creating its owninheritIO
does not work)