Beispiel #1
0
        protected virtual void ReportMessageAndThrowTemplateException(ITokenStream tokens, IToken templateToken, Parser parser, RecognitionException re)
        {
            if (re.Token.Type == TemplateLexer.EOF_TYPE)
            {
                string msg = "premature EOF";
                ErrorManager.CompiletimeError(ErrorType.SYNTAX_ERROR, templateToken, re.Token, msg);
            }
            else if (re is NoViableAltException)
            {
                string msg = "'" + re.Token.Text + "' came as a complete surprise to me";
                ErrorManager.CompiletimeError(ErrorType.SYNTAX_ERROR, templateToken, re.Token, msg);
            }
            else if (tokens.Index == 0)
            {
                // couldn't parse anything
                string msg = string.Format("this doesn't look like a template: \"{0}\"", tokens);
                ErrorManager.CompiletimeError(ErrorType.SYNTAX_ERROR, templateToken, re.Token, msg);
            }
            else if (tokens.LA(1) == TemplateLexer.LDELIM)
            {
                // couldn't parse expr
                string msg = "doesn't look like an expression";
                ErrorManager.CompiletimeError(ErrorType.SYNTAX_ERROR, templateToken, re.Token, msg);
            }
            else
            {
                string msg = parser.GetErrorMessage(re, parser.TokenNames);
                ErrorManager.CompiletimeError(ErrorType.SYNTAX_ERROR, templateToken, re.Token, msg);
            }

            // we have reported the error, so just blast out
            throw new TemplateException();
        }
Beispiel #2
0
        public virtual void RawDefineTemplate(string name, CompiledTemplate code, IToken defT)
        {
            CompiledTemplate prev;

            templates.TryGetValue(name, out prev);
            if (prev != null)
            {
                if (!prev.isRegion)
                {
                    ErrorManager.CompiletimeError(ErrorType.TEMPLATE_REDEFINITION, null, defT);
                    return;
                }
                if (prev.isRegion && prev.regionDefType == Template.RegionType.Embedded)
                {
                    ErrorManager.CompiletimeError(ErrorType.EMBEDDED_REGION_REDEFINITION, null, defT, GetUnmangledTemplateName(name));
                    return;
                }
                else if (prev.isRegion && prev.regionDefType == Template.RegionType.Explicit)
                {
                    ErrorManager.CompiletimeError(ErrorType.REGION_REDEFINITION, null, defT, GetUnmangledTemplateName(name));
                    return;
                }
            }

            code.NativeGroup = this;
            templates[name]  = code;
        }
Beispiel #3
0
        public virtual void ReferenceAttribute(IToken templateToken, CommonTree id)
        {
            string         name = id.Text;
            FormalArgument arg  = impl.TryGetFormalArgument(name);

            if (arg != null)
            {
                int index = arg.Index;
                Emit1(id, Bytecode.INSTR_LOAD_LOCAL, index);
            }
            else
            {
                if (Interpreter.PredefinedAnonymousSubtemplateAttributes.Contains(name))
                {
                    errMgr.CompiletimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE, templateToken, id.Token);
                    Emit(id, Bytecode.INSTR_NULL);
                }
                else
                {
                    Emit1(id, Bytecode.INSTR_LOAD_ATTR, name);
                }
            }
        }
Beispiel #4
0
        /** Make name and alias for target.  Replace any previous def of name */
        public virtual CompiledTemplate DefineTemplateAlias(IToken aliasT, IToken targetT)
        {
            string           alias  = aliasT.Text;
            string           target = targetT.Text;
            CompiledTemplate targetCode;

            templates.TryGetValue(target, out targetCode);
            if (targetCode == null)
            {
                ErrorManager.CompiletimeError(ErrorType.ALIAS_TARGET_UNDEFINED, null, aliasT, alias, target);
                return(null);
            }

            templates[alias] = targetCode;
            return(targetCode);
        }
Beispiel #5
0
        public virtual CompiledTemplate DefineRegion(string enclosingTemplateName, IToken regionT, string template, IToken templateToken)
        {
            string name = regionT.Text;

            template = Utility.TrimOneStartingNewline(template);
            template = Utility.TrimOneTrailingNewline(template);
            CompiledTemplate code    = Compile(FileName, enclosingTemplateName, null, template, regionT);
            string           mangled = GetMangledRegionName(enclosingTemplateName, name);

            if (LookupTemplate(mangled) == null)
            {
                ErrorManager.CompiletimeError(ErrorType.NO_SUCH_REGION, null, regionT, enclosingTemplateName, name);
                return(new CompiledTemplate());
            }

            code.name          = mangled;
            code.isRegion      = true;
            code.regionDefType = Template.RegionType.Explicit;

            RawDefineTemplate(mangled, code, regionT);
            code.DefineArgumentDefaultValueTemplates(this);
            code.DefineImplicitlyDefinedTemplates(this); // define any anonymous subtemplates
            return(code);
        }