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_characterObject



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

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

#_any_number_ofObject



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

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

#_followed_byObject



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

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

#_nodeObject



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

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

#_not_followed_byObject



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

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

#_one_or_moreObject



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

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

#_optionalObject



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

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

#_sequenceObject



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

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

#alternativesObject



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

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

#assignsObject



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

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

#bracketed_expressionObject



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

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

#definitionObject



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

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

#dividerObject



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

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

#double_quoted_stringObject



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

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

#elementObject



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

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

#elementsObject



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

def elements
  prefixed || suffixed || element
end

#end_of_lineObject



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

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

#equalsObject



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

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

#expressionObject



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

def expression
  alternatives || _sequence
end

#identifierObject



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

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

#ignoredObject



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

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

#prefixedObject



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

def prefixed
  ignored || _not_followed_by || _followed_by
end

#rootObject



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

def root
  text_peg
end

#single_quoted_stringObject



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

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

#spacingObject



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

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

#suffixedObject



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

def suffixed
  _optional || _any_number_of || _one_or_more
end

#terminal_character_rangeObject



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

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

#terminal_regexpObject



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

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

#terminal_stringObject



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

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

#text_pegObject



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

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