예제 #1
0
        public MixedToken(LexicToken lexicToken)
        {
            if (lexicToken == null)
                throw new ArgumentNullException("lexicToken");

            this.lexicToken = lexicToken;
        }
예제 #2
0
        public MixedToken(LexicToken lexicToken)
        {
            if (lexicToken == null)
            {
                throw new ArgumentNullException("lexicToken");
            }

            this.lexicToken = lexicToken;
        }
예제 #3
0
 public StringReader(string s, LexicToken token)
 {
     if (string.IsNullOrEmpty(s))
     {
         throw new ArgumentException();
     }
     this.S     = s;
     this.Token = token;
 }
예제 #4
0
 public override InputStream TryRead(InputStream stream, out LexicToken token)
 {
     token = null;
     if (stream.Content.StartsWith(this.S))
     {
         token = this.Token;
         return(stream.Move(this.S.Length));
     }
     return(stream);
 }
예제 #5
0
 public override InputStream TryRead(InputStream stream, out LexicToken token)
 {
     token = null;
     if (stream.Content[0] == C)
     {
         token = this.Token;
         return(stream.Move(1));
     }
     return(stream);
 }
예제 #6
0
		public override InputStream TryRead(InputStream stream, out LexicToken token)
		{
			token = null;
			Match match = regex.Match(stream.Content);
			if (match.Success)
			{
				token = GetToken(match.Value);
				return stream.Move(match.Value.Length);
			}
			return stream;
		}
예제 #7
0
        public override InputStream TryRead(InputStream stream, out LexicToken token)
        {
            token = null;

            if (stream.Content[0] == c)
            {
                token = this.token;
                return stream.Move(1);
            }

            return stream;
        }
예제 #8
0
        public override InputStream TryRead(InputStream stream, out LexicToken token)
        {
            token = null;
            char c = stream.Content[0];

            if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
            {
                token = new WhitespaceLexicToken();
                return(stream.Move(1));
            }
            return(stream);
        }
예제 #9
0
        public override InputStream TryRead(InputStream stream, out LexicToken token)
        {
            token = null;
            Match match = regex.Match(stream.Content);

            if (match.Success)
            {
                token = GetToken(match.Value);
                return(stream.Move(match.Value.Length));
            }
            return(stream);
        }
예제 #10
0
        public override InputStream TryRead(InputStream stream, out LexicToken token)
        {
            token = null;

            if (stream.Content.StartsWith(str))
            {
                token = this.token;
                return stream.Move(str.Length);
            }

            return stream;
        }
예제 #11
0
        public IEnumerable <LexicToken> Parse(InputStream input)
        {
            textInfo.Clear();
            parameterExpressions.Clear();

            // sorting to prevent situation when parameter 'x1' is parsed as parameter 'x' when 'x' is available, too.
            parameterReader.ParameterNames = parameters.OrderByDescending(s => s.Length);
            namedConstantReader.Constants  = NamedConstants;
            functionReader.Functions       = registeredFunctions;

            List <LexicToken> tokens = new List <LexicToken>();

            int start = 0;

            do
            {
                var copy = input;

                foreach (var reader in lexicReaders)
                {
                    LexicToken token = null;

                    if (input.IsEmpty)
                    {
                        break;
                    }

                    start = input.Position;
                    input = reader.TryRead(input, out token);

                    if (token != null)
                    {
                        TokenInTextInfo info = new TokenInTextInfo {
                            StartIndex = start, Length = input.Position - start, Token = token
                        };
                        textInfo.Add(info);

                        tokens.Add(token);
                    }
                }

                if (input == copy)
                {
                    throw new ParserException(String.Format("Unexpected character '{0}' in position {1}.", input.Content[0], input.Position));
                }
            } while (!input.IsEmpty);

            return(tokens);
        }
		public override InputStream TryRead(InputStream stream, out LexicToken token)
		{
			token = null;

			foreach (var function in Functions)
			{
				if (stream.Content.StartsWith(function.Name))
				{
					FunctionCallToken functionToken = new FunctionCallToken { Method = function.Method };
					token = functionToken;

					return stream.Move(function.Name.Length);
				}
			}

			return stream;
		}
예제 #13
0
		public override InputStream TryRead(InputStream stream, out LexicToken token)
		{
			token = null;

			char firstChar = stream.Content[0];

			if (firstChar == ' ' ||
				firstChar == '\t' ||
				firstChar == '\n' ||
				firstChar == '\r')
			{
				token = new WhitespaceToken();
				return stream.Move(1);
			}

			return stream;
		}
		public override InputStream TryRead(InputStream stream, out LexicToken token)
		{
			token = null;

			foreach (var parameterName in parameterNames)
			{
				if (stream.Content.StartsWith(parameterName))
				{
					ParameterToken paramToken = new ParameterToken(parameterName);
					token = paramToken;

					return stream.Move(parameterName.Length);
				}
			}

			return stream;
		}
        public override InputStream TryRead(InputStream stream, out LexicToken token)
        {
            token = null;

            foreach (var constant in Constants)
            {
                if (stream.Content.StartsWith(constant.Name))
                {
                    NamedConstantToken constantToken = new NamedConstantToken(constant.Name, constant.Value);
                    token = constantToken;

                    return(stream.Move(constant.Name.Length));
                }
            }

            return(stream);
        }
예제 #16
0
        public override InputStream TryRead(InputStream stream, out LexicToken token)
        {
            token = null;

            foreach (var parameterName in parameterNames)
            {
                if (stream.Content.StartsWith(parameterName))
                {
                    ParameterToken paramToken = new ParameterToken(parameterName);
                    token = paramToken;

                    return(stream.Move(parameterName.Length));
                }
            }

            return(stream);
        }
		public override InputStream TryRead(InputStream stream, out LexicToken token)
		{
			token = null;

			foreach (var constant in Constants)
			{
				if (stream.Content.StartsWith(constant.Name))
				{
					NamedConstantToken constantToken = new NamedConstantToken(constant.Name, constant.Value);
					token = constantToken;

					return stream.Move(constant.Name.Length);
				}
			}

			return stream;
		}
        public override InputStream TryRead(InputStream stream, out LexicToken token)
        {
            token = null;

            foreach (var function in Functions)
            {
                if (stream.Content.StartsWith(function.Name))
                {
                    FunctionCallToken functionToken = new FunctionCallToken {
                        Method = function.Method
                    };
                    token = functionToken;

                    return(stream.Move(function.Name.Length));
                }
            }

            return(stream);
        }
예제 #19
0
 public CharReader(char c, LexicToken token)
 {
     this.c = c;
     this.token = token;
 }
예제 #20
0
 public abstract InputStream TryRead(InputStream stream, out LexicToken token);
예제 #21
0
 public StringReader(string str, LexicToken token)
 {
     this.str   = str;
     this.token = token;
 }
예제 #22
0
 public CharReader(char c, LexicToken token)
 {
     this.C     = c;
     this.Token = token;
 }
예제 #23
0
 public abstract InputStream TryRead(InputStream stream, out LexicToken token);
예제 #24
0
 public StringReader(string str, LexicToken token)
 {
     this.str = str;
     this.token = token;
 }