Make :- a valid tack too
This commit is contained in:
parent
fef3df7f64
commit
79bea645da
2 changed files with 9 additions and 3 deletions
|
@ -156,12 +156,17 @@ class Analyzer(AnalyzerBase):
|
||||||
"""
|
"""
|
||||||
TACK0 = _t('⊢')
|
TACK0 = _t('⊢')
|
||||||
TACK1 = _t('|-')
|
TACK1 = _t('|-')
|
||||||
|
TACK2 = p.KeywordToken(":-", None, None)
|
||||||
LET = _t('let')
|
LET = _t('let')
|
||||||
DO = _t('do')
|
DO = _t('do')
|
||||||
FN = _t('fn')
|
FN = _t('fn')
|
||||||
LIST = _t('list')
|
LIST = _t('list')
|
||||||
QUOTE = _t('quote')
|
QUOTE = _t('quote')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _tackp(cls, t):
|
||||||
|
return t in [cls.TACK0, cls.TACK1, cls.TACK2]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _nows(cls, tokens):
|
def _nows(cls, tokens):
|
||||||
return [t for t in tokens if not isinstance(t, p.WhitespaceToken)]
|
return [t for t in tokens if not isinstance(t, p.WhitespaceToken)]
|
||||||
|
@ -172,7 +177,7 @@ class Analyzer(AnalyzerBase):
|
||||||
|
|
||||||
if len(tokens) == 1:
|
if len(tokens) == 1:
|
||||||
return cls.analyze(tokens[0]), []
|
return cls.analyze(tokens[0]), []
|
||||||
elif tokens[1] in [cls.TACK0, cls.TACK1]:
|
elif cls._tackp(tokens[1]):
|
||||||
if len(tokens) >= 3:
|
if len(tokens) >= 3:
|
||||||
return (
|
return (
|
||||||
AscribeExpr(
|
AscribeExpr(
|
||||||
|
@ -269,7 +274,7 @@ class Analyzer(AnalyzerBase):
|
||||||
if not binding_tokens:
|
if not binding_tokens:
|
||||||
raise SyntaxError(f"Analyzing `let` at {let_token.pos}, got binding expression without subsequent value expression!")
|
raise SyntaxError(f"Analyzing `let` at {let_token.pos}, got binding expression without subsequent value expression!")
|
||||||
|
|
||||||
if binding_tokens[0] in [cls.TACK0, cls.TACK1]:
|
if cls._tackp(binding_tokens[0]):
|
||||||
if len(binding_tokens) < 2:
|
if len(binding_tokens) < 2:
|
||||||
raise SyntaxError(f"Analyzing `let` at {let_token.pos}, got `⊢` at {binding_tokens[0].pos} without type!")
|
raise SyntaxError(f"Analyzing `let` at {let_token.pos}, got `⊢` at {binding_tokens[0].pos} without type!")
|
||||||
bind_ascription = cls.analyze(binding_tokens[1])
|
bind_ascription = cls.analyze(binding_tokens[1])
|
||||||
|
@ -311,7 +316,7 @@ class Analyzer(AnalyzerBase):
|
||||||
args.append(argexpr)
|
args.append(argexpr)
|
||||||
|
|
||||||
ascription = None
|
ascription = None
|
||||||
if tokens[1] in [cls.TACK0, cls.TACK1]:
|
if cls._tackp(tokens[1]):
|
||||||
ascription = cls.analyze(tokens[2])
|
ascription = cls.analyze(tokens[2])
|
||||||
tokens = tokens[2:]
|
tokens = tokens[2:]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -43,6 +43,7 @@ def test_analyze_constants(txt, exprtype):
|
||||||
'(fn [] 1)',
|
'(fn [] 1)',
|
||||||
'(fn [] ⊢ integer? x)',
|
'(fn [] ⊢ integer? x)',
|
||||||
'(fn [] x |- integer?)',
|
'(fn [] x |- integer?)',
|
||||||
|
'(fn [] x :- integer?)',
|
||||||
])
|
])
|
||||||
def test_analyze(txt):
|
def test_analyze(txt):
|
||||||
"""Make sure that do exprs work."""
|
"""Make sure that do exprs work."""
|
||||||
|
|
Loading…
Reference in a new issue