Exemple #1
0
 private bool TryParseWeekAndVenue(ITokenStream ts, ref Slot resultSlot)
 {
     if (!ts.PreviousToken().IsPositiveNumberThatContainDecimalPoint() || !ts.NextToken().IsPossiblyVenuValue())
     {
         return(false);
     }
     resultSlot.WeekNumber = WeekNumber.Parse(ts.CurrentToken().Value());
     resultSlot.Venue      = ts.NextToken().Value();
     return(true);
 }
Exemple #2
0
 protected override void ExtractToken(ITokenStream tokenStream)
 {
     tokenStream.GoToNextToken();
     _startDate = ParseDate(tokenStream.CurrentToken().Value());
     tokenStream.GoToNextToken();
     _endDate = ParseDate(tokenStream.NextToken().Value());
 }
Exemple #3
0
 private bool TryParseSubjectCode(ITokenStream ts, ref Slot resultSlot)
 {
     if (ts.CurrentToken().IsPossiblySubjectCode() && ts.NextToken().Value() == "-")
     {
         resultSlot.Code = ts.CurrentToken().Value();
         return(true);
     }
     return(false);
 }
Exemple #4
0
        //private static Token newLine = new Token("\n");

        /**
         * <returns> IPattern </returns>
         */
        public Object Parse(ITokenStream tokenStream)
        {
            Token    token;
            CAConfig pattern = new CAConfig(0, null); //LivingCell.DeadState);//Determine the size of the configuration!
            //CellState[,] patternState = new CellState[,];

            IList <IList <CellState> > rows = new List <IList <CellState> >();
            IList <CellState>          row  = null;
            Boolean rowOpened   = false;
            int     rowIndex    = 0;
            int     columnIndex = 0;

            while ((token = tokenStream.NextToken()) != null)
            {
                if (token.Equals(stateSeparator))
                {
                    //token=tokenStream.NextToken();
                    //do nothing
                }
                else if (token.Equals(rowStart)) //init a new row
                {
                    if (rowOpened)
                    {
                        throw new InvalidOperationException(string.Format("Missing enclosing bracket! Please, enclose the row, before creating a new one"));
                    }
                    row       = new List <CellState>();
                    rowOpened = true;
                    rowIndex++;
                    columnIndex = 0;
                }
                else if (token.Equals(rowEnd)) //add the existing row to the list of rows
                {
                    rows.Add(row);
                    rowOpened = false;
                }
                else if (!char.IsWhiteSpace(token.ToString(), 0)) //State Token
                {
                    if (row == null || !rowOpened)
                    {
                        throw new InvalidOperationException("You should define a cell state within a Row. Use the following format: {D,A,D,D} ");
                    }

                    CellState cellState = null;//CellState.ValueOf(token.ToString());
                    row.Add(cellState);
                    pattern.AddCellState(null, cellState);
                    columnIndex++;
                }
            }

            return(pattern);
        }
Exemple #5
0
        public Word ParseWord(String wordSource)
        {
            Word word = new Word();

            //using the lexer to parse the character sequence into symbols
            ITokenStream tokenStream = lexer.Analyze(wordSource);
            Token        nextToken   = null;

            while ((nextToken = tokenStream.NextToken()) != null)
            {
                word.Append(Symbol.valueOf(nextToken.ToString()));//in this case a token = a symbol
            }

            return(word);
        }
Exemple #6
0
 private bool TryParseStartTime(ITokenStream ts, ref Slot resultSlot)
 {
     if (!ts.CurrentToken().IsTime())
     {
         return(false);
     }
     if (!ts.PreviousToken().IsDay())
     {
         return(false);
     }
     resultSlot.StartTime = Time.CreateTime_12HourFormat(ts.CurrentToken().Value(), ts.NextToken().Value());
     return(true);
 }
Exemple #7
0
 private bool TryParseEndTime(ITokenStream ts, ref Slot resultSlot)
 {
     if (ts.CurrentToken().IsTime() && ts.PreviousToken().Value() == "-")
     {
         resultSlot.EndTime = Time.CreateTime_12HourFormat(ts.CurrentToken().Value(), ts.NextToken().Value());
         return(true);
     }
     return(false);
 }
 /// <summary>
 /// Gets the next token
 /// </summary>
 protected void GetNextToken()
 {
     currentToken = stream.NextToken();
 }
Exemple #9
0
 protected override bool HaltingCondition(ITokenStream ts)
 {
     return
         (ts.CurrentToken().Value().ToLower() == "user" &&
          ts.NextToken().Value().ToLower() == "guide");
 }