public
Description: Library for parsing and compiling OMeta grammars to ruby
Clone URL: git://github.com/aquasync/ruby-ometa.git
Cleanup directory structure a bit, and fix bootstrapping bug (minor eChar 
issue).
Charles Lowe (author)
Wed Sep 17 06:07:09 -0700 2008
commit  758634c94e4dda2ba3ae79874753b617f83a815c
tree    000bee855bc901121bd09639336251259f5dbadf
parent  03ed7374a97e7130fcfe339369a327333eb8d58d
0
...
1
2
3
 
4
5
6
7
8
9
10
11
12
 
...
1
2
 
3
4
5
6
 
 
7
8
9
 
10
0
@@ -1,12 +1,10 @@
0
 = About
0
 
0
-Briefly what OMeta is
0
+Briefly what OMeta is, some links to the ometajs stuff.
0
 
0
 = TODO
0
 
0
-* finish bootstrapping.
0
-* add in optimization pass by default, with some flags.
0
 * perhaps cache compiled rb files as "#{ometa_filename}.rb.cache" or
0
   similar, and use them based on mtime / flag combination.
0
 * try to optimize some more. profile wasn't particularly illuminating.
0
-
0
+* then write some actual tests.
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
 
58
 
 
 
 
 
 
59
60
61
...
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
...
 
 
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
3
4
5
6
7
8
9
10
11
12
...
29
30
31
 
32
33
34
35
36
37
 
 
 
 
 
38
39
40
0
@@ -1,61 +1,12 @@
0
-require 'runtime'
0
-require 'bootstrap'
0
 
0
-def bootstrap_test
0
-filename = 'ometa_translator.ometa'
0
-
0
-puts "* reading grammar"
0
-grammar = File.read(filename)
0
-
0
-#puts grammar
0
-
0
-puts "* parsing grammar into ast"
0
-ast = OMetaParser.matchAllwith(grammar, 'grammar')
0
-
0
-#p ast
0
-
0
-puts "* translating into ruby"
0
-str = RubyOMetaTranslator.matchwith(ast, 'trans')
0
-
0
-#puts str
0
-
0
-puts "* compiling into grammar object"
0
-open('temp.rb', 'w') { |f| f << '$xxx1 = ' + str }
0
-load 'temp.rb'
0
-cls1 = $xxx1
0
-#cls = eval str, binding
0
-
0
-puts "* re-translating ast into ruby with new compiled grammar"
0
-str2 = Cls1.matchwith(ast, 'trans')
0
-
0
-puts "* re-compiling into grammar object"
0
-open('temp2.rb', 'w') { |f| f << '$xxx2 = ' + str2 }
0
-cls2 = eval str2, binding
0
-#load 'temp2.rb'
0
-#Cls2 = $xxx2
0
-
0
-puts "* re-re-translating ast into ruby with new compiled grammar"
0
-#p Cls2
0
-str3 = Cls2.matchwith(ast, 'trans')
0
-
0
-puts "* checking for equality"
0
-raise unless str2 == str3
0
-
0
-puts "* checking correct parse of calculator ast"
0
-# now, with this class, which has bootstrapped itself, ensure it works
0
-# note that this hasn't tested the grammar, only the translator. lets
0
-# try a translated parser and see if that works
0
-
0
-filename = 'ometa_parser.ometa'
0
-grammar = File.read(filename)
0
-ast = OMetaParser.matchAllwith(grammar, 'grammar')
0
-str4 = Cls2.matchwith(ast, 'trans')
0
-# so this is a dynamically built parser, build from the builtin parser, and
0
-# a dynamically built translator built from a dynamic translator.
0
-open('temp3.rb', 'w') { |f| f << '$xxx3 = ' + str4 }
0
-cls3 = eval str4, binding
0
-end
0
+__END__
0
 
0
+#
0
+# later on the idea is to add a Ometa::Grammar function or something similar to wrap
0
+# up the process of creating a ruby class object from an ometa grammar file.
0
+#
0
+# as an example (this is missing the optimization pass):
0
+#
0
 class Ometa
0
   def self.Grammar(filename)
0
     grammar = File.read(filename)
0
@@ -78,18 +29,12 @@ class Ometa
0
   end
0
 end
0
 
0
-=begin
0
 class Calc < Ometa::Grammar('calc.ometa')
0
   def self.calc str
0
     matchAllwith str, 'expr'
0
   end
0
 end
0
 
0
-p Calc
0
-p Calc.calc('2^5^2')
0
-p Calc.calc('(2^5)^2')
0
-=end
0
-
0
 class JSParser < Ometa::Grammar('js_parser.ometa')
0
   KEYWORDS = ["break", "case", "catch", "continue", "default", "delete", "do", "else", "finally", "for", "function", "if", "in",
0
             "instanceof", "new", "return", "switch", "this", "throw", "try", "typeof", "var", "void", "while", "with", "ometa"]

Comments

    No one has commented yet.