dsl

How can I handle operations over many different types in my DSL?

独自空忆成欢 提交于 2019-12-05 16:45:50
Suppose Haskell is to be used to implement an interpreter for a domain specific language. The DSL has a large number of type, represented as data constructors, and a large number of binary expressions. A naive first attempt would be a type class BinaryOps encapsulating all binary operations over MyType in the DSL: data MyType = A String | B Integer | C Bool | D Double {- | E .. Z -} class BinaryOps a where f :: a -> a -> a g :: a -> a -> a h :: a -> a -> a j :: a -> a -> a {- many more binary ops -} instance BinaryOps MyType where f (A s1) (A s2) = {- Haskell expression on s1 and s2 -} f (A s1

Elasticsearch the terms filter raise “filter does not support [mediatest]”

天大地大妈咪最大 提交于 2019-12-05 14:48:32
问题 my query is like this: { "query": { "filtered": { "filter": { "bool": { "must": [ { "term": { "online": 1 } }, { "terms": { "mediaType": "flash" } } ] } } } } } it raise a QueryParsingException [[comos_v2] [terms] filter does not support [mediaType]] ,of which the field "mediaType" exactly does not exist in mapping. my question is why term filter does not raise the Exception? 回答1: The above is not a valid Query DSL. In the above Terms filter the values to "mediaType" field should be an array

Obtaining the client IP in Akka-http

女生的网名这么多〃 提交于 2019-12-05 10:50:53
I am trying to write an Akka HTTP microservice (akka version 2.4.11, Scala version 2.11.8, both latest versions at time of writing) which is aware of the client service's IP (i.e., remote address), and I cannot get this to work. I can create and run a service which says 'Hello!' using a route like this: val routeHello: Route = path("SayHello") { get { entity(as[String]) { body => complete { HttpResponse(entity = HttpEntity("Hello!")) } } } } I have constructed a similar route to the one above, which is extended so that it is aware of the client's IP address. I noted that I need to edit the

DSL block without argument in ruby

為{幸葍}努か 提交于 2019-12-05 05:23:31
I'm writing a simple dsl in ruby. Few weeks ago I stumbled upon some blog post, which show how to transform code like: some_method argument do |book| book.some_method_on_book book.some_other_method_on_book :with => argument end into cleaner code: some_method argument do some_method_on_book some_other_method_on_book :with => argument end I can't remember how to do this and I'm not sure about downsides but cleaner syntax is tempting. Does anyone have a clue about this transformation? def some_method argument, &blk #... book.instance_eval &blk #... end UPDATE: However, that omits book but don't

DSL in scala using case classes

孤街浪徒 提交于 2019-12-05 02:52:05
My use case has case classes something like case class Address(name:String,pincode:String){ override def toString =name +"=" +pincode } case class Department(name:String){ override def toString =name } case class emp(address:Address,department:Department) I want to create a DSL like below.Can anyone share the links about how to create a DSL and any suggestions to achieve the below. emp.withAddress("abc","12222").withDepartment("HR") Update: Actual use case class may have more fields close to 20. I want to avoid redudancy of code I created a DSL using reflection so that we don't need to add

Looking for good server-side language that will allow players to upload code that can be executed

て烟熏妆下的殇ゞ 提交于 2019-12-04 22:58:30
问题 I had an idea of a program I want to write, but which language would be best is my problem. If I have a car racing game and I want to allow users to submit code for new interactive 3D race tracks (think of tracks such as found in the Speed Racer movie), vehicles and for their autonomous vehicles, so, they would create the AI for their car that will enable the car to determine how to handle hazards. So, I need a language that will run fast, and as part of a world map that the server has of all

How to parse DSL input to high performance expression template

扶醉桌前 提交于 2019-12-04 21:34:24
( EDITED both title and main text and created a spin-off question that arose) For our application it would be ideal to parse a simple DSL of logical expressions. However the way I'd like to do this is to parse (at runtime) the input text which gives the expressions into some lazily evaluated structure (an expression template) which can then be later used within more performance sensitive code. Ideally the evaluation is as fast as possible using this technique as it will be used a large number of times with different values substituting into the placeholders each time. I'm not expecting the

Writing a simple parser

北战南征 提交于 2019-12-04 17:35:17
问题 I need to write a simple parser to a sort of Domain Specific Language. It needs to have basic arithmatics with proper operators evaluation order and a syntax to call functions of the underlying environment which can be overloaded. What is the simplest way to write such a parser? Is there something I can adapt or use out of the box? I'm writing in C++. 回答1: Take a look at Boost Spirit. 回答2: See MetaII parser technology. This tutorial walks you through everything: http://www

Apache Camel REST DSL - Validating Request Payload and return error response

匆匆过客 提交于 2019-12-04 15:16:41
I am exposing a rest service using "CamelHttpTransportServlet" that receive orders and place in jms queue. The code works fine on happy path and returns 200 response. I have written Processor to validate the input JSON, and set http_response_code based on the input. The issue is - for invalid requests though failure response code - 400 is set, the flow continues to the next route and pushes the data to the queue instead of sending the 400 response back to the calling app. rest("/ordermanagement") .post("/order").to("direct:checkInput"); from("direct:checkInput") .process(new Processor() {

Interpreting custom language

天大地大妈咪最大 提交于 2019-12-04 14:34:17
I need to develop an application that will read and understand text file in which I'll find a custom language that describe a list of operations (ie cooking recipe). This language has not been defined yet, but it will probably take one of the following shape : C++ like code (This code is randomly generated, just for example purpose) : begin repeat(10) { bar(toto, 10, 1999, xxx); } result = foo(xxxx, 10); if(foo == ok) { ... } else { ... } end XML code (This code is randomly generated, just for example purpose) : <recipe> <action name="foo" argument"bar, toto, xxx" repeat=10/> <action name="bar