func Token2int(tok common.Token) *IntTok { it, ok := tok.(*IntTok) if !ok { tok.Error("Not an integer token") } return it }
func Token2operator(tok common.Token) *OperatorTok { ot, ok := tok.(*OperatorTok) if !ok { tok.Error("Not an operator token") } return ot }
func Token2eof(tok common.Token) *EofTok { et, ok := tok.(*EofTok) if !ok { tok.Error("Not an EOF token") } return et }
func Token2simple(tok common.Token) *SimpleToken { st, ok := tok.(*SimpleToken) if !ok { tok.Error("Not a simple token") } return st }
func Token2id(tok common.Token) *IdTok { it, ok := tok.(*IdTok) if !ok { tok.Error("Not an ID token") } return it }
func Token2space(tok common.Token) *SpaceTok { st, ok := tok.(*SpaceTok) if !ok { tok.Error("Not a space token") } return st }
func Token2string(tok common.Token) *StringTok { st, ok := tok.(*StringTok) if !ok { tok.Error("Not a string token") } return st }
func Token2char(tok common.Token) *CharTok { ct, ok := tok.(*CharTok) if !ok { tok.Error("Not a character token") } return ct }
func recordIndent(indent int, tok common.Token, tb *tokBuf) { // we can have half indentations (2 spaces) and // full indentations (4 spaces) switch indent { case 2: tb.indentLevel++; tb.curTok = tb.tokBuf.PushBack(tb.lx.NewCopyTok(common.TOK_HALF_INDENT, tok)); case 4: tb.indentLevel += 2; tb.curTok = tb.tokBuf.PushBack(tb.lx.NewCopyTok(common.TOK_INDENT, tok)); default: tok.Error("Indentation error"); } }
func recordDedent(dedent int, tok common.Token, tb *tokBuf) { if dedent & 1 != 0 { tok.Error("Uneven dedentation error"); } recordOtherDedents(recordFirstDedent(dedent/2, tok, tb), tok, tb); }