1 ////////////////////////////////////////////////////////////////////////////////
2 // MillScript: an Open Spice interpreter and batch website creation tool
3 // Copyright (C) 2001-2004 Open World Ltd
4 // Copyright (C) 2005 Kevin Rogers
5 //
6 // This file is part of MillScript.
7 //
8 // MillScript is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
11 // any later version.
12 //
13 // MillScript is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 // more details.
17 //
18 // You should have received a copy of the GNU General Public License along with
19 // MillScript; if not, write to the Free Software Foundation, Inc., 59 Temple
20 // Place, Suite 330, Boston, MA 02111-1307 USA
21 ////////////////////////////////////////////////////////////////////////////////
22 package org.millscript.millscript.syntax;
23
24 import org.millscript.millscript.alert.Alerts;
25 import org.millscript.millscript.expr.Expr;
26 import org.millscript.millscript.expr.NameExpr;
27
28 /**
29 * This class implements the qualified name, <code>::</code> syntax.
30 *
31 * <p>
32 * <code><expr>::<expr></code>
33 * </p>
34 *
35 * <p>
36 * The left hand side expression is the qualifier and the right hand side
37 * expression is a name to qualify.
38 * </p>
39 *
40 * @see NameExpr
41 */
42 public final class QualifiedNameSyntax extends PostfixSyntax {
43
44 /**
45 * @see org.millscript.millscript.syntax.PostfixSyntaxInterface#postfix(java.lang.String, int, org.millscript.millscript.expr.Expr, org.millscript.millscript.syntax.Parser)
46 */
47 @Override
48 public NameExpr postfix( final String sym, final int prec, final Expr lhs, final Parser parser ) {
49 // We have to check that the left hand side expression is a name
50 // expression
51 if ( lhs instanceof NameExpr ) {
52 // It's a name expression, so make it one...
53 NameExpr left = (NameExpr)lhs;
54 // Get the nickname, which should not exist.
55 String nn = left.getNickname();
56 if ( nn != null ) {
57 throw(
58 Alerts.parse(
59 "Nested qualified names i.e. NAME::NAME::<etc>",
60 "Qualified name syntax has the form NAME::NAME"
61 ).
62 culprit( "name", left.getName() ).
63 culprit( "nickname", nn ).
64 mishap()
65 );
66 }
67 // Read the name to qualify
68 NameExpr name = parser.readName();
69 // Set it's qualifier
70 name.setNickname( left.getName() );
71 // Return the qualified name
72 return name;
73 } else {
74 // You can only use the qualified name syntax for names
75 throw(
76 Alerts.parse(
77 "Illegal use of ::",
78 ":: separates nicknames from names"
79 ).mishap()
80 );
81 }
82 }
83
84 }