Beispiel #1
0
func Token2int(tok common.Token) *IntTok {
	it, ok := tok.(*IntTok)
	if !ok {
		tok.Error("Not an integer token")
	}
	return it
}
Beispiel #2
0
func Token2operator(tok common.Token) *OperatorTok {
	ot, ok := tok.(*OperatorTok)
	if !ok {
		tok.Error("Not an operator token")
	}
	return ot
}
Beispiel #3
0
func Token2eof(tok common.Token) *EofTok {
	et, ok := tok.(*EofTok)
	if !ok {
		tok.Error("Not an EOF token")
	}
	return et
}
Beispiel #4
0
func Token2simple(tok common.Token) *SimpleToken {
	st, ok := tok.(*SimpleToken)
	if !ok {
		tok.Error("Not a simple token")
	}
	return st
}
Beispiel #5
0
func Token2id(tok common.Token) *IdTok {
	it, ok := tok.(*IdTok)
	if !ok {
		tok.Error("Not an ID token")
	}
	return it
}
Beispiel #6
0
func Token2space(tok common.Token) *SpaceTok {
	st, ok := tok.(*SpaceTok)
	if !ok {
		tok.Error("Not a space token")
	}
	return st
}
Beispiel #7
0
func Token2string(tok common.Token) *StringTok {
	st, ok := tok.(*StringTok)
	if !ok {
		tok.Error("Not a string token")
	}
	return st
}
Beispiel #8
0
func Token2char(tok common.Token) *CharTok {
	ct, ok := tok.(*CharTok)
	if !ok {
		tok.Error("Not a character token")
	}
	return ct
}
Beispiel #9
0
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");
  }
}
Beispiel #10
0
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);
}