meta_compile 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +40 -0
  2. data/bootstrap/meta_for_ruby.txt +36 -0
  3. metadata +3 -1
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ meta_compile
2
+ ============
3
+
4
+ A meta compilation framework for Ruby à la [Meta-II by Val Schorre](http://ibm-1401.info/Meta-II-schorre.pdf).
5
+
6
+ Uses a C version of Meta-II developed by Long Nguyen's ([meta](https://github.com/impeachgod/meta)) to bootstrap a Ruby version from a [fully self-contained 28 (non-empty) line specification file](https://raw.github.com/robertfeldt/meta_compile/master/bootstrap/meta_for_ruby.txt). The [generated Ruby Meta-II compiler file](https://github.com/robertfeldt/meta_compile/blob/master/bin/meta_compile) is 229 lines of non-empty Ruby code.
7
+
8
+ Install
9
+ -------
10
+
11
+ Clone the git repo and then run:
12
+
13
+ rake bootstrap
14
+
15
+ and it will bootstrap and print info about each step. This requires gcc, rake and a recent ruby.
16
+
17
+ If you only want the finished result you can just install as a gem:
18
+
19
+ gem install meta_compile
20
+
21
+ since it is available on [rubygems.org](https://rubygems.org/gems/meta_compile).
22
+
23
+ Manually verifying that it is a meta compiler
24
+ ---------------------------------------------
25
+
26
+ In your local copy of the git repo, use the pre-generated binary to compile the specification file to a ruby file:
27
+
28
+ bin/meta_compile bootstrap/meta_for_ruby.txt t.rb
29
+
30
+ This generates a t.rb which is itself a compiler for meta syntax specs. So lets use it to generate itself:
31
+
32
+ ruby t.rb bootstrap/meta_for_ruby.txt t2.rb
33
+
34
+ And ensure they are really the same:
35
+
36
+ diff t.rb t2.rb
37
+
38
+ Limitations
39
+ -----------
40
+ + Very bad/little error handling
@@ -0,0 +1,36 @@
1
+ .syntax RMetaII
2
+
3
+ arg = '$' <'@o.print @t'>
4
+ | .string <'@o.print ' $>;
5
+
6
+ output = '<' *arg '>' <'@o.print "\n"'>;
7
+
8
+ exp3 = .id <'compile_' $>
9
+ | .string <'@i.scan /\s*/; s=' $>
10
+ <'@f = (@i.peek(s.length) == s) ? (@t=s; @i.pos += s.length) : nil'>
11
+ | '.id' <'@i.scan /\s*/; @f = @t = @i.scan /[A-Za-z]+[A-Za-z0-9_]+/'>
12
+ | '.string' <'@i.scan /\s*/; @f = @t = @i.scan /\047[^\047]*\047/'>
13
+ | '(' exp1 ')'
14
+ | '.e' <'@f = true'>
15
+ | '*' <'begin'> exp3 <'end while @f'> <'@f = true'>;
16
+
17
+ exp2 = ( exp3 <'if @f'> | output <'if true'> )
18
+ *( exp3 <'raise("error at: " + @i.rest.split("\n")[0]) if !@f'>
19
+ | output ) <'end'>;
20
+
21
+ exp1 = <'begin'> exp2
22
+ *( '|' <'break if @f'> exp2 )
23
+ <'end while false'>;
24
+
25
+ stat = .id <'def compile_' $> '=' exp1 ';' <'end'>;
26
+
27
+ program = '.syntax' .id
28
+ <'#!/usr/bin/env ruby'> <'require "strscan"'>
29
+ <'class ' $> <'def compile(str, out)'>
30
+ <'@i, @o = StringScanner.new(str), out'>
31
+ <'compile_program'> <'end'>
32
+ *stat '.end' <'end'>
33
+ <'begin; puts "Use: meta_compile <in> <out>"; exit; end if ARGV.length != 2'>
34
+ <'File.open(ARGV[1], "w") {|f| RMetaII.new.compile(File.read(ARGV[0]), f)}'>;
35
+
36
+ .end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meta_compile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -19,6 +19,8 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - bin/meta_compile
22
+ - README.md
23
+ - bootstrap/meta_for_ruby.txt
22
24
  homepage: http://rubygems.org/gems/meta_compile
23
25
  licenses: []
24
26
  post_install_message: