public void InitCompiler(string expression, int pos) { root = new RootToken(); compiler = new ExpressionCompiler(expression); compiler.ParentTokens.Push(root); compiler.Pos = pos; }
public static FrameworkElement Build(RootToken rootToken, Hint hint) { var textBlock = new TextBlock().Fill(rootToken, hint); textBlock.TextWrapping = TextWrapping.WrapWithOverflow; return(new HintDecorator { Child = textBlock }); }
public UnityELExpression <T> Compile <T>() { RootToken rootToken = new RootToken(); ParentTokens.Clear(); ParentTokens.Push(rootToken); while (Pos < Expression.Length) { if (!ParseNextToken()) { throw new ParserException(Pos, "Unknown token found"); } } if (Parent != rootToken) { throw new ParserException(Pos, "Incomplete expression"); } rootToken.Validate(); return(new ExpressionImpl <T>(rootToken)); }
public static bool LogIn(string email, string senha) { LoginSend login = new LoginSend { grant_type = "password", password = senha, username = email }; RootToken retorno = JsonConvert .DeserializeObject <RootToken>( Utils.Json(Method.POST, "/Token", login, false, null) ); Biblioteca.SetToken(retorno.access_token); if (retorno != null) { UsuarioDTO userinfo = JsonConvert .DeserializeObject <UsuarioDTO>( Utils.Json(Method.GET, "/api/Account/UserInfo", null, true, Biblioteca.GetToken()) ); if (userinfo != null) { AddOrUpdate(userinfo); Biblioteca.SetSessao(userinfo); return(true); } else { return(false); } } else { return(false); } }
private static List <IToken> parseToTokens(string syntax) { string s = syntax ?? ""; var tokens = new List <IToken>(); IToken crurrentToken = new RootToken(); int iPos = 0; while (s.Length > 0) { IToken nextToken = null; foreach (var token in crurrentToken.getFollowableTokens()) { int i = token.getTokenEndIndex(s); if (i >= 0) { var tokenValue = s.Substring(0, i); nextToken = token.newToken(); nextToken.setToken(tokenValue); s = s.Substring(i); iPos += i; break; } } if (nextToken == null) { throw new FormatException("Unknown token. position: " + iPos + ". Unkown token: `" + s + "`"); } crurrentToken = nextToken; tokens.Add(nextToken); } return(tokens); }
internal override void Apply(RootToken rootToken) { ApplyImpl(rootToken); }
public IGrammarParser Build() { var nameToToken = new Dictionary <string, LLnToken>(); var nonTerminalTokens = new List <NonTerminalPair>(roots.Count + nonTerminals.Count); foreach (var kv in terminals) { nameToToken.Add( kv.Key, new TerminalToken( kv.Value.Id, kv.Value.Explicit, kv.Key, kv.Value.Token, kv.Value.Pattern ) ); } foreach (var kv in nonTerminals) { var token = new NonTerminalToken(kv.Key, kv.Value.Count); nameToToken.Add(kv.Key, token); nonTerminalTokens.Add(new NonTerminalPair { Token = token, Paths = kv.Value, }); } foreach (var pair in nonTerminalTokens) { var token = pair.Token; foreach (var path in pair.Paths) { var len = path.Path.Length; var tokens = new LLnToken[len]; for (int i = 0; i < len; i++) { if (!nameToToken.TryGetValue(path.Path[i], out var refToken)) { throw GrammarDefineException.NonTerminalRefTokenNotFound(token.Name, path.Path[i]); } tokens[i] = refToken; } token.AddPath(path.Id, path.Explicit, tokens); } } var rootToken = new RootToken(roots.Count); foreach (var path in roots) { var len = path.Path.Length; var tokens = new LLnToken[len + 1]; for (int i = 0; i < len; i++) { if (!nameToToken.TryGetValue(path.Path[i], out var refToken)) { throw GrammarDefineException.NonTerminalRefTokenNotFound(rootToken.Name, path.Path[i]); } tokens[i] = refToken; } tokens[len] = EOFToken.Instance; rootToken.AddPath(path.Id, false, tokens); } var parser = new LLnParser(rootToken); return(parser); }
/// <summary> /// Initializes the handlers for the buttons on the form that add the appropriate event handlers /// and keyboard shortcut handlers for all of the buttons on the form. This uses the /// <see cref="CreateTokenButton"/> method to create the event handlers. /// </summary> private void InitializeButtons() { #region Digits CreateTokenButton(button0, () => new DigitToken(0), "0 key", Keys.D0); CreateTokenButton(button1, () => new DigitToken(1), "1 key", Keys.D1); CreateTokenButton(button2, () => new DigitToken(2), "2 key", Keys.D2); CreateTokenButton(button3, () => new DigitToken(3), "3 key", Keys.D3); CreateTokenButton(button4, () => new DigitToken(4), "4 key", Keys.D4); CreateTokenButton(button5, () => new DigitToken(5), "5 key", Keys.D5); CreateTokenButton(button6, () => new DigitToken(6), "6 key", Keys.D6); CreateTokenButton(button7, () => new DigitToken(7), "7 key", Keys.D7); CreateTokenButton(button8, () => new DigitToken(8), "8 key", Keys.D8); CreateTokenButton(button9, () => new DigitToken(9), "9 key", Keys.D9); CreateTokenButton(buttonDecimalPoint, () => new SymbolicToken(SymbolicToken.SymbolicType.DecimalPoint), ". key", Keys.OemPeriod); #endregion #region Basic Operations CreateTokenButton(buttonAdd, () => new OperationToken(OperationToken.OperationType.Add), "Plus Key", Keys.Oemplus, Keys.Shift); CreateTokenButton(buttonSubtract, () => new OperationToken(OperationToken.OperationType.Subtract), "Minus Key", Keys.OemMinus); CreateTokenButton(buttonMultiply, () => new OperationToken(OperationToken.OperationType.Multiply), "Shift-8 (*)", Keys.D8, Keys.Shift); CreateTokenButton(buttonDivide, () => new OperationToken(OperationToken.OperationType.Divide), "Backslash", Keys.Oem5); #endregion #region Roots CreateTokenButton(buttonRoot, () => new RootToken(), "Ctrl-Shift-R", Keys.R, Keys.Control | Keys.Shift); CreateTokenButton(buttonSqrt, () => { var token = new RootToken(); token.Power.Add(new DigitToken(2)); return(token); }, "Ctrl-R", Keys.R, Keys.Control); #endregion #region Trig CreateTokenButton(buttonSin, () => new FunctionToken("sin")); CreateTokenButton(buttonCos, () => new FunctionToken("cos")); CreateTokenButton(buttonTan, () => new FunctionToken("tan")); CreateTokenButton(buttonArcsin, () => new FunctionToken("sin`")); CreateTokenButton(buttonArccos, () => new FunctionToken("cos`")); CreateTokenButton(buttonArctan, () => new FunctionToken("tan`")); #endregion #region Logs CreateTokenButton(buttonLogN, () => new LogToken(), "Ctrl-L", Keys.L, Keys.Control); CreateTokenButton(buttonLogE, () => { var token = new LogToken(); token.Base.Add(new ConstantToken(ConstantToken.ConstantType.E)); return(token); }, "Ctrl-Shift-L", Keys.L, Keys.Shift | Keys.Control); CreateTokenButton(buttonLog10, () => { var token = new LogToken(); token.Base.Add(new DigitToken(1)); token.Base.Add(new DigitToken(0)); return(token); }); #endregion #region Exponents CreateTokenButton(buttonExp, () => new ExpToken(), "Shift-6 (^)", Keys.D6, Keys.Shift); CreateTokenButton(buttonSquare, () => { var token = new ExpToken(); token.Power.Add(new DigitToken(2)); return(token); }, "Alt-2", Keys.D2, Keys.Alt); CreateTokenButton(buttonCube, () => { var token = new ExpToken(); token.Power.Add(new DigitToken(3)); return(token); }, "Alt-3", Keys.D3, Keys.Alt); CreateTokenButton(buttonReciprocate, () => { var token = new ExpToken(); token.Power.Add(new OperationToken(OperationToken.OperationType.Subtract)); token.Power.Add(new DigitToken(1)); return(token); }, "Alt-Minus", Keys.OemMinus, Keys.Alt); #endregion #region Constants CreateTokenButton(buttonPi, () => new ConstantToken(ConstantToken.ConstantType.Pi), "P", Keys.P); CreateTokenButton(buttonE, () => new ConstantToken(ConstantToken.ConstantType.E), "E", Keys.E); #endregion #region Misc CreateTokenButton(buttonFraction, () => new FractionToken(), "Forward-slash", Keys.OemQuestion); CreateTokenButton(buttonAbsolute, () => new AbsoluteToken(), "|", Keys.Oem5, Keys.Shift); CreateTokenButton(buttonBracket, () => new FunctionToken(""), "(", Keys.D9, Keys.Shift); // CreateExpressionButton(buttonComma, () => new SymbolicToken(SymbolicToken.SymbolicType.Comma), ",", Keys.Oemcomma); CreateTokenButton(buttonPercent, () => new SymbolicToken(SymbolicToken.SymbolicType.Percent), "%", Keys.D5, Keys.Shift); CreateTokenButton(buttonSymbolicExp, () => new SymbolicToken(SymbolicToken.SymbolicType.Exp10), "Ctrl-E", Keys.E, Keys.Control); #endregion CreateTokenButton(buttonXVariable, () => new VariableToken('x'), "X", Keys.X); CreateTokenButton(buttonYVariable, () => new VariableToken('y'), "Y", Keys.Y); CreateTokenButton(buttonCustomVariable, () => { // creates an EnterVariable dialog to allow the user to enter any variable // character they want (that isn't 'x' or 'y') char customVariable = CreateVariableDialog.EnterVariable(); if (customVariable != '\0') { return(new VariableToken(customVariable)); } else { return(null); } }, "Hash", Keys.Oem7); CreateTokenButton(buttonEquals, () => new SymbolicToken(SymbolicToken.SymbolicType.Equals), "Equals", Keys.Oemplus); }
internal abstract void Apply(RootToken rootToken);
public LLnParser(RootToken root) { this.rootToken = root; }
private static List <AuthScopes> BuildScopesList(RootToken token) { var scopes = new List <AuthScopes>(); foreach (var scope in token.Auth.Scopes) { switch (scope) { case "channel_check_subscription": scopes.Add(AuthScopes.Channel_Check_Subscription); break; case "channel_commercial": scopes.Add(AuthScopes.Channel_Commercial); break; case "channel_editor": scopes.Add(AuthScopes.Channel_Editor); break; case "channel_feed_edit": scopes.Add(AuthScopes.Channel_Feed_Edit); break; case "channel_feed_read": scopes.Add(AuthScopes.Channel_Feed_Read); break; case "channel_read": scopes.Add(AuthScopes.Channel_Read); break; case "channel_stream": scopes.Add(AuthScopes.Channel_Stream); break; case "channel_subscriptions": scopes.Add(AuthScopes.Channel_Subscriptions); break; case "chat_login": scopes.Add(AuthScopes.Chat_Login); break; case "collections_edit": scopes.Add(AuthScopes.Collections_Edit); break; case "communities_edit": scopes.Add(AuthScopes.Communities_Edit); break; case "communities_moderate": scopes.Add(AuthScopes.Communities_Moderate); break; case "user_blocks_edit": scopes.Add(AuthScopes.User_Blocks_Edit); break; case "user_blocks_read": scopes.Add(AuthScopes.User_Blocks_Read); break; case "user_follows_edit": scopes.Add(AuthScopes.User_Follows_Edit); break; case "user_read": scopes.Add(AuthScopes.User_Read); break; case "user_subscriptions": scopes.Add(AuthScopes.User_Subscriptions); break; case "openid": scopes.Add(AuthScopes.OpenId); break; case "viewing_activity_read": scopes.Add(AuthScopes.Viewing_Activity_Read); break; case "user:edit": scopes.Add(AuthScopes.Helix_User_Edit); break; case "user:read:email": scopes.Add(AuthScopes.Helix_User_Read_Email); break; case "clips:edit": scopes.Add(AuthScopes.Helix_Clips_Edit); break; case "bits:read": scopes.Add(AuthScopes.Helix_Bits_Read); break; case "analytics:read:games": scopes.Add(AuthScopes.Helix_Analytics_Read_Games); break; } } if (scopes.Count == 0) { scopes.Add(AuthScopes.None); } return(scopes); }
public RootNode(RootToken root) : base(root) { }
public ExpressionImpl(RootToken root) { this.root = root; }