Skip to content

Commit

Permalink
Slight improvement and preperations for 'where'
Browse files Browse the repository at this point in the history
  • Loading branch information
TheUnlocked committed Dec 9, 2018
1 parent 6b74552 commit fdab4b7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
6 changes: 6 additions & 0 deletions FAILang/FAILangVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ public override IType VisitDef([NotNull] FAILangParser.DefContext context)

public override IType VisitExpression([NotNull] FAILangParser.ExpressionContext context)
{
return VisitWhere(context.where());
}

public override IType VisitWhere([NotNull] FAILangParser.WhereContext context)
{
// TODO: Implement this
return VisitBoolean(context.boolean());
}

Expand Down
19 changes: 11 additions & 8 deletions FAILang/Grammar/FAILang.g4
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ imp

def
: update=UPDATE? memoize=MEMO? name L_PAREN fparams R_PAREN EQ expression
| update=UPDATE? name ( EQ | ASSIGN ) expression
| update=UPDATE? name EQ expression
| update=UPDATE memoize=MEMO name
;

Expand All @@ -49,6 +49,11 @@ param
;

expression
: where
;

where
//: boolean (WHERE (name EQ expression COMMA)* name EQ expression)?
: boolean
;

Expand Down Expand Up @@ -123,7 +128,7 @@ indexer
;

piecewise
: L_CURL condition+ (expression OTHERWISE SEMI_COLON)?
: L_CURL condition+ (expression OTHERWISE SEMI_COLON?)?
;

condition
Expand Down Expand Up @@ -270,9 +275,6 @@ ELIPSIS
ARROW
: '->'
;
ASSIGN
: ':='
;

NUMBER
: DIGIT* '.' DIGIT+ (E '-'? DIGIT+)?
Expand All @@ -292,9 +294,6 @@ UNDEFINED
: 'undefined'
;

LAMBDA
: 'lambda'
;
UPDATE
: 'update'
;
Expand All @@ -317,6 +316,10 @@ USING
: 'using'
;

WHERE
: 'where'
;

NAME
:
( UPPERCASE
Expand Down
2 changes: 1 addition & 1 deletion FAILang/Types/Unevaluated/FunctionExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public IType Evaluate(Dictionary<string, IType> lookups)
{
return new BakedExpression(new FunctionExpression(func, args), lookups);
}
if (func is IOperable n1 && args.Length == 1)
if (func is Number n1 && args.Length == 1)
return new BinaryOperatorExpression(BinaryOperator.MULTIPLY, n1, args[0].Item1).Evaluate(lookups);
return new Error("SyntaxError", $"You can't call an object of type {func.TypeName}.");
}
Expand Down

0 comments on commit fdab4b7

Please sign in to comment.