| 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 symbols |
| 16 | |
| 17 | import ( |
| 18 | "github.com/goccmack/gocc/internal/ast" |
| 19 | ) |
| 20 | |
| 21 | // key: string of range, e.g.: 'a'-'z' |
| 22 | type CharRangeSymbols struct { |
| 23 | idmap map[string]int |
| 24 | typeMap []*ast.LexCharRange |
| 25 | } |
| 26 | |
| 27 | func NewCharRangeSymbols() *CharRangeSymbols { |
| 28 | return &CharRangeSymbols{ |
| 29 | idmap: make(map[string]int), |
| 30 | typeMap: make([]*ast.LexCharRange, 0, 16), |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | func (this *CharRangeSymbols) Add(cr *ast.LexCharRange) { |
| 35 | this.typeMap = append(this.typeMap, cr) |
| 36 | this.idmap[cr.String()] = len(this.typeMap) - 1 |
| 37 | } |
| 38 | |
| 39 | func (this *CharRangeSymbols) Len() int { |
| 40 | return len(this.typeMap) |
| 41 | } |
| 42 | |
| 43 | func (this *CharRangeSymbols) List() []*ast.LexCharRange { |
| 44 | return this.typeMap |
| 45 | } |
| 46 | |
| 47 | func (this *CharRangeSymbols) StringList() []string { |
| 48 | symbols := make([]string, len(this.typeMap)) |
| 49 | for i, sym := range this.typeMap { |
| 50 | symbols[i] = sym.String() |
| 51 | } |
| 52 | return symbols |
| 53 | } |