Exemplo n.º 1
0
		public void parse() {
			// while not end of data found:
			while ( !_exit ) {
				// create empty token:
				QueryToken token;
				// skip all whitespace:
				skipIgnored();
				// if current character code is 0 end of data is reached:
				if ( currentCode() == 0 ) {
					break;
				}
				// remeber start position:
				int start = _position-1;
				// and check what is the character code:
				switch ( currentCode() ) {
					case 47: // /
						if ( preview() == 42 ) { // 42 is *
							// matched a multi line comment:
							next(); // skip *
							token = new QueryToken(null, TokenType.COMMENT, start, skipComment());
						} else {
							// matched single / operator:
							token = new QueryToken(null, TokenType.OPERATOR, start, skipOperator());
						}
						break;
					case 38:
					case 126:
					case 124:
					case 94:
					case 61:
					case 62:
					case 60:
					case 37:
					case 33:
					case 43:
					case 42:
                    case 45:
						// matched an operator:
                        int len = skipOperator();
						token = new QueryToken(_input.Substring(start,len), TokenType.OPERATOR, start, len);
						break;
					case 40: // (
					case 41: // )
					case 44: // ,
                        token = new QueryToken(ch, TokenType.TOKEN, start, 1);
						next(); // skip
						break;
					case 35: // # single line comment:
						token = new QueryToken(null, TokenType.COMMENT, start, skipUntilNl());
						break;
					case 46: // . for code hints
						next(); // skip .
						token = new QueryToken(ch, TokenType.DOT, start, 1);
						break;
					case 64: // @
						token = readVariable(start);
						break;
					case 39: // '
						// string:
						token = readString(start);
						break;
					case 96: // `
						// escaped key:
						token = readEscapedKey(start);
						break;
					default:
						if ( isDigit( currentCode() ) || currentCode() == 45 ) { // 45 is -
							token = readNumber(start);
						} else {
							token = readKey(start);
						}
						break;
				}
				// emit the token:
				emit(token);
			}
		}
Exemplo n.º 2
0
		private void emit(QueryToken token){
			_tokens.Add(token);
		}