Permalink
Browse files

Some infrastructure.

  • Loading branch information...
Brian Ford
Brian Ford committed Nov 21, 2010
1 parent f4db4b3 commit 74f3055222da3283a7eaa011901ade0ddce06d92
View
@@ -0,0 +1 @@
+*.rbc
View
@@ -0,0 +1,2 @@
+require 'syme/bootstrap'
+require 'syme/version'
View
@@ -0,0 +1,4 @@
+require 'syme/bootstrap/syntax'
+require 'syme/bootstrap/parser'
+require 'syme/bootstrap/compiler'
+require 'syme/bootstrap/library'
No changes.
No changes.
@@ -0,0 +1,47 @@
+module Syme
+ class Parser
+ def initialize
+ @error_position = 0
+ end
+
+ # The #parse_string method is defined in the parser C extension.
+
+ def parse(string)
+ @string = string
+ ast = parse_string string
+ show_syntax_error unless ast
+ ast
+ end
+
+ def parse_file(name)
+ string = IO.read name
+ parse string
+ end
+
+ # Parsing callbacks
+
+ def show_syntax_error
+ error_line = nil
+ count = 0
+
+ @string.each_line do |line|
+ count += line.size
+ if count > @error_position
+ error_line = line
+ break
+ end
+ end
+
+ message = <<-EOM
+
+#{error_line.chomp}
+#{" " *(error_line.size - (count - @error_position))}^
+EOM
+ raise Syntax::SyntaxError, message
+ end
+
+ def syntax_error(pos)
+ @error_position = pos
+ end
+ end
+end
@@ -0,0 +1,4 @@
+*.bundle
+*.so
+*.o
+parser.c
Oops, something went wrong.

0 comments on commit 74f3055

Please sign in to comment.