| 1 | //Copyright 2013 Vastech SA (PTY) LTD |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package ast |
| 16 | |
| 17 | import ( |
| 18 | "github.com/goccmack/gocc/internal/frontend/token" |
| 19 | "github.com/goccmack/gocc/internal/util" |
| 20 | ) |
| 21 | |
| 22 | type LexCharLit struct { |
| 23 | Val rune |
| 24 | Lit []byte |
| 25 | s string |
| 26 | } |
| 27 | |
| 28 | func NewLexCharLit(tok interface{}) (*LexCharLit, error) { |
| 29 | return newLexCharLit(tok), nil |
| 30 | } |
| 31 | |
| 32 | func newLexCharLit(tok interface{}) *LexCharLit { |
| 33 | c := new(LexCharLit) |
| 34 | t := tok.(*token.Token) |
| 35 | |
| 36 | c.Val = util.LitToRune(t.Lit) |
| 37 | c.Lit = t.Lit |
| 38 | c.s = util.RuneToString(c.Val) |
| 39 | |
| 40 | return c |
| 41 | } |
| 42 | |
| 43 | func newLexCharLitFromRune(c rune) *LexCharLit { |
| 44 | cl := &LexCharLit{ |
| 45 | Val: c, |
| 46 | s: util.RuneToString(c), |
| 47 | } |
| 48 | cl.Lit = []byte(cl.s) |
| 49 | return cl |
| 50 | } |
| 51 | |
| 52 | func (this *LexCharLit) IsTerminal() bool { |
| 53 | return true |
| 54 | } |
| 55 | func (this *LexCharLit) String() string { |
| 56 | return this.s |
| 57 | } |