private CommandTextInfo parseCommandText(ErrorReporter errorReporter) { String commandTextWithoutPhnameAttr = this.commandText; String commandText = commandTextWithoutPhnameAttr + ((userSuppliedPlaceholderName != null) ? " phname=\"" + userSuppliedPlaceholderName + "\"" : ""); // Handle callee name not listed as an attribute. Matcher ncnMatcher = NONATTRIBUTE_CALLEE_NAME.matcher(commandTextWithoutPhnameAttr); String delCalleeName; if (ncnMatcher.find()) { delCalleeName = ncnMatcher.group(1); if (!BaseUtils.isDottedIdentifier(delCalleeName)) { errorReporter.report(sourceLocation, INVALID_DELEGATE_NAME, delCalleeName); } commandTextWithoutPhnameAttr = commandTextWithoutPhnameAttr.substring(ncnMatcher.end()).trim(); } else { delCalleeName = null; errorReporter.report(sourceLocation, MISSING_CALLEE_NAME, commandText); } Map<String, String> attributes = ATTRIBUTES_PARSER.parse(commandTextWithoutPhnameAttr, errorReporter, sourceLocation); String variantExprText = attributes.get("variant"); ExprRootNode delCalleeVariantExpr; if (variantExprText == null) { delCalleeVariantExpr = null; } else { ExprNode expr = new ExpressionParser(variantExprText, sourceLocation, errorReporter).parseExpression(); // If the variant is a fixed string, do a sanity check. if (expr instanceof StringNode) { String fixedVariantStr = ((StringNode) expr).getValue(); if (!BaseUtils.isIdentifier(fixedVariantStr)) { errorReporter.report(sourceLocation, INVALID_VARIANT_EXPRESSION, variantExprText); } } delCalleeVariantExpr = new ExprRootNode(expr); } DataAttribute dataAttrInfo = parseDataAttributeHelper(attributes.get("data"), sourceLocation, errorReporter); String allowemptydefaultAttr = attributes.get("allowemptydefault"); Boolean allowsEmptyDefault = (allowemptydefaultAttr == null) ? null : allowemptydefaultAttr.equals("true"); return new CommandTextInfo( commandText, delCalleeName, delCalleeVariantExpr, allowsEmptyDefault, dataAttrInfo, userSuppliedPlaceholderName); }
@Override public String genBasePhName() { if (userSuppliedPlaceholderName != null) { return BaseUtils.convertToUpperUnderscore(userSuppliedPlaceholderName); } boolean isEndTag; String baseLcTagName; if (lcTagName.startsWith("/")) { isEndTag = true; baseLcTagName = lcTagName.substring(1); } else { isEndTag = false; baseLcTagName = lcTagName; } String basePlaceholderName = LC_TAG_NAME_TO_PLACEHOLDER_NAME_MAP.containsKey(baseLcTagName) ? LC_TAG_NAME_TO_PLACEHOLDER_NAME_MAP.get(baseLcTagName) : baseLcTagName; if (isEndTag) { basePlaceholderName = "end_" + basePlaceholderName; } else if (!isSelfEnding) { basePlaceholderName = "start_" + basePlaceholderName; } return basePlaceholderName.toUpperCase(); }
/** * Parses a 'requirecss' attribute value (for a Soy file or a template). * * @param requirecssAttr The 'requirecss' attribute value to parse. * @return A list of required CSS namespaces parsed from the given attribute value. */ static ImmutableList<String> parseRequirecssAttr( @Nullable String requirecssAttr, SourceLocation srcLoc) { if (requirecssAttr == null) { return ImmutableList.of(); } String[] namespaces = requirecssAttr.trim().split("\\s*,\\s*"); for (String namespace : namespaces) { if (!BaseUtils.isDottedIdentifier(namespace)) { throw LegacyInternalSyntaxException.createWithMetaInfo( "Invalid required CSS namespace name \"" + namespace + "\".", srcLoc); } } return ImmutableList.copyOf(namespaces); }
@Nullable private String computePlaceholderName(ErrorReporter errorReporter) { List<String> names = new ArrayList<>(); ImmutableList.Builder<StandaloneNode> transformedChildren = new ImmutableList.Builder<>(); for (StandaloneNode child : children) { transformedChildren.add(extractPlaceholderName(child, names)); } children = transformedChildren.build(); for (String name : names) { if (!BaseUtils.isIdentifier(name)) { errorReporter.report(sourceLocation, INVALID_PHNAME_ATTRIBUTE); } } if (names.size() > 1) { errorReporter.report(sourceLocation, MULTIPLE_PHNAME_ATTRIBUTES); } return Iterables.getFirst(names, null); }
private CommandTextInfo buildCommandText() { Preconditions.checkArgument(BaseUtils.isDottedIdentifier(delCalleeName)); String commandText = ""; commandText += delCalleeName; if (dataAttribute.isPassingAllData()) { commandText += " data=\"all\""; } else if (dataAttribute.isPassingData()) { assert dataAttribute.dataExpr() != null; // suppress warnings commandText += " data=\"" + dataAttribute.dataExpr().toSourceString() + '"'; } if (userSuppliedPlaceholderName != null) { commandText += " phname=\"" + userSuppliedPlaceholderName + '"'; } return new CommandTextInfo( commandText, delCalleeName, delCalleeVariantExpr, allowEmptyDefault, dataAttribute, userSuppliedPlaceholderName); }