Top Level Namespace
Defined Under Namespace
Modules: Indexable, Parse, Profiler, Rpdf2txt, SourceCodeDumpable
Classes: AmbigousParseException, AmbiguityNode, Array, ArrayNode, ArrayNodeBuilder, ArrayOfArrays, ArrayOfHashes, BackLinkedDirectedGraph, BooleanMatrix, BoundedLruCache, ComplexTest, DagPropagator, DefaultInitArray, DefaultInitHash, DirectedGraph, DotGraph, DotGraphFormatter, DotGraphPrinter, Element, EofToken, EpsilonToken, ForkingRegexpLexer, GeneralizedLrParser, Grammar, GrammarSymbol, GraphLink, GraphTraversalException, GroupingSyntaxTreeBuilder, Hash, HashOfHash, IndexableFactory, Integer, Item, LexerPosition, LexerToken, LiftingSyntaxTreeBuilder, ListElement, LrState, MaybeElement, MultElement, NonTerminal, Object, OperatorElement, OrElement, ParseException, ParseStack, ParseTable, PlusElement, Production, ReduceActionsGenerator, ReferencingRegexpLexer, Regexp, RegexpToken, StackPath, StringScanner, StringToken, SyntaxTree, SyntaxTreeAsDotGraph, SyntaxTreeBuilder, TerminalSet, Token, TokenRegexp
Constant Summary
collapse
- TimesClass =
(RUBY_VERSION < "1.7") ? Time : Process
Instance Method Summary
collapse
-
#as_array(subElements) ⇒ Object
-
#calc_masks(start, stop, masks = Array.new) ⇒ Object
-
#liste(subElements, separator) ⇒ Object
-
#make_element(anObject) ⇒ Object
To make it simple to enter productions some standard Ruby objects can be used in place of the “proper” objects.
-
#make_elements(anArrayOrElement, anArray = []) ⇒ Object
-
#maybe(*subElements) ⇒ Object
-
#mult(*subElements) ⇒ Object
-
#ore(*subElements) ⇒ Object
-
#parsestack_as_dot_digraph(stack, nodes = Hash.new, links = Hash.new) ⇒ Object
-
#parsestacks_as_dot_digraph(stacks) ⇒ Object
-
#plus(*subElements) ⇒ Object
-
#prod(nonterminal, elements, treeSpec = nil) ⇒ Object
-
#r?(tokenregexp) ⇒ Boolean
-
#regexp_token(regexp, *options) ⇒ Object
-
#rm(tokenregexp) ⇒ Object
-
#rockit_version ⇒ Object
-
#ror(*tokens) ⇒ Object
-
#rp(tokenregexp) ⇒ Object
-
#rseq(*tokens) ⇒ Object
-
#stack_to_node(stack, includeShape = false) ⇒ Object
-
#stb(nodeName, childrenNames = [], inactiveChildren = []) ⇒ Object
Short hand SyntaxTreeBuilder creator.
-
#string_token(string) ⇒ Object
-
#syntaxtree_as_dot_digraph(syntaxtree) ⇒ Object
-
#t(name, re, *options) ⇒ Object
-
#time_and_puts(string, &block) ⇒ Object
-
#tr(aStringOrRegexp) ⇒ Object
Short hands for composing token regexp’s.
-
#tre_compose(tokens, map, separator) ⇒ Object
Instance Method Details
#as_array(subElements) ⇒ Object
302
303
304
305
306
307
308
|
# File 'lib/rpdf2txt-rockit/grammar.rb', line 302
def as_array(subElements)
if subElements.length == 1 and subElements[0].kind_of?(Array)
subElements[0]
else
subElements
end
end
|
#calc_masks(start, stop, masks = Array.new) ⇒ Object
341
342
343
344
345
|
# File 'lib/rpdf2txt-rockit/directed_graph.rb', line 341
def calc_masks(start, stop, masks = Array.new)
mask = 1 << start
(start..stop).each {|i| masks[i] = mask; mask <<= 1}
masks
end
|
#liste(subElements, separator) ⇒ Object
314
|
# File 'lib/rpdf2txt-rockit/grammar.rb', line 314
def liste(subElements, separator); ListElement.new(subElements, separator); end
|
#make_element(anObject) ⇒ Object
To make it simple to enter productions some standard Ruby objects can be used in place of the “proper” objects. This function converts to the right type or raises an exception if object cannot be made into an element.
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/rpdf2txt-rockit/grammar.rb', line 71
def make_element(anObject)
if anObject.kind_of?(String)
string_token(anObject)
elsif anObject.kind_of?(Regexp)
regexp_token(anObject)
elsif anObject.kind_of?(Symbol)
NonTerminal.new(anObject.to_s)
elsif anObject.kind_of?(NonTerminal) or anObject.kind_of?(Token) or
anObject.kind_of?(OperatorElement)
anObject
else
raise ArgumentError, "cannot make an element from #{anObject.inspect}"
end
end
|
#make_elements(anArrayOrElement, anArray = []) ⇒ Object
86
87
88
89
90
91
92
93
|
# File 'lib/rpdf2txt-rockit/grammar.rb', line 86
def make_elements(anArrayOrElement, anArray = [])
if anArrayOrElement.kind_of?(Array)
anArrayOrElement += anArray
else
anArrayOrElement = [anArrayOrElement] + anArray
end
anArrayOrElement.map {|e| make_element(e)}
end
|
#maybe(*subElements) ⇒ Object
312
|
# File 'lib/rpdf2txt-rockit/grammar.rb', line 312
def maybe(*subElements); MaybeElement.new(as_array(subElements)); end
|
#mult(*subElements) ⇒ Object
311
|
# File 'lib/rpdf2txt-rockit/grammar.rb', line 311
def mult(*subElements); MultElement.new(as_array(subElements)); end
|
#ore(*subElements) ⇒ Object
313
|
# File 'lib/rpdf2txt-rockit/grammar.rb', line 313
def ore(*subElements); OrElement.new(as_array(subElements)); end
|
#parsestack_as_dot_digraph(stack, nodes = Hash.new, links = Hash.new) ⇒ Object
10
11
12
13
14
15
16
17
|
# File 'lib/rpdf2txt-rockit/graphdrawing.rb', line 10
def parsestack_as_dot_digraph(stack, nodes = Hash.new, links = Hash.new)
nodes[stack] = stack_to_node(stack, true)
stack.links.each do |link|
nodes, links = parsestack_as_dot_digraph(link.stack, nodes, links)
links[link] = "#{stack_to_node(stack).inspect} -> #{stack_to_node(link.stack).inspect} [label=#{link.tree.inspect_compact.inspect}]"
end
return nodes, links
end
|
#parsestacks_as_dot_digraph(stacks) ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/rpdf2txt-rockit/graphdrawing.rb', line 19
def parsestacks_as_dot_digraph(stacks)
nodes, links = {}, {}
stacks.each do |stack|
nodes, links = parsestack_as_dot_digraph(stack, nodes, links)
end
"digraph G {\nsize=\"8,11\"\n" +
nodes.values.uniq.join("\n") + "\n" +
links.values.uniq.join("\n") + "\n" +
"}"
end
|
#plus(*subElements) ⇒ Object
310
|
# File 'lib/rpdf2txt-rockit/grammar.rb', line 310
def plus(*subElements); PlusElement.new(as_array(subElements)); end
|
#prod(nonterminal, elements, treeSpec = nil) ⇒ Object
483
484
485
|
# File 'lib/rpdf2txt-rockit/grammar.rb', line 483
def prod(nonterminal, elements, treeSpec = nil)
Production.new(nonterminal, elements, treeSpec)
end
|
#r?(tokenregexp) ⇒ Boolean
50
51
52
|
# File 'lib/rpdf2txt-rockit/token.rb', line 50
def r?(tokenregexp)
tr("(%s)?" % tokenregexp.string)
end
|
#regexp_token(regexp, *options) ⇒ Object
194
195
196
|
# File 'lib/rpdf2txt-rockit/token.rb', line 194
def regexp_token(regexp, *options)
RegexpToken.new("RegexpToken" + regexp.hash.inspect, regexp, *options)
end
|
#rm(tokenregexp) ⇒ Object
54
55
56
|
# File 'lib/rpdf2txt-rockit/token.rb', line 54
def rm(tokenregexp)
tr("(%s)*" % tokenregexp.string)
end
|
#rockit_version ⇒ Object
1
2
3
|
# File 'lib/rpdf2txt-rockit/version.rb', line 1
def rockit_version
"0.3.8"
end
|
#ror(*tokens) ⇒ Object
42
43
44
|
# File 'lib/rpdf2txt-rockit/token.rb', line 42
def ror(*tokens)
tre_compose(tokens, "(%s)", "|")
end
|
#rp(tokenregexp) ⇒ Object
58
59
60
|
# File 'lib/rpdf2txt-rockit/token.rb', line 58
def rp(tokenregexp)
tr("(%s)+" % tokenregexp.string)
end
|
#rseq(*tokens) ⇒ Object
46
47
48
|
# File 'lib/rpdf2txt-rockit/token.rb', line 46
def rseq(*tokens)
tre_compose(tokens, "(%s)", "")
end
|
#stack_to_node(stack, includeShape = false) ⇒ Object
2
3
4
5
6
7
8
|
# File 'lib/rpdf2txt-rockit/graphdrawing.rb', line 2
def stack_to_node(stack, includeShape = false)
str = "#{stack.state} (#{stack.lexer.position.char_position})"
if includeShape
str = str.inspect + " [shape=box]"
end
str
end
|
#stb(nodeName, childrenNames = [], inactiveChildren = []) ⇒ Object
Short hand SyntaxTreeBuilder creator
141
142
143
144
145
146
147
148
|
# File 'lib/rpdf2txt-rockit/syntax_tree.rb', line 141
def stb(nodeName, childrenNames = [], inactiveChildren = [])
nodeName = nodeName.to_s
if nodeName == "^"
LiftingSyntaxTreeBuilder.new(childrenNames, inactiveChildren)
else
SyntaxTreeBuilder.new(nodeName, childrenNames, inactiveChildren)
end
end
|
#string_token(string) ⇒ Object
183
184
185
|
# File 'lib/rpdf2txt-rockit/token.rb', line 183
def string_token(string)
StringToken.new("StrToken" + string.hash.inspect, string)
end
|
#syntaxtree_as_dot_digraph(syntaxtree) ⇒ Object
102
103
104
|
# File 'lib/rpdf2txt-rockit/graphdrawing.rb', line 102
def syntaxtree_as_dot_digraph(syntaxtree)
SyntaxTreeAsDotGraph.new.to_graph(syntaxtree)
end
|
#t(name, re, *options) ⇒ Object
198
199
200
201
202
203
204
|
# File 'lib/rpdf2txt-rockit/token.rb', line 198
def t(name, re, *options)
if re.class == String
StringToken.new("StrToken" + re.hash.inspect, re)
else
Token.new(name, re, *options)
end
end
|
#time_and_puts(string, &block) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/rpdf2txt-rockit/base_extensions.rb', line 60
def time_and_puts(string, &block)
if $TIME_AND_PUTS_VERBOSE
print string; STDOUT.flush
end
starttime = [Time.new, TimesClass.times]
block.call
endtime = [Time.new, TimesClass.times]
duration = endtime[0] - starttime[0]
begin
load = [((endtime[1].utime+endtime[1].stime)-(starttime[1].utime+starttime[1].stime))/duration*100.0, 100.0].min
puts " (%.2f s %.2f%%)" % [duration, load] if $TIME_AND_PUTS_VERBOSE
rescue FloatDomainError
end
end
|
#tr(aStringOrRegexp) ⇒ Object
Short hands for composing token regexp’s
31
32
33
34
|
# File 'lib/rpdf2txt-rockit/token.rb', line 31
def tr(aStringOrRegexp)
aStringOrRegexp = aStringOrRegexp.source if aStringOrRegexp.class == Regexp
TokenRegexp.new(aStringOrRegexp)
end
|
#tre_compose(tokens, map, separator) ⇒ Object
36
37
38
39
40
|
# File 'lib/rpdf2txt-rockit/token.rb', line 36
def tre_compose(tokens, map, separator)
str = (map % tokens[0].string)
tokens[1..-1].each {|token| str += separator + (map % token.string)}
tr(str)
end
|