summaryrefslogtreecommitdiff
path: root/src/main/java/io/devnulllabs/openjava/syntax/NameRule.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/devnulllabs/openjava/syntax/NameRule.java')
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/NameRule.java74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/NameRule.java b/src/main/java/io/devnulllabs/openjava/syntax/NameRule.java
new file mode 100644
index 0000000..5d7ffd0
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/NameRule.java
@@ -0,0 +1,74 @@
+/*
+ * NameRule.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+
+import io.devnulllabs.openjava.ptree.ParseTree;
+import io.devnulllabs.openjava.ptree.Variable;
+import io.devnulllabs.openjava.tools.parser.Token;
+
+
+/**
+ * The interface <code>NameRule</code>
+ * <p>
+ * For example
+ * <pre>
+ * </pre>
+ * <p>
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: NameRule.java,v 1.2 2003/02/19 02:54:31 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class NameRule extends AbstractSyntaxRule
+{
+ /**
+ * Consumes a dot-separated name like <tt>java.lang.String</tt>.
+ *
+ * @param token_src token source
+ * @return a dummy <code>Variable</code> object.
+ * @see io.devnulllabs.openjava.ptree.Variable
+ */
+ public final ParseTree consume( TokenSource token_src )
+ throws SyntaxException
+ {
+ return consumeQualifiedName( token_src );
+ }
+
+ /**
+ * To override for modifying rule.
+ */
+ public Variable consumeQualifiedName( TokenSource token_src )
+ throws SyntaxException
+ {
+ IdentifierRule rule = new IdentifierRule();
+ Variable ident = rule.consumeIdentifier( token_src );
+ StringBuffer buf = new StringBuffer( ident.toString() );
+ while (lookaheadRest( token_src )) {
+ buf.append( token_src.getNextToken().image ); /* DOT */
+ buf.append( token_src.getNextToken().image ); /* IDENTIFIER */
+ }
+ return new Variable( buf.toString() );
+ }
+
+ /**
+ * A hard-coded lookahead for performance reason.
+ * (. <IDENTIFIER>)
+ */
+ protected static final boolean lookaheadRest( TokenSource token_src ) {
+ Token t1 = token_src.getToken( 1 );
+ Token t2 = token_src.getToken( 2 );
+ return (t1.kind == DOT && t2.kind == IDENTIFIER);
+ }
+
+}