dsl

How to materialize attrs data class from JSON schema defined by JSL document

好久不见. 提交于 2020-01-15 09:31:48
问题 Assuming you using Python JSL library for defining JSON schema of your data and you using attrs library for quick definition of your DTO. How can you easily validate data structure against its JSON schema definition (as jsl.Document class) and reify it into attrs instance conforming to its JSL definition without extra boilerplate? Because creating JSL documents and duplicate their definitions just to have a corresponding attrs DTO doesn’t feel to be the right way. 回答1: Define a function to

How to materialize attrs data class from JSON schema defined by JSL document

心不动则不痛 提交于 2020-01-15 09:30:12
问题 Assuming you using Python JSL library for defining JSON schema of your data and you using attrs library for quick definition of your DTO. How can you easily validate data structure against its JSON schema definition (as jsl.Document class) and reify it into attrs instance conforming to its JSL definition without extra boilerplate? Because creating JSL documents and duplicate their definitions just to have a corresponding attrs DTO doesn’t feel to be the right way. 回答1: Define a function to

Gradle task syntax: how is it explained from a Groovy perspective?

荒凉一梦 提交于 2020-01-14 01:44:47
问题 I'm having a hard time understanding how Gradle's Groovy DSL works. Unfortunately Gradle is the main use-case for Groovy that I come across in my day to day work, and I've noticed that for many devs, their exposure to Groovy is strictly through Gradle. And that a majority of Gradle users have a very limited grasp of Groovy as a consequence. In my limited understanding of Groovy, the following sintax tokenA tokenB { tokenC } where all tokens are not language keywords, tokenA would be a method

How to include Java Code Block in Xtext DSL?

陌路散爱 提交于 2020-01-13 19:12:11
问题 In an Xtext grammar I can include an Xbase code block using the XExpression / XBlockExpression types. How would I go to do the same with a Java code block? The included java should later be included in the Java generated from the DSL constructs. 回答1: You can do this now with JBase (https://github.com/LorenzoBettini/jbase). JBase was created specifically for the use case you described (see https://dl.acm.org/citation.cfm?id=2972217) and can be incorporated with minor changes by extending JBase

How to include Java Code Block in Xtext DSL?

我们两清 提交于 2020-01-13 19:12:06
问题 In an Xtext grammar I can include an Xbase code block using the XExpression / XBlockExpression types. How would I go to do the same with a Java code block? The included java should later be included in the Java generated from the DSL constructs. 回答1: You can do this now with JBase (https://github.com/LorenzoBettini/jbase). JBase was created specifically for the use case you described (see https://dl.acm.org/citation.cfm?id=2972217) and can be incorporated with minor changes by extending JBase

How can I recover sharing in a GADT?

杀马特。学长 韩版系。学妹 提交于 2020-01-12 02:57:11
问题 In Type-Safe Observable Sharing in Haskell Andy Gill shows how to recover sharing that existed on the Haskell level, in a DSL. His solution is implemented in the data-reify package. Can this approach be modified to work with GADTs? For example, given this GADT: data Ast e where IntLit :: Int -> Ast Int Add :: Ast Int -> Ast Int -> Ast Int BoolLit :: Bool -> Ast Bool IfThenElse :: Ast Bool -> Ast e -> Ast e -> Ast e I'd like to recover sharing by transforming the above AST to type Name =

What's the point of DSLs / fluent interfaces

﹥>﹥吖頭↗ 提交于 2020-01-11 16:40:31
问题 I was recently watching a webcast about how to create a fluent DSL and I have to admit, I don't understand the reasons why one would use such an approach (at least for the given example). The webcast presented an image resizing class, that allows you to specify an input-image, resize it and save it to an output-file using the following syntax (using C#): Sizer sizer = new Sizer(); sizer.FromImage(inputImage) .ToLocation(outputImage) .ReduceByPercent(50) .OutputImageFormat(ImageFormat.Jpeg)

Ruby Can't See Method

夙愿已清 提交于 2020-01-07 17:32:41
问题 I created deep_merged for my DSL (actually I copied it from configus gem), but ruby can't see that method, and I don't understand why. :/ Init.rb: require "./configus" require "pry" #Binding.pry config = Configus.config :staging, :production do production do key1 "value1" key2 "value2" group1 do key3 "value3" key4 "value4" end end staging do key2 "new value2" group1 do key4 "new value4" end end end p config.key1 Configus.rb: class Configus class InHash attr_reader :inner_hash def initialize

Extract info from a Groovy DSL file?

强颜欢笑 提交于 2020-01-06 06:05:12
问题 I recently switched my logback configuration file from logback.xml to logback.groovy. Using a DSL with Groovy is more versatile than XML for this sort of thing. I need to analyse this file programmatically, like I analysed the previous XML file (any of innumerable parsing tools). I realise that this will be imperfect, as a DSL config file sits on top of an object which it configures and must be executed, so its results are inevitably dynamic, whereas an XML file is static. If you want to

General stategy for designing Flexible Language application using ANTLR4

非 Y 不嫁゛ 提交于 2020-01-04 09:04:01
问题 Requirement: I am trying to develop a language application using antlr4. The language in question is not important. The important thing is that the grammar is very vast ( easily >2000 rules!!! ). I want to do a number of operations Extract bunch of informations. These can be call graphs, variable names. constant expressions etc. Any number of transformations: if a loop can be expanded, we go ahead and expand it If we can eliminate dead code we might choose to do that we might choose to rename