Exemplo n.º 1
0
        public NotificationMessage(StringToken stringToken, params TemplateValue[] values)
        {
            StringToken = stringToken;

            _template = new Template(stringToken, values);
            _message = new Lazy<string>(() => _template.Render());
        }
	protected Verifier( XmlReader document, ExpBuilder builder, ErrorHandler handler ) {
		this.document = document;
		this.handler = handler;
		this.builder = builder;
		this.attPruner = new AttPruner(builder);
		
		emptyStringToken = new StringToken("",builder,this);
	}
Exemplo n.º 3
0
        private void processToken(StringToken token)
        {
            var text = _repository.FindBy<LocalizedText>(x => x.Name == token.Key && x.Culture == EN_US);
            if (text != null) return;

            Console.WriteLine("Found new StringToken:  " + token.Key);
            text = new LocalizedText(token.Key, EN_US, token.DefaultValue);
            _repository.Save(text);
        }
Exemplo n.º 4
0
        public static IToken Parse(string text, int startPosition = 0, Action<IToken, int, string> callback = null)
        {
            if (string.IsNullOrWhiteSpace(text))
                return new NullToken();

            if (text.StartsWith("'") && text.IndexOf('\'', 1) <= 0)
                return new StringToken(text.Substring(1));

            List<string> blocks = text.SplitIntoBlocks(new[] {'\'', '\'', '"', '"', '^', '^', '{', '}', '(', ')'}, true,
                StringUtils.DelimiterInclude.IncludeSeparately);

            string simplifed = "";
            List<IToken> subResults = new List<IToken>();

            int currentPosition = startPosition;
            for (int i = 0; i < blocks.Count; i += 3)
            {
                string start = blocks[i];
                string entry = blocks[i + 1];
                IToken subResult = null;
                switch (start)
                {
                    case "\"":
                    case "'":
                        subResult = new StringToken(entry);
                        callback?.Invoke(subResult, currentPosition, "'" + entry + "'");
                        break;
                    case "^":
                        subResult = Parse(entry);
                        callback?.Invoke(subResult, currentPosition, "'" + entry + "'");
                        break;
                    case "{":
                        subResult = new ExpressionToken(null, new SubstitutionOperator(), Parse(entry));
                        callback?.Invoke(subResult, currentPosition, "{" + entry + "}");
                        break;
                    case "(":
                        subResult = Parse(entry, currentPosition + 1, callback);
                        break;
                    default:
                        simplifed += entry;
                        break;
                }
                if (subResult != null)
                {
                    simplifed += $"█{subResults.Count}█";
                    subResults.Add(subResult);
                }
                if (callback != null)
                    currentPosition += start.Length + entry.Length + blocks[i + 2].Length;
            }

            IToken result = ParseExpressionNoBrackets(simplifed, startPosition, callback);
            result = SubstituteValues(result, subResults);

            return result ?? new StringToken(text);
        }
        public string FindMissingText(StringToken key, CultureInfo culture)
        {
            var defaultValue = culture.Name + "_" + key.Key;
            if (key.DefaultValue.IsNotEmpty() && culture.Equals(_defaultCulture))
            {
                defaultValue = key.DefaultValue;
            }

            _storage.WriteMissing(key.Key, defaultValue, culture);

            return defaultValue;
        }
        /// <summary>
        /// Parse identifier list. Identifier list have the syntax: identifierList ::= stringDelimiter identifier* stringDelimiter
        /// </summary>
        /// <param name="token">Token containing the string with the identifier list.</param>
        /// <param name="parseErrorSink">Error sink for reporting parse errors.</param>
        /// <param name="sourceCodeService">Source code service that can convert tokens to source code span and reports issues.</param>
        /// <returns>A collection of sub-tokens if successful or null if token string is illegal.</returns>
        protected internal virtual IEnumerable<SourceReference<string>> ParseIdentifierList(StringToken token, IParseErrorSink parseErrorSink, ISourceCodeReferenceService sourceCodeService)
        {
            if (token == null)
                throw new ArgumentNullException("token");
            if (parseErrorSink == null)
                throw new ArgumentNullException("parseErrorSink");
            if (sourceCodeService == null)
                throw new ArgumentNullException("sourceCodeService");

            List<SourceReference<string>> result = new List<SourceReference<string>>();
            if (token.Value.Length == 0)
                return result;

            Scanner scanner = new Scanner(new StringReader(token.Value));
            Token t = scanner.GetToken();
            while (!(t is EofToken))
            {
                // Skip whitespaces (incl. comments).
                if (!(t is WhitespaceToken))
                {
                    // Offset the token to the position within the original token. +1 is due to the opening string ' quote.
                    t.SetTokenValues(
                        new SourceLocation(t.StartPosition.Position + token.StartPosition.Position + 1,
                            t.StartPosition.Line + token.StartPosition.Line,
                            t.StartPosition.Column + token.StartPosition.Column + 1),
                        new SourceLocation(t.StopPosition.Position + token.StartPosition.Position + 1,
                            t.StopPosition.Line + token.StartPosition.Line,
                            t.StopPosition.Column + token.StartPosition.Column + 1),
                        t.ScanError);

                    if (t is IdentifierToken)
                    {
                        // identifier  OK
                        result.Add(new SourceReference<string>(((IdentifierToken)t).Value, t.StartPosition, t.StopPosition, sourceCodeService));
                    }
                    else
                    {
                        // Non-identifier, report error
                        parseErrorSink.AddParserError(t.StartPosition, t.StopPosition, "Expected identifier", t);
                        return null; // Error condition
                    }
                }
                t = scanner.GetToken();
            }
            return result;
        }
Exemplo n.º 7
0
        public IToken Parse(string text)
        {
            List<string> blocks = text.SplitIntoBlocks(new[] {'\'', '\'', '"', '"', '{', '}', '(', ')'}, true, StringUtils.DelimiterInclude.IncludeSeparately);

            string simplifed = "";
            List<IToken> subResults = new List<IToken>();

            for (int i = 0; i < blocks.Count / 3; i++)
            {
                int index = i * 3;
                string start = blocks[index];
                string entry = blocks[index + 1];
                IToken subResult;
                switch (start)
                {
                    case "\"":
                    case "'":
                        subResult = new StringToken(entry);
                        simplifed += $"█{subResults.Count}█";
                        subResults.Add(subResult);
                        break;
                    case "{":
                        subResult = new ExpressionToken(null, new SubstitutionToken(), Parse(entry));
                        simplifed += $"█{subResults.Count}█";
                        subResults.Add(subResult);
                        break;
                    case "(":
                        subResult = Parse(entry);
                        simplifed += $"█{subResults.Count}█";
                        subResults.Add(subResult);
                        break;
                    default:
                        simplifed += entry;
                        break;
                }
            }

            IToken result = ParseExpressionNoBrackets(simplifed);
            result = SubstituteValues(result, subResults);

            return result ?? new StringToken(text);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Evaluate the function.
 /// </summary>
 /// <param name="parameters">The tokens that make up the function parameter list.</param>
 /// <param name="substitutions">The tokens that can be used for substitutions.</param>
 /// <param name="isFinal">Whether a result needs to be returned.</param>
 /// <returns></returns>
 public override IToken Perform(IToken parameters, TokenTreeList substitutions, bool isFinal)
 {
     ListToken listToken = parameters as ListToken;
     int count = listToken?.Tokens.Count ?? 0;
     if (count > 0)
     {
         IToken separator = new StringToken(" ");
         if (count > 1)
         {
             separator = listToken.Tokens[count - 1];
             --count;
         }
         IToken current = null;
         for (int i = 0; i < count; ++i)
         {
             IToken token = listToken.Tokens[i];
             if (token is ExpressionToken)
                 return UnParsed(parameters);
             current = AddToken(current, separator, token, substitutions, isFinal);
         }
         return current ?? new StringToken("");
     }
     return parameters;
 }
 public string GetTextForKey(StringToken key)
 {
     return _textValues.Retrieve(key);
 }
Exemplo n.º 10
0
        /**
         * This is the main lexing algorithm. It consumes source file as string and puts out token list.
         * Token consists of token type and range that token spans.
         */
        public static IToken[] Parse(string s)
        {
            LinkedList <IToken> ll = new LinkedList <IToken>();
            // use five kinds of token to produce token stream.
            var index = 0;
            var next  = 0;

            while (index < s.Length)
            {
                // try to parse as number
                if (NumberToken.ParseNumber(s, index, out var tokenNumber, out next))
                {
                    ll.AddLast(tokenNumber);
                    index = next;
                    continue;
                }

                // then try to parse as string
                if (StringToken.ParseString(s, index, out var tokenString, out next))
                {
                    ll.AddLast(tokenString);
                    index = next;
                    continue;
                }

                // then try to parse as identifier
                if (IdentifierToken.ParseIdentifier(s, index, out var tokenIdentifier, out next))
                {
                    ll.AddLast(tokenIdentifier);
                    index = next;
                    continue;
                }

                // then try to parse as comment
                if (CommentToken.ParseComment(s, index, out var tokensComment, out next))
                {
                    foreach (var t in tokensComment)
                    {
                        ll.AddLast(t);
                    }
                    index = next;
                    continue;
                }

                // then try to parse as symbol token
                if (SymbolToken.ParseSymbol(s, index, out var tokenSymbol, out next))
                {
                    ll.AddLast(tokenSymbol);
                    index = next;
                    continue;
                }

                if (Char.IsWhiteSpace(s[index]))
                {
                    // skip spaces
                    index++;
                    continue;
                }

                // otherwise token is unknown
                throw new Exception("unknown token " + s[index] + " at position " + index);
            }

            // return collected tokens
            return(ll.ToArray());
        }
Exemplo n.º 11
0
 public MaxValueFieldRule(IComparable bounds, StringToken token)
 {
     _bounds = bounds;
     Token = token;
 }
Exemplo n.º 12
0
        protected virtual StringToken VerifyIdentifierList(StringToken token, string errorMessage)
        {
            // stringDelimiter identifier* stringDelimiter
            if (token == null)
                return null;
            if (token.Value.Length == 0)
                return token;

            bool inComment = false;
            bool identifierStart = true;
            ScanResult scanResult = new ScanResult();
            foreach (char ch in token.Value)
            {
                scanResult.SetResult(ch);
                if (scanResult.IsCommentDelimiter())
                {
                    inComment = !inComment;
                    identifierStart = true;
                }
                else
                {
                    if (!inComment)
                    {
                        if (scanResult.IsWhitespace())
                        {
                            identifierStart = true;
                        }
                        else
                        {
                            if (identifierStart)
                            {
                                if (!scanResult.IsLetter())
                                {
                                    this.ReportParserError(errorMessage, token);
                                    return null;
                                }
                                identifierStart = false;
                            }
                            else
                            {
                                if (!(scanResult.IsLetter() || scanResult.IsDigit()))
                                {
                                    this.ReportParserError(errorMessage, token);
                                    return null;
                                }
                            }
                        }
                    }
                }
            }

            return token;
        }
Exemplo n.º 13
0
 public MenuNode this[StringToken parentKey]
 {
     set
     {
         var registration = new MenuRegistration(new AddBefore(), new Literal(parentKey), value);
         _registry._registrations.Add(registration);
     }
 }
Exemplo n.º 14
0
        public void Run(ICommandInteraction writer, [Values("set", "add", "rem", "create")] LiteralToken action, StringToken name)
        {
            Machine machine;

            switch (action.Value)
            {
            case "add":
                machine = new Machine();
                EmulationManager.Instance.CurrentEmulation.AddMachine(machine, name.Value);
                if (GetCurrentMachine() == null)
                {
                    SetCurrentMachine(machine);
                }
                break;

            case "set":
                Machine machineToSet;
                if (!EmulationManager.Instance.CurrentEmulation.TryGetMachineByName(name.Value, out machineToSet))
                {
                    writer.WriteError(string.Format("Machine {0} not found.", name.Value));
                    break;
                }
                SetCurrentMachine(machineToSet);
                break;

            case "rem":
                Machine machineToRemove;
                if (!EmulationManager.Instance.CurrentEmulation.TryGetMachineByName(name.Value, out machineToRemove))
                {
                    writer.WriteError(string.Format("Machine {0} not found.", name.Value));
                    break;
                }
                EmulationManager.Instance.CurrentEmulation.RemoveMachine(name.Value);
                if (GetCurrentMachine() == machineToRemove)
                {
                    SetCurrentMachine(null);
                }
                break;

            case "create":
                machine = new Machine();
                EmulationManager.Instance.CurrentEmulation.AddMachine(machine, name.Value);
                SetCurrentMachine(machine);
                break;
            }
        }
Exemplo n.º 15
0
 public bool Matches(StringToken token)
 {
     return token.ToLocalizationKey().ToString() == _name || token.Key == _name;
 }
Exemplo n.º 16
0
 public RangeLengthFieldRule(int min, int max, StringToken token)
 {
     _min  = min;
     _max  = max;
     Token = token;
 }
Exemplo n.º 17
0
        public void AddCriteria <T>(Expression <Func <T, object> > property, StringToken op, string value)
        {
            var criteria = Criteria.For(property, op.Key, value);

            AddCriteria(criteria);
        }
Exemplo n.º 18
0
 public NotificationMessage RegisterMessage <T>(Expression <Func <T, object> > property, StringToken message, params TemplateValue[] values)
 {
     return(RegisterMessage(property.ToAccessor(), message, values));
 }
Exemplo n.º 19
0
 public NotificationMessage RegisterMessage(PropertyInfo property, StringToken notificationMessage, params TemplateValue[] values)
 {
     return(RegisterMessage(new SingleProperty(property), notificationMessage, values));
 }
Exemplo n.º 20
0
 public void find_by_type()
 {
     StringToken.Find(typeof(TargetKey), "One").ShouldBeTheSameAs(TargetKey.One);
     StringToken.Find(typeof(TargetKey2), "One").ShouldBeTheSameAs(TargetKey2.One);
 }
Exemplo n.º 21
0
 public NotificationMessage(StringToken stringToken) : this(stringToken, new Dictionary <string, string>())
 {
 }
Exemplo n.º 22
0
 public void AddCriteria(Expression <Func <TEntity, object> > property, StringToken op, object value)
 {
     _initialCriteria.Add(Criteria.For(property, op.Key, value.ToString()));
 }
 public string GetTextForKey(StringToken key)
 {
     var localizationKey = key.ToLocalizationKey();
     return _localeCache
         .Retrieve(localizationKey, () => _missingHandler.FindMissingText(key, _localeCache.Culture));
 }
Exemplo n.º 24
0
 public MinValueFieldRule(IComparable bounds, StringToken token)
 {
     _bounds = bounds;
     Token   = token;
 }
 public bool Equals(StringToken obj)
 {
 }
Exemplo n.º 26
0
 public FieldValidationExpression GreaterOrEqualToZero(StringToken token)
 {
     return(register(new GreaterOrEqualToZeroRule(token)));
 }
Exemplo n.º 27
0
        private static IToken PerformSubstitutionOperation(IReadOnlyList<string> tokens, int startPosition, Action<IToken, int, string> callback)
        {
            IToken token = null;
            string firstToken = tokens[1];
            if (!string.IsNullOrWhiteSpace(firstToken))
                token = new StringToken(firstToken);

            IToken result = new ExpressionToken(null, new SubstitutionOperator(), token);
            //if (token != null)
            //    callback?.Invoke(result, startPosition + tokens[0].Length, firstToken);
            if (!string.IsNullOrWhiteSpace(tokens[0]))
            {
                token = ParseExpressionNoBrackets(tokens[0].Trim(), startPosition, null);
                ExpressionToken expression = token as ExpressionToken;
                if (expression?.NeedsSecond ?? false)
                    result = expression.SetSecond(result);
                else
                    result = new ExpressionToken(token, new StringPlusOperator(), result);
            }
            if (!string.IsNullOrWhiteSpace(tokens[4]))
            {
                token = ParseExpressionNoBrackets(tokens[4].Trim(), startPosition + tokens[0].Length + tokens[3].Length, null);
                result = new ExpressionToken(result, new StringPlusOperator(), token);
            }
            return result;
        }
Exemplo n.º 28
0
 public FieldValidationExpression Required(StringToken token)
 {
     return(register(new RequiredFieldRule(token)));
 }
Exemplo n.º 29
0
 public GreaterOrEqualToZeroRule(StringToken token)
 {
     Token = token;
 }
Exemplo n.º 30
0
 public FieldValidationExpression Email(StringToken token)
 {
     return(register(new EmailFieldRule(token)));
 }
Exemplo n.º 31
0
 public MenuItemAttribute(string title)
 {
     _title = new NavigationKey(title);
 }
Exemplo n.º 32
0
 public FieldValidationExpression MinimumLength(int length, StringToken token)
 {
     return(register(new MinimumLengthRule(length, token)));
 }
 public InterchangeVersionIdentifierNode(StringToken versionId)
 {
     this.VersionId = versionId;
 }
Exemplo n.º 34
0
 public FieldValidationExpression RangeLength(int min, int max, StringToken token)
 {
     return(register(new RangeLengthFieldRule(min, max, token)));
 }
Exemplo n.º 35
0
 public bool DependsOn(StringToken token)
 {
     return _matcher.Matches(token);
 }
Exemplo n.º 36
0
 public FieldValidationExpression MaxValue(IComparable bounds, StringToken token)
 {
     return(register(new MaxValueFieldRule(bounds, token)));
 }
        private string findMissingLocalizedText(StringToken token)
        {
            //return "Error String Not Found!";
            //var localizedText = _repository.FindBy<LocalizedText>(t => t.Name == token.Key && t.Culture == Culture.Name);
            //if (localizedText == null)
            //{
            string defaultText = "Error String Not Found!";

            if (token.DefaultValue.IsNotEmpty())
            {
                var prefix = ""; //((Culture.Name.Equals("en-US", StringComparison.InvariantCultureIgnoreCase)) ? "" : Culture.Name + "_");
                defaultText = prefix + token.DefaultValue;
            }
            //    else
            //    {
            //        defaultText = Culture + "_" + token.Key;
            //    }

            //    localizedText = new LocalizedText(token.Key, Culture.Name, defaultText);
            //    _repository.Save(localizedText);
            //}

            //return localizedText.Text;
            return defaultText;
        }
Exemplo n.º 38
0
 public FieldValidationExpression RegEx(string expression, StringToken token)
 {
     return(register(new RegularExpressionFieldRule(expression, token)));
 }
 public ViewDisplayExpression <VIEWMODEL> AddDisplayNameForHref(StringToken displayName)
 {
     _displayName = displayName.ToString();
     return(this);
 }
Exemplo n.º 40
0
 public FieldEqualityRuleExpression UseToken(StringToken token)
 {
     _rule.Token = token;
     return(this);
 }
 public static bool op_Inequality(StringToken a, StringToken b)
 {
 }
Exemplo n.º 42
0
 public MenuChain(StringToken key)
 {
     _key = key;
 }
Exemplo n.º 43
0
 private static IToken PerformSubstitutionOperation(IReadOnlyList<string> tokens)
 {
     IToken token = null;
     if (!string.IsNullOrWhiteSpace(tokens[1]))
     {
         token = new StringToken(tokens[1]);
     }
     IToken result = new ExpressionToken(null, new SubstitutionToken(), token);
     if (!string.IsNullOrWhiteSpace(tokens[0]))
     {
         token = ParseExpressionNoBrackets(tokens[0].Trim());
         ExpressionToken expression = token as ExpressionToken;
         if (expression?.NeedsSecond ?? false)
             result = expression.SetSecond(result);
         else
             result = new ExpressionToken(token, new StringPlusToken(), result);
     }
     if (!string.IsNullOrWhiteSpace(tokens[3]))
     {
         token = ParseExpressionNoBrackets(tokens[3].Trim());
         result = new ExpressionToken(result, new StringPlusToken(), token);
     }
     return result;
 }
Exemplo n.º 44
0
 /// <summary>
 /// Find
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public MenuNode FindByKey(StringToken key)
 {
     return(AllNodes().FirstOrDefault(x => x.Key == key));
 }
Exemplo n.º 45
0
 private static IToken CreateStringToken(IReadOnlyList<string> tokens, int startPosition, Action<IToken, int, string> callback)
 {
     string item = tokens[0];
     IToken token = new StringToken(item);
     //if (!item.Contains("█"))
     //    callback?.Invoke(token, startPosition, item);
     return token;
 }
Exemplo n.º 46
0
        public static Token Create(TokenKind kind, SourceLocation location)
        {
            Token token;

            switch (kind)
            {
                #region case KEYWORD:
            case TokenKind.T_AS:
            case TokenKind.T_BREAK:
            case TokenKind.T_CASE:
            case TokenKind.T_CATCH:
            case TokenKind.T_CONST:
            case TokenKind.T_CONTINUE:
            case TokenKind.T_DEFAULT:
            case TokenKind.T_DELETE:
            case TokenKind.T_DO:
            case TokenKind.T_ELSE:
            case TokenKind.T_ENUM:
            case TokenKind.T_FALSE:
            case TokenKind.T_FINALLY:
            case TokenKind.T_FOR:
            case TokenKind.T_FUNCTION:
            case TokenKind.T_IF:
            case TokenKind.T_IMPORT:
            case TokenKind.T_IN:
            case TokenKind.T_INSTANCEOF:
            case TokenKind.T_LET:
            case TokenKind.T_NEW:
            case TokenKind.T_NULL:
            case TokenKind.T_ON:
            case TokenKind.T_PRAGMA:
            case TokenKind.T_PROPERTY:
            case TokenKind.T_PUBLIC:
            case TokenKind.T_READONLY:
            case TokenKind.T_RESERVED_WORD:
            case TokenKind.T_RETURN:
            case TokenKind.T_SET:
            case TokenKind.T_SIGNAL:
            case TokenKind.T_SWITCH:
            case TokenKind.T_THIS:
            case TokenKind.T_THROW:
            case TokenKind.T_TRUE:
            case TokenKind.T_TRY:
            case TokenKind.T_TYPEOF:
            case TokenKind.T_VAR:
            case TokenKind.T_VOID:
            case TokenKind.T_WHILE:
            case TokenKind.T_WITH:
                #endregion
                token = new KeywordToken();
                break;

            case TokenKind.T_NUMERIC_LITERAL:
                token = new NumberToken();
                break;

            case TokenKind.T_MULTILINE_STRING_LITERAL:
            case TokenKind.T_STRING_LITERAL:
                token = new StringToken();
                break;

            case TokenKind.T_COMMENT:
                token = new CommentToken();
                break;

            default:
                token = new Token();
                break;
            }
            token.Kind     = kind;
            token.Location = location;
            return(token);
        }
Exemplo n.º 47
0
        public IEnumerable <MenuItemToken> MenuFor(StringToken key)
        {
            var chain = _navigation.MenuFor(key);

            return(chain.Select(BuildToken));
        }
Exemplo n.º 48
0
 public NotificationMessage RegisterMessage <T>(Expression <Func <T, object> > property, StringToken message)
 {
     return(RegisterMessage(property.ToAccessor(), message));
 }
 public string GetTextForKey(StringToken key)
 {
     return key.DefaultValue ?? Culture.Name + "_" + key.Key;
 }
Exemplo n.º 50
0
 public void Description(StringToken description)
 {
     alter = feed => feed.Description = description.ToString().ToContent();
 }
Exemplo n.º 51
0
        public MinimumLengthRule(int length, StringToken token)
        {
            _length = length;

            Token = token;
        }
Exemplo n.º 52
0
 public RegularExpressionFieldRule(string expression, StringToken token)
 {
     Expression = new Regex(expression);
     Token      = token;
 }
Exemplo n.º 53
0
        protected virtual StringToken VerifyIdentifierString(StringToken token, string errorMessage)
        {
            // stringDelimiter identifier stringDelimiter
            // identifier ::= letter (letter | digit)*
            if (token == null)
                return null;

            string str = token.Value;
            if (str.Length == 0)
            {
                this.ReportParserError(errorMessage, token);
                return null; // Empty
            }
            ScanResult scanResult = new ScanResult();
            scanResult.SetResult(str[0]);
            if (!scanResult.IsLetter())
            {
                this.ReportParserError(errorMessage, token);
                return null; // First char non-letter
            }
            foreach (char ch in str)
            {
                scanResult.SetResult(ch);
                if (!(scanResult.IsLetter() || scanResult.IsDigit()))
                {
                    this.ReportParserError(errorMessage, token);
                    return null; // Non-letter or non-digit char
                }

            }

            return token; // OK
        }
Exemplo n.º 54
0
        private StringToken buildCommonToken()
        {
            const string key = "test";

            return(StringToken.FromKeyString(key, "default"));
        }
Exemplo n.º 55
0
 public MenuItemAttribute(string key, string defaultText)
 {
     _title = new NavigationKey(key, defaultText);
 }
Exemplo n.º 56
0
 public void Title(StringToken title)
 {
     alter = feed => feed.Title = title.ToString().ToContent();
 }
Exemplo n.º 57
0
        public AddExpression ForMenu(StringToken key)
        {
            _lastKey = key;

            return new AddExpression(this);
        }
Exemplo n.º 58
0
 public bool Equals(StringToken obj)
 {
     if (ReferenceEquals(null, obj)) return false;
     if (ReferenceEquals(this, obj)) return true;
     return Equals(obj._key, _key);
 }
Exemplo n.º 59
0
 public void Run(ICommandInteraction writer, StringToken command)
 {
     Execute(command.Value, writer);
 }
Exemplo n.º 60
0
        public bool TryTokenize(byte currentByte, IInputBytes inputBytes, out IToken token)
        {
            var builder = new StringBuilder();

            token = null;

            if (inputBytes == null)
            {
                return(false);
            }

            if (currentByte != '(')
            {
                return(false);
            }

            int  numberOfBrackets = 1;
            bool isEscapeActive   = false;
            bool isLineBreaking   = false;

            bool octalModeActive = false;

            short[] octal      = { 0, 0, 0 };
            int     octalsRead = 0;

            while (inputBytes.MoveNext())
            {
                var b = inputBytes.CurrentByte;
                var c = (char)b;

                if (octalModeActive)
                {
                    var nextCharacterOctal = c >= '0' && c <= '7';

                    if (nextCharacterOctal)
                    {
                        // left shift the octals.
                        LeftShiftOctal(c, octalsRead, octal);
                        octalsRead++;
                    }

                    if (octalsRead == 3 || !nextCharacterOctal)
                    {
                        var characterCode = OctalHelpers.FromOctalDigits(octal);

                        // For now :(
                        // TODO: I have a sneaking suspicion this is wrong, not sure what behaviour is for large octal numbers
                        builder.Append((char)characterCode);

                        octal[0]        = 0;
                        octal[1]        = 0;
                        octal[2]        = 0;
                        octalsRead      = 0;
                        octalModeActive = false;
                    }

                    if (nextCharacterOctal)
                    {
                        continue;
                    }
                }

                switch (c)
                {
                case ')':
                    isLineBreaking = false;
                    if (!isEscapeActive)
                    {
                        numberOfBrackets--;
                    }

                    if (numberOfBrackets > 0)
                    {
                        builder.Append(c);

                        break;
                    }

                    // TODO: Check for other ends of string where the string is improperly formatted. See commented method
                    // numberOfBrackets = CheckForEndOfString(inputBytes, numberOfBrackets);

                    isEscapeActive = false;

                    break;

                case '(':
                    isLineBreaking = false;



                    if (!isEscapeActive)
                    {
                        numberOfBrackets++;
                    }

                    builder.Append(c);
                    break;

                // Escape
                case '\\':
                    isLineBreaking = false;
                    // Escaped backslash
                    if (isEscapeActive)
                    {
                        builder.Append(c);
                    }
                    else
                    {
                        isEscapeActive = true;
                    }
                    break;

                default:
                    if (isLineBreaking)
                    {
                        if (ReadHelper.IsEndOfLine(c))
                        {
                            continue;
                        }

                        isLineBreaking = false;
                        builder.Append(c);
                    }
                    else if (isEscapeActive)
                    {
                        ProcessEscapedCharacter(c, builder, octal, ref octalModeActive, ref octalsRead, ref isLineBreaking);
                        isEscapeActive = false;
                    }
                    else
                    {
                        builder.Append(c);
                    }

                    break;
                }

                if (numberOfBrackets <= 0)
                {
                    break;
                }
            }

            token = new StringToken(builder.ToString());

            return(true);
        }