예제 #1
0
        public bool Parse(string source, ref int index, out Block condition, out Block where)
        {
            var input = source.Sub(index);

            if (matcher.IsMatch(input, @"^\s*{"))
            {
                Runtime.Assert(blockParser.Scan(source, index), LOCATION, ERROR_MESSAGE);
                var result = blockParser.Result;
                index        = result.Position;
                Block        = (Block)result.Value;
                MultiCapable = true;
                condition    = null;
                where        = null;
                return(true);
            }
            if (matcher.IsMatch(input, @"^\s*=\s*"))
            {
                var length = matcher[0].Length;
                Parser.Color(index, length, IDEColor.EntityType.Structure);
                index       += length;
                Block        = OneLineBlockParser.Parse(source, ref index, false);
                MultiCapable = false;
                Block newBlock;
                if (createCondition(Block, out newBlock, out condition, out where))
                {
                    Block = newBlock;
                }
                return(true);
            }
            condition = null;
            where     = null;
            return(false);
        }
예제 #2
0
        public Block Parse(string source, ref int position, bool addEnd)
        {
            IsMacro   = false;
            Splatting = false;
            if (source.Skip(position).IsMatch("^ /s* ['{(']"))
            {
                var blockParser = new BlockParser(true);
                if (blockParser.Scan(source, position))
                {
                    position   = blockParser.Result.Position;
                    SingleLine = false;
                    Splatting  = false;
                    return((Block)blockParser.Result.Value);
                }
                Splatting = false;
                return(null);
            }
            if (source.Skip(position).IsMatch("^ /s* '.('"))
            {
                var macroParser = new MacroLiteralParser();
                if (macroParser.Scan(source, position))
                {
                    position   = macroParser.Result.Position;
                    SingleLine = false;
                    IsMacro    = true;
                    Splatting  = false;
                    return((Block)macroParser.Result.Value);
                }
            }
            SingleLine = true;
            Splatting  = false;
            if (bridge.IsNotEmpty())
            {
                if (matcher.IsMatch(source.Substring(position), bridge))
                {
                    var length = matcher[0].Length;
                    Parser.Color(length, Structures);
                    position += length;
                    Splatting = matcher.GroupCount(0) > 1 && matcher[0, 1] == "=>";
                }
                else
                {
                    return(null);
                }
            }
            var oneLineBlockParser = new OneLineBlockParser(addEnd);

            return(oneLineBlockParser.Parse(source, ref position) ? oneLineBlockParser.Block : null);
        }