regex - expression evaluator in scala (with maybe placeholders?) -


I am reading something like this from my configuration file:

  metric1.critical = " & lt; 2000 || & gt; 20000 "Metriklkoke =" = 1 "Metriklkwarning =" & lt; = 3000 "Metrik2koke =" & gt; 0.9 & amp; & amp; & lt; 1.1 " Metric3.warning = "(& gt; & amp; amp; amp; amp; amp;; 1.5) || (& lt; 500 & amp;; 200)"  

And I have some value in

  Metric1.value = //  

My goal is basically to evaluate

 < Code> if (metric1.value & lt; 2000 || metric1.value & gt; 20000) metric1.setAlert ("Important"); And if (metric 1.value = 1) metric.setlert ("ok"); // And so on  

I'm not really good with regex, so I'm going to try not to use it, I'm coding in Scala and want to know An existing library can help with it. Maybe I need to fill the vacant space and then place the placeholder to evaluate the expression? But how can I evaluate expression above the most efficiently and lesser land?

EDIT: How we are expression evaluator library in Java. I was hoping that I could get something similar for my code. Maybe I want to place the placeholder in the config file "?" These are my metrics 1.Weuvel (for variables reading) and then use an evaluator? Or is there a good regex suggestion for this? thank you in advanced!

It looks like you want to define your own syntax using a parser recombinant library.

The ska is a parser composer built in class library. Since the Scala library has been modularized, it is now a separate project that stays in.

UPDATE: Everyone should take a look at the fact that the conceptual Scala-Parser is similar to combinators looking for a Parser Combinator library. It's very fast, and does not use macros. Therefore, it can be used as a drop-in replacement for scale-parser-combinators.

How to use it, can be done in chapter 33, "coordinator parsing".

There is a small grammar, est and evaluator here to get you started. There are not many things in it, such as whotspace handling, operator priority etc. You should not even use the wire for different comparison operator encoding. But I think from this point and chapters from programming in Scala should enable you to come up with something that suits your needs.

  import scala.util.parsing.combinator. {JavaTokenParsers, PackratParsers} sealed abstract class AST seal abstract class BooleanExpression AST case classes BooleanOperation extends (op string, LHS: BooleanExpression, RHS: BooleanExpression) extends BooleanExpression case class comparison (op string, RHS: extends continuously) BooleanExpression case class extends (value: double) AST object continuously. Extends JavaTokenParsers with Pestaparars {Val Boolean Operator: Pacquer Parser [String] = Literal ("||") | Literal ("& amp; amp; amp; & amp; nbsp;) val comparisonOperator: PackratParser [string] = Literal (" & lt; = ") | Literal ("> gt; ="). Literal ("=="). Verbal ("! =") | Literal ("& lt;") | Literal ("& gt;") constant constant: packet operator [constant] = floating point number. ^^ {x = & gt; Constantly (X. Tood Double)} Compare Val: PacketRaparas [Comparison] = (Comparison Operator ~ Continuous) ^^ {case op ~ rhs = & gt; Comparison (session, RAS)} Lazy Val P1: Packetparers [Boolean Express] = Boolean Operation | Comparison val boolean operation = (p1 ~ boolean operator ~ p1) ^^ {case lHS ~ op ~ rss = & gt; Boolean operation (OPT, LHS, RAS)}} object Ivelyuetr {ARM evaluation (expression: Boolean Akspereshn, Value: Double): Boolean = expression match {case than ( "& lt; =", Costent (C)) = & gt ; Value & lt; = C case comparison ("& gt; =", continuous (C)) = & gt; Price & gt; = C Case Comparison ("==", Constant (C)) = & gt; Price == C Case Comparison ("! =", Constant (C)) = & gt; value! = Case comparison ("& lt;", Constant (C)) = & gt; Price & lt; C Case Comparison ("& gt;", Constant (C)) = & gt; Price & gt; C Case Boolean Operation ("||", A, B) = & gt; Evaluation (a, value) || Evaluation (B value) Case Boolean operation ( "& amp; A, A, B) = & gt; Evaluation (A value) & amp; amp; Evaluation (B value)}} object Test app {DRF parsing ( text: string) Extended is: Boolean expression = Conditions purser. Pira all (Conditions purser P1, text). val texts = seek ( "& lt; 2000", "& lt; 2000 (& Gt; 20000", " == 1 "," & lt; = 3000 ","> 0.9 & amp; amp; amp; 1.1;) "val xs = Seq (0.0, 1.0, 100000.0) {text & lt ; Expression of texts = parse (text) x  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -