class Pegmatite::Pattern::Label

Overview

Pattern::Label is used to provide a symbolic name for a pattern, usually for the purposes of producing a token that marks the range of bytes that was matched by the child pattern, though if @tokenize is set to false, then no token will be produced and the name is used only for description, which is useful for making clearer error messages when the match fails.

If the child pattern also produces tokens, those tokens will appear after the token that was created by this Pattern::Label, and these can be distinguished in the token stream by the fact that all such tokens will have offset ranges that are sub-ranges of the offset range of the prior.

Returns the result of the child pattern's parsing, possibly preceded with a new token whose symbol is the symbolic name assigned to this pattern.

Defined in:

pegmatite/pattern/label.cr

Constructors

Instance Method Summary

Instance methods inherited from class Pegmatite::Pattern

_match(source, offset, state) : MatchResult _match, match(source, offset, state) : MatchResult match

Instance methods inherited from module Pegmatite::DSL::Methods

>>(other) >>, ^(other) ^, |(other) |, ~ ~, dynamic_pop(label) dynamic_pop, dynamic_push(label) dynamic_push, maybe maybe, named(label, tokenize = true) named, repeat(min = 0, max = nil) repeat, repeat_exactly(times) repeat_exactly, then_eof then_eof

Constructor Detail

def self.new(child : Pattern, label : Symbol, tokenize : Bool = true) #

[View source]

Instance Method Detail

def _match(source, offset, state) : MatchResult #

[View source]
def description #

[View source]
def dsl_name #

[View source]
def inspect(io) #

[View source]