_Core/Lang/Plugins/Core/LexReplacePlugin.cs

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ComLib.Lang;


namespace ComLib.Lang.Extensions
{
    /// <summary>
    /// Combinator for handling comparisons.
    /// </summary>
    public class LexReplacePlugin : LexPlugin
    {        
        /// <summary>
        /// List of replacement word to their values.
        /// </summary>
        protected string[,] _replacements;


        /// <summary>
        /// A map of the replacement words to their value.
        /// </summary>
        protected Dictionary<string, string> _replaceMap;
        

        /// <summary>
        /// Initialize
        /// </summary>
        public LexReplacePlugin()
        {
            _canHandleToken = true;
        }


        /// <summary>
        /// Initialize multi-token replacements.
        /// </summary>
        /// <param name="replacements"></param>
        public void Init(string[,] replacements)
        {
            _replacements = replacements;
            _replaceMap = new Dictionary<string, string>();
            for(int ndx = 0; ndx < replacements.GetLength(0); ndx++)
            {
                string tokenToReplace = (string)replacements.GetValue(ndx, 0);
                string replaceVal = (string)replacements.GetValue(ndx, 1);
                _replaceMap[tokenToReplace] = replaceVal;
            }
        }


        /// <summary>
        /// run step 123.
        /// </summary>
        /// <returns></returns>
        public override Token[]  Parse()
        {
            var tokenText = _replaceMap[_lexer.LastTokenData.Token.Text];
            Token replacement = null;
后面还有 10 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。