generate: Add option token to lexer
This commit is contained in:
parent
50ca98f3c6
commit
17201a4c48
@ -10,6 +10,7 @@ const (
|
|||||||
TokenMethod parse.TokenKind = iota
|
TokenMethod parse.TokenKind = iota
|
||||||
TokenKey
|
TokenKey
|
||||||
TokenIdent
|
TokenIdent
|
||||||
|
TokenOption
|
||||||
TokenComma
|
TokenComma
|
||||||
TokenLBrace
|
TokenLBrace
|
||||||
TokenRBrace
|
TokenRBrace
|
||||||
@ -22,6 +23,7 @@ var tokenNames = map[parse.TokenKind] string {
|
|||||||
TokenMethod: "Method",
|
TokenMethod: "Method",
|
||||||
TokenKey: "Key",
|
TokenKey: "Key",
|
||||||
TokenIdent: "Ident",
|
TokenIdent: "Ident",
|
||||||
|
TokenOption: "Option",
|
||||||
TokenComma: "Comma",
|
TokenComma: "Comma",
|
||||||
TokenLBrace: "LBrace",
|
TokenLBrace: "LBrace",
|
||||||
TokenRBrace: "RBrace",
|
TokenRBrace: "RBrace",
|
||||||
@ -122,6 +124,11 @@ func (this *lexer) nextInternal() (token parse.Token, err error) {
|
|||||||
if this.eof { err = nil; return }
|
if this.eof { err = nil; return }
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
}
|
}
|
||||||
|
// Option
|
||||||
|
case this.rune == '?':
|
||||||
|
token.Kind = TokenOption
|
||||||
|
appendRune()
|
||||||
|
if this.eof { err = nil; return }
|
||||||
// Comma
|
// Comma
|
||||||
case this.rune == ',':
|
case this.rune == ',':
|
||||||
token.Kind = TokenComma
|
token.Kind = TokenComma
|
||||||
|
|||||||
@ -16,6 +16,7 @@ func TestLex(test *testing.T) {
|
|||||||
// wow
|
// wow
|
||||||
0001 Users []User,
|
0001 Users []User,
|
||||||
0002 Followers U32,
|
0002 Followers U32,
|
||||||
|
0003 Wings ?Int,
|
||||||
}`))
|
}`))
|
||||||
if err != nil { test.Fatal(parse.Format(err)) }
|
if err != nil { test.Fatal(parse.Format(err)) }
|
||||||
|
|
||||||
@ -42,6 +43,11 @@ func TestLex(test *testing.T) {
|
|||||||
tok(TokenIdent, "Followers"),
|
tok(TokenIdent, "Followers"),
|
||||||
tok(TokenIdent, "U32"),
|
tok(TokenIdent, "U32"),
|
||||||
tok(TokenComma, ","),
|
tok(TokenComma, ","),
|
||||||
|
tok(TokenKey, "0003"),
|
||||||
|
tok(TokenIdent, "Wings"),
|
||||||
|
tok(TokenOption, "?"),
|
||||||
|
tok(TokenIdent, "Int"),
|
||||||
|
tok(TokenComma, ","),
|
||||||
tok(TokenRBrace, "}"),
|
tok(TokenRBrace, "}"),
|
||||||
tok(parse.EOF, ""),
|
tok(parse.EOF, ""),
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user