Commit aa9ce614 authored by Robert Griesemer's avatar Robert Griesemer

change datafmt syntax to use '@' instead of '^' (to match

convention used in template.go)

R=rsc
DELTA=22  (3 added, 1 deleted, 18 changed)
OCL=29780
CL=29782
parent 43456b4a
...@@ -78,10 +78,10 @@ ...@@ -78,10 +78,10 @@
A field operand is a field name optionally followed by an alternate A field operand is a field name optionally followed by an alternate
rule name. The field name may be an identifier or one of the special rule name. The field name may be an identifier or one of the special
names ^ or *. names @ or *.
Field = FieldName [ ":" RuleName ] . Field = FieldName [ ":" RuleName ] .
FieldName = identifier | "^" | "*" . FieldName = identifier | "@" | "*" .
If the field name is an identifier, the current value must be a struct, If the field name is an identifier, the current value must be a struct,
and there must be a field with that name in the struct. The same lookup and there must be a field with that name in the struct. The same lookup
...@@ -91,8 +91,7 @@ ...@@ -91,8 +91,7 @@
and an error message is returned. (TODO consider changing the semantics and an error message is returned. (TODO consider changing the semantics
such that if a field is not found, it evaluates to nil). such that if a field is not found, it evaluates to nil).
The special name '^' denotes the current value. (TODO see if ^ can The special name '@' denotes the current value.
change to @ or be eliminated).
The meaning of the special name '*' depends on the type of the current The meaning of the special name '*' depends on the type of the current
value: value:
...@@ -252,7 +251,7 @@ type ( ...@@ -252,7 +251,7 @@ type (
literal [][]byte; // a list of string segments, possibly starting with '%' literal [][]byte; // a list of string segments, possibly starting with '%'
field struct { field struct {
fieldName string; // including "^", "*" fieldName string; // including "@", "*"
ruleName string; // "" if no rule name specified ruleName string; // "" if no rule name specified
}; };
...@@ -587,7 +586,7 @@ func (s *State) eval(fexpr expr, value reflect.Value, index int) bool { ...@@ -587,7 +586,7 @@ func (s *State) eval(fexpr expr, value reflect.Value, index int) bool {
case *field: case *field:
// determine field value // determine field value
switch t.fieldName { switch t.fieldName {
case "^": case "@":
// field value is current value // field value is current value
case "*": case "*":
......
...@@ -76,10 +76,10 @@ func TestCustomFormatters(t *testing.T) { ...@@ -76,10 +76,10 @@ func TestCustomFormatters(t *testing.T) {
f = parse(t, ``, fmap1); f = parse(t, ``, fmap1);
verify(t, f, `even odd even odd `, 0, 1, 2, 3); verify(t, f, `even odd even odd `, 0, 1, 2, 3);
f = parse(t, `/ =^:blank; float="#"`, fmap1); f = parse(t, `/ =@:blank; float="#"`, fmap1);
verify(t, f, `# # #`, 0.0, 1.0, 2.0); verify(t, f, `# # #`, 0.0, 1.0, 2.0);
f = parse(t, `float=^:nil`, fmap1); f = parse(t, `float=@:nil`, fmap1);
verify(t, f, ``, 0.0, 1.0, 2.0); verify(t, f, ``, 0.0, 1.0, 2.0);
// TODO needs more tests // TODO needs more tests
...@@ -212,7 +212,7 @@ func TestDefaultRule(t *testing.T) { ...@@ -212,7 +212,7 @@ func TestDefaultRule(t *testing.T) {
check(t, `default="%v"`, `42foo3.14`, 42, "foo", 3.14); check(t, `default="%v"`, `42foo3.14`, 42, "foo", 3.14);
check(t, `default="%v"; int="%x"`, `abcdef`, 10, 11, 12, 13, 14, 15); check(t, `default="%v"; int="%x"`, `abcdef`, 10, 11, 12, 13, 14, 15);
check(t, `default="%v"; int="%x"`, `ab**ef`, 10, 11, "**", 14, 15); check(t, `default="%v"; int="%x"`, `ab**ef`, 10, 11, "**", 14, 15);
check(t, `default="%x"; int=^:default`, `abcdef`, 10, 11, 12, 13, 14, 15); check(t, `default="%x"; int=@:default`, `abcdef`, 10, 11, 12, 13, 14, 15);
} }
......
...@@ -86,7 +86,7 @@ func (p *parser) next() { ...@@ -86,7 +86,7 @@ func (p *parser) next() {
func (p *parser) init(src []byte) { func (p *parser) init(src []byte) {
p.errors.Init(0); p.errors.Init(0);
p.scanner.Init(src, p, 0); p.scanner.Init(src, p, scanner.AllowIllegalChars); // return '@' as token.ILLEGAL w/o error message
p.next(); // initializes pos, tok, lit p.next(); // initializes pos, tok, lit
p.packs = make(map [string] string); p.packs = make(map [string] string);
p.rules = make(map [string] expr); p.rules = make(map [string] expr);
...@@ -231,8 +231,11 @@ func (p *parser) parseLiteral() literal { ...@@ -231,8 +231,11 @@ func (p *parser) parseLiteral() literal {
func (p *parser) parseField() expr { func (p *parser) parseField() expr {
var fname string; var fname string;
switch p.tok { switch p.tok {
case token.XOR: case token.ILLEGAL:
fname = "^"; if string(p.lit) != "@" {
return nil;
}
fname = "@";
p.next(); p.next();
case token.MUL: case token.MUL:
fname = "*"; fname = "*";
......
...@@ -44,7 +44,7 @@ ast.Decl = ...@@ -44,7 +44,7 @@ ast.Decl =
// Tokens and comments // Tokens and comments
token.Token = token.Token =
^:string; @:string;
ast.Comment = ast.Comment =
// TODO this doesn't indent properly after //-style comments because // TODO this doesn't indent properly after //-style comments because
...@@ -87,7 +87,7 @@ ast.StringList = ...@@ -87,7 +87,7 @@ ast.StringList =
{Strings / "\n"}; {Strings / "\n"};
ast.FuncLit = ast.FuncLit =
Type " " Body ^:clearOptSemi; // no optional ; after a func literal body Type " " Body @:clearOptSemi; // no optional ; after a func literal body
ast.CompositeLit = ast.CompositeLit =
Type "{" {Elts / ", "} "}"; Type "{" {Elts / ", "} "}";
...@@ -139,7 +139,7 @@ funcSignature = ...@@ -139,7 +139,7 @@ funcSignature =
*:signature; *:signature;
ast.FuncType = ast.FuncType =
[Position:isValidPos "func"] ^:signature; [Position:isValidPos "func"] @:signature;
ast.InterfaceType = ast.InterfaceType =
"interface" "interface"
...@@ -201,7 +201,7 @@ ast.BranchStmt = ...@@ -201,7 +201,7 @@ ast.BranchStmt =
Tok [" " Label]; Tok [" " Label];
stmtList = stmtList =
{^ / ^:optSemi "\n"}; {@ / @:optSemi "\n"};
blockStmt = // like ast.BlockStmt but w/o indentation blockStmt = // like ast.BlockStmt but w/o indentation
"{" "{"
...@@ -210,7 +210,7 @@ blockStmt = // like ast.BlockStmt but w/o indentation ...@@ -210,7 +210,7 @@ blockStmt = // like ast.BlockStmt but w/o indentation
List:stmtList List:stmtList
"\n" "\n"
] ]
"}" ^:setOptSemi; "}" @:setOptSemi;
blockStmtPtr = blockStmtPtr =
*:blockStmt; *:blockStmt;
...@@ -222,7 +222,7 @@ ast.BlockStmt = ...@@ -222,7 +222,7 @@ ast.BlockStmt =
List:stmtList List:stmtList
) "\n" ) "\n"
] ]
"}" ^:setOptSemi; "}" @:setOptSemi;
ast.IfStmt = ast.IfStmt =
"if " [Init "; "] [Cond " "] Body [" else " Else]; "if " [Init "; "] [Cond " "] Body [" else " Else];
...@@ -315,7 +315,7 @@ ast.GenDecl = ...@@ -315,7 +315,7 @@ ast.GenDecl =
{Specs / ";\n"} {Specs / ";\n"}
) "\n" ) "\n"
] ]
")" ^:setOptSemi ")" @:setOptSemi
| {Specs / ";\n"} | {Specs / ";\n"}
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment