Skip to content

Dialects: add basison (BASIC) and rubascal (Pascal/Ruby) - #6254

Open
runarorama wants to merge 2 commits into
pluggable-syntax-dialectsfrom
basison-rubascal
Open

Dialects: add basison (BASIC) and rubascal (Pascal/Ruby)#6254
runarorama wants to merge 2 commits into
pluggable-syntax-dialectsfrom
basison-rubascal

Conversation

@runarorama

Copy link
Copy Markdown
Contributor

Stacked on top of #6253 (base branch: pluggable-syntax-dialects).

Two more surface syntaxes over the same content-addressed AST — added "for shits and giggles" — both round-tripping through the Surface IR like the existing alt dialects:

basison — BASIC-flavored

FUNCTION name(p, …) … RETURN e END FUNCTION, SELECT CASE … END SELECT, IF c THEN t ELSE e END IF, LET bindings, AS for type ascription, UPPERCASE keywords, : statement separator. The full type rides on a preceding name AS Type signature line.

gcd AS Nat -> Nat -> Nat
FUNCTION gcd(a, b)
  go AS Nat -> Nat -> Nat
  FUNCTION go(x, y)
    RETURN IF y == 0 THEN x ELSE go(y, Nat.mod(x, y)) END IF
  END FUNCTION
  RETURN go(a, b)
END FUNCTION

rubascal — a Pascal/Ruby hybrid

def name(p, …) … end with an implicit return (the last expression is the result, Ruby-style), case … when p then body … end, if c then t else e end, := value bindings (Pascal), : type ascription, begin … end blocks, ->() lambdas, ; separators, bare end enders.

gcd : Nat -> Nat -> Nat
def gcd(a, b)
  go : Nat -> Nat -> Nat
  def go(x, y)
    if y == 0 then x else go(y, Nat.mod(x, y)) end
  end
  go(a, b)
end

Both are registered in Unison.Syntax.Dialect and selectable with syntax.set basison / syntax.set rubascal. The dialects transcript gains a demo section for each, and view/edit round-trip to identical hashes (verified on functions, recursion, tuples, pattern matching, documented definitions, and typed local helpers).

Two more surface syntaxes over the same content-addressed AST, both
round-tripping through the Surface IR like the existing alt dialects:

- basison: BASIC-flavored. FUNCTION name(p, …) … RETURN e END FUNCTION,
  SELECT CASE … END SELECT, IF c THEN t ELSE e END IF, LET bindings, AS for
  type ascription, UPPERCASE keywords, ':' statement separator. The full
  type rides on a preceding 'name AS Type' signature line.

- rubascal: a Pascal/Ruby hybrid. def name(p, …) … end with an implicit
  return (last expression is the result), case … when p then body … end,
  if c then t else e end, ':=' value bindings (Pascal), ':' type ascription,
  begin … end blocks, '->()' lambdas, ';' separators, bare 'end' enders.

Both are registered in Unison.Syntax.Dialect and selectable with
'syntax.set basison' / 'syntax.set rubascal'. The dialects transcript gains
a demo section for each.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant