Esempio n. 1
0
        public override void BreakApartParsedTokens()
        {
            SynLog.Log($"Breaking apart type {this.typeName}.");
            SynLog.LogFragments(this.declarationTokens);

            // For struct structname { ... }, remove everything except the ...
            this.declarationTokens.RemoveRange(0, 3);

            int lastIdx = this.declarationTokens.Count - 1;

            if (this.declarationTokens[lastIdx].MatchesSymbol(";"))
            {
                this.declarationTokens.RemoveRange(lastIdx - 1, 2);
            }
            else
            {
                this.declarationTokens.RemoveRange(lastIdx, 1);
            }

            while (this.declarationTokens.Count > 0)
            {
                if (this.declarationTokens[0].MatchesSymbol(";") == true)
                {
                    this.declarationTokens.RemoveAt(0);
                    continue;
                }

                SynRegion rgn = SynRegion.Parse(this, this.declarationTokens);
                if (rgn != null)
                {
                    this.regions.Add(rgn.name, rgn);
                    continue;
                }

                SynFuncDecl fnParse =
                    SynFuncDecl.Parse(
                        this,
                        this.declarationTokens,
                        this.typeName,
                        false,
                        SynFuncDecl.ParseType.StructContext);

                if (fnParse != null)
                {
                    this.AddFunction(fnParse);
                    continue;
                }

                SynVarValue varParse = SynVarValue.ParseBodyVar(this.declarationTokens, SynVarValue.OuterScope.Struct);
                if (varParse != null)
                {
                    this.AddVariable(varParse);
                    continue;
                }
            }
        }
Esempio n. 2
0
        public static SynRegion Parse(SynScope parentScope, List <Token> tokens)
        {
            int idx = 0;

            if (tokens[idx].Matches(TokenType.tyWord, "region") == false)
            {
                return(null);
            }

            ++idx;

            if (tokens[idx].Matches(TokenType.tyWord) == false)
            {
                throw new SynthExceptionSyntax(tokens[idx], $"Invalid region name.");
            }

            string scopeName = tokens[idx].fragment;

            ++idx;

            if (tokens[idx].Matches(TokenType.tySymbol, "{") == false)
            {
                throw new SynthExceptionSyntax(tokens[idx], $"Expected region to start with an opening brace.");
            }

            int bodyStart = idx;
            int end       = bodyStart;

            Parser.MovePastCurlScope(ref end, tokens);

            SynRegion ret = new SynRegion(parentScope);

            ret.name       = scopeName;
            ret.bodyStart  = bodyStart;
            ret.declPhrase = tokens.GetRange(0, end);
            tokens.RemoveRange(0, end);

            ret.BreakApartParsedTokens();

            return(ret);
        }