NimKalc 0.2.5: Exported all API for easier use

This commit is contained in:
nocturn9x 2021-07-25 18:03:49 +02:00
parent c39495309e
commit d1f96da9d1
5 changed files with 8 additions and 41 deletions

View File

@ -15,7 +15,6 @@ Features:
- `inf` (Infinity)
- `nan` (Not a number)
- Support for the following of nim's [math library](https://nim-lang.org/docs/math.html#log10%2Cfloat32) functions:
- `binom`
- `sin`
- `cos`
- `tan`
@ -105,12 +104,7 @@ where `name` is the function name and `args` is a list of arguments
Here is an example of a REPL using all of NimKalc's functionality to evaluate expressions from stdin (can be found at `examples/repl.nim`)
```nim
import nimkalc/objects/ast
import nimkalc/objects/token
import nimkalc/parsing/parser
import nimkalc/parsing/lexer
import nimkalc/objects/error
import nimkalc
import strformat
import strutils

View File

@ -12,14 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# A simple library to parse and evaluate mathematical expressions
# A simple REPL to parse and evaluate mathematical expressions
import nimkalc/objects/ast
import nimkalc/objects/token
import nimkalc/parsing/parser
import nimkalc/parsing/lexer
import nimkalc/objects/error
import nimkalc
import strformat
import strutils
@ -66,4 +62,4 @@ proc repl() =
when isMainModule:
repl()
repl()

View File

@ -1,6 +1,6 @@
# Package
version = "0.2.4"
version = "0.2.5"
author = "Mattia Giambirtone"
description = "An advanced parsing library for mathematical expressions and equations"
license = "Apache 2.0"

View File

@ -18,34 +18,10 @@ import nimkalc/parsing/parser
import nimkalc/objects/ast
import nimkalc/parsing/lexer
import nimkalc/objects/token
import nimkalc/objects/error
import strutils
import strformat
proc `$`*(self: AstNode): string =
## Stringifies an AST node
case self.kind:
of NodeKind.Grouping:
result = &"Grouping({self.expr})"
of NodeKind.Unary:
result = &"Unary({$self.unOp.kind}, {$self.operand})"
of NodeKind.Binary:
result = &"Binary({$self.left}, {$self.binOp.kind}, {$self.right})"
of NodeKind.Integer:
result = &"Integer({$int(self.value)})"
of NodeKind.Float:
result = &"Float({$self.value})"
of NodeKind.Call:
result = &"Call({self.function.name}, {self.arguments.join(\", \")})"
of NodeKind.Ident:
result = &"Identifier({self.name})"
proc `$`*(self: Token): string =
## Returns a string representation of a token
result = &"Token({self.kind}, '{self.lexeme}')"
export lexer, parser, error, token, ast
proc eval*(source: string): AstNode =

View File

@ -21,3 +21,4 @@ type
MathError* = object of NimKalcException
## An arithmetic error
EvaluationError* = object of NimKalcException