我们有一个图形设计师,现在他们想要一个基于文本的设计师。 建议?
很抱歉我想不出更好的标题。
问题如下:
对于我们的客户,我们创建了(作为更大应用程序的一部分) 他们可以使用图形设计器来构建“场景”。
这些场景由“复合材料”组成,而“复合材料”又包括 的“命令”。 这些命令对象都派生自 CommandBase 和 实现一个名为 ICompilable 的接口。
场景类还实现了 ICompilable。 当调用 Compile() 时 在命令上返回一个字节数组,然后可以将其发送到设备 它们的目的(抱歉,无法透露有关该硬件的太多信息)
只是为了给您一个想法:
var scenario = new Scenario();
scenario.Add(new DelayCommand(1));
scenario.Add(new CountWithValueCommand(1,ActionEnum.Add,1));
scenario.Add(new DirectPowerCommand(23,false,150));
scenario.Add(new WaitCommand(3));
scenario.Add(new DirectPowerCommand(23,false,150));
scenario.Add(new SkipIfCommand(1,OperatorEnum.SmallerThan,10));
scenario.Add(new JumpCommand(2));
byte[] compiledData = scenario.Compile();
图形设计师从用户那里抽象了所有这些,并允许 他(或她)只需将复合材料拖放到设计器表面上即可。 (复合材料可以对命令进行分组,这样我们就可以为返回任务提供构建块)
最近我们的客户来找我们说:“设计师真的很酷, 但我们有些人宁愿拥有某种编程语言, 只是一些简单的事情。”
(当然对他们来说很简单)
我非常想为他们提供一种简单的语言, 可以调用各种命令,也可以将 SkipIfCommand 替换为 更好的结构等等...
我不知道从哪里开始或者我的选择是什么(在不破坏我们现有的情况下)
我听说人们嵌入了Python等语言, 人们编写自己的语言和解析器等......
有什么建议吗?
PS:用户只使用组合,而不使用命令。 复合材料在运行时动态加载(及其图形设计器) 并且可以由第三方在单独的组件中提供。
I'm sorry I could not think of a better title.
The problem is the following:
For our customer we have created (as part of a larger application) a
graphical designer which they can use to build "scenario's".
These scenario's consist of "Composites" which in turn consist
of "Commands". These command objects all derive from CommandBase and
implement an interface called ICompilable.
The scenario class also implements ICompilable. When Compile() is called
on a command an array of bytes is returned which can then be send to the device
for which they are intended (can't disclose to much info about that hardware, sorry)
Just to give you an idea:
var scenario = new Scenario();
scenario.Add(new DelayCommand(1));
scenario.Add(new CountWithValueCommand(1,ActionEnum.Add,1));
scenario.Add(new DirectPowerCommand(23,false,150));
scenario.Add(new WaitCommand(3));
scenario.Add(new DirectPowerCommand(23,false,150));
scenario.Add(new SkipIfCommand(1,OperatorEnum.SmallerThan,10));
scenario.Add(new JumpCommand(2));
byte[] compiledData = scenario.Compile();
The graphical designer abstracts all this from the user and allows
him (or her) to simply drag en drop composites onto the designer surface.
(Composites can group commands so we can provide building blocks for returning tasks)
Recently our customer came to us and said, "well the designer is really cool,
but we have some people who would rather have some kind of programming language,
just something simple."
(Simple to them of course)
I would very much like to provide them with a simple language,
that can call various commmands and also replace SkipIfCommand with
a nicer structure, etc...
I have no idea where to start or what my options are (without breaking what we have)
I have heard about people embedding languages such as Python,
people writing their own language an parsers, etc...
Any suggestions?
PS: Users only work with composites, never with commands.
Composites are loaded dynamically at runtime (along with their graphical designer)
and may be provided by third parties in seperate assemblies.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
据我所知,您有两种选择,
您可以使用 XML 样式“标记”来让它们定义实体及其分组,但这可能不是最好的。
你的选择是肯定的,你可以嵌入一种语言,但你真的需要这样做吗?这不是矫枉过正吗?你如何控制它?
如果您只需要非常简单的语法,那么也许可以编写您自己的语言。 创建一个简单的解释器其实并不难,只要你有严格、明确的语言。 看看你使用的任何编译器的一些例子,c#?
我在大学用java写了一个非常简单的解释器,它并不像你想象的那么难。
From what i think i've understood you have two options
you could either use an XML style "markup" to let them define entities and their groupings, but that may not be best.
Your alternatives are yes, yoou could embedd a language, but do you really need to, wouldnt that be overkill, and how can you control it?
If you only need really simple syntax then perhaps write your own language. Its actually not that hard to create a simple interpreter, as long as you have a strict, unambiguous language. Have a look for some examples of compilers in whatever youre using, c#?
I wrote a very simple interperter in java at uni, it wasnt as hard as you'd think.
如果您真的只想要一种非常简单的语言,那么您需要一个“递归下降解析器”。
例如,像这样的语言:
您可能有这样的语法:
给出的代码如下:
If you really just want a dirt simple language, you want a 'recursive descent parser'.
For example, a language like this:
You might have a grammar like:
Which gives code like:
对于简单的 DSL 来说,这看起来是一个完美的场景。 请参阅 http://msdn.microsoft.com/en- us/library/bb126235(VS.80).aspx 了解一些信息。
您还可以使用脚本语言,例如 lua.Net。
This looks like a perfect scenario for a simple DSL. See http://msdn.microsoft.com/en-us/library/bb126235(VS.80).aspx for some information.
You could also use a scripting language such as lua.Net.
这是一个用于构建 DSL 的 Pythonic 解决方案,您可以使用它来编译和创建字节码数组。
编写一个简单的模块,使您的 C# 结构可用于 Python。 目标是将允许用户使用的每个 C# 类(复合或命令或其他)定义为 Python 类。
通常,这涉及实现一组最小的方法,以及从 C# 类型到本机 Python 类型的不同转换,反之亦然。
编写一些不错的演示,展示如何使用这些 Python 类定义来创建脚本。 您应该能够在 Python 中创建类似的东西。
这些是定义相对简单的类。 这里的每个类都相当容易实现为直接调用基本 C# 模块的 Python 模块。
语法是纯Python,不需要额外的解析或词法扫描。
Here's a Pythonic solution for building a DSL that you can use to compile and create byte code arrays.
Write a simple module that makes your C# structures available to Python. The goal is to define each C# class that users are allowed to work with (Composites or Commands or whatever) as a Python class.
Usually, this involves implementing a minimal set of methods with different conversions from C# types to native Python types and vice versa.
Write some nice demos showing how to use these Python class definitions to create their scripts. You should be able to create things like this in Python.
These are relatively simple classes to define. Each class here be reasonably easy to implement as Python modules that directly call your base C# modules.
The syntax is pure Python with no additional parsing or lexical scanning required.
要添加 S.Lott 的评论,请按以下方式评估来自 C# 的 Python 脚本
To add to S.Lott's comment, here's how you eval a Python script from C#
虽然创建这种迷你语言并对其进行编码可能会很有趣,但您需要问的真正问题是:
当现实可能表明对这种请求的真正答案是“不”时,“真正整洁”的功能有一种构建方式。
在继续之前先看看您是否有利益相关者愿意赞助此项目。 然后在提交项目之前与最终用户核实,了解他们真正想要什么。
干杯,
-R
While it might be great fun to create this mini-language and code it all up, the real questions you need to ask are:
"Really neat" features have a way of getting built when the reality might indicate the true answer to such a request is "no".
See if you have a stakeholder willing to sponsor this before proceeding. Then check with the end users to see what they really want before committing to the project.
Cheers,
-R