diff --git a/src/lexdcompiler.cc b/src/lexdcompiler.cc index c1971e7..71df981 100644 --- a/src/lexdcompiler.cc +++ b/src/lexdcompiler.cc @@ -197,7 +197,7 @@ LexdCompiler::finishLexicon() die("Lexicon '%S' is empty.", err(name(currentLexiconId))); } appendLexicon(currentLexiconId, currentLexicon); - + currentLexicon.clear(); currentLexicon_tags.clear(); } @@ -632,6 +632,7 @@ LexdCompiler::readToken(char_iter& iter, UnicodeString& line) if(iter.span().first == begin_charspan.first) die("Syntax error - missing index in parenthesis"); part = (unsigned int)StringUtils::stoi(to_ustring(line.tempSubStringBetween(begin_charspan.first, iter.span().first))); + if (part == 0) die("Invalid column number (0)"); ++iter; } diff --git a/tests/feature/Makefile b/tests/feature/Makefile index b89f146..1cc83d4 100644 --- a/tests/feature/Makefile +++ b/tests/feature/Makefile @@ -40,7 +40,16 @@ tests = \ sources = $(foreach test,$(tests),test-$(test).lexd) -check: $(foreach src,$(sources),$(O)/$(src).txt.strings.check) +check-pos: $(foreach src,$(sources),$(O)/$(src).txt.strings.check) + +negtests = \ + col0 \ + +negsources = $(foreach test,$(negtests),negtest-$(test).lexd) + +check-neg: $(foreach src,$(negsources),$(O)/$(src).txt.error) + +check: check-pos check-neg O=. @@ -54,6 +63,9 @@ $(O)/%.strings.diff: $(O)/%.strings %.strings.gold diff -U0 $^ > $@; [ $$? != 2 ] $(O)/%.strings.check: $(O)/%.strings.diff [ -s "$<" ] && cat "$<" && exit 1; touch $@ +$(O)/%.lexd.txt.error: ../../src/lexd %.lexd | $(O) + $^ $(LEXD_TEST_FLAGS) > /dev/null 2> $@; [ $$? = 1 ] clean: rm $(foreach src,$(sources),$(O)/$(src).txt.strings.check) + rm $(foreach src,$(negsources),$(O)/$(src).txt.error) rmdir $(O) diff --git a/tests/feature/negtest-col0.lexd b/tests/feature/negtest-col0.lexd new file mode 100644 index 0000000..aab435d --- /dev/null +++ b/tests/feature/negtest-col0.lexd @@ -0,0 +1,5 @@ +PATTERNS +X(0) + +LEXICON X +a:b