简体   繁体   English

我要做什么叫什么?

[英]What is the thing I'm trying to do called?

I think there must be a name for whatever it is I'm trying to do. 我认为无论我想做什么,都必须有个名字。 I want to have a list of... requests and what the responses should look like. 我要列出...请求以及响应的外观。 But the different requests and responses are not formatted the same. 但是不同的请求和响应的格式不同。 They are simple strings, so here's some examples: 它们是简单的字符串,因此这里有一些示例:

request => response
foo%% => "OK" 
foo? => "%%"
%%%%bar => "OK"  
Version? => "Baz-%%%%"

Where % could be a number or letter. 其中%可以是数字或字母。

I can code for each possible command with a big switch/case, but I wanted to make it more extend-able and maybe testable. 我可以使用较大的开关/案例为每个可能的命令编写代码,但我想使其更具扩展性,甚至可以进行测试。 Sorry this question is so vague. 抱歉,这个问题太含糊了。 Please rename it and/or tag it correctly. 请重命名和/或正确标记。

I'm doing this in javascript/node if it matters. 如果有问题,我正在javascript / node中执行此操作。

我不知道您要发明什么,但这听起来像是正则表达式。

在这种情况下,您将%称为通配符。

Your code will need parse the input to verify syntactic correctness and output a data structure that represents the input. 您的代码将需要解析输入以验证语法的正确性,并输出代表输入的数据结构。 Then you will need to analyze your intermediate data structure to determine semantics. 然后,您将需要分析中间数据结构以确定语义。 The simplest way would be to use objects that implement a common interface. 最简单的方法是使用实​​现公共接口的对象。

object FooRequest (value)
    implements Request
    method Process ()
        return "OK"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 这个日期格式叫什么,我该如何解析它? - What is this date format called and how do I parse it? 我正在尝试为每个解析 xml 文件 - I'm trying to parse and xml file with for each 任何人都可以告诉我,当我尝试在python中解析和xml时,味精“解析中的第1182行”意味着什么错误 - Can anyone tell me what error msg “line 1182 in parse” means when I'm trying to parse and xml in python <table>变空,当我试图通过 BeautifulSoup 获取它时 - <table> becomes empty, when I'm trying to get it via BeautifulSoup 我正在尝试在Eclipse上运行此程序,但在控制台中收到此错误 - I'm trying to Run this program on eclipse but get this error in console 我正在尝试使用自定义嵌套标签解析 html 中的一些文本 - I'm trying to parse some text in html with custom nested tags 我在这段代码中做错了什么 - What m i doing wrong in this code i have been stuck at 对于.NET存在的pyparsing最接近的是什么? - What's the closest thing to pyparsing that exists for .NET? 没有调用ParseKit汇编程序回调:我做错了什么? - ParseKit assembler callbacks not called: What am I doing wrong? 如何用数千和数百万替换“k”和“m”? - How do I replace “k” and “m” with thousands and millions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM