8000 Replaceable and more flexible Tokenizer · Issue #56 · fasseg/exp4j · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Replaceable and more flexible Tokenizer #56

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

Closed
hallvard opened this issue Mar 11, 2016 · 3 comments
Closed

Replaceable and more flexible Tokenizer #56

hallvard opened this issue Mar 11, 2016 · 3 comments

Comments

@hallvard
Copy link

I'm working on a charting application which should allow the user to add new time series by entering an expression that refers to existing ones, e.g. make an average of two other series. Each series have a name, so you could e.g. write (s1+s2)/2 to define the average of series s1 and s2. However, the series are grouped and only unique within a group, so it's natural to have a hierarchical naming scheme. The groups aren't named, but can be given a name based on the order. Hence, I end up with names like a_amount and b_amount. What I would like is to allow using $n.name for referring to series name within group n. To do this I need to make a custom Tokenizer that allows $ as the first char of a variable. This is currently not easy or possible, for several reasons:

  • the set of legal characters of operators is hard-coded in the Operator class
  • the method that creates the Tokenizer, ShuntingYard.convertToRPN is static and thus cannot be replaced
    I suggest the following changes:
  • move the logic for allowed operator chars to the Tokenizer, to make it easier to customise
  • add the Tokenizer as argument to ShuntingYard.convertToRPN and use a factory method in ExpressionBuilder to create ut, so you can replace it in a subclass
    There may be other changes necessary, and I will explore them in a branch. But it may be best to discuss it in this issue first?
@fasseg
Copy link
Owner
fasseg commented Apr 18, 2016

So what you're saying is that you want be able inject custom Tokenizers into exp4j using e.g.
ExpressionBuilder.tokenizer(Tokenizer t) ?
Have you already implemented this and if yes, can I take a look at it?

@fasseg
Copy link
Owner
fasseg commented Apr 18, 2016

Ah nevermind I just saw your pull request and will take a look at it.

@fasseg
Copy link
Owner
fasseg commented Apr 18, 2016

Closing this in favor of #58

@fasseg fasseg closed this as completed Apr 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0