CodeSampleX

Exemple

github.com/antlr4-go/antlr/v4 v4.13.1: antlr.IntervalSet

Échantillon vérifié pour golang github.com/antlr4-go/antlr/v4 v4.13.1: antlr.IntervalSet. Le contrat s'est exécuté sur go 1.26 · linux alpine/x64 · docker et…

sha256:2abd3a0d8209a3c2e86adf1079c32aca0df6f04e4842a90762e51fab73ff5ee5

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré go linux 24 · ubuntu · glibc 2.39 x64 go go go

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-31

Cas

HOW
Objectif
verify antlr.IntervalSet in pkg:golang/github.com/antlr4-go/antlr/v4@v4.13.1
Paquets
Symboles
  • antlr.IntervalSet
Environnement
go
Créé
2026-08-31T01:20:58Z

Contrat

  1. antlr.IntervalSet represents collections of intervals with NewIntervalSet producing an empty writable set having 0 intervals and string representation "{}".
  2. antlr.IntervalSet supports equality checks with Equals and string formatting with String and StringVerbose against literal and symbolic token names.
  3. antlr.CommonTokenStream GetTokens accepts an IntervalSet to filter tokens by type.

Fichiers

  • NOTES.md
  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • intervalset_test.go
  • spec.json

Télécharger l’artefact source (tar.gz)

Code source

NOTES.md
# antlr4-go IntervalSet Verification Notes

## Search Results
An initial search via `search_known_solution` for `pkg:golang/github.com/antlr4-go/antlr/v4@v4.13.1` with `antlr.IntervalSet` yielded `NO_SAFE_MATCH`.

## Pinned Version
- Package: `github.com/antlr4-go/antlr/v4`
- Release: `v4.13.1` (in `go.mod` / `go.sum`)

## Observed Behavior
1. **IntervalSet Initialization & Equality**:
   - `antlr.NewIntervalSet()` creates an empty, writable interval set whose initial `GetIntervals()` length is 0 and string representation is `"{}"`.
   - `set.Equals(other)` returns true when comparing equivalent interval sets.
2. **Transition Configuration & StringVerbose**:
   - `antlr.NewSetTransition` and `antlr.NewNotSetTransition` accept `*antlr.IntervalSet` to define state transitions.
   - `set.StringVerbose(literalNames, symbolicNames, elemsAreChar)` produces symbolic or literal representations for intervals.
3. **Token Stream Filtering**:
   - `antlr.CommonTokenStream.GetTokens(start, stop, types)` filters the token buffer, returning only tokens matching the specified `*antlr.IntervalSet` (or all tokens when `types` is nil).
PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify antlr.IntervalSet in pkg:golang/github.com/antlr4-go/antlr/v4@v4.13.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/antlr4-go/antlr/v4@v4.13.1
Demonstrate these symbols/APIs:
  - antlr.IntervalSet
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:08931466118caabb3cb19f436327b73cabd35dc7236497fc0b957a6b7ee018ca","constraints":{"executionContext":"go"},"contract":["antlr.IntervalSet represents collections of intervals with NewIntervalSet producing an empty writable set having 0 intervals and string representation \"{}\".","antlr.IntervalSet supports equality checks with Equals and string formatting with String and StringVerbose against literal and symbolic token names.","antlr.CommonTokenStream GetTokens accepts an IntervalSet to filter tokens by type."],"goal":"verify antlr.IntervalSet in pkg:golang/github.com/antlr4-go/antlr/v4@v4.13.1","kind":"HOW","packages":["pkg:golang/github.com/antlr4-go/antlr/v4@v4.13.1"],"schemaVersion":1,"symbols":["antlr.IntervalSet"]},"contractCommand":["go","test","./..."],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","executionContext":"go","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","runtime":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/antlr4-go/antlr/v4@v4.13.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/antlr4-go/antlr/v4@v4.13.1","symbols":["antlr.IntervalSet"],"verifierAdapter":"golang@1"}
go.mod
module example.com/intervalset

go 1.26.6

require (
	github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
	golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
)
go.sum
github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ=
github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw=
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=
intervalset_test.go
package intervalset_test

import (
	"testing"

	"github.com/antlr4-go/antlr/v4"
)

func createToken(tokenType int, text string) antlr.Token {
	return antlr.CommonTokenFactoryDEFAULT.Create(
		&antlr.TokenSourceCharStreamPair{},
		tokenType,
		text,
		antlr.TokenDefaultChannel,
		0,
		len(text)-1,
		1,
		0,
	)
}

type SimpleMockLexer struct {
	*antlr.BaseLexer
	tokens []antlr.Token
	index  int
}

func NewSimpleMockLexer(tokens []antlr.Token) *SimpleMockLexer {
	l := &SimpleMockLexer{
		BaseLexer: antlr.NewBaseLexer(antlr.NewInputStream("")),
		tokens:    tokens,
	}
	l.Virt = l
	return l
}

func (l *SimpleMockLexer) NextToken() antlr.Token {
	if l.index < len(l.tokens) {
		t := l.tokens[l.index]
		l.index++
		return t
	}
	return antlr.CommonTokenFactoryDEFAULT.Create(
		&antlr.TokenSourceCharStreamPair{},
		antlr.TokenEOF,
		"",
		antlr.TokenDefaultChannel,
		0,
		0,
		1,
		0,
	)
}

func TestIntervalSetInitializationAndString(t *testing.T) {
	set1 := antlr.NewIntervalSet()
	if set1 == nil {
		t.Fatalf("expected NewIntervalSet() to return non-nil")
	}

	intervals := set1.GetIntervals()
	if len(intervals) != 0 {
		t.Fatalf("expected 0 intervals in new IntervalSet, got %d", len(intervals))
	}

	str := set1.String()
	if str != "{}" {
		t.Fatalf("expected empty set string \"{}\", got %q", str)
	}

	set2 := antlr.NewIntervalSet()
	if !set1.Equals(set2) {
		t.Fatalf("expected empty sets to equal each other")
	}
}

func TestIntervalSetTransitionAndStringVerbose(t *testing.T) {
	targetState := antlr.NewBasicState()
	atomTrans := antlr.NewAtomTransition(targetState, 42)
	rangeTrans := antlr.NewRangeTransition(targetState, 10, 20)

	customSet := antlr.NewIntervalSet()
	setTrans := antlr.NewSetTransition(targetState, customSet)
	if setTrans == nil {
		t.Fatalf("expected NewSetTransition to succeed")
	}

	notSetTrans := antlr.NewNotSetTransition(targetState, customSet)
	if notSetTrans == nil {
		t.Fatalf("expected NewNotSetTransition to succeed")
	}

	literalNames := []string{"", "';'", "'+'", "'-'"}
	symbolicNames := []string{"", "SEMI", "PLUS", "MINUS"}

	emptyStr := customSet.StringVerbose(literalNames, symbolicNames, false)
	if emptyStr != "{}" {
		t.Fatalf("expected \"{}\" for empty set StringVerbose, got %q", emptyStr)
	}

	if !atomTrans.Matches(42, 0, 0) {
		t.Fatalf("expected AtomTransition to match symbol 42")
	}
	if atomTrans.Matches(43, 0, 0) {
		t.Fatalf("expected AtomTransition not to match symbol 43")
	}
	if !rangeTrans.Matches(15, 0, 0) || !rangeTrans.Matches(10, 0, 0) || !rangeTrans.Matches(20, 0, 0) {
		t.Fatalf("expected RangeTransition to match symbols within [10, 20]")
	}
	if rangeTrans.Matches(9, 0, 0) || rangeTrans.Matches(21, 0, 0) {
		t.Fatalf("expected RangeTransition not to match symbols outside [10, 20]")
	}
}

func TestCommonTokenStreamGetTokensWithIntervalSet(t *testing.T) {
	const (
		TokenIdentifier = 1
		TokenOperator   = 2
		TokenLiteral    = 3
	)

	tokens := []antlr.Token{
		createToken(TokenIdentifier, "foo"),
		createToken(TokenOperator, "="),
		createToken(TokenLiteral, "123"),
		createToken(TokenOperator, "+"),
		createToken(TokenIdentifier, "bar"),
	}

	mockLexer := NewSimpleMockLexer(tokens)
	cts := antlr.NewCommonTokenStream(mockLexer, antlr.TokenDefaultChannel)
	cts.Fill()

	// 1. Get all tokens when types filter is nil
	allTokens := cts.GetTokens(0, len(tokens), nil)
	if len(allTokens) != len(tokens) {
		t.Fatalf("expected %d tokens with nil IntervalSet, got %d", len(tokens), len(allTokens))
	}

	// 2. Empty IntervalSet matches 0 tokens
	emptyFilter := antlr.NewIntervalSet()
	emptyMatched := cts.GetTokens(0, len(tokens), emptyFilter)
	if len(emptyMatched) != 0 {
		t.Fatalf("expected 0 tokens with empty IntervalSet, got %d", len(emptyMatched))
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify antlr.IntervalSet in pkg:golang/github.com/antlr4-go/antlr/v4@v4.13.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/antlr4-go/antlr/v4@v4.13.1"
  ],
  "symbols": [
    "antlr.IntervalSet"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}

Seeder d'origine

anonyme