rpdf2txt 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. data/History.txt +5 -0
  2. data/LICENCE +515 -0
  3. data/Manifest.txt +126 -0
  4. data/README.txt +30 -0
  5. data/Rakefile +24 -0
  6. data/bin/rpdf2txt +58 -0
  7. data/config.save +12 -0
  8. data/install.rb +1098 -0
  9. data/lib/rpdf2txt-rockit/base_extensions.rb +73 -0
  10. data/lib/rpdf2txt-rockit/bootstrap.rb +120 -0
  11. data/lib/rpdf2txt-rockit/bounded_lru_cache.rb +43 -0
  12. data/lib/rpdf2txt-rockit/conflict_resolution.rb +302 -0
  13. data/lib/rpdf2txt-rockit/directed_graph.rb +401 -0
  14. data/lib/rpdf2txt-rockit/glr_parser.rb +393 -0
  15. data/lib/rpdf2txt-rockit/grammar.rb +644 -0
  16. data/lib/rpdf2txt-rockit/graphdrawing.rb +107 -0
  17. data/lib/rpdf2txt-rockit/graphviz_dot.rb +63 -0
  18. data/lib/rpdf2txt-rockit/indexable.rb +53 -0
  19. data/lib/rpdf2txt-rockit/lalr_parsetable_generator.rb +144 -0
  20. data/lib/rpdf2txt-rockit/parse_table.rb +273 -0
  21. data/lib/rpdf2txt-rockit/parsetable_generation.rb +164 -0
  22. data/lib/rpdf2txt-rockit/parsing_ambiguities.rb +84 -0
  23. data/lib/rpdf2txt-rockit/profiler.rb +168 -0
  24. data/lib/rpdf2txt-rockit/reduce_actions_generator.rb +523 -0
  25. data/lib/rpdf2txt-rockit/rockit.rb +76 -0
  26. data/lib/rpdf2txt-rockit/rockit_grammar_ast_eval.rb +187 -0
  27. data/lib/rpdf2txt-rockit/rockit_grammars_parser.rb +126 -0
  28. data/lib/rpdf2txt-rockit/sourcecode_dumpable.rb +181 -0
  29. data/lib/rpdf2txt-rockit/stringscanner.rb +54 -0
  30. data/lib/rpdf2txt-rockit/syntax_tree.rb +452 -0
  31. data/lib/rpdf2txt-rockit/token.rb +364 -0
  32. data/lib/rpdf2txt-rockit/version.rb +3 -0
  33. data/lib/rpdf2txt/attributesparser.rb +42 -0
  34. data/lib/rpdf2txt/cmapparser.rb +65 -0
  35. data/lib/rpdf2txt/data/_cmap.grammar +11 -0
  36. data/lib/rpdf2txt/data/_cmap_range.grammar +15 -0
  37. data/lib/rpdf2txt/data/_pdfattributes.grammar +32 -0
  38. data/lib/rpdf2txt/data/cmap.grammar +11 -0
  39. data/lib/rpdf2txt/data/cmap.rb +37 -0
  40. data/lib/rpdf2txt/data/cmap_range.grammar +15 -0
  41. data/lib/rpdf2txt/data/cmap_range.rb +43 -0
  42. data/lib/rpdf2txt/data/fonts/Courier-Bold.afm +342 -0
  43. data/lib/rpdf2txt/data/fonts/Courier-BoldOblique.afm +342 -0
  44. data/lib/rpdf2txt/data/fonts/Courier-Oblique.afm +342 -0
  45. data/lib/rpdf2txt/data/fonts/Courier.afm +342 -0
  46. data/lib/rpdf2txt/data/fonts/Helvetica-Bold.afm +2827 -0
  47. data/lib/rpdf2txt/data/fonts/Helvetica-BoldOblique.afm +2827 -0
  48. data/lib/rpdf2txt/data/fonts/Helvetica-Oblique.afm +3051 -0
  49. data/lib/rpdf2txt/data/fonts/Helvetica.afm +3051 -0
  50. data/lib/rpdf2txt/data/fonts/License-Adobe.txt +65 -0
  51. data/lib/rpdf2txt/data/fonts/Symbol.afm +213 -0
  52. data/lib/rpdf2txt/data/fonts/Times-Bold.afm +2588 -0
  53. data/lib/rpdf2txt/data/fonts/Times-BoldItalic.afm +2384 -0
  54. data/lib/rpdf2txt/data/fonts/Times-Italic.afm +2667 -0
  55. data/lib/rpdf2txt/data/fonts/Times-Roman.afm +2419 -0
  56. data/lib/rpdf2txt/data/fonts/ZapfDingbats.afm +225 -0
  57. data/lib/rpdf2txt/data/pdfattributes.grammar +32 -0
  58. data/lib/rpdf2txt/data/pdfattributes.rb +71 -0
  59. data/lib/rpdf2txt/data/pdftext.grammar +102 -0
  60. data/lib/rpdf2txt/data/pdftext.rb +146 -0
  61. data/lib/rpdf2txt/default_handler.rb +352 -0
  62. data/lib/rpdf2txt/lzw.rb +69 -0
  63. data/lib/rpdf2txt/object.rb +1114 -0
  64. data/lib/rpdf2txt/parser.rb +169 -0
  65. data/lib/rpdf2txt/symbol.rb +408 -0
  66. data/lib/rpdf2txt/text.rb +182 -0
  67. data/lib/rpdf2txt/text_state.rb +434 -0
  68. data/lib/rpdf2txt/textparser.rb +42 -0
  69. data/test/data/3392_obj +0 -0
  70. data/test/data/397_decrypted +15 -0
  71. data/test/data/450_decrypted +153 -0
  72. data/test/data/450_obj +0 -0
  73. data/test/data/452_decrypted +125 -0
  74. data/test/data/454_decrypted +108 -0
  75. data/test/data/456_decrypted +106 -0
  76. data/test/data/458_decrypted +111 -0
  77. data/test/data/458_obj +0 -0
  78. data/test/data/460_decrypted +118 -0
  79. data/test/data/460_obj +0 -0
  80. data/test/data/463_decrypted +117 -0
  81. data/test/data/465_decrypted +107 -0
  82. data/test/data/465_obj +0 -0
  83. data/test/data/90_obj +0 -0
  84. data/test/data/90_obj_comp +1 -0
  85. data/test/data/decrypted +0 -0
  86. data/test/data/encrypt_obj +0 -0
  87. data/test/data/encrypt_string +0 -0
  88. data/test/data/encrypt_string_128bit +0 -0
  89. data/test/data/encrypted_object_stream.pdf +0 -0
  90. data/test/data/firststream +1 -0
  91. data/test/data/index.pdfobj +0 -0
  92. data/test/data/index_2bit.pdfobj +0 -0
  93. data/test/data/index_masked.pdfobj +0 -0
  94. data/test/data/indexed.pdfobj +0 -0
  95. data/test/data/indexed_2bit.pdfobj +0 -0
  96. data/test/data/indexed_masked.pdfobj +0 -0
  97. data/test/data/inline.png +0 -0
  98. data/test/data/logo.png +0 -0
  99. data/test/data/lzw.pdfobj +0 -0
  100. data/test/data/lzw_index.pdfobj +0 -0
  101. data/test/data/page_tree.pdf +148 -0
  102. data/test/data/pdf_20.png +0 -0
  103. data/test/data/pdf_21.png +0 -0
  104. data/test/data/pdf_22.png +0 -0
  105. data/test/data/pdf_50.png +0 -0
  106. data/test/data/png.pdfobj +0 -0
  107. data/test/data/space_bug_stream.txt +119 -0
  108. data/test/data/stream.txt +292 -0
  109. data/test/data/stream_kerning_bug.txt +13 -0
  110. data/test/data/stream_kerning_bug2.txt +6 -0
  111. data/test/data/test.pdf +0 -0
  112. data/test/data/test.txt +8 -0
  113. data/test/data/test_text.txt +42 -0
  114. data/test/data/working_obj +0 -0
  115. data/test/data/working_obj2 +0 -0
  116. data/test/mock.rb +149 -0
  117. data/test/suite.rb +30 -0
  118. data/test/test_pdf_object.rb +1802 -0
  119. data/test/test_pdf_parser.rb +1340 -0
  120. data/test/test_pdf_text.rb +789 -0
  121. data/test/test_space_bug_05_2004.rb +87 -0
  122. data/test/test_stream.rb +194 -0
  123. data/test/test_text_state.rb +315 -0
  124. data/usage-en.txt +112 -0
  125. data/user-stories/UserStories_Rpdf2Txt.txt +34 -0
  126. data/user-stories/documents/swissmedicjournal/04_2004.pdf +0 -0
  127. metadata +220 -0
@@ -0,0 +1,76 @@
1
+ require 'rpdf2txt-rockit/glr_parser'
2
+ require 'rpdf2txt-rockit/lalr_parsetable_generator'
3
+ require 'rpdf2txt-rockit/base_extensions'
4
+ require 'rpdf2txt-rockit/rockit_grammar_ast_eval'
5
+ require 'rpdf2txt-rockit/rockit_grammars_parser'
6
+
7
+ # Facade for rockit
8
+ module Parse
9
+ def Parse.parser_from_grammar(aGrammar,
10
+ parserType = GeneralizedLrParser,
11
+ tableGenerator = LaLr1ParseTableGenerator)
12
+ pt = tableGenerator.new(aGrammar).generate_parse_table
13
+ parserType.new(pt)
14
+ end
15
+
16
+ def Parse.generate_parser(aString,
17
+ parserType = GeneralizedLrParser,
18
+ tableGenerator = LaLr1ParseTableGenerator)
19
+ ast = rockit_grammars_parser.parse(aString)
20
+ ast.compact!
21
+ grammar = rockit_grammar_eval(ast)
22
+ Parse.parser_from_grammar(grammar)
23
+ end
24
+
25
+ def Parse.generate_parser_from_file_to_file(grammarFile,
26
+ outputFile,
27
+ parserName = nil,
28
+ moduleName = "Parse",
29
+ grammarParser = rockit_grammars_parser,
30
+ parserType = GeneralizedLrParser,
31
+ tableGen =
32
+ LaLr1ParseTableGenerator)
33
+ if parserName == nil or parserName.kind_of?(String)
34
+ parserName = as_module_method_named(moduleName, parserName || "parser")
35
+ end
36
+ grammar_text = nil
37
+ File.open(grammarFile, "r") {|f| grammar_text = f.read}
38
+ ast, grammar, parser = nil, nil, nil
39
+ time_and_puts("Parsing #{grammarFile}") {
40
+ ast = grammarParser.parse(grammar_text)
41
+ ast.compact!
42
+ }
43
+
44
+ # File.open(outputFile + ".graph", "w") {|f| f.write ast.to_graph}
45
+
46
+ time_and_puts("Building grammar from abstract syntax tree") {
47
+ grammar = rockit_grammar_eval(ast)
48
+ }
49
+ time_and_puts("Generating parser from grammar") {
50
+ parser = Parse.parser_from_grammar(grammar)
51
+ }
52
+ File.open(outputFile, "w") do |f|
53
+ time_and_puts("Writing parser to file #{outputFile}") {
54
+ f.write "require 'rpdf2txt-rockit/rockit'\n" +
55
+ parser.to_src_in_module(parserName, moduleName)
56
+ }
57
+ end
58
+ end
59
+ end
60
+
61
+ if __FILE__ == $0
62
+ if ARGV.length < 2
63
+ puts <<EOS
64
+ Rockit parser generator version #{rockit_version}
65
+ usage: #{$0} <grammar_file> <output_file> [module [method]]
66
+ EOS
67
+ exit(-1)
68
+ end
69
+
70
+ $TIME_AND_PUTS_VERBOSE = true
71
+
72
+ Parse.generate_parser_from_file_to_file(ARGV[0], ARGV[1],
73
+ ARGV[3] || "parser",
74
+ ARGV[2] || "Parse")
75
+
76
+ end
@@ -0,0 +1,187 @@
1
+
2
+ module Parse
3
+ # Evaluate a Rockit tokens section and return an array with the tokens
4
+ def rockit_tokens_eval(tokensAst)
5
+ tokens = Array.new
6
+ tokensAst.each do |node|
7
+ if node.name == "TokenSpec"
8
+ # VERY simple handling of options right now since only one is valid.
9
+ # Needs to be generalized...
10
+ if node.options
11
+ tokens.push t(node.tokenname.lexeme,
12
+ eval(node.regexp.lexeme), :Skip)
13
+ else
14
+ tokens.push t(node.tokenname.lexeme, eval(node.regexp.lexeme))
15
+ end
16
+ end
17
+ end
18
+ tokens
19
+ end
20
+ module_function :rockit_tokens_eval
21
+
22
+ # Evaluate priorities section. If given an array with productions
23
+ # we try to map the given SymbolNames to productions; if not we simply use
24
+ # the symbol names (as Ruby symbols) directly and the mapping must be done
25
+ # later.
26
+ def rockit_priorities_eval(prioritiesAst, productions = nil)
27
+ relations = priorities_as_relations(prioritiesAst).flatten
28
+ relations = map_symbolnames_to_productions(relations, productions)
29
+ ProductionPriorities.new(relations)
30
+ end
31
+ module_function :rockit_priorities_eval
32
+
33
+ def priorities_as_relations(prioritiesAst)
34
+ relations = Array.new
35
+ prioritiesAst.each do |node|
36
+ case node.name
37
+ when "Associativity"
38
+ # We use the left and right shorthand funcs defined in
39
+ # conflict_resolution.rb.
40
+ prod_refs = node.productionrefs.map {|sn| ":" + sn.lexeme}
41
+ relations << eval(node.relation.lexeme + prod_refs.join(',') + ')')
42
+ when "Precedence"
43
+ left = node.first
44
+ node.rest.childrens.each do |relation, right|
45
+ if relation.lexeme == '>'
46
+ relations.push decreasing_precedence(left.lexeme.intern,
47
+ right.lexeme.intern)
48
+ elsif relation.lexeme == '='
49
+ relations.push equal_precedence(left.lexeme.intern,
50
+ right.lexeme.intern)
51
+ end
52
+ left = right
53
+ end
54
+ end
55
+ end
56
+ relations
57
+ end
58
+ module_function :priorities_as_relations
59
+
60
+ # Maps symbolnames used in priorities section to the corresponding
61
+ # productions. The production reference is determined by the rules:
62
+ # 1. It is the AST node name of the productions tree_builder if it is
63
+ # unique and not "^" or "_" or nil, or
64
+ # 2. It is the nonterminal name + an index starting at 1 for each unique
65
+ # nonterminal.
66
+ def map_symbolnames_to_productions(relationsWithStringsAsProductions,
67
+ productions)
68
+ return relationsWithStringsAsProductions unless productions
69
+ map = production_reference_map(productions)
70
+ relationsWithStringsAsProductions.map do |relation|
71
+ new_left, new_right = map[relation.left], map[relation.right]
72
+ if nil == new_left or nil == new_right
73
+ raise "Could not map #{relation.inspect} to the productions involved"
74
+ end
75
+ relation.left, relation.right = new_left, new_right
76
+ relation
77
+ end
78
+ end
79
+ module_function :map_symbolnames_to_productions
80
+
81
+ def production_reference_map(productions)
82
+ map, production_counts = Hash.new, Hash.new(0)
83
+ ast_name_counts, nonterminal_counts = Hash.new(0), Hash.new(0)
84
+
85
+ # Pass 1 to get the count of the AST names and assign numbers
86
+ productions.each do |p|
87
+ a = ast_name_counts[p.tree_builder.node_name] += 1
88
+ b = nonterminal_counts[p.nonterminal.name] += 1
89
+ production_counts[p] = [a, b]
90
+ end
91
+
92
+ # Pass 2 to assign the names
93
+ productions.each do |production|
94
+ ast_name = production.tree_builder.node_name
95
+ if ["^", "_", :_, :^, nil].include?(ast_name) or
96
+ ast_name_counts[ast_name] != 1
97
+ ref = production.nonterminal.name +
98
+ production_counts[production].last.inspect
99
+ map[ref.intern] = production
100
+ else
101
+ map[ast_name.intern] = production
102
+ end
103
+ end
104
+
105
+ map
106
+ end
107
+ module_function :production_reference_map
108
+
109
+ # Return Array with the productions from a productionsAST.
110
+ # If an Array with tokens are given the token with the correct name is
111
+ # substituted for the name. If no matching token is found a Ruby Symbol
112
+ # is inserted.
113
+ def rockit_productions_eval(productionsAst, tokens = [])
114
+ evaluator = RockitProductionsEvaluator.new(tokens)
115
+ evaluator.eval_ast(productionsAst)
116
+ end
117
+ module_function :rockit_productions_eval
118
+
119
+ class RockitProductionsEvaluator
120
+ def initialize(tokens = [])
121
+ @token_map = Hash.new
122
+ tokens.each {|token| @token_map[token.name] = token}
123
+ end
124
+
125
+ def eval_ast(ast)
126
+ return nil unless ast
127
+ case ast.name
128
+ when "Productions"
129
+ ast.productions.map {|prod| eval_ast(prod)}.flatten
130
+ when "Prod"
131
+ nonterminal = eval_ast(ast.nonterminal)
132
+ ast.alts.map do |alt|
133
+ elements, treespec = eval_ast(alt)
134
+ prod(nonterminal, elements, treespec)
135
+ end
136
+ when "Alt"
137
+ [ast.elements.map {|e| eval_ast(e)},
138
+ eval_ast(ast.astspec)]
139
+ when "SymbolName"
140
+ symbol = ast.lexeme
141
+ @token_map[symbol] || symbol.intern
142
+ when "ImplicitToken"
143
+ eval(ast.regexp.lexeme) # Eval to String or Regexp
144
+ when "Maybe"
145
+ maybe(eval_ast(ast.element))
146
+ when "Plus"
147
+ plus(eval_ast(ast.element))
148
+ when "Mult"
149
+ mult(eval_ast(ast.element))
150
+ when "Or"
151
+ ore(*(ast.elements.map {|e| eval_ast(e)}))
152
+ when "Sequence"
153
+ ast.elements.map {|e| eval_ast(e)}
154
+ when "List"
155
+ liste(eval_ast(ast.element), eval_ast(ast.delimiter))
156
+ when "AstSpec"
157
+ if ast.elemspecs
158
+ elemspecs = ast.elemspecs.map {|e| e.lexeme.intern}
159
+ else
160
+ elemspecs = []
161
+ end
162
+ if ast.prodspec
163
+ prodspec = (ast.prodspec.lexeme == "^" ? :^ :eval_ast(ast.prodspec))
164
+ else
165
+ prodspec = nil
166
+ end
167
+ stb(prodspec, elemspecs)
168
+ when "Lift"
169
+ :^
170
+ end
171
+ end
172
+ end
173
+
174
+ def rockit_grammar_eval(grammarAst)
175
+ if grammarAst.tokens
176
+ tokens = rockit_tokens_eval(grammarAst.tokens)
177
+ else
178
+ tokens = []
179
+ end
180
+ productions = rockit_productions_eval(grammarAst.productions, tokens)
181
+ if grammarAst.priorities
182
+ priorities = rockit_priorities_eval(grammarAst.priorities, productions)
183
+ end
184
+ Grammar.new(grammarAst.language.lexeme, productions, tokens, priorities)
185
+ end
186
+ module_function :rockit_grammar_eval
187
+ end
@@ -0,0 +1,126 @@
1
+ require 'rpdf2txt-rockit/rockit'
2
+ module Parse
3
+ # Parser for RockitGrammar
4
+ # created by Rockit version 0.3.8 on Mon Dec 02 20:05:20 CET 2002
5
+ # Rockit is copyright (c) 2001 Robert Feldt, feldt@ce.chalmers.se
6
+ # and licensed under GPL
7
+ # but this parser is under LGPL
8
+ tokens = [
9
+ t1 = EofToken.new("EOF",/^(�~~��~^^~5348086680)/n),
10
+ t2 = Token.new("Blank",/^(\s+)/n,:Skip),
11
+ t3 = Token.new("Comment",/^(#.*$)/n,:Skip),
12
+ t4 = Token.new("Regexp",/^(\/((\\\/)|[^\/])*\/[iomnux]*)/n),
13
+ t5 = Token.new("String",/^(('((\\')|[^'])*')|("((\\")|[^"])*"))/n),
14
+ t6 = Token.new("Arrow",/^((->)|(::=)|(:))/n),
15
+ t7 = Token.new("Int",/^(\d+)/n),
16
+ t8 = Token.new("SymbolName",/^([A-Z][A-Za-z_\d]*)/n),
17
+ t9 = Token.new("LanguageName",/^([A-Za-z\d]+([-_]*[A-Za-z\d]+)*)/n),
18
+ t10 = Token.new("ProductionReference",/^([A-Z][A-Za-z]*\d+)/n),
19
+ t11 = StringToken.new("StrToken133007101","Grammar"),
20
+ t12 = StringToken.new("StrToken-511371276","Tokens"),
21
+ t13 = StringToken.new("StrToken62","="),
22
+ t14 = StringToken.new("StrToken93","["),
23
+ t15 = RegexpToken.new("RegexpToken538042562",/:Skip/in),
24
+ t16 = StringToken.new("StrToken95","]"),
25
+ t17 = StringToken.new("StrToken-904297951","Productions"),
26
+ t18 = StringToken.new("StrToken64","?"),
27
+ t19 = StringToken.new("StrToken44","+"),
28
+ t20 = StringToken.new("StrToken43","*"),
29
+ t21 = StringToken.new("StrToken41","("),
30
+ t22 = StringToken.new("StrToken42",")"),
31
+ t23 = StringToken.new("StrToken-171340643","list("),
32
+ t24 = StringToken.new("StrToken45",","),
33
+ t25 = StringToken.new("StrToken3923673",": "),
34
+ t26 = StringToken.new("StrToken836483639","Priorities"),
35
+ t27 = StringToken.new("StrToken127","|"),
36
+ t28 = RegexpToken.new("RegexpToken538577468",/[a-z][a-z\d]*/n),
37
+ t29 = StringToken.new("StrToken97","_"),
38
+ t30 = StringToken.new("StrToken96","^"),
39
+ t31 = StringToken.new("StrToken927166384","left("),
40
+ t32 = StringToken.new("StrToken618373319","right("),
41
+ t33 = StringToken.new("StrToken63",">")
42
+ ]
43
+ productions = [
44
+ p1 = Production.new("Grammar'".intern,[:Grammar],SyntaxTreeBuilder.new("Grammar'",["grammar"],[])),
45
+ p2 = Production.new(:Grammar,[t11, t9, :Tokens, :Productions, :Priorities],SyntaxTreeBuilder.new("Grammar",["_", "language", "tokens", "productions", "priorities"],[])),
46
+ p3 = Production.new(:Grammar,[t11, t9, :Tokens, :Productions],SyntaxTreeBuilder.new("Grammar",["_", "language", "tokens", "productions", "priorities"],[4])),
47
+ p4 = Production.new(:Grammar,[t11, t9, :Productions, :Priorities],SyntaxTreeBuilder.new("Grammar",["_", "language", "tokens", "productions", "priorities"],[2])),
48
+ p5 = Production.new(:Grammar,[t11, t9, :Productions],SyntaxTreeBuilder.new("Grammar",["_", "language", "tokens", "productions", "priorities"],[2, 4])),
49
+ p6 = Production.new(:Tokens,[t12, :Plus538048422],LiftingSyntaxTreeBuilder.new(["_", "tokens"],[])),
50
+ p7 = Production.new(:Plus538048422,[:Plus538048422, :TokenSpec],ArrayNodeBuilder.new([1],0,nil,nil,[],true)),
51
+ p8 = Production.new(:Plus538048422,[:TokenSpec],ArrayNodeBuilder.new([0],nil,nil,nil,[],true)),
52
+ p9 = Production.new(:TokenSpec,[t8, t13, t5, :TokenOpts],SyntaxTreeBuilder.new("TokenSpec",["tokenname", "_", "regexp", "options"],[])),
53
+ p10 = Production.new(:TokenSpec,[t8, t13, t5],SyntaxTreeBuilder.new("TokenSpec",["tokenname", "_", "regexp", "options"],[3])),
54
+ p11 = Production.new(:TokenSpec,[t8, t13, t4, :TokenOpts],SyntaxTreeBuilder.new("TokenSpec",["tokenname", "_", "regexp", "options"],[])),
55
+ p12 = Production.new(:TokenSpec,[t8, t13, t4],SyntaxTreeBuilder.new("TokenSpec",["tokenname", "_", "regexp", "options"],[3])),
56
+ p13 = Production.new(:TokenOpts,[t14, t15, t16],LiftingSyntaxTreeBuilder.new(["_", "options", "_"],[])),
57
+ p14 = Production.new(:Productions,[t17, :Plus538037652],SyntaxTreeBuilder.new("Productions",["_", "productions"],[])),
58
+ p15 = Production.new(:Plus538037652,[:Plus538037652, :Prod],ArrayNodeBuilder.new([1],0,nil,nil,[],true)),
59
+ p16 = Production.new(:Plus538037652,[:Prod],ArrayNodeBuilder.new([0],nil,nil,nil,[],true)),
60
+ p17 = Production.new(:Prod,[t8, t6, :Alt, :List538034742],ArrayNodeBuilder.new([2],3,SyntaxTreeBuilder.new("Prod",["nonterminal", "_", "alts"],[]),2,[3],false)),
61
+ p18 = Production.new(:Prod,[t8, t6, :Alt],ArrayNodeBuilder.new([2],nil,SyntaxTreeBuilder.new("Prod",["nonterminal", "_", "alts"],[]),2,[],true)),
62
+ p19 = Production.new(:List538034742,[:List538034742, t27, :Alt],ArrayNodeBuilder.new([2],0,nil,nil,[],true)),
63
+ p20 = Production.new(:List538034742,[t27, :Alt],ArrayNodeBuilder.new([1],nil,nil,nil,[],true)),
64
+ p21 = Production.new(:Alt,[:Plus538032372, :AstSpec],SyntaxTreeBuilder.new("Alt",["elements", "astspec"],[])),
65
+ p22 = Production.new(:Alt,[:Plus538032372],SyntaxTreeBuilder.new("Alt",["elements", "astspec"],[1])),
66
+ p23 = Production.new(:Plus538032372,[:Plus538032372, :Element],ArrayNodeBuilder.new([1],0,nil,nil,[],true)),
67
+ p24 = Production.new(:Plus538032372,[:Element],ArrayNodeBuilder.new([0],nil,nil,nil,[],true)),
68
+ p25 = Production.new(:Element,[t8],LiftingSyntaxTreeBuilder.new([],[])),
69
+ p26 = Production.new(:Element,[t5],SyntaxTreeBuilder.new("ImplicitToken",["regexp"],[])),
70
+ p27 = Production.new(:Element,[t4],SyntaxTreeBuilder.new("ImplicitToken",["regexp"],[])),
71
+ p28 = Production.new(:Element,[:Element, t18],SyntaxTreeBuilder.new("Maybe",["element", "_"],[])),
72
+ p29 = Production.new(:Element,[:Element, t19],SyntaxTreeBuilder.new("Plus",["element", "_"],[])),
73
+ p30 = Production.new(:Element,[:Element, t20],SyntaxTreeBuilder.new("Mult",["element", "_"],[])),
74
+ p31 = Production.new(:Element,[t21, :Element, :List538599718, t22],ArrayNodeBuilder.new([1],2,SyntaxTreeBuilder.new("Or",["_", "elements", "_"],[]),1,[2],false)),
75
+ p32 = Production.new(:Element,[t21, :Element, t22],ArrayNodeBuilder.new([1],nil,SyntaxTreeBuilder.new("Or",["_", "elements", "_"],[]),1,[],true)),
76
+ p33 = Production.new(:List538599718,[:List538599718, t27, :Element],ArrayNodeBuilder.new([2],0,nil,nil,[],true)),
77
+ p34 = Production.new(:List538599718,[t27, :Element],ArrayNodeBuilder.new([1],nil,nil,nil,[],true)),
78
+ p35 = Production.new(:Element,[t21, :Plus538593838, t22],SyntaxTreeBuilder.new("Sequence",["_", "elements", "_"],[])),
79
+ p36 = Production.new(:Plus538593838,[:Plus538593838, :Element],ArrayNodeBuilder.new([1],0,nil,nil,[],true)),
80
+ p37 = Production.new(:Plus538593838,[:Element],ArrayNodeBuilder.new([0],nil,nil,nil,[],true)),
81
+ p38 = Production.new(:Element,[t23, :Element, t24, :Element, t22],SyntaxTreeBuilder.new("List",["_", "element", "_", "delimiter"],[])),
82
+ p39 = Production.new(:AstSpec,[t14, :ProdSpec, :ElemSpecs, t16],SyntaxTreeBuilder.new("AstSpec",["_", "prodspec", "elemspecs", "_"],[])),
83
+ p40 = Production.new(:AstSpec,[t14, :ProdSpec, t16],SyntaxTreeBuilder.new("AstSpec",["_", "prodspec", "elemspecs", "_"],[2])),
84
+ p41 = Production.new(:AstSpec,[t14, :ElemSpecs, t16],SyntaxTreeBuilder.new("AstSpec",["_", "prodspec", "elemspecs", "_"],[1])),
85
+ p42 = Production.new(:AstSpec,[t14, t16],SyntaxTreeBuilder.new("AstSpec",["_", "prodspec", "elemspecs", "_"],[1, 2])),
86
+ p43 = Production.new(:ElemSpecs,[t25, :ElemSpec, :List538580888],ArrayNodeBuilder.new([1],2,LiftingSyntaxTreeBuilder.new(["_", "specs"],[]),1,[2],false)),
87
+ p44 = Production.new(:ElemSpecs,[t25, :ElemSpec],ArrayNodeBuilder.new([1],nil,LiftingSyntaxTreeBuilder.new(["_", "specs"],[]),1,[],true)),
88
+ p45 = Production.new(:List538580888,[:List538580888, t24, :ElemSpec],ArrayNodeBuilder.new([2],0,nil,nil,[],true)),
89
+ p46 = Production.new(:List538580888,[t24, :ElemSpec],ArrayNodeBuilder.new([1],nil,nil,nil,[],true)),
90
+ p47 = Production.new(:ElemSpec,[t28],LiftingSyntaxTreeBuilder.new(["name"],[])),
91
+ p48 = Production.new(:ElemSpec,[t29],LiftingSyntaxTreeBuilder.new(["name"],[])),
92
+ p49 = Production.new(:ProdSpec,[t8],LiftingSyntaxTreeBuilder.new(["name"],[])),
93
+ p50 = Production.new(:ProdSpec,[t30],LiftingSyntaxTreeBuilder.new(["name"],[])),
94
+ p51 = Production.new(:Priorities,[t26, :Plus538571098],LiftingSyntaxTreeBuilder.new(["_", "priorities"],[])),
95
+ p52 = Production.new(:Plus538571098,[:Plus538571098, :Priority],ArrayNodeBuilder.new([1],0,nil,nil,[],true)),
96
+ p53 = Production.new(:Plus538571098,[:Priority],ArrayNodeBuilder.new([0],nil,nil,nil,[],true)),
97
+ p54 = Production.new(:Priority,[t31, :ProdRef, :List538566228, t22],ArrayNodeBuilder.new([1],2,SyntaxTreeBuilder.new("Associativity",["relation", "productionrefs", "_"],[]),1,[2],false)),
98
+ p55 = Production.new(:Priority,[t31, :ProdRef, t22],ArrayNodeBuilder.new([1],nil,SyntaxTreeBuilder.new("Associativity",["relation", "productionrefs", "_"],[]),1,[],true)),
99
+ p56 = Production.new(:List538566228,[:List538566228, t24, :ProdRef],ArrayNodeBuilder.new([2],0,nil,nil,[],true)),
100
+ p57 = Production.new(:List538566228,[t24, :ProdRef],ArrayNodeBuilder.new([1],nil,nil,nil,[],true)),
101
+ p58 = Production.new(:Priority,[t32, :ProdRef, :List538566228, t22],ArrayNodeBuilder.new([1],2,SyntaxTreeBuilder.new("Associativity",["relation", "productionrefs", "_"],[]),1,[2],false)),
102
+ p59 = Production.new(:Priority,[t32, :ProdRef, t22],ArrayNodeBuilder.new([1],nil,SyntaxTreeBuilder.new("Associativity",["relation", "productionrefs", "_"],[]),1,[],true)),
103
+ p60 = Production.new(:Priority,[:ProdRef, :Plus538561788],SyntaxTreeBuilder.new("Precedence",["first", "rest"],[])),
104
+ p61 = Production.new(:Plus538561788,[:Plus538561788, t33, :ProdRef],ArrayNodeBuilder.new([1, 2],0,nil,nil,[],true)),
105
+ p62 = Production.new(:Plus538561788,[:Plus538561788, t13, :ProdRef],ArrayNodeBuilder.new([1, 2],0,nil,nil,[],true)),
106
+ p63 = Production.new(:Plus538561788,[t33, :ProdRef],ArrayNodeBuilder.new([0, 1],nil,nil,nil,[],true)),
107
+ p64 = Production.new(:Plus538561788,[t13, :ProdRef],ArrayNodeBuilder.new([0, 1],nil,nil,nil,[],true)),
108
+ p65 = Production.new(:Priority,[:Priority, t24],LiftingSyntaxTreeBuilder.new(["priority", "_"],[])),
109
+ p66 = Production.new(:ProdRef,[t8],LiftingSyntaxTreeBuilder.new([],[])),
110
+ p67 = Production.new(:ProdRef,[t10],LiftingSyntaxTreeBuilder.new([],[]))
111
+ ]
112
+ relations = [
113
+
114
+ ]
115
+ priorities = ProductionPriorities.new(relations)
116
+ action_table = [[5, 1024], [13, 256], [2, 1], [25, 65536, 29, 2048], [33, 33554432, 16, 1], [25, 65536], [45, 128], [57, 128], [69, 128, 77, 512, 81, 1073741824, 85, 2147483648], [12, 1], [33, 33554432, 8, 1], [101, 32], [60, 8589849273], [45, 128, 52, 7560237697], [109, 4096], [28, 1040183481], [57, 128, 20, 1040163001], [260, 7526683265], [117, 4294967296, 121, 4096], [264, 7526683265], [69, 128, 77, 512], [69, 128, 77, 512], [137, 8388608, 208, 7526683265], [69, 128, 77, 512, 81, 1073741824, 85, 2147483648, 200, 1], [4, 1], [145, 16, 149, 128, 165, 1048576, 169, 8, 173, 4194304], [56, 8589849273], [177, 16, 181, 8], [24, 1040183481], [69, 128, 77, 512], [69, 128, 77, 512], [193, 4294967296, 197, 4096, 236, 7526683265], [205, 2097152, 209, 8388608], [217, 2097152, 209, 8388608], [256, 7526683265], [137, 8388608, 204, 7526683265], [100, 8589849273], [96, 8589849273], [221, 131072, 225, 262144, 229, 524288, 92, 8589849273], [233, 67108864, 68, 8589849273], [145, 16, 149, 128, 249, 8192, 165, 1048576, 169, 8, 173, 4194304, 84, 8589849273], [145, 16, 149, 128, 165, 1048576, 169, 8, 173, 4194304], [104, 8589849273], [145, 16, 149, 128, 165, 1048576, 169, 8, 173, 4194304], [269, 8192, 36, 1040183481], [269, 8192, 44, 1040183481], [248, 7526683265], [252, 7526683265], [69, 128, 77, 512], [69, 128, 77, 512], [285, 2097152, 289, 8388608], [216, 7526683265], [69, 128, 77, 512], [297, 2097152, 289, 8388608], [232, 7526683265], [108, 8589849273], [112, 8589849273], [116, 8589849273], [145, 16, 149, 128, 165, 1048576, 169, 8, 173, 4194304], [305, 67108864, 64, 8589849273], [80, 8589849273], [221, 131072, 225, 262144, 229, 524288, 88, 8589849273], [309, 536870912, 313, 128, 317, 16777216, 321, 32768], [221, 131072, 333, 67108864, 225, 262144, 229, 524288, 341, 2097152, 144, 83755160], [145, 16, 149, 128, 165, 1048576, 169, 8, 349, 2097152, 173, 4194304], [221, 131072, 225, 262144, 229, 524288, 353, 8388608], [32, 1040183481], [357, 16384], [40, 1040183481], [240, 7526683265], [244, 7526683265], [212, 7526683265], [69, 128, 77, 512], [224, 10485760], [228, 7526683265], [76, 8589849273], [145, 16, 149, 128, 165, 1048576, 169, 8, 173, 4194304], [196, 427851776], [192, 427851776], [369, 268435456, 373, 134217728], [164, 8589849273], [381, 32768], [317, 16777216, 385, 32768], [145, 16, 149, 128, 165, 1048576, 169, 8, 173, 4194304], [397, 67108864, 401, 2097152], [124, 8589849273], [221, 131072, 225, 262144, 229, 524288, 140, 83755160], [136, 8589849273], [145, 16, 149, 128, 165, 1048576, 169, 8, 173, 4194304], [409, 32768], [220, 10485760], [72, 8589849273], [188, 411074560], [184, 411074560], [417, 8388608, 172, 32768], [160, 8589849273], [156, 8589849273], [421, 32768], [221, 131072, 225, 262144, 229, 524288, 132, 69206016], [145, 16, 149, 128, 165, 1048576, 169, 8, 173, 4194304], [120, 8589849273], [221, 131072, 225, 262144, 229, 524288, 429, 2097152], [48, 1040183481], [433, 8388608, 168, 32768], [369, 268435456, 373, 134217728], [152, 8589849273], [221, 131072, 225, 262144, 229, 524288, 128, 69206016], [148, 8589849273], [369, 268435456, 373, 134217728], [180, 8421376], [176, 8421376]]
117
+ goto_hash = {104 => {18 => 109}, 82 => {16 => 97}, 49 => {25 => 70}, 16 => {4 => 28}, 5 => {6 => 10}, 99 => {12 => 106}, 88 => {12 => 101}, 44 => {5 => 66}, 33 => {23 => 53}, 0 => {1 => 2}, 94 => {17 => 103}, 83 => {12 => 98}, 72 => {25 => 90}, 39 => {9 => 59}, 6 => {7 => 13, 8 => 12}, 45 => {5 => 68}, 23 => {22 => 35, 25 => 18}, 62 => {16 => 81, 19 => 82}, 40 => {12 => 61, 15 => 60}, 29 => {25 => 46}, 18 => {24 => 31}, 7 => {3 => 16, 4 => 15}, 79 => {18 => 94}, 13 => {8 => 26}, 63 => {13 => 84}, 52 => {25 => 73}, 41 => {12 => 63, 14 => 64}, 30 => {25 => 47}, 8 => {22 => 22, 25 => 18, 21 => 23}, 58 => {11 => 40, 12 => 38, 10 => 75}, 25 => {11 => 40, 12 => 38, 10 => 39}, 3 => {6 => 4, 2 => 5}, 108 => {18 => 110}, 64 => {12 => 86}, 20 => {25 => 32}, 48 => {25 => 69}, 4 => {20 => 9}, 76 => {11 => 40, 12 => 38, 10 => 91}, 43 => {12 => 65}, 32 => {23 => 50}, 21 => {25 => 33}, 10 => {20 => 24}}
118
+ @@parse_table538472678 = ParseTable.new(productions,tokens,priorities,action_table,goto_hash,2,[
119
+ :REDUCE,
120
+ :SHIFT,
121
+ :ACCEPT
122
+ ])
123
+ def Parse.rockit_grammars_parser
124
+ GeneralizedLrParser.new(@@parse_table538472678)
125
+ end
126
+ end
@@ -0,0 +1,181 @@
1
+ module SourceCodeDumpable
2
+ def to_src_in_module(name, moduleName, *restargs)
3
+ str = to_src(name, *restargs)
4
+ "module #{moduleName}\n" +
5
+ indent_lines(str) + (str[-1,1] == "\n" ? "" : "\n") +
6
+ "end\n"
7
+ end
8
+
9
+ def to_compact_src(name = nil, nameHash = {})
10
+ to_src(name, nameHash)
11
+ end
12
+
13
+ def type_to_src
14
+ self.class.inspect.split("::").last
15
+ end
16
+
17
+ def create_new
18
+ type_to_src + ".new(%s)"
19
+ end
20
+
21
+ def name_hash(array, &nameGenerator)
22
+ conflicthash, namehash, counts = Hash.new, Hash.new, Hash.new([0,nil])
23
+ array.each do |element|
24
+ name = nameGenerator.call(element)
25
+ if conflicthash[name]
26
+ count, first = counts[name]
27
+ if count == 0
28
+ namehash.delete name
29
+ namehash[name + "1"] = first
30
+ counts[name][0] = 1
31
+ end
32
+ name += "#{counts[name][0] += 1}"
33
+ else
34
+ counts[name] = [0,element]
35
+ conflicthash[name] = true
36
+ end
37
+ namehash[name] = element
38
+ end
39
+ namehash.invert # Assuming all elements are unique
40
+ end
41
+ module_function :name_hash
42
+
43
+ def as_code(aString)
44
+ SpecialString.new(aString)
45
+ end
46
+ module_function :as_code
47
+
48
+ def parameter_named(name)
49
+ SpecialString.new(aString)
50
+ end
51
+
52
+ def new_of_my_type(*args)
53
+ create_new % args.map do |arg|
54
+ if arg.class == SpecialString
55
+ arg
56
+ elsif arg.methods.include?("to_src")
57
+ arg.to_src
58
+ else
59
+ arg.inspect
60
+ end
61
+ end.join(",")
62
+ end
63
+
64
+ protected
65
+
66
+ class SpecialString < String; end
67
+
68
+ # When producing source code of an object we can choose how the object is
69
+ # to be created/accessed:
70
+ # * method: By using the 'as_method_named' modifier we get a method
71
+ # * module_method:
72
+ # * default: We get the object in a variable with the given name
73
+ MethodNamed = Struct.new("MethodNamed", :name)
74
+ ModuleMethodNamed = Struct.new("ModuleMethodNamed", :module, :name)
75
+
76
+ def as_method_named(name)
77
+ MethodNamed.new(name)
78
+ end
79
+ module_function :as_method_named
80
+
81
+ def as_module_method_named(moduleName, methodName)
82
+ ModuleMethodNamed.new(moduleName, methodName)
83
+ end
84
+ module_function :as_module_method_named
85
+
86
+ def assign_to(name, str)
87
+ if name.kind_of?(MethodNamed)
88
+ "def #{name.name}\n" + indent_lines(str) + "\nend\n"
89
+ elsif name.kind_of?(ModuleMethodNamed)
90
+ "def #{name.module}.#{name.name}\n" + indent_lines(str) + "\nend\n"
91
+ elsif name != nil
92
+ name + " = " + str
93
+ else
94
+ str
95
+ end
96
+ end
97
+
98
+ def new_of_my_type_with_name(name, *args)
99
+ assign_to(name, new_of_my_type(*args))
100
+ end
101
+
102
+ def indent_lines(string, indentString = " ")
103
+ indentString + string.split("\n").join("\n" + indentString) +
104
+ (string[-1,1] == "\n" ? "\n" : "")
105
+ end
106
+ module_function :indent_lines
107
+ end
108
+
109
+ class Array
110
+ include SourceCodeDumpable
111
+
112
+ def to_src(name = nil, elementNameHash = {})
113
+ strings = self.map do |e|
114
+ " " + e.to_src(elementNameHash[e], elementNameHash)
115
+ end
116
+ ary_src = "[\n" + strings.join(",\n") + "\n]"
117
+ assign_to(name, ary_src)
118
+ end
119
+
120
+ def to_compact_src(name = nil, elementNameHash = {})
121
+ strings = self.map do |e|
122
+ e.to_compact_src(elementNameHash[e], elementNameHash)
123
+ end
124
+ ary_src = "[" + strings.join(", ") + "]"
125
+ assign_to(name, ary_src)
126
+ end
127
+ end
128
+
129
+ class Object
130
+ include SourceCodeDumpable
131
+
132
+ def to_src(name = nil, nameHash = {})
133
+ assign_to(name, self.inspect)
134
+ end
135
+ end
136
+
137
+ class Regexp
138
+ def to_src(name = nil, nameHash = {})
139
+ assign_to(name, "/" + source + "/" + (casefold? ? "i" : "")) + (kcode ? kcode[0,1] : "")
140
+ end
141
+ end
142
+
143
+ class Hash
144
+ include SourceCodeDumpable
145
+
146
+ def to_src(name = nil, nameHash = {})
147
+ if self.keys.length == 0
148
+ hash_src = "{}"
149
+ else
150
+ hash_src = "{\n%s\n}" % self.keys.map do |key|
151
+ " " + key.to_src(nameHash[key], nameHash) + " => " +
152
+ self[key].to_src(nameHash[self[key]], nameHash)
153
+ end.join(",\n")
154
+ end
155
+ assign_to(name, hash_src)
156
+ end
157
+
158
+ def to_compact_src(name = nil, nameHash = {})
159
+ if self.keys.length == 0
160
+ hash_src = "{}"
161
+ else
162
+ hash_src = "{%s}" % self.keys.map do |key|
163
+ if self[key]
164
+ key.to_compact_src(nameHash[key], nameHash) + " => " +
165
+ self[key].to_compact_src(nameHash[self[key]], nameHash)
166
+ else
167
+ nil
168
+ end
169
+ end.compact.join(", ")
170
+ end
171
+ assign_to(name, hash_src)
172
+ end
173
+ end
174
+
175
+ class Integer
176
+ include SourceCodeDumpable
177
+
178
+ def to_src(name = nil, nameHash = {})
179
+ assign_to(name, inspect)
180
+ end
181
+ end