project-eutopia / keisan Goto Github PK
View Code? Open in Web Editor NEWA Ruby-based expression parser, evaluator, and programming language
License: MIT License
A Ruby-based expression parser, evaluator, and programming language
License: MIT License
We need to manipulate date & time. We also need some basic date & time function like NOW
, TODAY
. They can be added if date & time data type is supported.
Hi! Thank you for your amazing library for computations.
I would like to ask if it is possible to include some basic set operation for Array (like in basic Ruby).
In particular:
Difference: [1,2,3] - [2,3,4] = [1]
Intersection: [1,2,3] & [2,3,4] = [2,3]
Union: [1,2,3] | [2,3,4] = [1,2,3,4]
In the meanwhile I will implement them with "define_function" method.
Need to let AST know how to differentiate basic math functions like sin
and exp
.
Instances of ExpressionFunction
contain the original AST expression that defined the function, so it should be possible to take derivatives of them. This is unlike ProcFunction
which loses the mathematical structure behind the Proc
instance.
Hello! I ran into another issue with the tokenizer in (related to #94) regards to strings whereby having a hash character (which marks the remainder of the line as a comment) in a string literal will cause tokenization to fail, as the closing quote at the end of the line is regarded as part of the comment.
Version: 0.8.3
Executing the following demonstrates the issue:
Keisan::Calculator.new.ast('"#1"')
# raises Keisan::Exceptions::TokenizingError (Tokenizing error, no closing quote ')
Keisan::Calculator.new.ast("'#1'")
# raises Keisan::Exceptions::TokenizingError (Tokenizing error, no closing quote ")
Expected behavior: comment sequences should be treated as part of the string literal, only being ignored if encountered outside a string literal. I'm guessing the expression syntax is supposed to be much like actual Ruby, and I know that string literals like '#' definitely treat the hash as part of the literal and not a comment sequence.
Currently can only get values inside of arrays or get the size of an array. Could add support for splices, or even functional math operations on arrays.
Hello, I've run into another issue with escaped quotes in strings. Parsing works great with escaped strings, but if the string literal is enclosed in a group, the tokenizer fails:
# Simple string
Keisan::Calculator.new.ast('"a"')
# => #<Keisan::AST::String:0x00007fdf97128bc0 @content="a">
# With escaped double quote
Keisan::Calculator.new.ast('"\"a"')
# => #<Keisan::AST::String:0x00007fdf9b8d8c68 @content="\"a">
# Escaped double quote in a group
Keisan::Calculator.new.ast('("\"a")')
# Raises Keisan::Exceptions::TokenizingError (Tokenizing error, no closing quote ")
It occurs for any form of group, and either quote style—single or double.
Edit: I should add a more practical example along with an example of some of the more wacky behavior:
# Calling a function with a string arg that contains an escaped quote
Keisan::Calculator.new.ast('my_fn("\"a")')
# Raises Keisan::Exceptions::TokenizingError (Tokenizing error, no closing quote ")
# The expression gets modified in a strange way if your escaped quotes are actually closed, e.g.
Keisan::Calculator.new.ast('("\"a\"")').to_s
# => "(\"\"*a)*\"\""
# The above line is output from Rails console, so it's an `inspect`ed string. The actual value of the string it spits out is:
# (""*a)*""
# but it should be
# "\"a\""
Currently using Keisan version 0.8.4
Gem version: 0.8.0
Hello, I came across an issue involving grouping symbols in string literals throwing off the tokenizer. It looks like the grouping regex is not ignoring grouping symbols inside of string literals. This isn't a problem if the string literal itself uses matched groups (see second example below), but if you put an unpaired grouping symbol anywhere in the string it causes issues.
Running the following in an interactive console demonstrates the issue:
Keisan::Calculator.new.ast("f('a')")
# => #<Keisan::AST::Function ...>
Keisan::Calculator.new.ast("f('a()')")
# => #<Keisan::AST::Function ...>
Keisan::Calculator.new.ast("f('a]')")
# raises Keisan::Exceptions::TokenizingError (Unexpected token: "(")
# Another error example
Keisan::Calculator.new.ast("f('a)')")
# raises Keisan::Exceptions::TokenizingError (Unexpected token: "'")
Not much support for strings except for basic comparison and concatenation. Add support for things like splicing and searching too. See Ruby String
methods for ideas.
Required changes:
Array.split
Array.wrap
Object.present?
and Object.blank?
String.underscore
try
to safe navigation operator &.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.