在C#中解析自定义搜索条件语法 [英] Parsing a Custom Search Criteria Grammar in C#

查看:70
本文介绍了在C#中解析自定义搜索条件语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#应用中,我希望用户能够以这种格式输入搜索条件:

In a C# app, I would like users to be able to enter search criteria in this kind of format:

(Name = 'Fred' OR Name = 'Jim') AND Age > 30

我需要某种方法来解析输入,以便我可以根据条件测试潜在的搜索匹配.几年前,我曾尝试 Malcolm Crowe的.NET编译器工具,但我我想知道在当今的DSL和表达式树中是否应该发现任何新的东西.解决此问题的最佳方法是什么?

What I need is some way to parse the input so I can test potential search matches against the criteria. I did experiment with Malcolm Crowe's compiler tools for .NET years ago, but I'm wondering if there is any new stuff I should be aware of in these days of DSLs and expression trees. What is the best way of approaching this problem?

推荐答案

我一直在查看讽刺,最近.它几乎可以满足您的需求,但确实属于我应该注意的新事物"类别.

I've been looking at Irony, recently. It's almost overpowered for what you need, but does fall into the category of "new stuff I should be aware of".

这是一个示例,使用反讽,似乎可以满足您的要求(不过需要注册才能阅读).

Here's an example, using Irony, which seems to do what you require (registration required to read it, though).

这篇关于在C#中解析自定义搜索条件语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆