构建和处理宏的最佳实践
我正在构建一个 IOS 应用程序,并希望为用户提供针对系统不同方面使用宏的能力。
例如,我可能有一个简单的宏:
{include name="some name" pre="some it of htmk" post="some other bit of html"}
这将包括用户正在处理的文档正文中名为“some name”的项目的内容。
或者我可能有像这样更复杂的东西:
{notesForTag name={ListAllTags pre="some bit of html" post="some other bit of html"} pre="..." post="..."}
它将列出系统中按标签分组的所有文档..在返回的每个标签的开头和结尾添加数据(如html)的能力将允许用户,例如,将响应格式化为表格,或使用特定的样式等。
从概念上讲,我知道我希望它如何工作,但我想知道是否有任何宏构造和处理最佳实践可以帮助我我的方式。任何面向 Objective C / IOS 的东西都是最有帮助的。
编辑:为了在这里增加一些清晰度,我希望发现的是一种有效且准确的方法来解析此类内容。解析完之后,我想剩下的事情就相当简单了。
谢谢。
I'm building an IOS application, and would like to offer the user the ability to use macros for different aspects of the system.
For example, I might have a simple macro this this:
{include name="some name" pre="some it of htmk" post="some other bit of html"}
That would include the contents of the item named "some name" in the body of the document the user is working on.
or I might have something more complex like this:
{notesForTag name={ListAllTags pre="some bit of html" post="some other bit of html"} pre="..." post="..."}
Which would list all the documents in the system grouped by tag.. the ability to add on data (like html) at the beginning and the end of each tag returned would allow the user, for example, to format the response as a table, or use particular styling, etc.
Conceptually, I know how I want this to work, but I'm wondering if there are any macro construction and processing best practices out there that would help me on my way. Anything geared towards Objective C / IOS would be most helpful.
Edit: To add some clarity here, what I'm looking to discover is an efficient and accurate way to parse something like this. Having parsed things, I think the rest will be fairly straightforward.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NSScanner 会可能很适合解析这样的东西,也许可以使用递归函数来允许像第二个这样的嵌套宏。您可能还需要考虑使用 XML 来表示宏,这将允许您使用 NSXMLParser 来解析它,所以你只需要担心内容而不是结构。
NSScanner would probably work well for parsing something like this, perhaps with a recursive function to allow nested macros like the second one. You may also want to consider using XML to represent your macros, which would allow you to use NSXMLParser to parse it, so you only have to worry about the content and not the structure.