/*
get -- return the next character from stdin. Watch out for lookahead. If
the character is a control character, translate it to a space or
linefeed.
422881
private int get(boolean inStringLiteral) throws IOException {
		int c = theLookahead;
		theLookahead = EOF;
		if (c == EOF) {
			c = in.read();
			if (c != EOF) {
				currentByteIndex++;
			}
		}
		if (c == '\n') {
			line++;
			column = 0;
		} else {
			column++;
		}
		if (c >= ' ' || c == '\n' || c == EOF || (inStringLiteral && c == '\t')) { // Handle
																					// the
																					// case
																					// of
																					// tab
																					// character
																					// in
																					// String
																					// literal
			return c;
		}

		if (c == '\r') {
			return '\n';
		}
		return ' ';
	}
1198592
public Token lookahead() {
        Token current = token;
        if (current.next == null) {
            current.next = token_source.getNextToken();
        }
        return current.next;
    }
597672
function next_line() {

// Put the next line of source in source_line. If the line contains tabs,
// replace them with spaces and give a warning. Also warn if the line contains
// unsafe characters or is too damn long.

            let at;
            column = 0;
            line += 1;
            source_line = lines[line];
            if (source_line !== undefined) {
                at = source_line.search(rx_tab);
                if (at >= 0) {
                    if (!option.white) {
                        warn_at("use_spaces", line, at + 1);
                    }
                    source_line = source_line.replace(rx_tab, " ");
                }
                at = source_line.search(rx_unsafe);
                if (at >= 0) {
                    warn_at(
                        "unsafe",
                        line,
                        column + at,
                        "U+" + source_line.charCodeAt(at).toString(16)
                    );
                }
                if (option.maxlen && option.maxlen < source_line.length) {
                    warn_at("too_long", line, source_line.length);
                } else if (!option.white && source_line.slice(-1) === " ") {
                    warn_at(
                        "unexpected_trailing_space",
                        line,
                        source_line.length - 1
                    );
                }
            }
            return source_line;
        }
1074635
def nextstring(quot)
      c = buf = ""
      while true
	c = self.nextchar()
	case c
	when /\0|\n\r/
	  raise "Unterminated string"
	when "\\"
	  chr = self.nextchar()
	  case chr
	  when 'b'
	    buf << "\b"
	  when 't'
	    buf << "\t"
	  when 'n'
	    buf << "\n"
	  when 'f'
	    buf << "\f"
	  when 'r'
	    buf << "\r"
	  when 'u'
	    buf << utf8str(Integer("0x" + self.nextchars(4)))
	  else
	    buf << chr
	  end
	else
	  return(buf) if (c == quot)
	  buf << c
	end
      end
    end
1150506
def next_token(self):
        """"""
        while self.char is not None:

            if self.char.isspace():
                # The current character is a whitespace
                self.whitespace()
                continue

            elif self.char == '#':
                # The current character is `#`
                self.advance()
                self.comment()
                continue

            elif self.char.isalpha() or self.char == '_':
                # The current character is a letter or `_`
                return self._id()

            elif self.char == ';':
                # The current character is `;`
                self.advance()
                return Token(Nature.SEMI, ';')

            elif self.char == ',':
                # The current character is `,`
                self.advance()
                return Token(Nature.COMMA, ';')

            elif self.char.isdigit():
                # The current character is a number
                return self.number()

            elif self.char == '=' and self.peek() == '=':
                # The current character is `==`
                self.advance()
                self.advance()
                return Token(Nature.EQ, '==')

            elif self.char == '!' and self.peek() == '=':
                # The current character is `!=`
                self.advance()
                self.advance()
                return Token(Nature.NE, '!=')

            elif self.char == '<' and self.peek() == '=':
                # The current character is `<=`
                self.advance()
                self.advance()
                return Token(Nature.LE, '<=')

            elif self.char == '>' and self.peek() == '=':
                # The current character is `>=`
                self.advance()
                self.advance()
                return Token(Nature.GE, '>=')

            elif self.char == '<':
                # The current character is `<`
                self.advance()
                return Token(Nature.LT, '<')

            elif self.char == '>':
                # The current character is `>`
                self.advance()
                return Token(Nature.GT, '>')

            elif self.char == '=':
                # The current character is `=`
                self.advance()
                return Token(Nature.ASSIGN, '=')

            elif self.char == '+':
                # The current character is `+`
                self.advance()
                return Token(Nature.PLUS, '+')

            elif self.char == '-':
                # The current character is `-`
                self.advance()
                return Token(Nature.MINUS, '-')

            elif self.char == '*':
                # The current character is `*`
                self.advance()
                return Token(Nature.MUL, '*')

            elif self.char == '/' and self.peek() == '/':
                # The current character is `//`
                self.advance()
                self.advance()
                return Token(Nature.INT_DIV, '//')

            elif self.char == '/':
                # The current character is `/`
                self.advance()
                return Token(Nature.DIV, '/')

            elif self.char == '(':
                # The current character is `(`
                self.advance()
                return Token(Nature.LPAREN, '(')

            elif self.char == ')':
                # The current character is `)`
                self.advance()
                return Token(Nature.RPAREN, ')')

            elif self.char == '{':
                # The current character is `{`
                self.advance()
                return Token(Nature.LBRACKET, '{')

            elif self.char == '}':
                # The current character is `}`
                self.advance()
                return Token(Nature.RBRACKET, '}')

            else:
                # The current character is unknown
                raise LexicalError(f"Invalid character `{self.char}`.")

        # End of raw input
        return Token(Nature.EOF, None)
600847
def get_character(self, position, offset=0):
        """"""
        position = self.get_position(position) + offset
        cursor = self.textCursor()
        cursor.movePosition(QTextCursor.End)
        if position < cursor.position():
            cursor.setPosition(position)
            cursor.movePosition(QTextCursor.Right,
                                QTextCursor.KeepAnchor)
            return to_text_string(cursor.selectedText())
        else:
            return ''
815069
def find_next_character(code, position, char):
    """"""
    end = LineCol(code, *position)
    while not end.eof and end.char() in WHITESPACE:
        end.inc()

    if not end.eof and end.char() == char:
        return end.tuple(), inc_tuple(end.tuple())
    return None, None
1359339
private char nextChar() throws IOException {
		if (missedChar != null) {
			// RETURNS THE PREVIOUS PARSED CHAR
			c = missedChar.charValue();
			missedChar = null;

		} else {
			c = (char) in.read();

			if (c == '\\') {
				char c2 = (char) in.read();
				if (c2 == 'u') {
					// DECODE UNICODE CHAR
					final StringBuilder buff = new StringBuilder();
					for (int i = 0; i < 4; ++i)
						buff.append((char) in.read());

					cursor += 6;

					return (char) Integer.parseInt(buff.toString(), 16);
				} else {
					// REMEMBER THE CURRENT CHAR TO RETURN NEXT TIME
					missedChar = c2;
				}
			}
		}

		cursor++;

		if (c == NEW_LINE) {
			++lineNumber;
			columnNumber = 0;
		} else
			++columnNumber;

		return c;
	}

	public char lastChar() {
		return c;
	}

	public String getValue() {
		return value;
	}

	public int getLineNumber() {
		return lineNumber;
	}

	public int getColumnNumber() {
		return columnNumber;
	}

	public boolean hasNext() throws IOException {
		return in.ready();
	}
}
196711
private int next(int ch) throws IOException {
    // TODO: try my own form of indirect jump... look up char class and index directly into handling implementation?
    for(;;) {
      switch (ch) {
        case ' ': // this is not the exclusive list of whitespace chars... the rest are handled in default:
        case '\t':
        case '\r':
        case '\n':
          ch = getCharNWS(); // calling getCharNWS here seems faster than letting the switch handle it
          break;
        case '"' :
          stringTerm = '"';
          valstate = STRING;
          return STRING;
        case '\'' :
          if ((flags & ALLOW_SINGLE_QUOTES) == 0) {
            throw err("Single quoted strings not allowed");
          }
          stringTerm = '\'';
          valstate = STRING;
          return STRING;
        case '{' :
          push();
          state= DID_OBJSTART;
          return OBJECT_START;
        case '[':
          push();
          state=DID_ARRSTART;
          return ARRAY_START;
        case '0' :
          out.reset();
          //special case '0'?  If next char isn't '.' val=0
          ch=getChar();
          if (ch=='.') {
            start--; ch='0';
            readNumber('0',false);
            return valstate;
          } else if (ch>'9' || ch<'0') {
            out.unsafeWrite('0');
            if (ch!=-1) start--;
            lval = 0;
            valstate=LONG;
            return LONG;
          } else {
            throw err("Leading zeros not allowed");
          }
        case '1' :
        case '2' :
        case '3' :
        case '4' :
        case '5' :
        case '6' :
        case '7' :
        case '8' :
        case '9' :
          out.reset();
          lval = readNumber(ch,false);
          return valstate;
        case '-' :
          out.reset();
          out.unsafeWrite('-');
          ch = getChar();
          if (ch<'0' || ch>'9') throw err("expected digit after '-'");
          lval = readNumber(ch,true);
          return valstate;
        case 't':
          // TODO: test performance of this non-branching inline version.
          // if ((('r'-getChar())|('u'-getChar())|('e'-getChar())) != 0) throw err("");
          if (matchBareWord(JSONUtil.TRUE_CHARS)) {
            bool = true;
            valstate = BOOLEAN;
            return valstate;
          } else {
            valstate = STRING;
            return STRING;
          }
        case 'f':
          if (matchBareWord(JSONUtil.FALSE_CHARS)) {
            bool = false;
            valstate = BOOLEAN;
            return valstate;
          } else {
            valstate = STRING;
            return STRING;
          }
        case 'n':
          if (matchBareWord(JSONUtil.NULL_CHARS)) {
            valstate = NULL;
            return valstate;
          } else {
            valstate = STRING;
            return STRING;
          }
        case '/':
          getSlashComment();
          ch = getChar();
          break;
        case '#':
          getNewlineComment();
          ch = getChar();
          break;
        case ']':  // This only happens with a trailing comma (or an error)
          if (state != DID_ARRELEM || (flags & ALLOW_EXTRA_COMMAS)==0) {
            throw err("Unexpected array closer ]");
          }
          pop();
          return event = ARRAY_END;
        case '}':  // This only happens with a trailing comma (or an error)
          if (state != DID_MEMVAL || (flags & ALLOW_EXTRA_COMMAS)==0) {
            throw err("Unexpected object closer }");
          }
          pop();
          return event = ARRAY_END;
        case ',': // This only happens with input like [1,]
          if ((state != DID_ARRELEM && state != DID_MEMVAL) || (flags & ALLOW_EXTRA_COMMAS)==0) {
            throw err("Unexpected comma");
          }
          ch = getChar();
          break;
        case -1:
          if (getLevel()>0) throw err("Premature EOF");
          return EOF;
        default:
          // Handle unusual unicode whitespace like no-break space (0xA0)
          if (isWhitespace(ch)) {
            ch = getChar();  // getCharNWS() would also work
            break;
          }
          handleNonDoubleQuoteString(ch, false);
          valstate = STRING;
          return STRING;
          // throw err(null);
      }

    }
  }
828140
function(skip){
    skip = skip || 0;
    var start = this.input[skip];
    assert(start === '(' || start === '{' || start === '[',
           'The start character should be "(", "{" or "["');
    var end = characterParser.BRACKETS[start];
    var range;
    try {
      range = characterParser.parseUntil(this.input, end, {start: skip + 1});
    } catch (ex) {
      if (ex.index !== undefined) {
        var idx = ex.index;
        // starting from this.input[skip]
        var tmp = this.input.substr(skip).indexOf('\n');
        // starting from this.input[0]
        var nextNewline = tmp + skip;
        var ptr = 0;
        while (idx > nextNewline && tmp !== -1) {
          this.incrementLine(1);
          idx -= nextNewline + 1;
          ptr += nextNewline + 1;
          tmp = nextNewline = this.input.substr(ptr).indexOf('\n');
        };

        this.incrementColumn(idx);
      }
      if (ex.code === 'CHARACTER_PARSER:END_OF_STRING_REACHED') {
        this.error('NO_END_BRACKET', 'The end of the string reached with no closing bracket ' + end + ' found.');
      } else if (ex.code === 'CHARACTER_PARSER:MISMATCHED_BRACKET') {
        this.error('BRACKET_MISMATCH', ex.message);
      }
      throw ex;
    }
    return range;
  }
5486
def char(self):
        
        # Read a new chunk from the input stream if necessary
        if self.chunkOffset >= self.chunkSize:
            if not self.readChunk():
                return EOF

        chunkOffset = self.chunkOffset
        char = self.chunk[chunkOffset]
        self.chunkOffset = chunkOffset + 1

        return char
1051897
public Token next() throws ScanException {
		if (token != null) {
			position += token.getSize();
		}
	
		int length = input.length();
				
		if (isEval()) {
			while (position < length && Character.isWhitespace(input.charAt(position))) {
				position++;
			}
		}

		if (position == length) {
			return token = fixed(Symbol.EOF);
		}

		return token = nextToken();
	}
708853
public String getLeftOf(String srcStr, int charCount) {

        String retValue = "";

        if (isNotBlank(srcStr)) {

            int length = srcStr.length();

            if (charCount < length) {
                retValue = srcStr.substring(0, charCount);
            } else {
                retValue = srcStr;
            }
        }

        return retValue;
    }
1019656
public String lookupNextToken() {
        skipWhitespace();
        int start = index;
        for (int end = index; end < originalInput.length(); end++) {
            if (Character.isWhitespace(originalInput.charAt(end))) {
                if (end > start) {
                    return originalInput.subSequence(start, end).toString();
                }
                return null;
            }
        }
        if (start < originalInput.length()) {
            return originalInput.subSequence(start, originalInput.length())
                    .toString();
        }
        return null;
    }
149601
def _get_char(self):
        

        if self.ungotten_char is None:
            if self.eof:
                c = ''
            else:
                c = self.file.read(1)
                if c == '':
                    self.eof = True
                elif c == '\n':
                    self.line_number += 1
        else:
            c = self.ungotten_char
            self.ungotten_char = None
        return c
955101
function eatCharacter(stream) {
        var first = stream.next();
        // Read special literals: backspace, newline, space, return.
        // Just read all lowercase letters.
        if (first.match(/[a-z]/) && stream.match(/[a-z]+/, true)) {
            return;
        }
        // Read unicode character: \u1000 \uA0a1
        if (first === "u") {
            stream.match(/[0-9a-z]{4}/i, true);
        }
    }
517808
def _getch():
    '''  '''
    import tty

    with TermStack() as fd:
        tty.setraw(fd)
        return sys.stdin.read(1)