diff options
Diffstat (limited to 'src/main/java/io/devnulllabs/openjava/syntax/IdentifierRule.java')
-rw-r--r-- | src/main/java/io/devnulllabs/openjava/syntax/IdentifierRule.java | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/IdentifierRule.java b/src/main/java/io/devnulllabs/openjava/syntax/IdentifierRule.java new file mode 100644 index 0000000..facd82a --- /dev/null +++ b/src/main/java/io/devnulllabs/openjava/syntax/IdentifierRule.java @@ -0,0 +1,79 @@ +/* + * IdentifierRule.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 class <code>IdentifierRule</code> represents syntax rule of + * Identifier. + * returns as <code>Variable</code>. + * <p> + * return + * <pre> + * </pre> + * <p> + * + * @author Michiaki Tatsubori + * @version 1.0 + * @since $Id: IdentifierRule.java,v 1.2 2003/02/19 02:54:32 tatsubori Exp $ + * @see java.lang.Object + */ +public class IdentifierRule extends AbstractSyntaxRule +{ + + private String specifying; + + /** + * For specified identifier. + * + * @param specifying a string value specifying the identifier + * to consume. + */ + public IdentifierRule( String specifying ) { + this.specifying = specifying; + } + + /** + * For any identifier. + * + */ + public IdentifierRule() { + this( null ); + } + + public final ParseTree consume( TokenSource token_src ) + throws SyntaxException + { + return consumeIdentifier( token_src ); + } + + public Variable consumeIdentifier( TokenSource token_src ) + throws SyntaxException + { + Token t = token_src.getNextToken(); + if (t.kind != IDENTIFIER) { + /***** to become specified error report */ + throw new SyntaxException( "needs Identifier" ); + } + if (specifying != null && ! specifying.equals( t.image )) { + /***** to become specified error report */ + throw new SyntaxException( "needs " + specifying ); + } + return new Variable( t.image ); + } + +} |