julia-script / julia-script/silk

syntax: Add range operators .. and ..=

Open
#8 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement lexer needs-definition new feature P3 parser spec-change type-system
Dominant language
TypeScript
Stars
48
Forks
0
Avg merge
4h 49m
Merged PRs (30d)
213

Description

Context

Silk has no range value. A user who wants to walk a sequence of numbers writes a
while loop with an index variable. A range operator makes this shorter and gives a
value that a future for statement can use.

Current behavior

The lexer makes a DotDot token (packages/compiler/src/Lexer.ts:74). The parser
consumes that token in one place only: the rest pattern inside a nominal pattern
(packages/compiler/src/Parser.ts:830-831). There is no ..= token.

let mut index = 0
while index < limit {
  index = index + 1
}

Requirements

  1. The lexer must make a token for ..=.
  2. The parser must accept a .. b and a ..= b in expression position.
  3. a .. b must exclude the value b.
  4. a ..= b must include the value b.
  5. Both operands must have the same integer type.
  6. The range must be an ordinary value that a user can pass to a function.
  7. The parser must keep the rest pattern behavior in pattern position.

Example

pub fn sum(limit: usize) -> usize {
  let mut total = usize.add(0, 0)
  // The range gives the values 0 to limit minus 1.
  let span = 0 .. limit
  return total
}

Out of scope

  • A for statement. That is a separate decision.
  • Range patterns in a match arm. Add those after this ticket lands.
  • A range over a non-integer type.

Dependencies

None.

Acceptance criteria

  • The lexer makes a ..= token.
  • The parser accepts a range in expression position.
  • The parser still accepts .. as the rest pattern in a nominal pattern.
  • A test shows both forms in the same file.
  • openspec/specs/bootstrap-syntax/spec.md:746-750 gets an amendment.

Implementation note

The conflict with the rest pattern is smaller than it looks. The parser consumes
DotDot in exactly one production, inside a nominal pattern field list, and only where
it expects a field. A range in expression position never reaches that production.
Disambiguate by grammatical position. Do not choose a different spelling.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the lexer token at packages/compiler/src/Lexer.ts:74 and the expression parser alongside the rest-pattern production at packages/compiler/src/Parser.ts:830-831. Add coverage for both range forms in one file, preserving the nominal-pattern rest behavior, and amend openspec/specs/bootstrap-syntax/spec.md:746-750; done means the stated lexer, parser, integer-type, inclusivity, and ordinary-value requirements are covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.