Add support for {{foo.bar.baz}}
This commit is contained in:
+26
-1
@@ -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
@@ -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'; }
|
||||
|
||||
Reference in New Issue
Block a user