Class: TextPeg

Inherits:
RubyPeg show all
Defined in:
lib/textpeg.rb

Instance Attribute Summary

Attributes inherited from RubyPeg

#index, #sequences, #text_to_parse

Instance Method Summary collapse

Methods inherited from RubyPeg

#any_character, #any_number_of, #followed_by, #ignore, #node, #not_followed_by, #one_or_more, #optional, #parse, parse, parse_and_dump, #pretty_print_cache, #sequence, #terminal

Instance Method Details

#_any_character ⇒ Object



146
147
148
149
150
# File 'lib/textpeg.rb', line 146

def _any_character
  node :any_character do
    ignore { terminal(".") } && spacing
  end
end

#_any_number_of ⇒ Object



98
99
100
101
102
# File 'lib/textpeg.rb', line 98

def _any_number_of
  node :any_number_of do
    element && ignore { terminal("*") }
  end
end

#_followed_by ⇒ Object



80
81
82
83
84
# File 'lib/textpeg.rb', line 80

def _followed_by
  node :followed_by do
    ignore { terminal("&") } && element
  end
end

#_node ⇒ Object



16
17
18
19
20
# File 'lib/textpeg.rb', line 16

def _node
  node :node do
    identifier && assigns && expression && end_of_line
  end
end

#_not_followed_by ⇒ Object



74
75
76
77
78
# File 'lib/textpeg.rb', line 74

def _not_followed_by
  node :not_followed_by do
    ignore { terminal("!") } && element
  end
end

#_one_or_more ⇒ Object



104
105
106
107
108
# File 'lib/textpeg.rb', line 104

def _one_or_more
  node :one_or_more do
    element && ignore { terminal("+") }
  end
end

#_optional ⇒ Object



92
93
94
95
96
# File 'lib/textpeg.rb', line 92

def _optional
  node :optional do
    element && ignore { terminal("?") }
  end
end

#_sequence ⇒ Object



46
47
48
49
50
# File 'lib/textpeg.rb', line 46

def _sequence
  node :sequence do
    one_or_more { (elements && spacing) }
  end
end

#alternatives ⇒ Object



52
53
54
55
56
# File 'lib/textpeg.rb', line 52

def alternatives
  node :alternatives do
    elements && one_or_more { (divider && elements) }
  end
end

#assigns ⇒ Object



34
35
36
# File 'lib/textpeg.rb', line 34

def assigns
  ignore { terminal(":=") } && spacing
end

#bracketed_expression ⇒ Object



114
115
116
117
118
# File 'lib/textpeg.rb', line 114

def bracketed_expression
  node :bracketed_expression do
    ignore { terminal("(") } && spacing && expression && ignore { terminal(")") } && spacing
  end
end

#definition ⇒ Object



22
23
24
25
26
# File 'lib/textpeg.rb', line 22

def definition
  node :definition do
    identifier && equals && expression && end_of_line
  end
end

#divider ⇒ Object



58
59
60
# File 'lib/textpeg.rb', line 58

def divider
  ignore { terminal("|") } && spacing
end

#double_quoted_string ⇒ Object



126
127
128
# File 'lib/textpeg.rb', line 126

def double_quoted_string
  ignore { terminal("\"") } && terminal(/[^"]*/) && ignore { terminal("\"") } && spacing
end

#element ⇒ Object



110
111
112
# File 'lib/textpeg.rb', line 110

def element
  bracketed_expression || identifier || terminal_string || terminal_regexp || terminal_character_range || _any_character
end

#elements ⇒ Object



62
63
64
# File 'lib/textpeg.rb', line 62

def elements
  prefixed || suffixed || element
end

#end_of_line ⇒ Object



152
153
154
# File 'lib/textpeg.rb', line 152

def end_of_line
  ignore { terminal(/[\n\r]+|\z/) }
end

#equals ⇒ Object



38
39
40
# File 'lib/textpeg.rb', line 38

def equals
  ignore { terminal("=") } && spacing
end

#expression ⇒ Object



42
43
44
# File 'lib/textpeg.rb', line 42

def expression
  alternatives || _sequence
end

#identifier ⇒ Object



28
29
30
31
32
# File 'lib/textpeg.rb', line 28

def identifier
  node :identifier do
    terminal(/[a-zA-Z_][a-zA-Z0-9_]*/) && spacing
  end
end

#ignored ⇒ Object



86
87
88
89
90
# File 'lib/textpeg.rb', line 86

def ignored
  node :ignored do
    ignore { terminal("`") } && element
  end
end

#prefixed ⇒ Object



66
67
68
# File 'lib/textpeg.rb', line 66

def prefixed
  ignored || _not_followed_by || _followed_by
end

#root ⇒ Object



6
7
8
# File 'lib/textpeg.rb', line 6

def root
  text_peg
end

#single_quoted_string ⇒ Object



130
131
132
# File 'lib/textpeg.rb', line 130

def single_quoted_string
  ignore { terminal("'") } && terminal(/[^']*/) && ignore { terminal("'") } && spacing
end

#spacing ⇒ Object



156
157
158
# File 'lib/textpeg.rb', line 156

def spacing
  ignore { terminal(/[ \t]*/) }
end

#suffixed ⇒ Object



70
71
72
# File 'lib/textpeg.rb', line 70

def suffixed
  _optional || _any_number_of || _one_or_more
end

#terminal_character_range ⇒ Object



134
135
136
137
138
# File 'lib/textpeg.rb', line 134

def terminal_character_range
  node :terminal_character_range do
    terminal(/\[[a-zA-Z\-0-9]*\]/) && spacing
  end
end

#terminal_regexp ⇒ Object



140
141
142
143
144
# File 'lib/textpeg.rb', line 140

def terminal_regexp
  node :terminal_regexp do
    ignore { terminal("/") } && terminal(/(\\\/|[^\x2f])*/) && ignore { terminal("/") } && spacing
  end
end

#terminal_string ⇒ Object



120
121
122
123
124
# File 'lib/textpeg.rb', line 120

def terminal_string
  node :terminal_string do
    single_quoted_string || double_quoted_string
  end
end

#text_peg ⇒ Object



10
11
12
13
14
# File 'lib/textpeg.rb', line 10

def text_peg
  node :text_peg do
    any_number_of { (spacing && (_node || definition)) }
  end
end