]> Cypherpunks repositories - gostls13.git/commitdiff
- completed parser - accepts full language (modulo bugs)
authorRobert Griesemer <gri@golang.org>
Wed, 9 Jul 2008 21:01:17 +0000 (14:01 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 9 Jul 2008 21:01:17 +0000 (14:01 -0700)
SVN=126551

usr/gri/src/parser.go

index 5238be5e494338a5f279fc2537bb3af67ee02ac0..355120d4d5621585fa47c136f8f8e0998c9b0a19 100644 (file)
@@ -692,6 +692,67 @@ func (P *Parser) ParseSwitchStat() {
 }
 
 
+func (P *Parser) ParseCommCase() {
+  P.Trace("CommCase");
+  if P.tok == Scanner.CASE {
+       P.Next();
+       if P.tok == Scanner.GTR {
+               // send
+               P.Next();
+               P.ParseExpression();
+               P.Expect(Scanner.EQL);
+               P.ParseExpression();
+       } else {
+               // receive
+               if P.tok != Scanner.LSS {
+                       P.ParseIdent();
+                       P.Expect(Scanner.ASSIGN);
+               }
+               P.Expect(Scanner.LSS);
+               P.ParseExpression();
+       }
+  } else {
+       P.Expect(Scanner.DEFAULT);
+  }
+  P.Expect(Scanner.COLON);
+  P.Ecart();
+}
+
+
+func (P *Parser) ParseCommClause() {
+       P.Trace("CommClause");
+       P.ParseCommCase();
+       if P.tok != Scanner.CASE && P.tok != Scanner.DEFAULT && P.tok != Scanner.RBRACE {
+               P.ParseStatementList();
+               P.Optional(Scanner.SEMICOLON);
+       }
+       P.Ecart();
+}
+
+
+func (P *Parser) ParseRangeStat() bool {
+       P.Trace("RangeStat");
+       P.Expect(Scanner.RANGE);
+       P.ParseIdentList();
+       P.Expect(Scanner.DEFINE);
+       P.ParseExpression();
+       P.ParseBlock();
+       P.Ecart();
+}
+
+
+func (P *Parser) ParseSelectStat() bool {
+       P.Trace("SelectStat");
+       P.Expect(Scanner.SELECT);
+       P.Expect(Scanner.LBRACE);
+       for P.tok != Scanner.RBRACE {
+               P.ParseCommClause();
+       }
+       P.Next();
+       P.Ecart();
+}
+
+
 func (P *Parser) TryStatement() bool {
        P.Trace("Statement (try)");
        switch P.tok {
@@ -724,9 +785,9 @@ func (P *Parser) TryStatement() bool {
        case Scanner.SWITCH:
                P.ParseSwitchStat();
        case Scanner.RANGE:
-               panic "range statement";
+               P.ParseRangeStat();
        case Scanner.SELECT:
-               panic "select statement";
+               P.ParseSelectStat();
        default:
                // no statement found
                P.Ecart();