regexps

package
v0.0.0-...-a997442 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2014 License: MIT Imports: 5 Imported by: 9

Documentation

Index

Constants

View Source
const (
	CC_ALPHA = `a-zA-Z`
	CC_ALNUM = `a-zA-Z0-9`
	CC_BLANK = `[ \t]`
	// non-blank character
	CC_GRAPH = `[\x21-\x7E]`
	CC_EOL   = `(?=\n|$)`
)

Variables

View Source
var ADMONITION_STYLES utils.Arr = []string{"NOTE", "TIP", "IMPORTANT", "WARNING", "CAUTION"}
View Source
var AdmonitionParagraphRx, _ = regexp.Compile(fmt.Sprintf("^(%v):%v", ADMONITION_STYLES.Mult("|"), CC_BLANK))

Matches an admonition label at the start of a paragraph.

Examples
  NOTE: Just a little note.
  TIP: Don't forget!
View Source
var AttributeReferenceRx, _ = regexp.Compile(`(\\)?\{((set|counter2?):.+?|\w+(?:[\-]\w+)*)(\\)?\}`)
Matches an inline attribute reference.

Examples

{foo}
{counter:pcount:1}
{set:foo:bar}
{set:name!}

 AttributeReferenceRx = /(\\)?\{((set|counter2?):.+?|\w+(?:[\-]\w+)*)(\\)?\}/
View Source
var DoubleQuotedMultiRx, _ = regexp.Compile(`(?s)^("|)(.*?)("|)$`)
Matches multiple lines of text enclosed in double quotes,

capturing the quote char and text.

# Examples
#   "I am a run-on sentence and I like
#   to take up multiple lines and I
#   still want to be matched."

DoubleQuotedMultiRx = /^("|)(.*)\1$/

View Source
var DoubleQuotedRx, _ = regexp.Compile(`(?m)^("|)(.*?)("|)$`)
Matches a single-line of text enclosed in double quotes,

capturing the quote char and text.

Examples
  "Who goes there?"

DoubleQuotedRx = /^("|)(.*)\1$/

View Source
var EmailInlineMacroRx, _ = regexp.Compile(`([\\>:\/])?\w[\w.%+-]*@[a-zA-Z0-9][a-zA-Z0-9.-]*\.[a-zA-Z]{2,4}`)
View Source
var EolRx, _ = regexp.Compile(`[\r\n]+`)
View Source
var EscapedBracketRx, _ = regexp.Compile(`\\\]`)

Detects escaped brackets

View Source
var FootnoteInlineMacroRx, _ = regexp.Compile(`\\?(footnote(?:ref)?):\[(.*?[^\\])\]`)
View Source
var ImageInlineMacroRx, _ = regexp.Compile(`\\?(?:image|icon):([^:\[][^\[]*)\[((?:\\\]|[^\]])*?)\]`)
View Source
var IndextermInlineMacroRx, _ = regexp.Compile(`\\?(?:(indexterm2?):\[(.*?[^\\])\]|\(\((.+?)\)\)([^\)]|$))`)
View Source
var InlineAnchorRx, _ = regexp.Compile(`\\?(?:\[\[([a-zA-Z:_][\w:.-]*)(?:,[\t ]*(\S.*?))?\]\]|anchor:(\S+)\[(.*?[^\\])?\])`)
View Source
var InlineBiblioAnchorRx, _ = regexp.Compile(`\\?\[\[\[([\w:][\w:.-]*?)\]\]\]`)
View Source
var KbdBtnInlineMacroRx, _ = regexp.Compile(`\\?(?:kbd|btn):\[((?:\\\]|[^\]])+?)\]`)

Matches either the kbd or btn inline macro. Examples

kbd:[F3]
kbd:[Ctrl+Shift+T]
kbd:[Ctrl+\]]
kbd:[Ctrl,T]
btn:[Save]

KbdBtnInlineMacroRx = /\\?(?:kbd|btn):\[((?:\\\]|[^\]])+?)\]/

View Source
var KbdDelimiterRx, _ = regexp.Compile(`(?:\+|,)([ \t]*[^ \t])`)
Matches the delimiter used for kbd value.

Examples

Ctrl + Alt+T
Ctrl,T

KbdDelimiterRx = /(?:\+|,)(?=#{CC_BLANK}*[^\1])/

View Source
var LinkInlineMacroRx, _ = regexp.Compile(`\\?(?:link|mailto):([^\s\[]+)(?:\[((?:\\\]|[^\]])*?)\])`)
Match a link or e-mail inline macro.
Examples
  link:path[label]
  mailto:doc.writer@example.com[]

LinkInlineMacroRx = /\\?(?:link|mailto):([^\s\[]+)(?:\[((?:\\\]|[^\]])*?)\])/

View Source
var LinkInlineRx, _ = regexp.Compile(`(^|link:|&lt;|[\s>\(\)\[\];])(\\?(?:https?|file|ftp|irc)://[^\s\[\]<]*[^\s.,\[\]<])(?:\[((?:\\\]|[^\]])*?)\])?`)
Matches an implicit link and some of the link inline macro.
Examples
  http://github.com
  http://github.com[GitHub]

FIXME revisit! the main issue is we need different rules for implicit vs explicit

LinkInlineRx = %r{(^|link:|&lt;|[\s>\(\)\[\];])(\\?(?:https?|file|ftp|irc)://[^\s\[\]<]*[^\s.,\[\]<])(?:\[((?:\\\]|[^\]])*?)\])?}

View Source
var MathInlineMacroRx, _ = regexp.Compile(`(?sm)\\?((?:latex|ascii)?math):([a-z,]*)\[(.*?[^\\])\]`)
Matches a math inline macro, which may span multiple lines.

Examples

math:[x != 0]
asciimath:[x != 0]
latexmath:[\sqrt{4} = 2]

MathInlineMacroRx = /\\?((?:latex|ascii)?math):([a-z,]*)\[(.*?[^\\])\]/m

View Source
var MenuInlineMacroRx, _ = regexp.Compile(`(?sm)\\?menu:(\w|\w.*?\S)\[[ \t]*(.+?)?\]`)

Matches a menu inline macro.

 # Examples
menu:File[New...]
menu:View[Page Style > No Style]
menu:View[Page Style, No Style]
MenuInlineMacroRx = /\\?menu:(\w|\w.*?\S)\[#{CC_BLANK}*(.+?)?\]/
View Source
var MenuInlineRx, _ = regexp.Compile(`(?sm)\\?"(\w[^"]*?[ \t]*&gt;[ \t]*[^" \t][^"]*)"`)
# Matches an implicit menu inline macro.
Examples
  "File > New..."

MenuInlineRx = /\\?"(\w[^"]*?#{CC_BLANK}*&gt;#{CC_BLANK}*[^" \t][^"]*)"/

View Source
var ORDERED_LIST_KEYWORDS = map[string]rune{
	"loweralpha": 'a',
	"lowerroman": 'i',
	"upperalpha": 'A',
	"upperroman": 'I',
}
View Source
var PassInlineLiteralRx, _ = regexp.Compile("(?sm)(^|[^`\\w])(?:\\[([^\\]]+?)\\])?(\\\\?`([^`\\s]|[^`\\s].*?\\S)`)([^`\\w])")
View Source
var PassInlineMacroRx, _ = regexp.Compile(`(?s)\\?(?:(\+{3})(.*?)\+{3}|(\${2})(.*?)\${2}|pass:([a-z,]*)\[(.*?[^\\])\])`)
Matches several variants of the passthrough inline macro,

which may span multiple lines.

Examples

  +++text+++
  $$text$$
  pass:quotes[text]

http://stackoverflow.com/questions/6770898/unknown-escape-sequence-error-in-go

View Source
var Replacements []*Replacement = iniReplacements()
View Source
var UriSniffRx, _ = regexp.Compile(fmt.Sprintf("^([%v][%v.+-]*:/{0,2}).*", CC_ALPHA, CC_ALNUM))

Detects strings that resemble URIs.

Examples
  http://domain
  https://domain
  data:info
View Source
var UriTerminator, _ = regexp.Compile(`[);:]$`)
Detects the end of an implicit URI in the text
Examples
  (http://google.com)
  &gt;http://google.com&lt;
  (See http://google.com):

UriTerminator = /[);:]$/

View Source
var XrefInlineMacroRx, _ = regexp.Compile(`(?s)\\?(?:&lt;&lt;([\w":].*?)&gt;&gt;|xref:([\w":].*?)\[(.*?)\])`)

Functions

func Rtos

func Rtos(runes ...rune) string

Types

type AttributeReferenceRxres

type AttributeReferenceRxres struct {
	*Reres
}

func NewAttributeReferenceRxres

func NewAttributeReferenceRxres(s string) *AttributeReferenceRxres

Results for AttributeReferenceRx

func (*AttributeReferenceRxres) Directive

func (arr *AttributeReferenceRxres) Directive() string

Return directive of the reference, as 'counter' in '{counter:pcount:1}'

func (*AttributeReferenceRxres) PostEscaped

func (arr *AttributeReferenceRxres) PostEscaped() bool

Return true if last group is non empty and include an '\'

func (*AttributeReferenceRxres) PreEscaped

func (arr *AttributeReferenceRxres) PreEscaped() bool

Return true if first group is non empty and include an '\'

func (*AttributeReferenceRxres) Reference

func (arr *AttributeReferenceRxres) Reference() string

Return reference, as in 'counter:pcount:1' in {counter:pcount:1}'

type DoubleQuotedMultiRxres

type DoubleQuotedMultiRxres struct {
	*Reres
}

func NewDoubleQuotedMultiRxres

func NewDoubleQuotedMultiRxres(s string) *DoubleQuotedMultiRxres

Results for DoubleQuotedMultiRx

func (*DoubleQuotedMultiRxres) DQMQuote

func (dqr *DoubleQuotedMultiRxres) DQMQuote() string

Return quote used for 'xxx' or '"yyy"'

func (*DoubleQuotedMultiRxres) DQMText

func (dqr *DoubleQuotedMultiRxres) DQMText() string

Return quoted text in 'xxx' or '"yyy"'

type DoubleQuotedRxres

type DoubleQuotedRxres struct {
	*Reres
}

func NewDoubleQuotedRxres

func NewDoubleQuotedRxres(s string) *DoubleQuotedRxres

Results for DoubleQuotedRx

func (*DoubleQuotedRxres) DQQuote

func (dqr *DoubleQuotedRxres) DQQuote() string

Return quote used for 'xxx' or '"yyy"'

func (*DoubleQuotedRxres) DQText

func (dqr *DoubleQuotedRxres) DQText() string

Return quoted text in 'xxx' or '"yyy"'

type EmailInlineMacroRxres

type EmailInlineMacroRxres struct {
	*Reres
}

func NewEmailInlineMacroRxres

func NewEmailInlineMacroRxres(s string) *EmailInlineMacroRxres

Results for EmailInlineMacroRx

func (*EmailInlineMacroRxres) EmailLead

func (eimr *EmailInlineMacroRxres) EmailLead() string

Return lead of the macro in '>xx:@yyy.com'

type FootnoteInlineMacroRxres

type FootnoteInlineMacroRxres struct {
	*Reres
}

func NewFootnoteInlineMacroRxres

func NewFootnoteInlineMacroRxres(s string) *FootnoteInlineMacroRxres

Results for FootnoteInlineMacroRx

func (*FootnoteInlineMacroRxres) FootnotePrefix

func (fimr *FootnoteInlineMacroRxres) FootnotePrefix() string

Return prefix 'footnote' of the macro in 'footnote:[xxx]'

func (*FootnoteInlineMacroRxres) FootnoteText

func (fimr *FootnoteInlineMacroRxres) FootnoteText() string

Return text 'xxx' of the macro in 'footnote:[xxx]'

type ImageInlineMacroRxres

type ImageInlineMacroRxres struct {
	*Reres
}

func NewImageInlineMacroRxres

func NewImageInlineMacroRxres(s string) *ImageInlineMacroRxres

Results for ImageInlineMacroRx

func (*ImageInlineMacroRxres) ImageAttributes

func (iimr *ImageInlineMacroRxres) ImageAttributes() string

Return attributes of the macro in 'image:target[attr1 attr2]'

func (*ImageInlineMacroRxres) ImageTarget

func (iimr *ImageInlineMacroRxres) ImageTarget() string

Return target of the macro in 'image:target[attr1 attr2]'

type IndextermInlineMacroRxres

type IndextermInlineMacroRxres struct {
	*Reres
}

func NewIndextermInlineMacroRxres

func NewIndextermInlineMacroRxres(s string) *IndextermInlineMacroRxres

Results for IndextermInlineMacroRx

func (*IndextermInlineMacroRxres) IndextermMacroName

func (itimr *IndextermInlineMacroRxres) IndextermMacroName() string

Return name indexterm of the macro in 'indexterm:[Tigers,Big cats]'

func (*IndextermInlineMacroRxres) IndextermTextInBrackets

func (itimr *IndextermInlineMacroRxres) IndextermTextInBrackets() string

Return text in brackets of the macro in '((Tigers))'

func (*IndextermInlineMacroRxres) IndextermTextOrTerms

func (itimr *IndextermInlineMacroRxres) IndextermTextOrTerms() string

Return terms of the macro in 'indexterm:[Tigers,Big cats]'

type InlineAnchorRxres

type InlineAnchorRxres struct {
	*Reres
}

func NewInlineAnchorRxres

func NewInlineAnchorRxres(s string) *InlineAnchorRxres

Results for InlineAnchorRx

func (*InlineAnchorRxres) BibAnchorId

func (iar *InlineAnchorRxres) BibAnchorId() string

Return id of the macro in '[[idname]]' or 'anchor:idname[]'

func (*InlineAnchorRxres) BibAnchorText

func (iar *InlineAnchorRxres) BibAnchorText() string

Return text of the macro in '[[idname,Reference Text]]' or 'anchor:idname[Reference Text]'

type InlineBiblioAnchorRxres

type InlineBiblioAnchorRxres struct {
	*Reres
}

func NewInlineBiblioAnchorRxres

func NewInlineBiblioAnchorRxres(s string) *InlineBiblioAnchorRxres

Results for InlineBiblioAnchorRx

func (*InlineBiblioAnchorRxres) BibId

func (ibar *InlineBiblioAnchorRxres) BibId() string

Return id of the macro in '[[[id]]]'

type KbdBtnInlineMacroRxres

type KbdBtnInlineMacroRxres struct {
	*Reres
}

func NewKbdBtnInlineMacroRxres

func NewKbdBtnInlineMacroRxres(s string) *KbdBtnInlineMacroRxres

Results for KbdBtnInlineMacroRx

func (*KbdBtnInlineMacroRxres) Key

func (kbimr *KbdBtnInlineMacroRxres) Key() string

Return key of the macro xxx in ':[xxx]'

type KbdDelimiterRxres

type KbdDelimiterRxres struct {
	*Reres
}

func NewKbdDelimiterRxres

func NewKbdDelimiterRxres(s string) *KbdDelimiterRxres

Results for KbdDelimiterRx

type LinkInlineMacroRxres

type LinkInlineMacroRxres struct {
	*Reres
}

func NewLinkInlineMacroRxres

func NewLinkInlineMacroRxres(s string) *LinkInlineMacroRxres

Results for LinkInlineMacroRx

func (*LinkInlineMacroRxres) LinkInlineTarget

func (limr *LinkInlineMacroRxres) LinkInlineTarget() string

Return 'xxx' in 'link:xxx[yyy]'

func (*LinkInlineMacroRxres) LinkInlineText

func (limr *LinkInlineMacroRxres) LinkInlineText() string

Return 'yyy' in 'link:xxx[yyy]'

type LinkInlineRxres

type LinkInlineRxres struct {
	*Reres
}

func NewLinkInlineRxres

func NewLinkInlineRxres(s string) *LinkInlineRxres

Results for LinkInlineRx

func (*LinkInlineRxres) IsLinkEscaped

func (lir *LinkInlineRxres) IsLinkEscaped() bool

Return true if '\' found in 'link:\http:xxx[yyy]'

func (*LinkInlineRxres) LinkPrefix

func (lir *LinkInlineRxres) LinkPrefix() string

Return 'link:' in 'link:http:xxx[yyy]'

func (*LinkInlineRxres) LinkTarget

func (lir *LinkInlineRxres) LinkTarget() string

Return 'xxx' in 'link:http:xxx[yyy]'

func (*LinkInlineRxres) LinkText

func (lir *LinkInlineRxres) LinkText() string

Return 'yyy' in 'link:http:xxx[yyy]'

type MathInlineMacroRxres

type MathInlineMacroRxres struct {
	*Reres
}

func NewMathInlineMacroRxres

func NewMathInlineMacroRxres(s string) *MathInlineMacroRxres

Results for MathInlineMacroRx

func (*MathInlineMacroRxres) MathSub

func (mimr *MathInlineMacroRxres) MathSub() string

Return sub 'xx' in 'math:xx[yyy]'

func (*MathInlineMacroRxres) MathText

func (mimr *MathInlineMacroRxres) MathText() string

Return text 'yyy' in 'math:xx[yyy]'

func (*MathInlineMacroRxres) MathType

func (mimr *MathInlineMacroRxres) MathType() string

Return type 'math' in 'math:xx[yyy]'

type MenuInlineMacroRxres struct {
	*Reres
}

func NewMenuInlineMacroRxres

func NewMenuInlineMacroRxres(s string) *MenuInlineMacroRxres

Results for KbdBtnInlineMacroRx

func (mimr *MenuInlineMacroRxres) MenuItems() string

Return items of the macro xxx in 'menu:name[xxx]'

func (mimr *MenuInlineMacroRxres) MenuName() string

Return name of the macro in 'menu:name[xxx]'

type MenuInlineRxres struct {
	*Reres
}

func NewMenuInlineRxres

func NewMenuInlineRxres(s string) *MenuInlineRxres

Results for MenuInlineRx

func (mir *MenuInlineRxres) MenuInput() string

Return input of the macro in '"File &gt; New"'

type PassInlineLiteralRxres

type PassInlineLiteralRxres struct {
	*Reres
}

func NewPassInlineLiteralRxres

func NewPassInlineLiteralRxres(s string) *PassInlineLiteralRxres

Results for PassInlineLiteralRx

func (*PassInlineLiteralRxres) Attributes

func (pilr *PassInlineLiteralRxres) Attributes() string

func (*PassInlineLiteralRxres) FirstChar

func (pilr *PassInlineLiteralRxres) FirstChar() string

func (*PassInlineLiteralRxres) Literal

func (pilr *PassInlineLiteralRxres) Literal() string

func (*PassInlineLiteralRxres) LiteralText

func (pilr *PassInlineLiteralRxres) LiteralText() string

type PassInlineMacroRxres

type PassInlineMacroRxres struct {
	*Reres
}

func NewPassInlineMacroRxres

func NewPassInlineMacroRxres(s string) *PassInlineMacroRxres

Results for PassInlineMacroRx

func (*PassInlineMacroRxres) HasPassSub

func (pr *PassInlineMacroRxres) HasPassSub() bool

Check if has sub 'xx' in 'pass:xx[yyy]'

func (*PassInlineMacroRxres) HasPassText

func (pr *PassInlineMacroRxres) HasPassText() bool

Check if has text 'yyy' in 'pass:xx[yyy]'

func (*PassInlineMacroRxres) InlineSub

func (pr *PassInlineMacroRxres) InlineSub() string

Return text 'xx' in 'xxyyyxx'

func (*PassInlineMacroRxres) InlineText

func (pr *PassInlineMacroRxres) InlineText() string

Return text 'yyy' in 'xxyyyxx'

func (*PassInlineMacroRxres) PassSub

func (pr *PassInlineMacroRxres) PassSub() string

Return sub 'xx' in 'pass:xx[yyy]'

func (*PassInlineMacroRxres) PassText

func (pr *PassInlineMacroRxres) PassText() string

Return text 'yyy' in 'pass:xx[yyy]'

type Qualifier

type Qualifier func(lh string, match []int, s string) bool

type Replacement

type Replacement struct {
	// contains filtered or unexported fields
}

func (*Replacement) Bounding

func (r *Replacement) Bounding() bool

func (*Replacement) EndsWithLookAhead

func (r *Replacement) EndsWithLookAhead() bool

func (*Replacement) Leading

func (r *Replacement) Leading() bool

func (*Replacement) None

func (r *Replacement) None() bool

func (*Replacement) Repl

func (r *Replacement) Repl() string

func (*Replacement) Reres

func (r *Replacement) Reres(text string) *Reres

func (*Replacement) Rx

func (r *Replacement) Rx() *regexp.Regexp

type Reres

type Reres struct {
	// contains filtered or unexported fields
}
Encapsulate a regex and a string,

for managing results from FindAllStringSubmatchIndex

func NewReres

func NewReres(s string, r *regexp.Regexp) *Reres

Build new result from FindAllStringSubmatchIndex on a string

func NewReresLAGroup

func NewReresLAGroup(s string, r *regexp.Regexp) *Reres
Build new result from FindAllStringSubmatchIndex on a string,

validated by last group being a lookahead after each match

func NewReresLAQual

func NewReresLAQual(s string, r *regexp.Regexp, q Qualifier) *Reres
Build new result from FindAllStringSubmatchIndex on a string,

validated by last group being a lookahead after each match, if that last group match qualifies

func (*Reres) FirstChar

func (rr *Reres) FirstChar() uint8

First character of the current match

func (*Reres) FullMatch

func (rr *Reres) FullMatch() string

Full string matched for the current group

func (*Reres) Group

func (rr *Reres) Group(i int) string

return the ith group string, if present in the current match

func (*Reres) HasAnyMatch

func (rr *Reres) HasAnyMatch() bool

Check if there is any match

func (*Reres) HasGroup

func (rr *Reres) HasGroup(j int) bool

Check if the ith group if present in the current match

func (*Reres) HasNext

func (rr *Reres) HasNext() bool

Check if there is one more match

func (*Reres) IsEscaped

func (rr *Reres) IsEscaped() bool

Test if first character of the current match is an escape

func (*Reres) Next

func (rr *Reres) Next()

Refers to the next match, for Group() to works with

func (*Reres) Prefix

func (rr *Reres) Prefix() string

String from the last match to current one

func (*Reres) ResetNext

func (rr *Reres) ResetNext()

Get back to the first match

func (*Reres) String

func (r *Reres) String() string

func (*Reres) Suffix

func (rr *Reres) Suffix() string

String from current match to the end ofthe all string

func (*Reres) Text

func (rr *Reres) Text() string

full initial text on which the regex was applied

type XrefInlineMacroRxres

type XrefInlineMacroRxres struct {
	*Reres
}

func NewXrefInlineMacroRxres

func NewXrefInlineMacroRxres(s string) *XrefInlineMacroRxres

Results for XrefInlineMacroRx

func (*XrefInlineMacroRxres) XId

func (ximr *XrefInlineMacroRxres) XId() string

Return id of '<<id,reftext>>' or xref:id[reftext]'

func (*XrefInlineMacroRxres) XrefText

func (ximr *XrefInlineMacroRxres) XrefText() string

Return reftext of '<<id,reftext>>' or xref:id[reftext]'

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL