Ejemplo n.º 1
0
        public override IMatched <Unit> ParseStatement(ParseState state, Token[] tokens)
        {
            var className = tokens[3].Text;

            Module.Global.ForwardReference(className);
            state.Colorize(tokens, Color.Keyword, Color.Whitespace, Color.Class);

            state.SkipEndOfLine();
            state.Advance();

            var mixins = new List <Mixin>();

            while (state.More)
            {
                var mixinIncludesParser = new MixinIncludesParser(mixins);
                if (mixinIncludesParser.Scan(state).If(out _, out var anyException))
                {
                }
                else if (anyException.If(out var exception))
                {
                    state.Regress();
                    return(failedMatch <Unit>(exception));
                }
                else
                {
                    break;
                }
            }

            state.SkipEndOfLine();
            state.Regress();

            if (getBlock(state).ValueOrCast <Unit>(out var block, out var asUnit))
            {
                var builder = new ClassBuilder(className, Parameters.Empty, "", new Expression[0], false, block, mixins);
                if (builder.Register().ValueOrOriginal(out _, out asUnit))
                {
                    var cls = new Class(builder);
                    state.AddStatement(cls);

                    var classItemsParser = new ClassItemsParser(builder);
                    while (state.More)
                    {
                        if (classItemsParser.Scan(state).If(out _, out var anyException))
                        {
                        }
                        else if (anyException.If(out var exception))
                        {
                            return(failedMatch <Unit>(exception));
                        }
                        else
                        {
                            break;
                        }
                    }

                    Module.Global.RegisterMixin(new Mixin(className));
                    return(Unit.Matched());
                }
                else
                {
                    return(asUnit);
                }
            }
            else
            {
                return(asUnit);
            }
        }
Ejemplo n.º 2
0
        public override IMatched <Unit> ParseStatement(ParseState state, Token[] tokens)
        {
            var className     = tokens[3].Text;
            var hasParameters = tokens[4].Text == "(";

            state.Colorize(tokens, Color.Keyword, Color.Whitespace, Color.Class, Color.OpenParenthesis);

            Parameters parameters;

            if (hasParameters)
            {
                if (getParameters(state).ValueOrCast <Unit>(out parameters, out var asUnit))
                {
                }
                else if (asUnit.IsNotMatched)
                {
                    parameters = new Parameters(0);
                }
                else
                {
                    return(asUnit);
                }
            }
            else
            {
                parameters = Parameters.Empty;
            }

            state.SkipEndOfLine();

            state.Advance();
            var parentClassParser = new ParentClassParser();

            var parentClassName = "";
            var initialize      = false;
            var arguments       = new Expression[0];

            if (parentClassParser.Scan(state).If(out _, out var anyException))
            {
                (parentClassName, initialize, arguments) = parentClassParser.Parent;
            }
            else if (anyException.If(out var exception))
            {
                state.Regress();
                return(failedMatch <Unit>(exception));
            }

            var mixins = new List <Mixin>();

            while (state.More)
            {
                var mixinIncludesParser = new MixinIncludesParser(mixins);
                if (mixinIncludesParser.Scan(state).If(out _, out anyException))
                {
                }
                else if (anyException.If(out var exception))
                {
                    state.Regress();
                    return(failedMatch <Unit>(exception));
                }
                else
                {
                    break;
                }
            }

            state.SkipEndOfLine();
            state.Regress();

            Module.Global.ForwardReference(className);

            state.SkipEndOfLine();
            if (getBlock(state).ValueOrCast <Unit>(out var block, out var asUnit2))
            {
                var builder = new ClassBuilder(className, parameters, parentClassName, arguments, initialize, block, mixins);
                if (builder.Register().ValueOrOriginal(out _, out asUnit2))
                {
                    var cls = new Class(builder);
                    state.AddStatement(cls);

                    var classItemsParser = new ClassItemsParser(builder);
                    while (state.More)
                    {
                        if (classItemsParser.Scan(state).If(out _, out anyException))
                        {
                        }
                        else if (anyException.If(out var exception))
                        {
                            return(failedMatch <Unit>(exception));
                        }
                        else
                        {
                            break;
                        }
                    }

                    return(Unit.Matched());
                }
                else
                {
                    return(asUnit2);
                }
            }
            else
            {
                return(asUnit2);
            }
        }