-
Notifications
You must be signed in to change notification settings - Fork 1
HW 01 Bash #1
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
base: master
Are you sure you want to change the base?
HW 01 Bash #1
Changes from all commits
d17aeb6
961f4f7
f6221f3
733aab5
aae09ec
5dba122
4f82697
c3396ba
63b021f
6d0bf64
29c8690
e5a8b58
b1f3a87
92b7fdc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| language: kotlin | ||
|
|
||
| jdk: | ||
| - oraclejdk9 | ||
|
|
||
| os: | ||
| - linux | ||
|
|
||
| before_script: | ||
| - wget https://services.gradle.org/distributions/gradle-4.5.1-bin.zip | ||
| - unzip gradle-4.5.1-bin.zip | ||
| - export GRADLE_HOME=$PWD/gradle-4.5.1 | ||
| - export PATH=$GRADLE_HOME/bin:$PATH | ||
|
|
||
| script: | ||
| - chmod +x build.sh | ||
| - bash build.sh |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Архитектура | ||
|  | ||
|
|
||
| На картинке показана упрощённая модель потока данных в архитектуре | ||
|
|
||
| Сначала строка из stdin попадает в лексер, где разбивается на токены | ||
|
|
||
| Оттуда токены передаются в парсер вместе с окружением, где по пайпам токены делятся на команды: первый токен - имя, остальные - аргументы | ||
|
|
||
| Дальше этот массив передаётся контроллеру, который исполняет команды, передавая выходной поток одной команды на вход другой |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| plugins { | ||
| id 'org.jetbrains.kotlin.jvm' version '1.2.51' | ||
| } | ||
|
|
||
| version '1.0-SNAPSHOT' | ||
|
|
||
| apply plugin: 'kotlin' | ||
| apply plugin: 'application' | ||
|
|
||
| mainClassName = 'hse.nedikov.bash.Main' | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| } | ||
|
|
||
| dependencies { | ||
| compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А JUint из воздуха возьмётся? |
||
| // https://mvnrepository.com/artifact/junit/junit | ||
| testCompile group: 'junit', name: 'junit', version: '4.12' | ||
|
|
||
| } | ||
|
|
||
| jar { | ||
| manifest { attributes 'Main-Class': "${mainClassName}" } | ||
| from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } | ||
| } | ||
|
|
||
| compileKotlin { | ||
| kotlinOptions.jvmTarget = "1.8" | ||
| } | ||
| compileTestKotlin { | ||
| kotlinOptions.jvmTarget = "1.8" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| distributionBase=GRADLE_USER_HOME | ||
| distributionPath=wrapper/dists | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-bin.zip | ||
| zipStoreBase=GRADLE_USER_HOME | ||
| zipStorePath=wrapper/dists |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| rootProject.name = 'bash' | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package hse.nedikov.bash | ||
|
|
||
| import hse.nedikov.bash.logic.Command | ||
| import java.io.PipedReader | ||
| import java.io.PipedWriter | ||
|
|
||
|
|
||
| class Controller(val exceptionHandler: (Exception) -> Unit) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вообще, каждому классу нужны комментарии |
||
| private val env = Environment() | ||
|
|
||
| fun isWorking() = env.isWorking() | ||
|
|
||
| fun runCommandLine(line: String, outputHandler: (String) -> Unit) { | ||
| val tokens = Lexer(line, env.variables).lex() | ||
| val commands = parse(tokens, env) | ||
| val flow = makeFlow(commands); | ||
| flow.invoke().forEachLine { outputHandler(it) } | ||
| } | ||
|
|
||
| fun makeFlow(commands: ArrayList<Command>): () -> PipedReader = | ||
| if (commands.isEmpty()) { | ||
| { emptyCommandFlow() } | ||
| } else commandFlow(commands[0], commands.apply { removeAt(0) }) | ||
|
|
||
| private fun commandFlow(command: Command, commands: ArrayList<Command>): () -> PipedReader = { | ||
| commands.reversed().fold(command.execute()) { reader, command -> | ||
| try { | ||
| command.execute(reader) | ||
| } catch (e: Exception) { | ||
| exceptionHandler(e) | ||
| emptyCommandFlow() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun emptyCommandFlow(): PipedReader { | ||
| val reader = PipedReader() | ||
| PipedWriter(reader).close() | ||
| return reader | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Собирающийся jar файл нельзя запустить т.к. не указана точка входа в программу