<commit_before>//
// Copyright 2011 <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//

// The swatcl package implements a rudimentary Tcl interpreter for the
// purpose of writing debugger commands.
package swatcl

import (
	"os"
)

type parserState int

const (
	_             = iota
	stateOK       // evaluation successful
	stateError    // evaluation error, check returned error
	stateReturn   // 'return' command status
	stateBreak    // 'break' command status
	stateContinue // 'continue' command status
)

type parserToken int

const (
	_              = iota
	tokenEscape    // escape token
	tokenString    // string token
	tokenBrace     // uninterpreted string token
	tokenCommand   // command token
	tokenVariable  // variable token
	tokenFunction  // expression function call
	tokenOperator  // expression operator
	tokenInteger   // integer literal
	tokenFloat     // floating point literal
	tokenSeparator // separator token
	tokenComma     // comma (argument separator)
	tokenParen     // open parenthesis
	tokenEOL       // end-of-line token
	tokenEOF       // end-of-file token
)

// Parser represents the internal state of the Tcl parser, including the
// text being parsed and the current token.
type Parser struct {
	text        string      // the text being parsed
	p           int         // current text position
	len         int         // remaining length to be parsd
	start       int         // start of current token
	end         int         // end of current token
	token       parserToken // token type (one of the token* constants)
	insidequote bool        // true if inside quotes
}

// callFrame is a frame within the call stack of the Tcl interpreter.
type callFrame struct {
	vars map[string]string
}

// commandFunc is a function that implements a built-in command. The
// argv parameter provides the incoming arguments, with the first entry
// being the name of the command being invoked. The data parameter is
// that which was passed to the RegisterCommand method of Interpreter.
// The function returns the parser state and the result of the command.
type commandFunc func(i *Interpreter, argv []string, data []string) (parserState, string)

// swatclCmd represents a built-in command.
type swatclCmd struct {
	function commandFunc // the command function
	privdata []string    // private data given at time of registration
}

// Interpreter contains the internal state of the Tcl interpreter,
// including register commands, the call frame, and result of the
// interpretation.
type Interpreter struct {
	level    int                  // level of nesting
	frames   []callFrame          // call stack frames
	commands map[string]swatclCmd // registered commands
	result   string               // result of evaluation
}

// Error constants
const (
	_         = iota
	EBRACE    // found unmatched curly brace ({)
	ECMDDEF   // command is already defined
	EVARUNDEF // variable not defined
	ECMDUNDEF // command not defined
	ENOSTACK  // no call frames on the stack
	EILLARG   // interpreter given illegal method arguments
	EBADBOOL  // interpreter given a malformed boolean value
	EBADEXPR  // invalid characters in expression
	EOPERAND  // missing or malformed operand
	EOPERATOR // invalid or unknown operator
	EBADSTATE // expression evaluator in a bad state
	EINVALNUM // invalid numeric expression
	ENUMRANGE // numeric value out of supported range
)

// TclError is used to provide information on the type of error that
// occurred while parsing or evaluating the Tcl script. It implements
// the error interface.
type TclError struct {
	Errno   os.Errno
	Message string
}

// NewTclError creates a new TclError based on the given values.
func NewTclError(err int, msg string) *TclError {
	return &TclError{os.Errno(err), msg}
}

// String returns the string representation of the error.
func (e *TclError) String() string {
	return e.Message
}

// Error returns the string representation of the error.
func (e *TclError) Error() string {
	return e.Message
}
<commit_msg>Errno moved to syscall package.<commit_after>//
// Copyright 2011 <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//

// The swatcl package implements a rudimentary Tcl interpreter for the
// purpose of writing debugger commands.
package swatcl

import (
	"syscall"
)

type parserState int

const (
	_             = iota
	stateOK       // evaluation successful
	stateError    // evaluation error, check returned error
	stateReturn   // 'return' command status
	stateBreak    // 'break' command status
	stateContinue // 'continue' command status
)

type parserToken int

const (
	_              = iota
	tokenEscape    // escape token
	tokenString    // string token
	tokenBrace     // uninterpreted string token
	tokenCommand   // command token
	tokenVariable  // variable token
	tokenFunction  // expression function call
	tokenOperator  // expression operator
	tokenInteger   // integer literal
	tokenFloat     // floating point literal
	tokenSeparator // separator token
	tokenComma     // comma (argument separator)
	tokenParen     // open parenthesis
	tokenEOL       // end-of-line token
	tokenEOF       // end-of-file token
)

// Parser represents the internal state of the Tcl parser, including the
// text being parsed and the current token.
type Parser struct {
	text        string      // the text being parsed
	p           int         // current text position
	len         int         // remaining length to be parsd
	start       int         // start of current token
	end         int         // end of current token
	token       parserToken // token type (one of the token* constants)
	insidequote bool        // true if inside quotes
}

// callFrame is a frame within the call stack of the Tcl interpreter.
type callFrame struct {
	vars map[string]string
}

// commandFunc is a function that implements a built-in command. The
// argv parameter provides the incoming arguments, with the first entry
// being the name of the command being invoked. The data parameter is
// that which was passed to the RegisterCommand method of Interpreter.
// The function returns the parser state and the result of the command.
type commandFunc func(i *Interpreter, argv []string, data []string) (parserState, string)

// swatclCmd represents a built-in command.
type swatclCmd struct {
	function commandFunc // the command function
	privdata []string    // private data given at time of registration
}

// Interpreter contains the internal state of the Tcl interpreter,
// including register commands, the call frame, and result of the
// interpretation.
type Interpreter struct {
	level    int                  // level of nesting
	frames   []callFrame          // call stack frames
	commands map[string]swatclCmd // registered commands
	result   string               // result of evaluation
}

// Error constants
const (
	_         = iota
	EBRACE    // found unmatched curly brace ({)
	ECMDDEF   // command is already defined
	EVARUNDEF // variable not defined
	ECMDUNDEF // command not defined
	ENOSTACK  // no call frames on the stack
	EILLARG   // interpreter given illegal method arguments
	EBADBOOL  // interpreter given a malformed boolean value
	EBADEXPR  // invalid characters in expression
	EOPERAND  // missing or malformed operand
	EOPERATOR // invalid or unknown operator
	EBADSTATE // expression evaluator in a bad state
	EINVALNUM // invalid numeric expression
	ENUMRANGE // numeric value out of supported range
)

// TclError is used to provide information on the type of error that
// occurred while parsing or evaluating the Tcl script. It implements
// the error interface.
type TclError struct {
	Errno   syscall.Errno
	Message string
}

// NewTclError creates a new TclError based on the given values.
func NewTclError(err int, msg string) *TclError {
	return &TclError{syscall.Errno(err), msg}
}

// String returns the string representation of the error.
func (e *TclError) String() string {
	return e.Message
}

// Error returns the string representation of the error.
func (e *TclError) Error() string {
	return e.Message
}

{'fraction_non_alphanumeric': 0.0642848462753676, 'fraction_numerical': 0.0009721715882853323, 'mean_word_length': 2.8314711359404097, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6237509', 'n_tokens_mistral': 2160, 'n_tokens_neox': 2116, 'n_words': 982}