diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-05-11 23:24:11 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-05-11 23:24:11 +0900 |
commit | 6979b9b13409dd56869cc881292a544bd8eea7ba (patch) | |
tree | 150438027aaf93e75a4e5d3edb51ea257e7977f5 /driver/lexer.go | |
parent | Fix a text representation of an error token (diff) | |
download | tre-6979b9b13409dd56869cc881292a544bd8eea7ba.tar.gz tre-6979b9b13409dd56869cc881292a544bd8eea7ba.tar.xz |
Add --compression-level option to compile command
--compression-level specifies a compression level. The default value is 2.
Diffstat (limited to 'driver/lexer.go')
-rw-r--r-- | driver/lexer.go | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/driver/lexer.go b/driver/lexer.go index bac478f..278a104 100644 --- a/driver/lexer.go +++ b/driver/lexer.go @@ -319,13 +319,29 @@ func (l *Lexer) next() (*Token, error) { } func (l *Lexer) lookupNextState(mode spec.LexModeNum, state int, v int) (int, bool) { - tab := l.clspec.Specs[mode].DFA.Transition - rowNum := tab.RowNums[state] - d := tab.UniqueEntries.RowDisplacement[rowNum] - if tab.UniqueEntries.Bounds[d+v] != rowNum { - return tab.UniqueEntries.EmptyValue, false + switch l.clspec.CompressionLevel { + case 2: + tab := l.clspec.Specs[mode].DFA.Transition + rowNum := tab.RowNums[state] + d := tab.UniqueEntries.RowDisplacement[rowNum] + if tab.UniqueEntries.Bounds[d+v] != rowNum { + return tab.UniqueEntries.EmptyValue, false + } + return tab.UniqueEntries.Entries[d+v], true + case 1: + tab := l.clspec.Specs[mode].DFA.Transition + next := tab.UncompressedUniqueEntries[tab.RowNums[state]*tab.OriginalColCount+v] + if next == 0 { + return 0, false + } + return next, true + } + spec := l.clspec.Specs[mode] + next := spec.DFA.UncompressedTransition[state*spec.DFA.ColCount+v] + if next == 0 { + return 0, false } - return tab.UniqueEntries.Entries[d+v], true + return next, true } func (l *Lexer) mode() spec.LexModeNum { |