BadScript 2
Loading...
Searching...
No Matches
BadExportExpressionParser.cs
Go to the documentation of this file.
7
9
14{
16 public override bool IsValue(BadSourceParser parser)
17 {
18 return parser.Reader.IsKey(BadStaticKeys.EXPORT_KEY);
19 }
20
27 public static bool IsNamed(BadExpression expr, out string? name)
28 {
29 if (expr is IBadNamedExpression namedExpr)
30 {
31 name = namedExpr.GetName();
32
33 return true;
34 }
35
36 if (expr is BadAssignExpression assign)
37 {
38 if (assign.Left is IBadNamedExpression named)
39 {
40 name = named.GetName();
41
42 return true;
43 }
44 }
45
46 name = null;
47
48 return false;
49 }
50
53 {
55 parser.Reader.SkipNonToken();
56 bool isDefault = parser.Reader.IsKey(BadStaticKeys.DEFAULT_KEY);
57 if (isDefault)
58 {
60 parser.Reader.SkipNonToken();
61 }
62
63 BadExpression expr = parser.ParseExpression();
64
65 bool isNamed = IsNamed(expr, out string? name);
66
67 if (!isDefault && isNamed)
68 {
69 return new BadNamedExportExpression(name, expr, pos.Combine(expr.Position));
70 }
71
72 if (isDefault && !isNamed)
73 {
74 throw new BadRuntimeException("Default Export must be a named expression", pos);
75 }
76
77 return new BadDefaultExportExpression(expr, pos.Combine(expr.Position));
78 }
79}
Describes a specific position inside a source file.
BadSourcePosition Combine(BadSourcePosition other)
Combines two Source Positions.
Contains Static Data for the BadScript Language.
The Parser of the Language. It turns Source Code into an Expression Tree.
BadSourceReader Reader
The Source Reader.
BadExpression ParseExpression(BadExpression? left=null, int precedence=int.MaxValue)
Parses an Expression with a precedence greater than the given precedence. Moves the reader to the nex...
Base Implementation for all Expressions used inside the Script.
BadSourcePosition Position
The source Position of the Expression.
Implements the Assign Expression LEFT = RIGHT.
Base class for all Value Parsers.
override BadExpression ParseValue(BadSourceParser parser)
static bool IsNamed(BadExpression expr, out string? name)
Returns true if the specified expression is a named expression.
BadSourcePosition Eat(char c)
Asserts that the current character matches the specified character.
Gets inherited by all Expressions that have a Name(e.g. Variable Definitions, Function Definitions,...
Contains Shared Data Structures and Functionality.
Contains the Binary Expressions for the BadScript2 Language.
Contains the Expressions for the BadScript2 Language.
Contains the Source Reader for the BadScript2 Language.
Contains the Error Objects for the BadScript2 Language.