generative-programming

Generative regular expressions

∥☆過路亽.° 提交于 2019-12-18 12:34:44
问题 Typically in our work we use regular expressions in capture or match operations. However, regular expressions can be used - manually at least - to generate legal sentences that match the regular expression. Of course, some regular expressions can match infinitely long sentences, e.g., the expression .+ . I have a problem that could be solved by using a regular expression sentence generating algorithm. In pseudocode, it would operate something like this: re = generate("foo(bar|baz)?", max

Generative regular expressions

妖精的绣舞 提交于 2019-11-30 07:24:49
Typically in our work we use regular expressions in capture or match operations. However, regular expressions can be used - manually at least - to generate legal sentences that match the regular expression. Of course, some regular expressions can match infinitely long sentences, e.g., the expression .+ . I have a problem that could be solved by using a regular expression sentence generating algorithm. In pseudocode, it would operate something like this: re = generate("foo(bar|baz)?", max_match = 100); #Don't give me more than 100 results assert re == ("foobar", "foobaz", "foo"); What algorithm

Are there any Parsing Expression Grammar (PEG) libraries for Javascript or PHP?

随声附和 提交于 2019-11-29 11:21:28
问题 I find myself drawn to the Parsing Expression Grammar formalism for describing domain specific languages, but so far the implementation code I've found has been written in languages like Java and Haskell that aren't web server friendly in the shared hosting environment that my organization has to live with. Does anyone know of any PEG libraries or PackRat Parser Generators for Javascript or PHP? Of course code generators in any languages that can produce Javascript or PHP source code would do

Implementing variadic type traits

自古美人都是妖i 提交于 2019-11-28 06:54:45
Intro I'm looking for a pattern to convert C++ type traits into their variadic counterparts . A methodology to approach the problem would be appreciated and generative programming patterns to automate the task would be ideal. Example Take the following : std::is_same<T, U>::value; I want to write a trait that works like so : std::are_same<T1, T2, T3, T4>::value; Current approach It's pretty straightforward to implement the are_same ; Seeking a general solution we can come up with a tool for any variadic trait implementing universal quantification : template<template<class,class> class F,

Implementing variadic type traits

こ雲淡風輕ζ 提交于 2019-11-27 01:35:57
问题 Intro I'm looking for a pattern to convert C++ type traits into their variadic counterparts . A methodology to approach the problem would be appreciated and generative programming patterns to automate the task would be ideal. Example Take the following : std::is_same<T, U>::value; I want to write a trait that works like so : std::are_same<T1, T2, T3, T4>::value; Current approach It's pretty straightforward to implement the are_same ; Seeking a general solution we can come up with a tool for