diff --git a/README.md b/README.md index 2a1c1de..9f5df75 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/examples/repl.nim b/examples/repl.nim index 495ad41..8e7a0d0 100644 --- a/examples/repl.nim +++ b/examples/repl.nim @@ -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() \ No newline at end of file + repl() diff --git a/nimkalc.nimble b/nimkalc.nimble index 3815e16..fc8982e 100644 --- a/nimkalc.nimble +++ b/nimkalc.nimble @@ -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" diff --git a/src/nimkalc.nim b/src/nimkalc.nim index 03f6889..b7deedb 100644 --- a/src/nimkalc.nim +++ b/src/nimkalc.nim @@ -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 = diff --git a/src/nimkalc/objects/error.nim b/src/nimkalc/objects/error.nim index df19e81..ba2d75d 100644 --- a/src/nimkalc/objects/error.nim +++ b/src/nimkalc/objects/error.nim @@ -21,3 +21,4 @@ type MathError* = object of NimKalcException ## An arithmetic error EvaluationError* = object of NimKalcException +