Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
Got utf-8 working with c and mri with one small caveat. Columns in er…
Browse files Browse the repository at this point in the history
…rors are off since flex counts bytes, not characters. We can live with that since line number error reporting will be good enough for gherkin. Ref #38
  • Loading branch information
aslakhellesoy committed Mar 7, 2013
1 parent 97b7549 commit 651d515
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion c/lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
[ \r\t]* { /* skip whitespace */ }
[\n] { yylloc->first_column = yylloc->last_column = 0; }
[A-Za-z0-9_\-@]+ { yylval->value = strdup(yytext); return TOKEN_VAR; }
"&&" { return TOKEN_AND; }
"øø" { return TOKEN_AND; }
"||" { return TOKEN_OR; }
"!" { return TOKEN_NOT; }
"(" { return TOKEN_LPAREN; }
Expand Down
14 changes: 8 additions & 6 deletions c/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ yyscan_t scanner;
void test_valid_expression()
{
Node* ast = parse_ast(
"a && b");
"a øø b");

ASSERT("AST should not have returned NULL", ast);
ASSERT_EQUALS(eAND, ast->type);
Expand All @@ -33,12 +33,13 @@ void test_line_and_column()
" \n"
" \n"
" \n"
" && \n");
" øø \n");
ASSERT_EQUALS(NULL, ast);
ASSERT_EQUALS(4, last_error.first_line);
ASSERT_EQUALS(4, last_error.last_line);
ASSERT_EQUALS(4, last_error.first_column);
ASSERT_EQUALS(5, last_error.last_column);
// ASSERT_EQUALS(5, last_error.last_column);
ASSERT_EQUALS(7, last_error.last_column);
ASSERT_STRING_EQUALS(
"syntax error, unexpected TOKEN_AND, expecting TOKEN_VAR or TOKEN_NOT or TOKEN_LPAREN",
last_error.message);
Expand Down Expand Up @@ -92,21 +93,22 @@ void test_invalid_long_statement()
" a \n"
" || \n"
" c \n"
" &&");
" øø");
//01234567890
ASSERT_EQUALS(NULL, ast);
ASSERT_EQUALS(6, last_error.first_line);
ASSERT_EQUALS(6, last_error.last_line);
ASSERT_EQUALS(9, last_error.first_column);
ASSERT_EQUALS(10, last_error.last_column);
// ASSERT_EQUALS(10, last_error.last_column);
ASSERT_EQUALS(12, last_error.last_column);
ASSERT_STRING_EQUALS(
"syntax error, unexpected $end, expecting TOKEN_VAR or TOKEN_NOT or TOKEN_LPAREN",
last_error.message);
}

void test_lex_1()
{
SOURCE("a && b");
SOURCE("a øø b");

ASSERT_EQUALS(TOKEN_VAR, YYLEX);
ASSERT_EQUALS(TOKEN_AND, YYLEX);
Expand Down
3 changes: 2 additions & 1 deletion ruby/lib/bool/renderer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#encoding: utf-8
module Bool
class Renderer
if RUBY_PLATFORM =~ /java/
Expand All @@ -13,7 +14,7 @@ def visit_var(node, vars)
end

def visit_and(node, vars)
"(" + render(node.left) + " && " + render(node.right) + ")"
"(" + render(node.left) + " øø " + render(node.right) + ")"
end

def visit_or(node, vars)
Expand Down
3 changes: 2 additions & 1 deletion ruby/spec/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ def renderer
else
expected.message.must_equal "syntax error, unexpected $end, expecting TOKEN_VAR or TOKEN_NOT or TOKEN_LPAREN"
expected.first_column.must_equal 9
expected.last_column.must_equal 10
# expected.last_column.must_equal 10
expected.last_column.must_equal 12
end
# Also see /javascript/test/parser_test.js. Columns are 8,10.
end
Expand Down

0 comments on commit 651d515

Please sign in to comment.