Skip to content

Commit

Permalink
feature: Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kezz committed May 1, 2024
0 parents commit d3829d8
Show file tree
Hide file tree
Showing 28 changed files with 1,481 additions and 0 deletions.
89 changes: 89 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
[.editorconfig]
ij_editorconfig_align_group_field_declarations = false
ij_editorconfig_space_after_colon = false
ij_editorconfig_space_after_comma = true
ij_editorconfig_space_before_colon = false
ij_editorconfig_space_before_comma = false
ij_editorconfig_spaces_around_assignment_operators = true

[{*.gradle.kts, *.kt, *.kts}]
ij_kotlin_align_in_columns_case_branch = false
ij_kotlin_align_multiline_binary_operation = false
ij_kotlin_align_multiline_extends_list = false
ij_kotlin_align_multiline_method_parentheses = false
ij_kotlin_align_multiline_parameters = true
ij_kotlin_align_multiline_parameters_in_calls = false
ij_kotlin_allow_trailing_comma = false
ij_kotlin_allow_trailing_comma_on_call_site = false
ij_kotlin_assignment_wrap = off
ij_kotlin_blank_lines_after_class_header = 0
ij_kotlin_blank_lines_around_block_when_branches = 0
ij_kotlin_blank_lines_before_declaration_with_comment_or_annotation_on_separate_line = 1
ij_kotlin_block_comment_at_first_column = true
ij_kotlin_call_parameters_new_line_after_left_paren = false
ij_kotlin_call_parameters_right_paren_on_new_line = false
ij_kotlin_call_parameters_wrap = off
ij_kotlin_catch_on_new_line = false
ij_kotlin_class_annotation_wrap = split_into_lines
ij_kotlin_continuation_indent_for_chained_calls = true
ij_kotlin_continuation_indent_for_expression_bodies = true
ij_kotlin_continuation_indent_in_argument_lists = true
ij_kotlin_continuation_indent_in_elvis = true
ij_kotlin_continuation_indent_in_if_conditions = true
ij_kotlin_continuation_indent_in_parameter_lists = true
ij_kotlin_continuation_indent_in_supertype_lists = true
ij_kotlin_else_on_new_line = false
ij_kotlin_enum_constants_wrap = off
ij_kotlin_extends_list_wrap = off
ij_kotlin_field_annotation_wrap = split_into_lines
ij_kotlin_finally_on_new_line = false
ij_kotlin_if_rparen_on_new_line = false
ij_kotlin_import_nested_classes = false
ij_kotlin_insert_whitespaces_in_simple_one_line_method = true
ij_kotlin_keep_blank_lines_before_right_brace = 2
ij_kotlin_keep_blank_lines_in_code = 2
ij_kotlin_keep_blank_lines_in_declarations = 2
ij_kotlin_keep_first_column_comment = true
ij_kotlin_keep_indents_on_empty_lines = false
ij_kotlin_keep_line_breaks = true
ij_kotlin_lbrace_on_next_line = false
ij_kotlin_line_comment_add_space = false
ij_kotlin_line_comment_at_first_column = true
ij_kotlin_method_annotation_wrap = split_into_lines
ij_kotlin_method_call_chain_wrap = off
ij_kotlin_method_parameters_new_line_after_left_paren = false
ij_kotlin_method_parameters_right_paren_on_new_line = false
ij_kotlin_method_parameters_wrap = off
ij_kotlin_parameter_annotation_wrap = off
ij_kotlin_space_after_comma = true
ij_kotlin_space_after_extend_colon = true
ij_kotlin_space_after_type_colon = true
ij_kotlin_space_before_catch_parentheses = true
ij_kotlin_space_before_comma = false
ij_kotlin_space_before_extend_colon = true
ij_kotlin_space_before_for_parentheses = true
ij_kotlin_space_before_if_parentheses = true
ij_kotlin_space_before_lambda_arrow = true
ij_kotlin_space_before_type_colon = false
ij_kotlin_space_before_when_parentheses = true
ij_kotlin_space_before_while_parentheses = true
ij_kotlin_spaces_around_additive_operators = true
ij_kotlin_spaces_around_assignment_operators = true
ij_kotlin_spaces_around_equality_operators = true
ij_kotlin_spaces_around_function_type_arrow = true
ij_kotlin_spaces_around_logical_operators = true
ij_kotlin_spaces_around_multiplicative_operators = true
ij_kotlin_spaces_around_range = false
ij_kotlin_spaces_around_relational_operators = true
ij_kotlin_spaces_around_unary_operator = false
ij_kotlin_spaces_around_when_arrow = true
ij_kotlin_variable_annotation_wrap = off
ij_kotlin_while_on_new_line = false
ij_kotlin_wrap_elvis_expressions = 1
ij_kotlin_wrap_expression_body_functions = 0
ij_kotlin_wrap_first_method_in_call_chain = false
ij_continuation_indent_size = 4
ij_kotlin_name_count_to_use_star_import = 1000
ij_kotlin_name_count_to_use_star_import_for_members = 1000
ij_kotlin_packages_to_use_import_on_demand = nothing
ij_kotlin_imports_layout = *
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.gradle
.idea
**/build
**/run
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Noxcrew Online Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# SMP

SMP (Simple Maths Parser) is a library that can solve relatively simple mathematical expressions in a textual format.
It is written in Kotlin, and is a Kotlin-first library.

## What is SMP?

### Values
Values can be provided as either an integer, double or a named variable.
Variables can consist of letters and underscores and are resolved either at or before computation using a suspending provider.
This allows for variables to be easily computed from costly sources.

### Operators
Support is provided for the following operators:
* addition (+),
* subtraction (-),
* multiplication (*),
* division (/), and
* exponentiation (^).

Additionally, parentheses can be used.

## What is SMP not?
SMP is not a general purpose expression solver.
It is intended for simple use cases that can be easily and simply represented with strings.

It is not a library intended for consumption in Java or other non-Kotlin JVM languages.

## Usage
### Dependency
SMP can be found on Noxcrew's public Maven repository and added to a Gradle project as follows:

```kotlin
repositories {
mavenCentral()
}

dependencies {
implementation("com.noxcrew.smp:smp:VERSION")
}
```

### Example
Some simple examples of how to use the library can be seen below.
For further examples, see the test files.

```kotlin
// Computes an expression, skipping the resolve steps.
SMP.computeUnresolved("10+(100^2)")

// You can create your own instances with variable resolution.
val myInstance = SMP.create(...)

// You can store the IR of an expression for later computation.
val expression = myInstance.parse("100/my_variable")
expression.compute()
```

## Documentation
Documentation for how to use the library can be found on the library's entrypoint, the `SMP` interface.
Javadocs/Dokka docs are also provided.
92 changes: 92 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode

plugins {
alias(libs.plugins.dokka)
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.spotless)

`java-library`
`maven-publish`
}

group = "com.noxcrew.smp"
version = "1.0.0-SNAPSHOT"

repositories {
mavenCentral()
}

dependencies {
api(libs.kotlin.coroutines)
}

kotlin {
explicitApi = ExplicitApiMode.Strict
jvmToolchain(21)
}

spotless {
kotlin {
ktlint()
}

kotlinGradle {
ktlint()
}
}

java {
withJavadocJar()
withSourcesJar()
}

publishing {
repositories {
maven {
name = "noxcrew-public"
url = uri("https://maven.noxcrew.com/public")

credentials {
username = System.getenv("NOXCREW_MAVEN_PUBLIC_USERNAME")
password = System.getenv("NOXCREW_MAVEN_PUBLIC_PASSWORD")
}

authentication {
create<BasicAuthentication>("basic")
}
}
}

publications {
create<MavenPublication>("maven") {
from(components["java"])

pom {
name = "smp"
description = "A simple maths parser in Kotlin."
url = "https://github.com/Noxcrew/smp"

scm {
url = "https://github.com/Noxcrew/smp"
connection = "scm:git:https://github.com/Noxcrew/smp.git"
developerConnection = "scm:git:https://github.com/Noxcrew/smp.git"
}

licenses {
license {
name = "MIT License"
url = "https://opensource.org/licenses/MIT"
}
}

developers {
developer {
id = "noxcrew"
name = "Noxcrew"
email = "[email protected]"
}
}
}
}
}
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kotlin.code.style=official
13 changes: 13 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[versions]
coroutines = "1.8.0"
dokka = "1.9.20"
kotlin = "1.9.23"
spotless = "6.25.0"

[libraries]
kotlin-coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutines" }

[plugins]
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Tue Apr 30 12:02:07 BST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit d3829d8

Please sign in to comment.