예제 #1
0
 public override Element Clone() => new PatternElement((Pattern)pattern.Clone())
 {
     Next        = cloneNext(),
     Alternate   = cloneAlternate(),
     Replacement = cloneReplacement(),
     ID          = CompilerState.ObjectID()
 };
예제 #2
0
 public BlockReplacement(Block block, Parameters parameters, bool returnValue)
 {
     this.block       = block;
     this.parameters  = parameters;
     this.returnValue = returnValue;
     id = CompilerState.ObjectID();
 }
예제 #3
0
 public override Element Clone() => new FailElement
 {
     Next        = cloneNext(),
     Alternate   = cloneAlternate(),
     Replacement = cloneReplacement(),
     ID          = CompilerState.ObjectID()
 };
예제 #4
0
 public AssignReplacement(string variableName, bool local, bool bind)
 {
     this.variableName = variableName;
     this.local        = local;
     this.bind         = bind;
     id = CompilerState.ObjectID();
 }
예제 #5
0
        public override Verb CreateVerb(string[] tokens)
        {
            Color(position, tokens[1].Length, Whitespaces);
            var variableName = tokens[2];

            if (CompilerState.IsRegisteredOperator(variableName))
            {
                Color(tokens[2].Length, Operators);
                return(CompilerState.Operator(variableName));
            }
            var star       = tokens[3];
            var entityType = Variables;

            if (source.Skip(position + length).IsMatch("^ ['([']"))
            {
                entityType = Invokeables;
            }
            if (IsClassName(variableName))
            {
                entityType = Types;
            }
            Color(variableName.Length, entityType);
            Color(star.Length, Operators);
            if (star == "*")
            {
                variableName += "_" + CompilerState.ObjectID();
            }
            var variable = new Variable(variableName);

            result.Value = variable;
            return(new Push(variable));
        }
예제 #6
0
 public Indexer(Array array, Array intKeys)
     : base(VAR_ANONYMOUS + CompilerState.ObjectID())
 {
     this.array   = array;
     this.intKeys = intKeys;
     isInteger    = true;
 }
예제 #7
0
 public Indexer(Array array, Block keyBlock)
     : base(VAR_ANONYMOUS + CompilerState.ObjectID())
 {
     this.array    = array;
     this.keyBlock = keyBlock;
     isInteger     = false;
 }
예제 #8
0
파일: Region.cs 프로젝트: toddcoder/Orange
 public Region()
 {
     variables         = new AutoHash <string, Value>("");
     Name              = MangledName($"region{CompilerState.ObjectID()}");
     deinitializations = new Hash <string, bool>();
     readonlys         = new AutoHash <string, ReadOnlyType>(ReadWrite);
     visibilityTypes   = new AutoHash <string, VisibilityType>(VisibilityType.Public);
     initializers      = new Set <string>();
 }
예제 #9
0
        public override Verb CreateVerb(string[] tokens)
        {
            Color(position, tokens[1].Length, Whitespaces);
            var variableName = tokens[2];

            Color(variableName.Length, Variables);
            Color(tokens[3].Length, Operators);
            variableName += "-" + CompilerState.ObjectID();
            return(new Push(new Variable(variableName)));
        }
예제 #10
0
        Value evaluateArray(Variable variable, Value value)
        {
            Array yArray;
            var   list = new List <Value>();

            var xValue       = variable.Value;
            var variableName = VAR_ANONYMOUS + CompilerState.ObjectID();

            if (xValue.IsArray)
            {
                var      xArray = (Array)xValue.SourceArray;
                Variable anonymousVariable;
                if (value.IsArray)
                {
                    yArray = (Array)value.SourceArray;
                    var minLength = Math.Min(xArray.Length, yArray.Length);
                    for (var i = 0; i < minLength; i++)
                    {
                        var xItem = xArray[i];
                        var yItem = yArray[i];
                        Regions.Current.CreateVariable(variableName);
                        anonymousVariable = new Variable(variableName)
                        {
                            Value = xItem
                        };
                        list.Add(evaluate(anonymousVariable, yItem));
                    }

                    Regions.Current.Remove(variableName);
                    return(new Array(list));
                }

                anonymousVariable = new Variable(variableName);
                foreach (var item in xArray)
                {
                    anonymousVariable.Value = item.Value;
                    list.Add(evaluate(anonymousVariable, value));
                }

                Regions.Current.Remove(variableName);
                return(new Array(list));
            }

            if (value.IsArray)
            {
                yArray = (Array)value.SourceArray;
                list.AddRange(yArray.Select(i => evaluate(variable, i.Value)));
                return(new Array(list));
            }

            return(evaluate(variable, variable));
        }
예제 #11
0
        public override Verb CreateVerb(string[] tokens)
        {
            Color(position, tokens[1].Length, KeyWords);
            Color(1, Structures);
            var        index           = position + length;
            var        superName       = "";
            Parameters superParameters = null;

            if (inheritanceParser.Scan(source, index))
            {
                superName       = inheritanceParser.VariableName;
                superParameters = inheritanceParser.Parameters;
                index           = inheritanceParser.Result.Position;
            }
            var traits = new List <string>();

            if (doesParser.Scan(source, index))
            {
                traits = doesParser.Traits;
                index  = doesParser.Result.Position;
            }

            Block objectBlock;

            try
            {
                InClassDefinition = true;
                ParseBlock(source, index, "'}'").Assign(out objectBlock, out index);
            }
            finally
            {
                InClassDefinition = false;
            }

            var builder = new Class(new Parameters(), objectBlock, GetStaticBlock(), superName, traits.ToArray(),
                                    superParameters, false);

            result.Value     = builder;
            overridePosition = index;
            return(new CreateObject(VAR_ANONYMOUS + CompilerState.ObjectID(), builder, false, Protected));
        }
예제 #12
0
        public override Verb CreateVerb(string[] tokens)
        {
            var parsers = new List <Parser>
            {
                new StringElementParser(),
                new FieldScanElementParser(),
                new ListElementParser(),
                new BalanceElementParser(),
                new LengthElementParser(),
                new FieldDelimiterElementParser(),
                new TabElementParser(),
                new RemElementParser(),
                new WordBoundaryElementParser(),
                new StringBoundaryElementParser(),
                new AtElementParser(),
                new AssertElementParser(),
                new BreakXElementParser(),
                new SpanElementParser(),
                new ArbNoElementParser(),
                new ArbElementParser(),
                new ClassElementParser(),
                new AlternateElementParser(),
                new OptionalElementParser(),
                new RangeElementParser(),
                new CountElementParser(),
                new PatternParser(true, true),
                new AnyElementParser(),
                new BlockElementParser(),
                new SingleCharacterElementParser(),
                new HexElementParser(),
                new FunctionElementParser(),
                new ConstantElementParser(),
                new VariableElementParser(),
                new EndPatternParser(IgnoreReplacement)
            };

            var index = position + length;

            Color(position, length, Structures);

            Element head           = null;
            Element currentElement = null;

            var          scanning          = true;
            var          sourceLength      = source.Length;
            var          isAlternate       = false;
            var          isOptional        = false;
            IReplacement replacement       = null;
            var          not               = false;
            var          conditionalParser = new ConditionalParser();
            var          replacementParser = new ReplacementParser();
            var          found             = false;

            while (scanning && index < sourceLength)
            {
                scanning = false;
                found    = false;
                foreach (var parser in parsers.Where(parser => parser.Scan(source, index)))
                {
                    if (parser is EndPatternParser endPatternParser)
                    {
                        replacement = endPatternParser.Replacement;
                        index       = endPatternParser.Result.Position;
                        found       = true;
                        break;
                    }

                    if (parser is AlternateElementParser)
                    {
                        isAlternate = true;
                        index       = parser.Result.Position;
                        scanning    = true;
                        found       = true;
                        break;
                    }

                    if (parser is OptionalElementParser)
                    {
                        isOptional = true;
                        index      = parser.Result.Position;
                        scanning   = true;
                        found      = true;
                        break;
                    }

                    if (!(parser is IElementParser elementParser))
                    {
                        continue;
                    }

                    var element = elementParser.Element;

                    if (not)
                    {
                        element.Not = true;
                        not         = false;
                    }

                    if (element is NegateElement)
                    {
                        not      = true;
                        index    = parser.Result.Position;
                        scanning = true;
                        found    = true;
                        break;
                    }

                    element.ID = CompilerState.ObjectID();
                    index      = parser.Result.Position;

                    if (replacementParser.Scan(source, index))
                    {
                        element.Replacement = replacementParser.Replacement;
                        index = replacementParser.Result.Position;
                    }

                    if (conditionalParser.Scan(source, index))
                    {
                        index = conditionalParser.Result.Position;
                    }
                    element.Conditional = conditionalParser.Conditional;

                    if (isOptional)
                    {
                        element.Alternate = new StringElement("");
                        isOptional        = false;
                    }

                    if (element.AutoOptional)
                    {
                        element.Alternate = new StringElement("");
                    }

                    if (isAlternate)
                    {
                        currentElement.AppendAlternate(element);
                        isAlternate = false;
                    }
                    else
                    {
                        if (head == null)
                        {
                            head = element;
                        }
                        else
                        {
                            currentElement.AppendNext(element);
                        }
                        currentElement = element;
                    }
                    scanning = true;
                    found    = true;
                    break;
                }
            }

            Assert(found, "Pattern parser", $"Didn't understand pattern '{source.Substring(index)}'");

            if (head == null)
            {
                head = new FailElement();
            }

            var newPattern = new Pattern(head)
            {
                Replacement = replacement,
                LastElement = currentElement,
                SubPattern  = subPattern
            };

            overridePosition  = index;
            newPattern.Source = source.Substring(position, index - position).Trim();
            if (resultElement)
            {
                Element = new PatternElement(newPattern);
                return(new NullOp());
            }

            result.Value = newPattern;
            return(new Push(newPattern));
        }
예제 #13
0
 public PrintBlockReplacement(Lambda lambda)
 {
     Assert(lambda.Parameters != null && lambda.Parameters.Length > 0, LOCATION, "No parameter provided");
     this.lambda = lambda;
     id          = CompilerState.ObjectID();
 }
예제 #14
0
 public StringIndexer(String text, Block indexesBlock)
     : base(VAR_ANONYMOUS + CompilerState.ObjectID())
 {
     this.text         = text;
     this.indexesBlock = indexesBlock;
 }
예제 #15
0
 public ObjectIndexer(Object obj, Block indexes)
     : base(VAR_ANONYMOUS + CompilerState.ObjectID())
 {
     this.obj     = obj;
     this.indexes = indexes;
 }
예제 #16
0
 public AtReplacement(string variableName, bool push)
 {
     this.variableName = variableName;
     this.push         = push;
     id = CompilerState.ObjectID();
 }
예제 #17
0
 public ValueReplacement(string variableName)
 {
     this.variableName = variableName;
     id = CompilerState.ObjectID();
 }
예제 #18
0
 protected BaseIndexer(Array array)
     : base(VAR_ANONYMOUS + CompilerState.ObjectID()) => this.array = array;
예제 #19
0
 public PrintBlockReplacement(Lambda lambda)
 {
     lambda.Parameters?.Length.Must().BeGreaterThan(0).OrThrow(LOCATION, () => "No parameter provided");
     this.lambda = lambda;
     id          = CompilerState.ObjectID();
 }
예제 #20
0
        public override Verb CreateVerb(string[] tokens)
        {
            var whitespace = tokens[1];

            Color(position, whitespace.Length, Whitespaces);
            var type = tokens[2];

            Color(type.Length, Structures);
            var message = tokens[3];
            var star    = tokens[4];

            if (star == "*")
            {
                message += "-" + CompilerState.ObjectID();
            }

            Color(message.Length, Messaging);
            Color(star.Length, Operators);
            Color(1, Structures);
            Block      actualArguments;
            Block      executable = null;
            Parameters parameters = null;
            var        index      = NextPosition;
            var        bracket    = tokens[5];
            Lambda     lambda     = null;
            int        newIndex;

            if (bracket == "(")
            {
                Color(1, Structures);
                if (GetExpression(source, index, CloseParenthesis()).If(out actualArguments, out newIndex))
                {
                    index = newIndex;
                }
                else
                {
                    actualArguments = new Block();
                }
            }
            else
            {
                actualArguments = new Block();
            }

            var splatting = false;

            if (useBlockOrLambda && getBlock(blockOrLambdaParser, index).If(out parameters, out executable, out splatting, out newIndex))
            {
                index = newIndex;
            }

            if (executable != null)
            {
                lambda = new Lambda(new Region(), executable, new Parameters(), false);
            }

            if (extraMessageWordParser.Parse(source, index).If(out newIndex, out var word, out var wordLambda))
            {
                message   += word;
                executable = wordLambda.Block;
                parameters = wordLambda.Parameters;
                index      = newIndex;
            }

            overridePosition = index;
            MessagingState.RegisterMessageCall(message);
            var arguments = new Arguments(actualArguments, executable, parameters)
            {
                Splatting = splatting
            };

            result.Value = lambda;

            return(getVerb(type, message, arguments, index));
        }
예제 #21
0
 public TestReplacement(string character)
 {
     this.character = character;
     id             = CompilerState.ObjectID();
 }
예제 #22
0
 public StringReplacement(String text)
 {
     this.text = text;
     id        = CompilerState.ObjectID();
 }
예제 #23
0
 public ListIndexer(List list, Block indexesBlock)
     : base($"{VAR_ANONYMOUS}{CompilerState.ObjectID()}")
 {
     this.list         = list;
     this.indexesBlock = indexesBlock;
 }
예제 #24
0
파일: Value.cs 프로젝트: toddcoder/Orange
 public Value()
 {
     id          = CompilerState.ObjectID();
     PerformElse = null;
     options     = OptionType.None;
 }