// Copyright (c) 2009-2022 The MathJax Consortium
// SPDX-License-Identifier: Apache-2.0
// Sources: ts/input/tex/base/BaseMethods.ts, TexParser.ts, FilterUtil.ts.

package tex

import 

func ( *parser) ( string) ([]*mml.Node, error) {
	,  := .readUpTo(, "\\over")
	if  != nil {
		return nil, 
	}
	,  := .parseChild()
	if  != nil {
		return nil, 
	}
	// ParseArg uses GetNext's JavaScript whitespace before capturing its
	// one argument. Keep this boundary independent of ordinary tokenization.
	for .pos < len(.source) && internalTextSpace(.peekRune()) {
		.consumeRune()
	}
	, ,  := .readArgumentAtCursor(, false)
	if  != nil {
		return nil, 
	}
	,  := .parseChild()
	if  != nil {
		return nil, 
	}
	// BuildRel creates munderover(base, null, top). FilterUtil.cleanSubSup
	// reduces that absent under-script to mover; construct the same final
	// shape, without Overset's accent or movable-limit adjustments.
	return []*mml.Node{texAtom(node("mover", , ), mml.TeXClassRel)}, nil
}

// readUpTo ports TexParser.GetUpTo's lexical control-sequence search. Braces
// protect the terminator; macros and comments are not expanded or interpreted
// until ParseUpTo creates the independent child parser for the captured text.
func ( *parser) (,  string) (string, error) {
	 := func() {
		for .pos < len(.source) && internalTextSpace(.peekRune()) {
			.consumeRune()
		}
	}
	()
	,  := .pos, 0
	for .pos < len(.source) {
		 := .pos
		()
		if .pos >= len(.source) {
			break
		}
		 := string(.consumeRune())
		switch  {
		case "\\":
			 += .readControlSequence()
		case "{":
			++
		case "}":
			if  == 0 {
				return "", texError("ExtraCloseLooking", "Extra close brace while looking for %s", )
			}
			--
		}
		if  == 0 &&  ==  {
			return .source[:], nil
		}
	}
	return "", texError("TokenNotFoundForCommand", "Could not find %s for \\%s", , )
}