{"id":25053733,"url":"https://github.com/hypertino/expression-parser","last_synced_at":"2025-04-14T09:50:19.890Z","repository":{"id":57725077,"uuid":"73424893","full_name":"hypertino/expression-parser","owner":"hypertino","description":"Expression parser and evaluator for Scala powered by parboiled2.","archived":false,"fork":false,"pushed_at":"2020-01-15T10:33:10.000Z","size":130,"stargazers_count":8,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T23:05:37.885Z","etag":null,"topics":["expression-evaluator","expression-parser","parser","scala"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hypertino.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-10T22:09:13.000Z","updated_at":"2024-05-16T13:50:16.000Z","dependencies_parsed_at":"2022-09-11T17:13:37.460Z","dependency_job_id":null,"html_url":"https://github.com/hypertino/expression-parser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypertino%2Fexpression-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypertino%2Fexpression-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypertino%2Fexpression-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hypertino%2Fexpression-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hypertino","download_url":"https://codeload.github.com/hypertino/expression-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248859326,"owners_count":21173334,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["expression-evaluator","expression-parser","parser","scala"],"created_at":"2025-02-06T11:51:02.752Z","updated_at":"2025-04-14T09:50:19.866Z","avatar_url":"https://github.com/hypertino.png","language":"Scala","readme":"[![Build Status](https://travis-ci.org/hypertino/expression-parser.svg)](https://travis-ci.org/hypertino/expression-parser)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.hypertino/expression-parser_2.13/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.hypertino/expression-parser_2.13)\n\n[ Latest releases and snapshots](https://oss.sonatype.org/#nexus-search;gav~com.hypertino~expression-parser_*~~~)\n\n# About\nThis is a ready to use expression parser and evaluator for Scala powered by `parboiled2`.\n\nExample:\n\n```scala\nval result = HEval(\"4*5+3*2\").toInt\n// result = 26\n```\n\nIt's possible to provide a context with variables to the parser:\n\n```scala\nval context = Obj.from(\"user\" -\u003e Obj.from(\"count\" -\u003e 10))\nval result = HEval(\"4*user.count+1*2\", context).toInt\n// result = 42\n```\n\nYou also can add your own functions into the context:\n\n```scala\nval context = new ValueContext(Obj.empty) {\n    override def function: PartialFunction[(Identifier, Seq[Value]), Value] = {\n        case (Identifier(Seq(\"pow\")), args) =\u003e args.head.toBigDecimal.pow(args.tail.head.toInt)\n    }\n}\n\nval result = HEval(\"pow(2,8)\", context).toInt\n// result = 256\n```\n\n## TODO\n + HParser function\n\n## Built-in operators \n `+, -, *, /` - arithmetical operations\n \n `!, =, !=, and, or, xor` - boolean operations\n \n `%` - remainder (modulus) operation\n \n `\u003e, \u003c, \u003e=, \u003c=` - comparison operations\n \n `someObject.someField` - evaluate value of 'someField' of 'someObject'\n \n `has, has not` - tests if collection has (or has not) specified element \n \n `like, not like` - tests if value matches regexp\n \n `++` - adds one collection to another\n \n `--` - computes difference between two collections\n\n## Built-in functions\n `case` - takes two arguments: index and collection. Returns value placed in collection with specified index\n \n `isEmpty` - tests whether value is empty\n \n `isExists` - tests whether value is present in context\n \n `length` - returns length of collection or string. Boolean argument is a special case: function returns '1' in case of 'true' and '0' in case of 'false'\n \n `upper, lower` - returns string in upper or lower case\n \n `split` - takes two arguments: string and separator and returns collection made by splitting of incoming string by specified separator\n \n `indexOf` - takes two arguments: string and substring. Returns the index within this string of the first occurrence of the specified substring\n \n `substr` - takes 2 or 3 arguments: string, beginIndex[, endIndex] - returns substring of string\n \n `compareIgnoreCase` - compares two strings ignoring their case\n\n## Context field access\n 1. Values of fields of some object should be dot-separated:\n ```scala\n user.field.subField\n ```\n\n 2. Strings can be written with quotes of apostrophes (later ignores escapes):\n ```scala\n 'someString\\nabcde' // escaping ignored\n \"someString\\nSecondLine\" // newline inserted\n ```\n\n 3. Numbers should be written as is, without any additional symbols\n\n## Other Examples (TODO)\n ```scala\n user.isDefined\n !user.isDefined\n user.isDefined = true \n user.isDefined != true\n user.roles has \"qa\"\n user.roles has not \"admin\"\n (user.isDefined = true) and (user.roles has \"qa\") \n (user.isDefined) and (user.roles has \"qa\")) \n (!user.isDefined) or (user.roles has \"admin\")\n ```\n\n# Download\n\n```sbt\nlibraryDependencies += \"com.hypertino\" %% \"expression-parser\" % \"0.3.0\"\n```\nReleases published to Maven Central for Scala 2.11 - 2.13 JVM \u0026 JS (user `%%%` for Scala.js enabled projects)\n\nSnapshots live in Sonatype repository, include it additionally:\n```sbt\nresolvers ++= Seq(\n  Resolver.sonatypeRepo(\"public\")\n)\n```\n\n# License\n\nlibrary is available under the BSD 3-Clause License","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypertino%2Fexpression-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhypertino%2Fexpression-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypertino%2Fexpression-parser/lists"}