@xnoxs/flux-lang 3.5.2 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -85,6 +85,7 @@ export class Parser:
85
85
  if tok.type == T.FN: return self.parseFnDecl(false)
86
86
  if tok.type == T.ASYNC: return self.parseAsyncFn()
87
87
  if tok.type == T.CLASS: return self.parseClassDecl()
88
+ if tok.type == T.DECLARE: return self.parseDeclareDecl()
88
89
  if tok.type == T.IF: return self.parseIf()
89
90
  if tok.type == T.FOR: return self.parseFor()
90
91
  if tok.type == T.WHILE: return self.parseWhile()
@@ -668,6 +669,46 @@ export class Parser:
668
669
  if not self.check(T.FN): self.err('Expected fn after async')
669
670
  return self.parseFnDecl(true)
670
671
 
672
+ fn parseDeclareDecl():
673
+ val loc = self.eat(T.DECLARE)
674
+ val tok = self.peek()
675
+
676
+ if tok.type == T.FN or tok.type == T.ASYNC:
677
+ val isAsync = tok.type == T.ASYNC
678
+ self.skip()
679
+ if isAsync: self.eat(T.FN)
680
+ val name = self.check(T.IDENT) ? self.skip().value : null
681
+ val params = self.parseParamList()
682
+ var retType = null
683
+ if self.check(T.ARROW):
684
+ self.pos = self.pos + 1
685
+ retType = self.parseTypeAnn()
686
+ else if self.check(T.COLON):
687
+ self.pos = self.pos + 1
688
+ retType = self.parseTypeAnn()
689
+ self.skipNewlines()
690
+ val decl = { type: 'FnDecl', name, params, retType, body: [], inline: false, async: isAsync, loc: tok }
691
+ return { type: 'DeclareDecl', decl, loc }
692
+
693
+ if tok.type == T.VAL or tok.type == T.VAR:
694
+ val kind = tok.type == T.VAR ? 'var' : 'val'
695
+ self.skip()
696
+ val name = self.eat(T.IDENT).value
697
+ var typeAnn = null
698
+ if self.maybe(T.COLON): typeAnn = self.parseTypeAnn()
699
+ self.skipNewlines()
700
+ val decl = { type: 'VarDecl', kind, name, typeAnn, init: null, loc: tok }
701
+ return { type: 'DeclareDecl', decl, loc }
702
+
703
+ if tok.type == T.CLASS:
704
+ self.skip()
705
+ val name = self.eat(T.IDENT).value
706
+ self.skipNewlines()
707
+ val decl = { type: 'ClassDecl', name, fields: [], methods: [], loc: tok }
708
+ return { type: 'DeclareDecl', decl, loc }
709
+
710
+ self.err('Expected fn, async fn, val, var, or class after declare')
711
+
671
712
  fn parseParamList():
672
713
  self.eat(T.LPAREN)
673
714
  val params = []