Skip to content
Browse files

Merge branch 'racktastic'

Conflicts:

	lib/parser.rb
	lib/web.rb
  • Loading branch information...
2 parents d3fdfd5 + ce578cf commit 1777cb23ac11d874dbbfe1ac81e17c7fbfa5aec7 @technomancy committed
Showing with 17 additions and 9 deletions.
  1. +1 −0 README.txt
  2. +7 −3 examples/blog/blog.scm
  3. +2 −4 lib/parser.rb
  4. +2 −2 lib/web.rb
  5. +5 −0 test/test_parser.rb
View
1 README.txt
@@ -88,6 +88,7 @@ Bus Scheme is currently missing pieces of functionality:
* regular expressions
=== General
+* should get error loading incomplete s-expressions in a file
* filter stacktrace
* continuations
* macros
View
10 examples/blog/blog.scm
@@ -7,7 +7,11 @@
(list 'h1 title)
body))))))
-(collection "/" (resources "/\d+"))
+(collection "/" (list
+ (post 1 "hello world"
+ "This is my bus scheme blog"
+ (now))
-(load "posts/1.sexp")
-(load "posts/2.sexp")
+ (post 2 "hello bus scheme"
+ "This is the awesome blog"
+ (now))))
View
6 lib/parser.rb
@@ -64,7 +64,6 @@ def pop_token(input)
return pop_token(input)
when /\A(\(|\))/ # parens
Regexp.last_match[1].intern
- # when /\A#([^\)])/
when /\A#\(/ # vector
input[0 ... 2] = ''
return [:'(', :vector.sym, tokenize(input)]
@@ -85,9 +84,6 @@ def pop_token(input)
Regexp.last_match[1].to_i
when /\A("(.*?)")/m # string
Regexp.last_match[2]
- # Official Scheme valid identifiers:
- # when /\A([A-Za-z!\$%&\*\.\/:<=>\?@\^_~][A-Za-z0-9!\$%&\*\+\-\.\/:<=>\?@\^_~]*)/ # symbol
- # when /\A([^-0-9\. \n\)][^ \n\)]*)/
when /\A#\\(.)/ # Character literal
char = Regexp.last_match[1]
# TODO: generalize this. shouldn't be littered with literal numbers
@@ -102,6 +98,8 @@ def pop_token(input)
input[0 ... 1] = ''
end
return char
+ when /\A(\/(.*?)\/)/m # Regex
+ Regexp.new(Regexp.escape(Regexp.last_match[2]))
when /\A([^ \n\)]+)/ # symbols
# puts "#{Regexp.last_match[1]} - #{@@lines}"
# cannot begin with a character that may begin a number
View
4 lib/web.rb
@@ -2,12 +2,12 @@
require 'rubygems'
require 'rack'
require 'mongrel'
-require 'yaml'
require 'xml'
module BusScheme
define 'resource', lambda { |*args| Resource.new(*args) }
-
+ define 'resources', lambda { |arg| Resource[arg] }
+
module_function
def serve(port = 2000)
# TODO: fallback to webrick if mongrel is not found
View
5 test/test_parser.rb
@@ -37,6 +37,11 @@ def test_parses_two_strings
def test_parse_list_of_numbers
assert_parses_to "(2 2)", [2, 2]
end
+
+ def test_parses_regex
+ $trace = true
+ assert_parses_to "/hi/", /hi/
+ end
def test_parse_dotted_cons
assert_parses_to "(22 . 11)", [:cons.sym, 22, 11]

0 comments on commit 1777cb2

Please sign in to comment.
Something went wrong with that request. Please try again.