示例#1
0
        public void WriteXml(XmlWriter writer)
        {
            writer.WriteStartAttribute("TimeInNode");
            writer.WriteValue(TimeInNode.ToString("N") + " usec");
            writer.WriteEndAttribute();

            writer.WriteStartAttribute("IsAMatch");
            writer.WriteValue(IsAMatch);
            writer.WriteEndAttribute();

            writer.WriteStartAttribute("Lexemes");
            if (Lexemes.Any())
            {
                writer.WriteValue(Lexemes.Aggregate((workingOutput, next) => workingOutput + " " + next));
            }
            writer.WriteEndAttribute();

            writer.WriteStartAttribute("Goal");
            writer.WriteValue(TheGoal.Symbol.TheSymbol);
            writer.WriteEndAttribute();

            writer.WriteStartAttribute("GoalRange");
            writer.WriteValue(TheGoal.InputPos + "-" + (TheGoal.InputPos + TheGoal.Length - 1));
            writer.WriteEndAttribute();

            writer.WriteStartAttribute("Rule");
            writer.WriteValue(TheRuleRange == null ? String.Empty : TheRuleRange.TheRule.ToString());
            writer.WriteEndAttribute();

            writer.WriteStartAttribute("RuleRange");
            writer.WriteValue(TheRuleRange == null ? String.Empty : String.Format(" {0}-{1}", TheRuleRange.InputPos, TheRuleRange.InputPos + TheRuleRange.Length - 1));
            writer.WriteEndAttribute();
        }
示例#2
0
        public string ConsumeEscapedString()
        {
            if (next < 0)
            {
                return(null);
            }
            if (next >= str.Length || str[next] != '"')
            {
                next = -1;
                return(null);
            }
            next++;
            var start = next;

            while (next < str.Length && str[next] != '"')
            {
                next++;
            }
            if (next >= str.Length)
            {
                next = -1;
                return(null);
            }
            var end = next - 1;

            next++;
            // TODO: Exception
            return(Lexemes.JavaScriptUnescape(str.Substring(start, end - start + 1)));
        }
示例#3
0
        public GameWindowPresenter(IGameView view)
        {
            this.gameView = view;
            int themeID = 0;

            try
            {
                Lexemes.Clear();
                themeID = GetSelectedThemeID();
                if (themeID == -1)
                {
                    throw new Exception("Selected theme for game could not be found, please, select existing one in the Settings menu");
                }

                Lexemes.LexemeDictionary = LexemGateway.GetLexemes(themeID);
                if (Lexemes.LexemeDictionary.Count < 3)
                {
                    throw new Exception("The theme should contain at least 3 words to start a game");
                }
            }
            catch (Exception ex)
            {
                this.HandleException("", ex);
                CanBeStarted = false;
                return;
            }
            this.GameView.OnPlayEnd    += new PlayEnd(GameView_OnPlayEnd);
            this.GameView.OnThrowBegin += new ThrowBegin(GameView_OnThrowBegin);
            this.GameView.OnThrowEnd   += new ThrowEnd(GameView_OnThrowEnd);
            CanBeStarted = true;
        }
        private IBindingPathExpression BindingPath(Lexemes <ˍ> lexemes, IBindingPathExpression lhs)
        {
            lhs = this.IndexerAccessor(lexemes, lhs);
            lhs = this.PropertyAccessor(lexemes, lhs);

            return(lhs);
        }
示例#5
0
        // Заполнение таблиц
        private void AddLexeme(LexemeType lexemeType, StringBuilder lexeme)
        {
            ObservableCollection <string> list = null;
            string value = lexeme.ToString();

            switch (lexemeType)
            {
            case LexemeType.KEY:
            case LexemeType.DL1:
            case LexemeType.DL2:
            case LexemeType.DLS: list = Keywords; break;

            case LexemeType.IDN: list = Identifiers; break;

            case LexemeType.INT:
            case LexemeType.STR: list = Literals; break;

            default: throw new ArgumentOutOfRangeException($"Lexeme Type '{lexemeType}' is not supported");
            }

            int index = list.IndexOf(value);

            if (index == -1)
            {
                list.Add(value);
                index = list.Count - 1;
            }

            Lexemes.Add(new Lexeme(lexemeType, index, value));
        }
示例#6
0
    public Lexemes NextLexeme()
    {
        Lexemes l = lexeme;

        lexeme = Scan();
        return(l);
    }
示例#7
0
 private static void PushTermOnStack(string term, TermIndexAccessor index, Stack opStack)
 {
     if (!FullTextIndexer.isValuableToken(term))
     {
         opStack.Push(new StopwordTerm());
         if (Stopwords.IndexOf(term) == -1)
         {
             Stopwords.Add(term);
         }
     }
     else
     {
         TermIndexRecord record = index.GetRecord(term);
         if (record != null)
         {
             int order = Lexemes.IndexOf(term);
             if (order == -1)
             {
                 Lexemes.Add(term);
                 order = Lexemes.Count - 1;
             }
             record.PopulateRecordID((ushort)order);
         }
         opStack.Push(record);
     }
 }
示例#8
0
        private Expression MagnitudeExpression(Lexemes lexemes, Expression lhs, ParseSettings parseSettings)
        {
            if (lexemes.AcceptToken(Constants.Power))
            {
                var constantExpression = this.ConstantExpression(lexemes, parseSettings);
                return(this.MagnitudeExpression(
                           lexemes,
                           new MagnitudeExpression(lhs, constantExpression),
                           parseSettings));
            }

            string exponent;

            if (lexemes.AcceptTokenType(TokenType.Exponent, out exponent))
            {
                var constantExpression =
                    new ConstantExpression(
                        double.Parse(CharacterConverter.FromExponentNotation(exponent), parseSettings.CultureInfo));
                return(this.MagnitudeExpression(
                           lexemes,
                           new MagnitudeExpression(lhs, constantExpression),
                           parseSettings));
            }

            return(lhs);
        }
示例#9
0
        public static string GetMarker(this Lexemes value)
        {
            FieldInfo fi = value.GetType().GetField(value.ToString());

            DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
            return(attributes[0].Description);
        }
        private static Expression Prefix(Lexemes lexemes, IUnitRegistry unitRegistry)
        {
            IUnit  unit;
            Prefix prefix;

            if (lexemes.AcceptTokenFrom(unitRegistry, out prefix))
            {
                if (lexemes.AcceptTokenFrom(unitRegistry, out unit))
                {
                    return(Unit(prefix, unit));
                }

                lexemes.MoveToPrevious();
            }

            if (lexemes.AcceptTokenFrom(unitRegistry, out unit))
            {
                return(Unit(null, unit));
            }

            string variable;

            if (lexemes.AcceptTokenFrom(VariableRegex, out variable))
            {
                return(new VariableExpression(variable));
            }

            throw CreateParseException(UnitError.PrefixUnitOrUnitOrVariableNotFound, lexemes.Current);
        }
        private static Expression Prefix(Lexemes lexemes, IUnitRegistry unitRegistry)
        {
            IUnit unit;
            Prefix prefix;
            if (lexemes.AcceptTokenFrom(unitRegistry, out prefix))
            {
                if (lexemes.AcceptTokenFrom(unitRegistry, out unit))
                {
                    return Unit(prefix, unit);
                }

                lexemes.MoveToPrevious();
            }

            if (lexemes.AcceptTokenFrom(unitRegistry, out unit))
            {
                return Unit(null, unit);
            }

            string variable;
            if (lexemes.AcceptTokenFrom(VariableRegex, out variable))
            {
                return new VariableExpression(variable);
            }

            throw CreateParseException(UnitError.PrefixUnitOrUnitOrVariableNotFound, lexemes.Current);
        }
示例#12
0
 private void Consume(Lexemes lexeme)
 {
     if (Lexeme != lexeme)
     {
         throw new Exception("Parse Exception");
     }
     NextLexeme();
 }
示例#13
0
 //constructor
 public Locomotion(Participant character, GameObject target, Lexemes.Locomotion manner,
             float start = 0f, float end = 1f)
 {
     Character = character;
     Target = target;
     Manner = manner;
     Start = start;
     End = end;
 }
        private IBindingPathExpression IndexerAccessor(Lexemes <ˍ> lexemes, IBindingPathExpression lhs)
        {
            var indexerResult = this.Indexer(lexemes);

            if (indexerResult != null)
            {
                return(new IndexerAccessor(lhs, indexerResult));
            }

            return(lhs);
        }
示例#15
0
        private ConstantExpression ConstantExpression(Lexemes lexemes, ParseSettings parseSettings)
        {
            string number;

            if (lexemes.AcceptTokenType(TokenType.Number, out number))
            {
                return(new ConstantExpression(double.Parse(number, parseSettings.CultureInfo)));
            }

            throw CreateParseException(ExpressionError.NumberNotFound, lexemes.Current);
        }
示例#16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GazeShift"/> class.
 /// </summary>
 /// <param name="character">Character to execute the behaviour.</param>
 /// <param name="target">Target to be gazed at.</param>
 /// <param name="influence">Body part to be influenced by the headlook controller.</param>
 /// <param name="start">When the character starts to gaze.</param>
 /// <param name="ready">When the character is currently gazing.</param>
 /// <param name="relax">When the character starts looking away.</param>
 /// <param name="end">When the character is done looking.</param>
 public GazeShift(string id, Participant character, GameObject target, Lexemes.Influence influence,
                  float start = 0f, float ready = -1f, float relax = -1f, float end = 1f)
 {
     Character = character;
     Target = target;
     Influence = influence;
     Start = start;
     Ready = ready;
     Relax = relax;
     End = end;
 }
示例#17
0
 private void AddLexeme(string value, int line, IdentifierType type = IdentifierType.Unknown)
 {
     Lexemes.Add(new LexemeInCode
     {
         Index      = GetIndex(type, value),
         SubString  = value,
         LineNumber = line,
         Token      = GetToken(value, type)
     }
                 );
 }
示例#18
0
文件: Face.cs 项目: HASParty/ggpai
 /// <summary>
 /// Initializes a new instance of the <see cref="Face"/> class.
 /// </summary>
 /// <param name="character">Character to execute the behaviour.</param>
 /// <param name="lexeme">Which expression to execute.</param>
 /// <param name="start">Start of animation from the given moment.</param>
 /// <param name="attackPeak">Attack peak - peak of animation.</param>
 /// <param name="relax">Relax - when expression starts ending.</param>
 /// <param name="end">End - expression ended.</param>
 public Face(string id, Participant character, Lexemes.Face lexeme,
             float start, float attackPeak, float relax, float end, float modifier = 0)
 {
     ID = id;
     Character = character;
     Lexeme = lexeme;
     Start = start;
     AttackPeak = attackPeak;
     Relax = relax;
     End = end;
     Modifier = modifier;
 }
示例#19
0
文件: Gaze.cs 项目: HASParty/ggpai
 /// <summary>
 /// Initializes a new instance of the <see cref="VirtualReykjavik.Behaviour.Gaze"/> class.
 /// </summary>
 /// <param name="id">Identifier for the behaviour.</param>
 /// <param name="character">Character to execute the behaviour.</param>
 /// <param name="target">Target to be gazed at.</param>
 /// <param name="influence">Body part to be influenced by the headlook controller.</param>
 /// <param name="start">When the character starts to gaze.</param>
 /// <param name="ready">When the character is currently gazing.</param>
 /// <param name="relax">When the character starts looking away.</param>
 /// <param name="end">When the character is done looking.</param>
 public Gaze(string id, Participant character, GameObject target, Lexemes.Influence influence,
             float start = 0f, float ready = -1f, float relax = -1f, float end = 1f, int priority = 1)
 {
     ID = id;
     Character = character;
     Target = target;
     Influence = influence;
     Start = start;
     Ready = ready;
     Relax = relax;
     End = end;
     Priority = priority;
 }
示例#20
0
        private static Result<Quantity, Error<QuantityError>> GetError(
            ParseSettings parseSettings,
            QuantityError quantityError,
            Lexemes lexemes)
        {
            var error = Error.From(quantityError, lexemes.Current);
            if (parseSettings.ThrowOnError)
            {
                throw new QuantityParseException(error);
            }

            return Result.Error(error);
        }
        private XamlType XamlType(Lexemes <ˍ> lexemes)
        {
            var namespacePrefix = string.Empty;

            lexemes.AcceptTokenType(ˍ._, out var identifier);
            if (lexemes.AcceptToken(":"))
            {
                namespacePrefix = identifier;
                lexemes.AcceptTokenType(ˍ._, out identifier);
            }

            return(new XamlType(namespacePrefix, identifier));
        }
示例#22
0
        private static Result <Quantity, Error <QuantityError> > GetError(
            ParseSettings parseSettings,
            QuantityError quantityError,
            Lexemes lexemes)
        {
            var error = Error.From(quantityError, lexemes.Current);

            if (parseSettings.ThrowOnError)
            {
                throw new QuantityParseException(error);
            }

            return(Result.Error(error));
        }
        private IPropertyExpression AttachedDependencyProperty(Lexemes <ˍ> lexemes)
        {
            if (lexemes.AcceptToken("("))
            {
                var xamlType = this.XamlType(lexemes);
                lexemes.AcceptToken(".");
                lexemes.AcceptTokenType(ˍ._, out var propertyName);
                if (lexemes.AcceptToken(")"))
                {
                    return(new AttachedDependencyProperty(xamlType, propertyName));
                }
            }

            return(null);
        }
        private IBindingPathExpression PropertyAccessor(Lexemes <ˍ> lexemes, IBindingPathExpression lhs)
        {
            if (lexemes.AcceptToken("."))
            {
                var result = this.AttachedDependencyProperty(lexemes);
                if (result == null)
                {
                    result = this.Property(lexemes, true);
                }

                return(this.BindingPath(lexemes, new PropertyAccessor(lhs, result)));
            }

            return(lhs);
        }
示例#25
0
        public static Entry[]  ProcessQuery(QueryPostfixForm postfixForm, TermIndexAccessor termIndex, bool appendIdMappings)
        {
            Stack opStack = new Stack();

            Entry[] result = null;
            Error = ErrorStatus.NoError;
            MappedInstances.Clear();

            if (!appendIdMappings)
            {
                Lexemes.Clear();
                Stopwords.Clear();
            }

            try
            {
                IteratePostfixExpression(postfixForm, termIndex, opStack);

                //-----------------------------------------------------------------
                //  Now only one Entry[] must remain on the top of the stack. It may
                //  be null if no document correspond to the query
                //-----------------------------------------------------------------
                if (opStack.Count != 1)
                {
                    throw new ApplicationException("QueryParser -- Illegal query statement found");
                }

                if (!(opStack.Peek() is StopwordTerm))
                {
                    result = ExtractOperandFromStack(opStack);
                    if (result != null)
                    {
                        Array.Sort(result, new CompareByTfIdf());
                    }
                }
            }
            catch (Exception exc)
            {
                Trace.WriteLine("QueryProcessor -- exception [" + exc.Message + "] occured.");
                //  Exception is raised if the expression was constructed with
                //  the syntactic errors.
                //  Clear the stack and put special marker on the top of it
                Error  = ErrorStatus.IllegalQuerySyntax;
                result = null;
            }
            opStack.Clear();
            return(result);
        }
示例#26
0
 //constructor
 public Pointing(string id, Participant character, GameObject target, Lexemes.Mode mode, Lexemes.Head lexeme,
                float start = 0f, float ready = -1f, float strokeStart = -1f,
                float stroke = -1f, float strokeEnd = -1f, float relax = -1f,
                float end = 1f)
 {
     ID = id;
     Character = character;
     Target = target;
     Mode = mode;
     Start = start;
     StrokeStart = strokeStart;
     Stroke = stroke;
     StrokeEnd = strokeEnd;
     Ready = ready;
     Relax = relax;
     End = end;
 }
示例#27
0
文件: Gesture.cs 项目: HASParty/ggpai
 /// <summary>
 /// Initializes a new instance of the <see cref="Gesture"/> class.
 /// </summary>
 /// <param name="id">the name of the chunk</param>
 /// <param name="character">the actor</param>
 /// <param name="mode">which hand, etc.</param>
 /// <param name="lexeme">what gesture</param>
 /// <param name="start">time of the start of the gesture</param>
 /// <param name="ready">the time when the gesture is ready to stroke</param>
 /// <param name="strokeStart">when the stroke begins</param>
 /// <param name="stroke">the beat of the stroke</param>
 /// <param name="strokeEnd">the end of the stroke</param>
 /// <param name="relax">when the gesture begins to relax</param>
 /// <param name="end">the end of the gesture</param>
 public Gesture(string id, Participant character, Lexemes.Mode mode, Lexemes.Gestures lexeme,
                float start = 0f, float ready = -1f, float strokeStart = -1f,
                float stroke = -1f, float strokeEnd = -1f, float relax = -1f,
                float end = 1f)
 {
     ID = id;
     Character = character;
     Mode = mode;
     Lexeme = lexeme;
     Start = start;
     StrokeStart = strokeStart;
     Stroke = stroke;
     StrokeEnd = strokeEnd;
     Ready = ready;
     Relax = relax;
     End = end;
 }
        private Expression MultiplicativeExpression(Lexemes lexemes, Expression lhs, ParseSettings parseSettings)
        {
            if (lexemes.AcceptToken(Constants.Multiply) || lexemes.AcceptToken(Constants.MultiplyDot)
                || lexemes.AcceptToken(Constants.MultiplyCross))
            {
                var rhs = this.TryMagnitudeExpression(lexemes, parseSettings);
                return this.MultiplicativeExpression(lexemes, new MultiplicationExpression(lhs, rhs), parseSettings);
            }

            if (lexemes.AcceptToken(Constants.Divide))
            {
                var rhs = this.TryMagnitudeExpression(lexemes, parseSettings);
                return this.MultiplicativeExpression(lexemes, new DivisionExpression(lhs, rhs), parseSettings);
            }

            return lhs;
        }
示例#29
0
        private Expression MultiplicativeExpression(Lexemes lexemes, Expression lhs, ParseSettings parseSettings)
        {
            if (lexemes.AcceptToken(Constants.Multiply) || lexemes.AcceptToken(Constants.MultiplyDot) ||
                lexemes.AcceptToken(Constants.MultiplyCross))
            {
                var rhs = this.TryMagnitudeExpression(lexemes, parseSettings);
                return(this.MultiplicativeExpression(lexemes, new MultiplicationExpression(lhs, rhs), parseSettings));
            }

            if (lexemes.AcceptToken(Constants.Divide))
            {
                var rhs = this.TryMagnitudeExpression(lexemes, parseSettings);
                return(this.MultiplicativeExpression(lexemes, new DivisionExpression(lhs, rhs), parseSettings));
            }

            return(lhs);
        }
示例#30
0
        private void AddIdentifier(string value)
        {
            if (Identifiers.Any(e => e.Name.Equals(value)))
            {
                return;
            }

            int index = Identifiers.Count + 1;

            Identifiers.Add(new Identifier
            {
                Index = index,
                Type  = Lexemes.Any() ? Lexemes.Last()?.Token ?? "" : "",
                Name  = value
            }
                            );
        }
示例#31
0
文件: Head.cs 项目: HASParty/ggpai
 /// <summary>
 /// Initializes a new instance of the <see cref="Head"/> class.
 /// </summary>
 /// <param name="id">name of the chunk</param>
 /// <param name="character">the actor</param>
 /// <param name="repetition">whether the action should repeat</param>
 /// <param name="amount">the degree/intensity of the action</param>
 /// <param name="lexeme">which action</param>
 /// <param name="start">the start of the action</param>
 /// <param name="ready">when the action is ready</param>
 /// <param name="strokeStart">the start of the stroke</param>
 /// <param name="stroke">the exact moment of the stroke</param>
 /// <param name="strokeEnd">the end of the stroke</param>
 /// <param name="relax">relaxation of the action</param>
 /// <param name="end">duration of the action</param>
 public Head(string id, Participant character, int repetition, float amount, Lexemes.Head lexeme,
                float start = 0f, float ready = -1f, float strokeStart = -1f,
                float stroke = -1f, float strokeEnd = -1f, float relax = -1f,
                float end = 1f)
 {
     ID = id;
     Character = character;
     Repetition = repetition;
     Amount = amount;
     Lexeme = lexeme;
     Start = start;
     StrokeStart = strokeStart;
     Stroke = stroke;
     StrokeEnd = strokeEnd;
     Ready = ready;
     Relax = relax;
     End = end;
 }
示例#32
0
文件: Grasp.cs 项目: HASParty/ggpai
 /// <summary>
 /// Initializes a new instance of the <see cref="Grasp"/> class.
 /// </summary>
 /// <param name="id">the name of the chunk</param>
 /// <param name="character">the actor</param>
 /// <param name="target">the target object</param>
 /// <param name="mode">wihich hand</param>
 /// <param name="callback">a delegate to call on grasping completion</param>
 /// <param name="start">The start of the movement</param>
 /// <param name="end">The duration of the movement</param>
 public Grasp(string id, Participant character, GameObject target, Lexemes.Mode mode,
              UnityAction<ActorMotion.Arm> callback,
                float start = 0f, float ready = -1f, float strokeStart = -1f,
                float stroke = -1f, float strokeEnd = -1f, float relax = -1f,
                float end = 1f)
 {
     ID = id;
     Character = character;
     Target = target;
     Mode = mode;
     Start = start;
     StrokeStart = strokeStart;
     Stroke = stroke;
     StrokeEnd = strokeEnd;
     Ready = ready;
     Relax = relax;
     End = end;
     Callback = callback;
 }
示例#33
0
        // Keep in sync with InteropRewriter::ShimFullName in InteropRewriter.
        public static string ShimFullName(string delegateFullName)
        {
            var regex  = new Regex("^(.*)(`[0-9]+)$");
            var match  = regex.Match(delegateFullName);
            var prefix = default(string);
            var suffix = default(string);

            if (match.Success)
            {
                prefix = match.Groups[1].Value;
                suffix = match.Groups[2].Value;
            }
            else
            {
                prefix = delegateFullName;
                suffix = "";
            }

            return(prefix + "_Shim_" + Lexemes.HashToIdentifier(delegateFullName) + suffix);
        }
        private IPropertyExpression Property(Lexemes <ˍ> lexemes, bool isRequired)
        {
            if (lexemes.AcceptTokenType(ˍ._, out var value))
            {
                if (lexemes.AcceptTokenType(TokenInfo.End))
                {
                    lexemes.MoveToPrevious();
                    return(new Property(value));
                }

                return(new PropertyPart(value));
            }

            if (isRequired)
            {
                throw CreateParseException(BindingPathError.PropertyNameMissing, lexemes.Current);
            }

            return(null);
        }
示例#35
0
        /// <summary>
        /// Parses the specified quantity.
        /// </summary>
        /// <param name="lexemes">The lexemes.</param>
        /// <param name="parseSettings">The parse settings.</param>
        /// <returns>
        /// A <see cref="Quantity" />.
        /// </returns>
        /// <exception cref="QuantityParseException">Exception thrown when parsing fails.</exception>
        public Result <Quantity, Error <QuantityError> > Parse(Lexemes lexemes, ParseSettings parseSettings)
        {
            if (lexemes.AcceptTokenType(TokenType.Number, out var number))
            {
                var value  = double.Parse(number, parseSettings.CultureInfo);
                var result = this.expressionParser.Parse(
                    lexemes,
                    new ParseSettings(parseSettings.CultureInfo, false, false));

                if (parseSettings.AssertEnd && lexemes.AcceptTokenType(TokenType.End))
                {
                    return(GetError(parseSettings, QuantityError.EndOfDataNotFound, lexemes));
                }

                return(result.Convert(
                           expression => new Quantity(value, this.unitFactory.Create(expression)),
                           error => Error.From(QuantityError.UnitNotFound, lexemes.Current, error)));
            }

            return(GetError(parseSettings, QuantityError.NumberNotFound, lexemes));
        }
示例#36
0
        private Expression PrimaryExpression(Lexemes lexemes, ParseSettings parseSettings)
        {
            if (lexemes.AcceptToken(Constants.LeftParenthesis))
            {
                var expression = this.Expression(lexemes, parseSettings);
                if (lexemes.AcceptToken(Constants.RightParenthesis))
                {
                    return(new ParenthesisExpression(expression));
                }

                throw CreateParseException(ExpressionError.RightParenthesisNotFound, lexemes.Current);
            }

            if (lexemes.AcceptToken(Constants.LeftWeakParenthesis))
            {
                var expression = this.Expression(lexemes, parseSettings);
                if (lexemes.AcceptToken(Constants.RightWeakParenthesis))
                {
                    return(expression);
                }

                throw CreateParseException(ExpressionError.RightWeakParenthesisNotFound, lexemes.Current);
            }

            string identifier;

            if (lexemes.AcceptTokenType(TokenType.Identifier, true, out identifier))
            {
                var result = this.unitExpressionParser.Parse(identifier, false);
                if (result)
                {
                    return(result.Value);
                }

                throw CreateParseException(ExpressionError.IdentifierNotFound, lexemes.MoveToPrevious(), result.Error);
            }

            return(this.ConstantExpression(lexemes, parseSettings));
        }
        private IIndexerExpression Indexer(Lexemes <ˍ> lexemes)
        {
            if (lexemes.AcceptToken("["))
            {
                var literalList = new List <Literal>();
                this.LiteralList(lexemes, literalList);
                if (lexemes.AcceptToken("]"))
                {
                    if (lexemes.AcceptTokenType(TokenInfo.End))
                    {
                        lexemes.MoveToPrevious();
                        return(new Indexer(literalList));
                    }

                    return(new IndexerPart(literalList));
                }

                throw CreateParseException(BindingPathError.RightAngleBracketMissing, lexemes.Current);
            }

            return(null);
        }
示例#38
0
        void DisplayLexims(int themeID)
        {
            Lexemes.Clear();
            System.GC.Collect();
            ILexemGateway lexemGateway = Gateway.LexemGateway;

            Lexemes.LexemeDictionary = lexemGateway.GetLexemes(themeID);
            this.ThemeView.LeximListBox.ClearAllItems();
            foreach (Lexeme lex in Lexemes.LexemeCollection)
            {
                LeximDTView ldt = new LeximDTView(lex.ID, lex.ParentThemeID, lex.Word, lex.Picture, lex.Sound);
                this.ThemeView.LeximListBox.AddDisplayLexim(ldt, this.ThemeView.Play);
            }
            if (Lexemes.LexemeCollection.Count > 0)
            {
                this.ThemeView.LeximListBox.SetSelectionAt(0);
            }
            else
            {
                this.ThemeView.DisplayLexim(new LeximDTView(0, themeID, string.Empty, null, null), this.ThemeView.Play);
            }
        }
示例#39
0
        /// <summary>
        /// Parses the specified quantity.
        /// </summary>
        /// <param name="lexemes">The lexemes.</param>
        /// <param name="parseSettings">The parse settings.</param>
        /// <returns>
        /// A <see cref="Quantity" />.
        /// </returns>
        /// <exception cref="QuantityParseException">Exception thrown when parsing fails.</exception>
        public Result<Quantity, Error<QuantityError>> Parse(Lexemes lexemes, ParseSettings parseSettings)
        {
            string number;
            if (lexemes.AcceptTokenType(TokenType.Number, out number))
            {
                var value = double.Parse(number, parseSettings.CultureInfo);
                var result = this.expressionParser.Parse(
                    lexemes,
                    new ParseSettings(parseSettings.CultureInfo, false, false));

                if (parseSettings.AssertEnd && lexemes.AcceptTokenType(TokenType.End))
                {
                    return GetError(parseSettings, QuantityError.EndOfDataNotFound, lexemes);
                }

                return Result.For(
                    result,
                    expression => new Quantity(value, this.unitFactory.Create(expression)),
                    error => Error.From(QuantityError.UnitNotFound, lexemes.Current, error));
            }

            return GetError(parseSettings, QuantityError.NumberNotFound, lexemes);
        }
示例#40
0
        /// <summary>
        /// Parses the specified lexeme list.
        /// </summary>
        /// <param name="lexemes">The lexemes.</param>
        /// <param name="parseSettings">The parse settings.</param>
        /// <returns>
        /// The parsed expression.
        /// </returns>
        public Result <Expression, Error <ExpressionError> > Parse(Lexemes lexemes, ParseSettings parseSettings)
        {
            try
            {
                var    expression = this.Expression(lexemes, parseSettings);
                string token;
                if (parseSettings.AssertEnd && !lexemes.AcceptTokenType(TokenType.End, out token))
                {
                    throw CreateParseException(ExpressionError.EndOfDataNotFound, lexemes.Current);
                }

                return(Result.Success(expression));
            }
            catch (ExpressionParseException expressionParseException)
            {
                if (parseSettings.ThrowOnError)
                {
                    throw;
                }

                return(Result.Error(expressionParseException.Error));
            }
        }
        /// <summary>
        /// Parses the specified lexeme list.
        /// </summary>
        /// <param name="lexemes">The lexemes.</param>
        /// <param name="parseSettings">The parse settings.</param>
        /// <returns>
        /// The parsed expression.
        /// </returns>
        public Result<Expression, Error<ExpressionError>> Parse(Lexemes lexemes, ParseSettings parseSettings)
        {
            try
            {
                var expression = this.Expression(lexemes, parseSettings);
                string token;
                if (parseSettings.AssertEnd && !lexemes.AcceptTokenType(TokenType.End, out token))
                {
                    throw CreateParseException(ExpressionError.EndOfDataNotFound, lexemes.Current);
                }

                return Result.Success(expression);
            }
            catch (ExpressionParseException expressionParseException)
            {
                if (parseSettings.ThrowOnError)
                {
                    throw;
                }

                return Result.Error(expressionParseException.Error);
            }
        }
        private IBindingPathExpression PrimaryExpression(Lexemes <ˍ> lexemes)
        {
            if (lexemes.AcceptToken("."))
            {
                return(new DataContextSource());
            }

            var indexerResult = this.Indexer(lexemes);

            if (indexerResult != null)
            {
                return(indexerResult);
            }

            var dependencyPropertyResult = this.AttachedDependencyProperty(lexemes);

            if (dependencyPropertyResult != null)
            {
                return(dependencyPropertyResult);
            }

            return(this.Property(lexemes, false));
        }
        private void LiteralList(Lexemes <ˍ> lexemes, List <Literal> literalList)
        {
            XamlType castXamlType = default;

            if (lexemes.AcceptToken("("))
            {
                castXamlType = this.XamlType(lexemes);
                if (!lexemes.AcceptToken(")"))
                {
                    throw CreateParseException(BindingPathError.RightParenthesisMissing, lexemes.Current);
                }
            }

            if (!lexemes.AcceptTokenType(ˍ._, true, out var value))
            {
                throw CreateParseException(BindingPathError.ValueMissing, lexemes.Current);
            }

            literalList.Add(new Literal(castXamlType, value.Trim()));
            if (lexemes.AcceptToken(","))
            {
                this.LiteralList(lexemes, literalList);
            }
        }
 private Expression TryMagnitudeExpression(Lexemes lexemes, ParseSettings parseSettings)
 {
     var lhs = this.PrimaryExpression(lexemes, parseSettings);
     return this.MagnitudeExpression(lexemes, lhs, parseSettings);
 }
示例#45
0
文件: Parser.cs 项目: localchart/racr
	private void Consume(Lexemes lexeme) {
		if (Lexeme != lexeme) throw new Exception("Parse Exception");
		NextLexeme();
	}
        private Expression MagnitudeExpression(Lexemes lexemes, Expression lhs, ParseSettings parseSettings)
        {
            if (lexemes.AcceptToken(Constants.Power))
            {
                var constantExpression = this.ConstantExpression(lexemes, parseSettings);
                return this.MagnitudeExpression(
                    lexemes,
                    new MagnitudeExpression(lhs, constantExpression),
                    parseSettings);
            }

            string exponent;
            if (lexemes.AcceptTokenType(TokenType.Exponent, out exponent))
            {
                var constantExpression =
                    new ConstantExpression(
                        double.Parse(CharacterConverter.FromExponentNotation(exponent), parseSettings.CultureInfo));
                return this.MagnitudeExpression(
                    lexemes,
                    new MagnitudeExpression(lhs, constantExpression),
                    parseSettings);
            }

            return lhs;
        }
        private Expression PrimaryExpression(Lexemes lexemes, ParseSettings parseSettings)
        {
            if (lexemes.AcceptToken(Constants.LeftParenthesis))
            {
                var expression = this.Expression(lexemes, parseSettings);
                if (lexemes.AcceptToken(Constants.RightParenthesis))
                {
                    return new ParenthesisExpression(expression);
                }

                throw CreateParseException(ExpressionError.RightParenthesisNotFound, lexemes.Current);
            }

            if (lexemes.AcceptToken(Constants.LeftWeakParenthesis))
            {
                var expression = this.Expression(lexemes, parseSettings);
                if (lexemes.AcceptToken(Constants.RightWeakParenthesis))
                {
                    return expression;
                }

                throw CreateParseException(ExpressionError.RightWeakParenthesisNotFound, lexemes.Current);
            }

            string identifier;
            if (lexemes.AcceptTokenType(TokenType.Identifier, true, out identifier))
            {
                var result = this.unitExpressionParser.Parse(identifier, false);
                if (result)
                {
                    return result.Value;
                }

                throw CreateParseException(ExpressionError.IdentifierNotFound, lexemes.MoveToPrevious(), result.Error);
            }

            return this.ConstantExpression(lexemes, parseSettings);
        }
        private ConstantExpression ConstantExpression(Lexemes lexemes, ParseSettings parseSettings)
        {
            string number;
            if (lexemes.AcceptTokenType(TokenType.Number, out number))
            {
                return new ConstantExpression(double.Parse(number, parseSettings.CultureInfo));
            }

            throw CreateParseException(ExpressionError.NumberNotFound, lexemes.Current);
        }
 private Expression Expression(Lexemes lexemes, ParseSettings parseSettings)
 {
     return this.TryMultiplicativeExpression(lexemes, parseSettings);
 }
 private Expression TryMultiplicativeExpression(Lexemes lexemes, ParseSettings parseSettings)
 {
     var expression = this.TryMagnitudeExpression(lexemes, parseSettings);
     return this.MultiplicativeExpression(lexemes, expression, parseSettings);
 }