Mercurial > hg > monetdb-java
view src/main/java/org/monetdb/mcl/parser/MCLParser.java @ 943:ff075ed5ce81
Spell check.
author | Sjoerd Mullender <sjoerd@acm.org> |
---|---|
date | Thu, 09 Jan 2025 10:56:14 +0100 (2 months ago) |
parents | d416e9b6b3d0 |
children |
line wrap: on
line source
/* * SPDX-License-Identifier: MPL-2.0 * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Copyright 2024, 2025 MonetDB Foundation; * Copyright August 2008 - 2023 MonetDB B.V.; * Copyright 1997 - July 2008 CWI. */ package org.monetdb.mcl.parser; /** * Interface for parsers in MCL. The parser family in MCL is set up as * a reusable object. This allows the same parser to be used again for * the same type of work. While this is a very unnatural solution in * the Java language, it prevents many object creations on a low level * of the protocol. This favours performance. * * A typical parser has a method parse() which takes a String, and the * methods hasNext() and next() to retrieve the values that were * extracted by the parser. Parser specific methods may be available to * perform common tasks. * * @author Fabian Groffen */ public abstract class MCLParser { /** The String values found while parsing. Public, you may touch it. */ public final String values[]; protected int colnr = 0; /** * Creates an MCLParser targeted at a given number of field values. * The lines parsed by an instance of this MCLParser should have * exactly capacity field values. * * @param capacity the number of field values to expect */ protected MCLParser(final int capacity) { values = new String[capacity]; } /** * Parse the given string, and populate the internal field array * to allow for next() and hasNext() calls. * * @param source the String containing the line to parse * @return value * @throws MCLParseException if source cannot be (fully) parsed by * this parser * @see #next() * @see #hasNext() */ abstract public int parse(final String source) throws MCLParseException; /** * Repositions the internal field offset to the start, such that the * next call to next() will return the first field again. */ final public void reset() { colnr = 0; } /** * Returns whether the next call to next() or nextInt() succeeds. * * @return true if the next call to next() or nextInt() is bound to * succeed * @see #next() */ final public boolean hasNext() { return colnr < values.length; } /** * Returns the current field value, and advances the field counter * to the next value. This method may fail with a RuntimeError if * the current field counter is out of bounds. Call hasNext() to * determine if the call to next() will succeed. * * @return the current field value * @see #hasNext() */ final public String next() { return values[colnr++]; } }