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
Closed
@hallvard

Description

@hallvard

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0