Exemplo n.º 1
0
        internal static int GetId(StringConstant str, Builder.Localization.Locale locale)
        {
            int output = GetId(str.Value);

            if (output == -1)
            {
                throw ParserException.ThrowException(
                          locale,
                          Builder.Localization.ErrorMessages.UNKNOWN_CORE_FUNCTION_ID,
                          str.FirstToken,
                          str.Value);
            }
            return(output);
        }
Exemplo n.º 2
0
 internal void AddDependency(Token throwToken, LocalizedAssemblyView view)
 {
     if (this.dependenciesAndViews.ContainsKey(view.Scope))
     {
         if (this.dependenciesAndViews[view.Scope] != view)
         {
             throw ParserException.ThrowException(
                       view.Locale,
                       ErrorMessages.CANNOT_IMPORT_SAME_LIBRARY_FROM_DIFFERENT_LOCALES,
                       throwToken);
         }
     }
     this.dependenciesAndViews[view.Scope] = view;
     this.Metadata.RegisterDependencies(view.Scope.Metadata);
 }
Exemplo n.º 3
0
 // returns an exception so that you can throw this function call in situations where you want
 // the compiler to think the codepath terminates
 public System.Exception ThrowEofException()
 {
     throw ParserException.ThrowEofException(this.file.Name);
 }
Exemplo n.º 4
0
        internal virtual TopLevelEntity Parse(
            TokenStream tokens,
            TopLevelEntity owner,
            FileScope fileScope)
        {
            AnnotationCollection annotations = this.parser.AnnotationParser.ParseAnnotations(tokens);

            ModifierCollection modifiers = ModifierCollection.Parse(tokens);

            string value = tokens.PeekValue();

            if (value == this.parser.Keywords.IMPORT)
            {
                throw this.parser.GenerateParseError(
                          ErrorMessages.ALL_IMPORTS_MUST_OCCUR_AT_BEGINNING_OF_FILE,
                          tokens.Pop());
            }

            // TODO: check for annotations that aren't used.
            // https://github.com/blakeohare/crayon/issues/305

            if (value == this.parser.Keywords.NAMESPACE)
            {
                return(this.ParseNamespace(tokens, owner, fileScope, annotations));
            }
            if (value == this.parser.Keywords.CONST)
            {
                return(this.ParseConst(tokens, owner, fileScope, modifiers, annotations));
            }
            if (value == this.parser.Keywords.FUNCTION)
            {
                return(this.ParseFunction(tokens, owner, fileScope, modifiers, annotations));
            }
            if (value == this.parser.Keywords.CLASS)
            {
                return(this.ParseClassDefinition(tokens, owner, fileScope, modifiers, annotations));
            }
            if (value == this.parser.Keywords.ENUM)
            {
                return(this.ParseEnumDefinition(tokens, owner, fileScope, modifiers, annotations));
            }
            if (value == this.parser.Keywords.CONSTRUCTOR && owner is ClassDefinition)
            {
                return(this.ParseConstructor(tokens, (ClassDefinition)owner, modifiers, annotations));
            }

            FunctionDefinition nullableFunctionDef = this.MaybeParseFunctionDefinition(tokens, owner, fileScope, annotations, modifiers);

            if (nullableFunctionDef != null)
            {
                return(nullableFunctionDef);
            }

            tokens.EnsureNotEof();

            Token token = tokens.Peek();

            throw ParserException.ThrowException(
                      this.parser.CurrentLocale,
                      ErrorMessages.UNEXPECTED_TOKEN_NO_SPECIFIC_EXPECTATIONS,
                      token,
                      token.Value);
        }