Add support for {{foo.bar.baz}}

This commit is contained in:
tomhuda
2011-03-03 20:08:28 -08:00
parent 32d7e52182
commit 51d2543ba1
2 changed files with 30 additions and 3 deletions
+26 -1
View File
@@ -11,7 +11,9 @@ describe "Tokenizer" do
lexer.setInput(string)
out = []
while result = parser.terminals_[lexer.lex] and result != "EOF"
while token = lexer.lex
result = parser.terminals_[token]
break if !result || result == "EOF"
out << Token.new(result, lexer.yytext)
end
@@ -37,12 +39,35 @@ describe "Tokenizer" do
result[1].should be_token("ID", "foo")
end
it "tokenizes a simple path" do
result = tokenize("{{foo/bar}}")
result.should match_tokens(%w(OPEN ID SEP ID CLOSE))
end
it "allows dot notation" do
result = tokenize("{{foo.bar}}")
result.should match_tokens(%w(OPEN ID SEP ID CLOSE))
tokenize("{{foo.bar.baz}}").should match_tokens(%w(OPEN ID SEP ID SEP ID CLOSE))
end
it "tokenizes {{.}} as OPEN ID CLOSE" do
result = tokenize("{{.}}")
result.should match_tokens(%w(OPEN ID CLOSE))
end
it "tokenizes a path as 'OPEN (ID SEP)* ID CLOSE'" do
result = tokenize("{{../foo/bar}}")
result.should match_tokens(%w(OPEN ID SEP ID SEP ID CLOSE))
result[1].should be_token("ID", "..")
end
it "tokenizes a path with .. as a parent path" do
result = tokenize("{{../foo.bar}}")
result.should match_tokens(%w(OPEN ID SEP ID SEP ID CLOSE))
result[1].should be_token("ID", "..")
end
it "tokenizes a path with this/foo as OPEN ID SEP ID CLOSE" do
result = tokenize("{{this/foo}}")
result.should match_tokens(%w(OPEN ID SEP ID CLOSE))
+4 -2
View File
@@ -16,12 +16,14 @@
<mu>"{{!".*?"}}" { yytext = yytext.substr(3,yyleng-5); this.begin("INITIAL"); return 'COMMENT'; }
<mu>"{{" { return 'OPEN'; }
<mu>"/" { return 'SEP'; }
<mu>"."/[} ] { return 'ID'; }
<mu>".." { return 'ID'; }
<mu>[/.] { return 'SEP'; }
<mu>\s+ { /*ignore whitespace*/ }
<mu>"}}}" { this.begin("INITIAL"); return 'CLOSE'; }
<mu>"}}" { this.begin("INITIAL"); return 'CLOSE'; }
<mu>'"'("\\"["]|[^"])*'"' { yytext = yytext.substr(1,yyleng-2).replace(/\\"/g,'"'); return 'STRING'; }
<mu>[a-zA-Z0-9_.]+/[} /] { return 'ID'; }
<mu>[a-zA-Z0-9_]+/[} /.] { return 'ID'; }
<mu>. { return 'INVALID'; }
<INITIAL,mu><<EOF>> { return 'EOF'; }