if (isParent) {
return "getAttribSafe(node, \"" + cleanProp + "\")";
} else if (Generator.childrenContains(ast.extendedClasses.get(cls).multiChildren.keySet(), child)) {
return "getAttribSafe(node, \"" + child + "_" + cleanProp + "_last\")";
} else {
throw new InvalidGrammarException("Cannot access $$ attrib of a non-multi child / self reduction: " + lhs);
}
} else if (prop.contains("$i")) {
if (isParent) {
//FIXME fine for reduction?...
throw new InvalidGrammarException("Rhs: Cannot access $i of self attrib in class/interface " + cls.getName() + ": " + lhs);
//return "getAttribSafe(node.getAttribute(\"" + cleanProp + "\"))";
} else if (Generator.childrenContains(ast.extendedClasses.get(cls).multiChildren.keySet(), child)) {
String maybeD = getInputDefaultMaybe(cls.getChildByName(child), cleanProp, ast);
if (maybeD == null) {
ALEParser.ExtendedVertex ev = Generator.lookupAttributeExtended(child + "@" + cleanProp, cls, ast);
return (ev != null && ev.isMaybeType) ?
("getInputMaybeAttribSafe(child, \"" + cleanProp + "\")")
: ("getAttribSafe(child, \"" + cleanProp + "\")");
} else return "getInputAttribSafe(child, \"" + cleanProp + "\", " + maybeD + ")";
} else {
throw new InvalidGrammarException("Cannot access $i attrib of a non-multi child: " + lhs);
//return "getAttribSafe(getChildByRefName(node,\"" + child + "\").getAttribute(\"" + cleanProp + "\"))";
}
} else if (prop.contains("$-")) {
if (isParent) {
return "getAttribSafe(node, \"" + cleanProp + "\")";
//cleanProp + "_last"; //FIXME check acc assign happens last
} else if (Generator.childrenContains(ast.extendedClasses.get(cls).multiChildren.keySet(), child)) {
return "getAttribSafe(i == 0 ? node : children[i-1], i == 0 ? (\"" + child.toLowerCase() + "_" + cleanProp + "_init\") : (\"" + cleanProp + "\"))";
} else {
throw new InvalidGrammarException("Cannot access $- attrib of a non-multi child: " + lhs);
}
} else if (prop.contains("[-1]")) {
if (isParent) {
throw new InvalidGrammarException("cannot use [-1] on a self attrib: " + lhs);
} else if (Generator.childrenContains(ast.extendedClasses.get(cls).multiChildren.keySet(), child)) {
return "getAttribSafe(node, (\"" + child.toLowerCase() + "_" + cleanProp + "_init\"))";
} else {
throw new InvalidGrammarException("Cannot access $- attrib of a non-multi child: " + lhs);
}
} else {
if (isParent) {
String maybeD = getInputDefaultMaybe(cls, cleanProp, ast);
if (maybeD == null) {
ALEParser.ExtendedVertex ev = Generator.lookupAttributeExtended(prop, cls, ast);
return (ev != null && ev.isMaybeType) ?
("getInputMaybeAttribSafe(node, \"" + cleanProp + "\")") :
("getAttribSafe(node, \"" + cleanProp+ "\")");
}
else return "getInputAttribSafe(node, \"" + cleanProp + "\", " + maybeD + ")";
} else if (Generator.childrenContains(ast.extendedClasses.get(cls).multiChildren.keySet(), child)) {
//throw new InvalidGrammarException("Cannot read multichild attrib without indexer ($-, ...): " + cls.getName() + "::?? := ... " + lhs);
//FIXME currently allowed because logging might read back on "loop ... { ... child.x := ... }"
String maybeD = getInputDefaultMaybe(cls.getChildByName(child), cleanProp, ast);
try {
if (maybeD == null) {
ALEParser.ExtendedVertex ev = Generator.lookupAttributeExtended(child + "@" + cleanProp, cls, ast);
return (ev != null && ev.isMaybeType) ?
("getInputMaybeAttribSafe(child, \"" + cleanProp + "\")") :
("getAttribSafe(child, \"" + cleanProp + "\")");
} else return "getInputAttribSafe(child, \"" + cleanProp + "\", " + maybeD + ")";
} catch (InvalidGrammarException e) {
throw new InvalidGrammarException("rhs val fail ( " + cls.getName() + "): " + lhs + " => " + prop + " => " + cleanProp + ", " + maybeD + "\n"
+ e.getMessage());
}
} else {
String maybeD = getInputDefaultMaybe(cls.getChildByName(child), cleanProp, ast);