Permalink
Browse files

Added quote (`) and unquote (~) symbols to parser. Don't do anything …

…yet but that'll change :)
  • Loading branch information...
1 parent b17c589 commit 4be3f57752eb8078fcd2dac546a314c2bd2485e9 @bakkdoor committed Feb 25, 2011
Showing with 29 additions and 1 deletion.
  1. +5 −1 lib/parser/ext/lexer.lex
  2. +16 −0 lib/parser/ext/parser.y
  3. +8 −0 lib/parser/methods.fy
@@ -14,7 +14,9 @@ bindigit [01]
capital [A-Z]
lower [a-z]
letter [A-Za-z]
-special [-+?!=*/^><%&~]
+quote `
+unquote ~
+special ([-+?!=*/^><%&]|[-+?!=*/^><%&]{unquote})
special_under ({special}|"_")
operator ({special}+|"||"{special_under}*)
int_lit [-+]?{digit}({digit}|_{digit})*
@@ -115,6 +117,8 @@ escaped_newline "\\".*\n
{arrow} { return ARROW; }
{thin_arrow} { return THIN_ARROW; }
{equals} { return EQUALS; }
+{quote} { return QUOTE; }
+{unquote} { return UNQUOTE; }
{operator} {
yylval.object = rb_str_new2(yytext);
return OPERATOR;
@@ -70,6 +70,8 @@ extern char *yytext;
%token MULTI_STRING_LITERAL
%token SYMBOL_LITERAL
%token REGEX_LITERAL
+%token QUOTE
+%token UNQUOTE
%token OPERATOR
%left DOT
@@ -146,6 +148,8 @@ extern char *yytext;
%type <object> operator_send
%type <object> send_args
%type <object> arg_exp
+%type <object> quoted_expression
+%type <object> unquoted_expression
%type <object> try_catch_block
%type <object> catch_blocks
@@ -230,13 +234,25 @@ exp: primary
| message_send
| ruby_send
| ruby_oper_send
+ | quoted_expression
+ | unquoted_expression
| SUPER { $$ = rb_funcall(self, rb_intern("ast:super_exp:"), 2, INT2NUM(yylineno), Qnil); }
| RETRY { $$ = rb_funcall(self, rb_intern("ast:retry_exp:"), 2, INT2NUM(yylineno), Qnil); }
| exp DOT space {
$$ = $1;
}
;
+quoted_expression: QUOTE exp {
+ $$ = rb_funcall(self, rb_intern("ast:quoted:"), 2, INT2NUM(yylineno), $2);
+ }
+ ;
+
+unquoted_expression: UNQUOTE exp {
+ $$ = rb_funcall(self, rb_intern("ast:unquoted:"), 2, INT2NUM(yylineno), $2);
+ }
+ ;
+
assignment: any_identifier EQUALS space exp {
$$ = rb_funcall(self, rb_intern("ast:assign:to:"), 3, INT2NUM(yylineno), $4, $1);
}
@@ -290,6 +290,14 @@ class Fancy {
AST RubyArgs new: line args: args block: block
}
+ def ast: line quoted: expr {
+ "GOT QUOTE: " ++ (expr inspect) println
+ }
+
+ def ast: line unquoted: expr {
+ "GOT UNQUOTE: " ++ (expr inspect) println
+ }
+
def ast: line parse_error: text {
ParseError new: line message: text filename: @filename . raise!
}

0 comments on commit 4be3f57

Please sign in to comment.