Skip to content

Commit

Permalink
feat: Update go version.
Browse files Browse the repository at this point in the history
Note: I know some people have asked noot to depend on the sort.Slices, which is still flagged as
experimental.  However, it won't be one day it is well implemented. It is only used in one
place in the runtime and two places in an optional build tag antlr.statistics, I advise
users to make a fork if the really need to remove sort.Slice.

Signed-off-by: Jim.Idle <jimi@idle.ws>
  • Loading branch information
jimidle committed May 15, 2024
1 parent 329d984 commit 4d7e188
Show file tree
Hide file tree
Showing 17 changed files with 216 additions and 100 deletions.
8 changes: 4 additions & 4 deletions antlrdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ ANTLR4 that it is compatible with (I.E. uses the /v4 path).
However, this was found to be problematic, as it meant that with the runtime embedded so far underneath the root
of the repo, the `go get` and related commands could not properly resolve the location of the go runtime source code.
This meant that the reference to the runtime in your `go.mod` file would refer to the correct source code, but would not
list the release tag such as @4.12.0 - this was confusing, to say the least.
list the release tag such as @4.13.1 - this was confusing, to say the least.
As of 4.12.1, the runtime is now available as a go module in its own repo, and can be imported as `github.com/antlr4-go/antlr`
As of 4.13.0, the runtime is now available as a go module in its own repo, and can be imported as `github.com/antlr4-go/antlr`
(the go get command should also be used with this path). See the main documentation for the ANTLR4 project for more information,
which is available at [ANTLR docs]. The documentation for using the Go runtime is available at [Go runtime docs].
Expand Down Expand Up @@ -49,7 +49,7 @@ Here is a general/recommended template for an ANTLR based recognizer in Go:
.
├── parser
│ ├── mygrammar.g4
│ ├── antlr-4.12.1-complete.jar
│ ├── antlr-4.13.1-complete.jar
│ ├── generate.go
│ └── generate.sh
├── parsing - generated code goes here
Expand All @@ -71,7 +71,7 @@ And the generate.sh file will look similar to this:
#!/bin/sh
alias antlr4='java -Xmx500M -cp "./antlr4-4.12.1-complete.jar:$CLASSPATH" org.antlr.v4.Tool'
alias antlr4='java -Xmx500M -cp "./antlr4-4.13.1-complete.jar:$CLASSPATH" org.antlr.v4.Tool'
antlr4 -Dlanguage=Go -no-visitor -package parsing *.g4
depending on whether you want visitors or listeners or any other ANTLR options. Not that another option here
Expand Down
8 changes: 3 additions & 5 deletions atn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

package antlr

import "sync"

// ATNInvalidAltNumber is used to represent an ALT number that has yet to be calculated or
// which is invalid for a particular struct such as [*antlr.BaseRuleContext]
var ATNInvalidAltNumber int
Expand Down Expand Up @@ -56,9 +54,9 @@ type ATN struct {
//
states []ATNState

mu sync.Mutex
stateMu sync.RWMutex
edgeMu sync.RWMutex
mu Mutex
stateMu RWMutex
edgeMu RWMutex
}

// NewATN returns a new ATN struct representing the given grammarType and is used
Expand Down
3 changes: 0 additions & 3 deletions atn_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ func NewATNConfig1(c *ATNConfig, state ATNState, context *PredictionContext) *AT
// NewATNConfig creates a new ATNConfig instance given an existing config, a state, a context and a semantic context, other 'constructors'
// are just wrappers around this one.
func NewATNConfig(c *ATNConfig, state ATNState, context *PredictionContext, semanticContext SemanticContext) *ATNConfig {
if semanticContext == nil {
panic("semanticContext cannot be nil") // TODO: Remove this - probably put here for some bug that is now fixed
}
b := &ATNConfig{}
b.InitATNConfig(c, state, c.GetAlt(), context, semanticContext)
b.cType = parserConfig
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/antlr4-go/antlr/v4

go 1.20
go 1.22

require golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc
require golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc h1:mCRnTeVUjcrhlRmO0VK8a6k6Rrf6TF9htwo2pJVSjIU=
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
2 changes: 1 addition & 1 deletion input_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (is *InputStream) GetTextFromInterval(i Interval) string {
}

func (*InputStream) GetSourceName() string {
return ""
return "Obtained from string"
}

// String returns the entire input stream as a string
Expand Down
5 changes: 2 additions & 3 deletions jcollect.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"container/list"
"runtime/debug"
"sort"
"sync"
)

// Collectable is an interface that a struct should implement if it is to be
Expand Down Expand Up @@ -587,12 +586,12 @@ type VisitRecord struct {

type VisitList struct {
cache *list.List
lock sync.RWMutex
lock RWMutex
}

var visitListPool = VisitList{
cache: list.New(),
lock: sync.RWMutex{},
lock: RWMutex{},
}

// NewVisitRecord returns a new VisitRecord instance from the pool if available.
Expand Down
2 changes: 1 addition & 1 deletion lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (b *BaseLexer) NextToken() Token {
for {
b.thetype = TokenInvalidType

ttype := b.safeMatch()
ttype := b.safeMatch() // Defaults to LexerSkip

if b.input.LA(1) == TokenEOF {
b.hitEOF = true
Expand Down
1 change: 1 addition & 0 deletions ll1_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (la *LL1Analyzer) getDecisionLookahead(s ATNState) []*IntervalSet {
for alt := 0; alt < count; alt++ {

look[alt] = NewIntervalSet()
// TODO: This is one of the reasons that ATNConfigs are allocated and freed all the time - fix this tomorrow jim!
lookBusy := NewJStore[*ATNConfig, Comparator[*ATNConfig]](aConfEqInst, ClosureBusyCollection, "LL1Analyzer.getDecisionLookahead for lookBusy")
la.look1(s.GetTransitions()[alt].getTarget(), nil, BasePredictionContextEMPTY, look[alt], lookBusy, NewBitSet(), false, false)

Expand Down
41 changes: 41 additions & 0 deletions mutex.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//go:build !antlr.nomutex
// +build !antlr.nomutex

package antlr

import "sync"

// Mutex is a simple mutex implementation which just delegates to sync.Mutex, it
// is used to provide a mutex implementation for the antlr package, which users
// can turn off with the build tag -tags antlr.nomutex
type Mutex struct {
mu sync.Mutex
}

func (m *Mutex) Lock() {
m.mu.Lock()
}

func (m *Mutex) Unlock() {
m.mu.Unlock()
}

type RWMutex struct {
mu sync.RWMutex
}

func (m *RWMutex) Lock() {
m.mu.Lock()
}

func (m *RWMutex) Unlock() {
m.mu.Unlock()
}

func (m *RWMutex) RLock() {
m.mu.RLock()
}

func (m *RWMutex) RUnlock() {
m.mu.RUnlock()
}
32 changes: 32 additions & 0 deletions mutex_nomutex.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//go:build antlr.nomutex
// +build antlr.nomutex

package antlr

type Mutex struct{}

func (m *Mutex) Lock() {
// No-op
}

func (m *Mutex) Unlock() {
// No-op
}

type RWMutex struct{}

func (m *RWMutex) Lock() {
// No-op
}

func (m *RWMutex) Unlock() {
// No-op
}

func (m *RWMutex) RLock() {
// No-op
}

func (m *RWMutex) RUnlock() {
// No-op
}
4 changes: 1 addition & 3 deletions parser_atn_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"strings"
)

var ()

// ClosureBusy is a store of ATNConfigs and is a tiny abstraction layer over
// a standard JStore so that we can use Lazy instantiation of the JStore, mostly
// to avoid polluting the stats module with a ton of JStore instances with nothing in them.
Expand Down Expand Up @@ -883,7 +881,7 @@ func (p *ParserATNSimulator) getPredicatePredictions(ambigAlts *BitSet, altToPre
// the ERROR state was reached, outerContext as the initial parser context from the paper
// or the parser stack at the instant before prediction commences.
//
// Teh func returns the value to return from [AdaptivePredict], or
// The func returns the value to return from [AdaptivePredict], or
// [ATNInvalidAltNumber] if a suitable alternative was not
// identified and [AdaptivePredict] should report an error instead.
func (p *ParserATNSimulator) getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(configs *ATNConfigSet, outerContext ParserRuleContext) int {
Expand Down
Loading

0 comments on commit 4d7e188

Please sign in to comment.