简体   繁体   English

您可以在ParseKit的令牌中使用通配符吗?

[英]Can you use wildcards in a token with ParseKit?

I'm trying to add a symbol token using ParseKit below: 我正在尝试使用下面的ParseKit添加符号令牌:

    [t.symbolState add:@"<p style=\"margin-left: 20px;\">"];

I'm wondering if ParseKit allows for wildcards when adding a symbol, such as: 我想知道ParseKit在添加符号时是否允许通配符,例如:

    [t.symbolState add:@"<p style=\"margin-left: ##px;\">"];

I want to be able to then extract the wildcard from the token during the parsing procedure. 我希望能够在解析过程中从令牌中提取通配符。

Is such a thing possible with ParseKit? ParseKit有可能发生这种情况吗?

Developer of ParseKit here. 这里是ParseKit的开发人员。

I think using ParseKit in this way is not a good idea. 我认为以这种方式使用ParseKit并不是一个好主意。

ParseKit (and its successor PEGKit ) excel at tokenizing input and then parsing at the token level . ParseKit(及其后继PEGKit )擅长对输入进行令牌化,然后令牌级别进行解析

There are several natural tokens in the example input you've provided, but what you are trying to do here is ignore those natural tokens, combine them into a blob of input, and then do fancy sub-token matching using patterns. 您提供的示例输入中有几个自然标记,但是您在此处尝试做的是忽略这些自然标记,将它们组合成一小段输入,然后使用模式进行精美的子标记匹配。

There is a popular, powerful tool for fancy sub-token matching using patterns: Regular Expressions. 有一个流行的,功能强大的工具,可以使用模式进行花式子令牌匹配:正则表达式。 They will be a much better solution for that kind of thing than PEGKit. 对于这种事情,它们将是比PEGKit更好的解决方案。

However, I still don't think Regular Expressions are the tool you want to use here (or, at least not the only tool). 但是,我仍然不认为正则表达式是您要在此处使用的工具 (或者至少不是唯一的工具)。

It looks like you want to parse XML input. 看起来您想解析XML输入。 Don't use Regex or PEGKit for that. 不要为此使用Regex或PEGKit。 Use an XML parser. 使用XML解析器。 Always use an XML parser for parsing XML input. 始终使用XML解析器来解析XML输入。

You may choose to use another XML API layered on top of the XML Parser (SAX, StAX, DOM, XSLT, XQuery, etc.) but, underneath it all, you should be parsing with an XML parser (and, of course, all of those tools I listed, do). 您可以选择使用位于XML解析器之上的另一个XML API(SAX,StAX,DOM,XSLT,XQuery等),但是在所有这些之下,您应该使用XML解析器(当然,所有我列出的那些工具中)。

See here for more info . 有关更多信息,请参见此处

Then, once you have the style attribute string value you are looking for, use Regex to do fancy pattern matching. 然后,找到所需的style属性字符串值后,请使用Regex进行花式匹配。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM