Browse files

Merge branch 'master' into develop

  • Loading branch information...
2 parents b658e08 + 25be906 commit 7f7a6e2422d0285ec7dd4da9d864ab62eef75469 Shunichi Shinohara committed Aug 17, 2011
Showing with 90 additions and 16 deletions.
  1. +10 −0 .travis.yml
  2. +9 −0 README.rst
  3. +2 −2 src/eini_lexer.xrl
  4. +20 −14 src/eini_parser.yrl
  5. +49 −0 test/eini_tests.erl
View
10 .travis.yml
@@ -0,0 +1,10 @@
+language: erlang
+notifications:
+ email: false
+otp_release:
+ - R14B03
+ - R14B02
+ - R14B01
+branches:
+ only:
+ - develop
View
9 README.rst
@@ -28,6 +28,15 @@ Result form::
History
=======
+1.0.1
+-----
+
+:release: 2011-08-17
+:summary: Line number bug fix
+
+- Line numbers in error messages were wrong.
+ Thanks to @Hexa for reporting the bug.
+
1.0.0
-----
View
4 src/eini_lexer.xrl
@@ -35,8 +35,8 @@ B = [\n\r]
Rules.
-%% skip empty lines or lines with space/tab chars
-{B}{S}*{B} : {skip_token, "\n"}.
+%% skip empty or blank lines or lines with space/tab chars
+{B}({S}*{B})+ : {token, {break, TokenLine}}.
%% mark line break by token 'break' in order to use as delimiters
{B} : {token, {break, TokenLine}}.
View
34 src/eini_parser.yrl
@@ -19,7 +19,9 @@
Nonterminals
whole
- sections section
+ sections
+ sections_with_skip_lines
+ section
title_part
title
property_with_skip_lines
@@ -40,10 +42,23 @@ Terminals
Rootsymbol whole.
-whole -> sections : '$1'.
-whole -> skip_lines sections : '$2'.
-whole -> blank_line sections : '$2'.
-whole -> blank_line skip_lines sections : '$3'.
+%% Leex smash out all blank lines, but at the beggining of file is NOT.
+whole -> sections_with_skip_lines : '$1'.
+whole -> blank_line sections_with_skip_lines : '$2'.
+
+blank_line -> blank break : '$1'.
+
+%% Comment lines are treated as:
+%% 1. At the biggining of file are included into sections_with_skip_lines
+%% 2. Other comment lines are included to title_part and property_with_skip_lines
+
+skip_lines -> comment_line : ['$1'].
+skip_lines -> comment_line skip_lines : ['$1', '$2'].
+
+comment_line -> comment break : '$1'.
+
+sections_with_skip_lines -> sections : '$1'.
+sections_with_skip_lines -> skip_lines sections : '$2'.
sections -> '$empty' : [].
sections -> section sections : ['$1' | '$2'].
@@ -83,15 +98,6 @@ single_value -> '[' : "[".
single_value -> '=' : "=".
single_value -> ']' : "]".
-%% ONLY a comment line at the beggining of file is NOT skipped by leex
-skip_lines -> comment_line : ['$1'].
-skip_lines -> comment_line skip_lines : ['$1', '$2'].
-
-comment_line -> comment break : '$1'.
-
-blank_line -> blank break : '$1'.
-
-
Erlang code.
-spec value_of({atom(), _Line, TokenChars::string()}) -> TokenChars::string().
View
49 test/eini_tests.erl
@@ -271,6 +271,14 @@ one_section_title_and_one_prop_test_() ->
"[title] \n"
"key1=value1;continue\n"
)),
+ %% key has preceding spaces
+ ?_assertEqual({ok, [
+ {title, [{key1, <<"value1">>}]}
+ ]},
+ parse(
+ "[title] \n"
+ " key1=value1\n"
+ )),
%% key has trailing spaces
?_assertEqual({ok, [
{title, [{key1, <<"value1">>}]}
@@ -279,6 +287,14 @@ one_section_title_and_one_prop_test_() ->
"[title] \n"
"key1 =value1\n"
)),
+ %% key has preceding and trailing spaces
+ ?_assertEqual({ok, [
+ {title, [{key1, <<"value1">>}]}
+ ]},
+ parse(
+ "[title] \n"
+ " key1 =value1\n"
+ )),
%% value has preceding and trailing spaces
?_assertEqual({ok, [
{title, [{key1, <<"value1">>}]}
@@ -410,6 +426,26 @@ syntax_error_title_test_() ->
%% blank char before section title
?_assertMatch({error, {syntax_error, 1, ["syntax error before: ", _]}},
parse(" [title]")),
+ %% blank char before section title, with a preceding empty line
+ ?_assertMatch({error, {syntax_error, 2, ["syntax error before: ", _]}},
+ parse("\n"
+ " [title]")),
+ %% blank char before section title, with preceding empty lines
+ ?_assertMatch({error, {syntax_error, 3, ["syntax error before: ", _]}},
+ parse("\n"
+ "\n"
+ " [title]")),
+ %% blank char before section title, with preceding blank lines
+ ?_assertMatch({error, {syntax_error, 3, ["syntax error before: ", _]}},
+ parse(" \n"
+ "\t\n"
+ " [title]")),
+ %% blank char before section title, with preceding comment lines
+ ?_assertMatch({error, {syntax_error, 4, ["syntax error before: ", _]}},
+ parse("; comment 1\n"
+ ";\n"
+ "; comment 2\n"
+ " [title]")),
%% blank char in section title
?_assertMatch({error, {syntax_error, 3, _Reason}},
parse(
@@ -420,6 +456,19 @@ syntax_error_title_test_() ->
))
]}.
+syntax_error_property_test_() ->
+ {setup,
+ fun setup/0,
+ fun teardown/1,
+ [
+ %% blank char in key
+ ?_assertMatch({error, {syntax_error, 2, _Reason}},
+ parse(
+ "[title]\n"
+ "key with blank=value\n"
+ ))
+ ]}.
+
dup_title_test_() ->
{setup,
fun setup/0,

0 comments on commit 7f7a6e2

Please sign in to comment.