riml 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,57 @@
1
+ require 'readline'
2
+ require_relative 'riml'
3
+
4
+ module Riml
5
+ class Repl
6
+ attr_reader :line
7
+
8
+ def initialize(vi_readline = false)
9
+ @indent_amount = 0
10
+ @line = nil
11
+ Readline.vi_editing_mode if vi_readline
12
+ end
13
+
14
+ def run
15
+ while @line = Readline.readline(current_indent, true)
16
+ line.strip!
17
+ next if line.empty?
18
+ exit_repl if line == 'quit' || line == 'q'
19
+ if line == 'c'
20
+ next if current_compilation_unit.empty?
21
+ compile_unit!
22
+ else
23
+ current_compilation_unit << line
24
+ check_indents
25
+ end
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def check_indents
32
+ @lexer = Lexer.new("#{line}\n")
33
+ @lexer.ignore_indentation_check = true
34
+ @lexer.tokenize
35
+ indent = @lexer.current_indent
36
+ @indent_amount += indent
37
+ end
38
+
39
+ def current_indent
40
+ " " * @indent_amount.abs
41
+ end
42
+
43
+ def compile_unit!
44
+ @indent_amount = 0
45
+ puts Riml.compile(current_compilation_unit.join("\n"))
46
+ current_compilation_unit.clear
47
+ end
48
+
49
+ def current_compilation_unit
50
+ @current_compilation_unit ||= []
51
+ end
52
+
53
+ def exit_repl
54
+ exit
55
+ end
56
+ end
57
+ end
@@ -39,11 +39,11 @@ module Riml
39
39
  end
40
40
 
41
41
  # expects `file_names` to be readable files
42
- def self.compile_files(*file_names)
42
+ def self.compile_files(*filenames)
43
43
  threads = []
44
- file_names.each do |file_name|
44
+ filenames.each do |fname|
45
45
  threads << Thread.new do
46
- f = File.open(file_name)
46
+ f = File.open(fname)
47
47
  # `compile` will close file handle
48
48
  compile(f)
49
49
  end
@@ -51,6 +51,20 @@ module Riml
51
51
  threads.each {|t| t.join}
52
52
  end
53
53
 
54
+ # checks syntax of `input` (lexes + parses) without going through ast rewriting or compilation
55
+ def self.check_syntax(input)
56
+ raise ArgumentError.new(input) unless input.is_a?(String)
57
+ parse(input, false)
58
+ true
59
+ end
60
+
61
+ def self.check_syntax_files(*filenames)
62
+ filenames.each do |fname|
63
+ File.open(fname) {|f| check_syntax(f.read)}
64
+ end
65
+ true
66
+ end
67
+
54
68
  def self.source_path
55
69
  @source_path ||= Dir.getwd
56
70
  end
@@ -75,8 +89,8 @@ module Riml
75
89
 
76
90
  FILE_HEADER = File.read(File.expand_path("../header.vim", __FILE__)) % VERSION.join('.')
77
91
 
78
- def self.write_file(output, file_name)
79
- file_basename = File.basename(file_name)
92
+ def self.write_file(output, fname)
93
+ file_basename = File.basename(fname)
80
94
  unless File.extname(file_basename).empty?
81
95
  file_basename = file_basename.split(".").tap {|parts| parts.pop}.join(".")
82
96
  end
data/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Riml
2
- # last changed: Dec. 24, 2012
3
- VERSION = [0,1,7]
2
+ # last changed: Jan. 13, 2013
3
+ VERSION = [0,1,8]
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-26 00:00:00.000000000Z
12
+ date: 2013-01-13 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: racc
16
- requirement: &82321280 !ruby/object:Gem::Requirement
16
+ requirement: &80512100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *82321280
24
+ version_requirements: *80512100
25
25
  description: ! " Riml is a superset of VimL that includes some nice features:\n classes,
26
26
  string interpolation, heredocs, default case-sensitive string\n comparison and
27
27
  other things most programmers take for granted.\n"
@@ -37,6 +37,7 @@ files:
37
37
  - lib/parser.rb
38
38
  - lib/class_map.rb
39
39
  - lib/errors.rb
40
+ - lib/repl.rb
40
41
  - lib/walker.rb
41
42
  - lib/header.vim
42
43
  - lib/ast_rewriter.rb
@@ -47,6 +48,10 @@ files:
47
48
  - lib/grammar.y
48
49
  - lib/lexer.rb
49
50
  - lib/constants.rb
51
+ - Rakefile
52
+ - CONTRIBUTING
53
+ - Gemfile
54
+ - Gemfile.lock
50
55
  - bin/riml
51
56
  homepage: https://github.com/luke-gru/riml
52
57
  licenses:
@@ -72,5 +77,5 @@ rubyforge_project:
72
77
  rubygems_version: 1.8.10
73
78
  signing_key:
74
79
  specification_version: 3
75
- summary: Relaxed Vimscript
80
+ summary: Relaxed VimL (Vimscript)
76
81
  test_files: []