TIP #246: Unify Pattern Matching


TIP:246
Title:Unify Pattern Matching
Version:$Revision: 1.5 $
Author:Reinhard Max <max at tclers dot tk>
State:Draft
Type:Project
Tcl-Version:8.7
Vote:Pending
Created:Wednesday, 27 April 2005
Keywords:pattern, match, glob, exact, regexp, case sensitive, Tcl

Abstract

Many Tcl commands take arguments that are patterns to match against. Some of these commands allow options to specify whether the pattern should be treated as a literal, a glob pattern, or a regular expression, and whether or not matching should be case sensitive. This TIP proposes a unique set of options for all commands that accept pattern arguments.

Rationale

It is hard to memorize which of the commands that take a pattern argument allows to modify the matching mode, and in which way. With this TIP in place pattern matching will be orthogonal throughout Tcl, so the rules learned once can be applied to every command that uses pattern matching.

Current situation

The following commands currently take pattern arguments with varying combinations of switches to specify their behaviour:

The following commands which also take pattern arguments are outside the scope of this TIP:

* Commands that match patterns against file names

auto_import, auto_mkindex, pkg_mkIndex, tcltest.

* Commands that use regular expressions by design

regexp, and regsub.

Specification

The commands listed above shall allow for two optional switches, one that specifies the matching mode, and can be -exact, -glob, or -regexp, and one that specifies case sensitivity, and can be -case, or -nocase. Their current behaviour shall become the default behaviour in absence of the respective switch. (Some commands may accept other switches as well.)

Also shall there be two new manual pages, one that describes glob matching similar to the re_syntax page, and one that describes the pattern matching options. These manuals shall be referenced by the manuals for the individual commands instead of repeating the detailed descriptions.

Objections

Some of the mentioned commands could become somewhat slower when they need to check for more options. This needs to be checked when implementing this TIP.

Reference Implementation

There is no reference implementation yet.

The idea is to have common code for option checking, and matching, that can be used by all mentioned commands. That way it would be easy to add new algorithms or options, and have them immediately available for all commands that can do pattern matching.

The C API for this will first be worked out as a private API when creating the reference implementation and later be published by a separate TIP, so that extensions can also make use of it.

Notes

There might be need for a similar unification in Tk as well, but that's outside the scope of this TIP, and should be easy to add once this TIP is implemented so that Tcl provides the needed infrastructure.

Copyright

This document has been placed in the public domain.


Powered by Tcl[Index] [History] [Edit] [HTML Format] [Source Format] [LaTeX Format] [Text Format] [XML Format] [*roff Format (experimental)] [RTF Format (experimental)]

TIP AutoGenerator - written by Donal K. Fellows