github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/regexp/syntax/parse.go (about)

     1  // Copyright 2011 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package syntax
     6  
     7  // エラーは正規表現の解析に失敗し、問題のある表現を示します。
     8  type Error struct {
     9  	Code ErrorCode
    10  	Expr string
    11  }
    12  
    13  func (e *Error) Error() string
    14  
    15  // 「ErrorCode」は正規表現の解析に失敗したことを説明します。
    16  type ErrorCode string
    17  
    18  const (
    19  	// 予期しないエラー
    20  	ErrInternalError ErrorCode = "regexp/syntax: internal error"
    21  
    22  	// パースエラー
    23  	ErrInvalidCharClass      ErrorCode = "invalid character class"
    24  	ErrInvalidCharRange      ErrorCode = "invalid character class range"
    25  	ErrInvalidEscape         ErrorCode = "invalid escape sequence"
    26  	ErrInvalidNamedCapture   ErrorCode = "invalid named capture"
    27  	ErrInvalidPerlOp         ErrorCode = "invalid or unsupported Perl syntax"
    28  	ErrInvalidRepeatOp       ErrorCode = "invalid nested repetition operator"
    29  	ErrInvalidRepeatSize     ErrorCode = "invalid repeat count"
    30  	ErrInvalidUTF8           ErrorCode = "invalid UTF-8"
    31  	ErrMissingBracket        ErrorCode = "missing closing ]"
    32  	ErrMissingParen          ErrorCode = "missing closing )"
    33  	ErrMissingRepeatArgument ErrorCode = "missing argument to repetition operator"
    34  	ErrTrailingBackslash     ErrorCode = "trailing backslash at end of expression"
    35  	ErrUnexpectedParen       ErrorCode = "unexpected )"
    36  	ErrNestingDepth          ErrorCode = "expression nests too deeply"
    37  	ErrLarge                 ErrorCode = "expression too large"
    38  )
    39  
    40  func (e ErrorCode) String() string
    41  
    42  // Flagsはパーサーの動作を制御し、正規表現のコンテキストに関する情報を記録します。
    43  type Flags uint16
    44  
    45  const (
    46  	FoldCase Flags = 1 << iota
    47  	Literal
    48  	ClassNL
    49  	DotNL
    50  	OneLine
    51  	NonGreedy
    52  	PerlX
    53  	UnicodeGroups
    54  	WasDollar
    55  	Simple
    56  
    57  	MatchNL = ClassNL | DotNL
    58  
    59  	Perl        = ClassNL | OneLine | PerlX | UnicodeGroups
    60  	POSIX Flags = 0
    61  )
    62  
    63  // Parseは指定されたフラグによって制御された正規表現文字列sを解析し、正規表現の解析木を返します。構文はトップレベルのコメントに記載されています。
    64  func Parse(s string, flags Flags) (*Regexp, error)