简体   繁体   English

您如何使用java.util.regex.Pattern.Node

[英]How do you use java.util.regex.Pattern.Node

I need to parse a sequence of Prolog statements and I've been putting together ad-hoc regexs to handle them but the result is not very robust. 我需要解析一系列Prolog语句,并且我一直在整理临时的正则表达式来处理它们,但是结果不是很可靠。 I noticed java.util.regex.Pattern.Prolog , which is a subclass of java.util.regex.Pattern.Node , but I can't seem to find anything that explains what these classes are for or how to use them. 我注意到java.util.regex.Pattern.Prolog ,这是的一个子类java.util.regex.Pattern.Node ,但我似乎无法找到任何解释了这些类是或如何使用它们。 The Javadocs are mostly empty. Javadocs通常是空的。 Are there tutorials or fleshed-out documentation of the purpose and usage of these classes? 是否有关于这些类的用途和用法的教程或充实的文档? Can they be used to parse Prolog? 可以用来解析Prolog吗?

Those classes have package access modifiers. 这些类具有包访问修饰符。 For example, Node , in Oracle JDK 7, is declared as 例如,在Oracle JDK 7中, Node声明为

static class Node extends Object {

They can only be accessed from classes in the same package. 只能从同一包中的类访问它们。 However, since that package is typically secured by the JVM, you cannot add your classes to it. 但是,由于该程序包通常由JVM保护,因此您无法向其中添加类。 You'll get an exception like 您会收到类似的异常

Exception in thread "main" java.lang.SecurityException: Prohibited package name: java.util.regex

You can find and copy the source code if you want, but you will not be able to use the classes themselves. 您可以根据需要查找并复制源代码,但是您将无法使用这些类本身。


As for their purpose, you have to again go to the source code and look at the comments. 至于它们的目的,您必须再次转到源代码并查看注释。

/**
 * The following classes are the building components of the object
 * tree that represents a compiled regular expression. The object tree
 * is made of individual elements that handle constructs in the Pattern.
 * Each type of object knows how to match its equivalent construct with
 * the match() method.
 */

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

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