-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84de014
commit 61feefc
Showing
26 changed files
with
2,154 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:result_type/result_type.dart'; | ||
import 'package:ying_shared/cli/command.dart'; | ||
import 'package:ying_shared/cli/command_execution_context.dart'; | ||
import 'package:ying_shared/cli/flag.dart'; | ||
import 'package:ying_shared/languages/yang/parser.dart'; | ||
import 'package:ying_shared/logging/logger.dart'; | ||
import 'package:ying_shared/source_file.dart'; | ||
|
||
class BuildCommand extends Command { | ||
final Logger logger = Logger.withSimpleNameFromEnv("build"); | ||
|
||
BuildCommand() | ||
: super("build", [], [], [ | ||
FileFlag("entrypoint", ["e"], true, true), | ||
]); | ||
|
||
@override | ||
void execute(CommandExecutionContext commandExecutionContext) async { | ||
final File entrypoint = commandExecutionContext.parsedFlags["entrypoint"]; | ||
|
||
if (entrypoint.existsSync() == false) { | ||
logger.error("File ${entrypoint.absolute.path} does not exist"); | ||
|
||
return; | ||
} | ||
|
||
final sourceFile = await SourceFile.readFromPath(entrypoint.absolute.path); | ||
|
||
switch (YangFrontend.parseFromSourceFile(sourceFile)) { | ||
case Success(value: var parsedStatements): | ||
logger.debug("Result: $parsedStatements"); | ||
break; | ||
|
||
case Failure(failure: var reason): | ||
logger.error("Could not parse ${sourceFile.uri}: $reason"); | ||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
import 'package:ying_shared/text_span.dart'; | ||
|
||
enum DiagnosticSeverity { | ||
error(1), | ||
warning(2), | ||
information(3), | ||
hint(4); | ||
|
||
final int value; | ||
|
||
const DiagnosticSeverity(this.value); | ||
} | ||
|
||
enum DiagnosticTag { | ||
unnecessary(1), | ||
deprecated(2); | ||
|
||
final int value; | ||
|
||
const DiagnosticTag(this.value); | ||
} | ||
|
||
class Location { | ||
final String uri; | ||
|
||
final TextSpan range; | ||
|
||
const Location(this.uri, this.range); | ||
|
||
@override | ||
bool operator ==(Object other) => | ||
identical(this, other) || | ||
other is Location && | ||
runtimeType == other.runtimeType && | ||
uri == other.uri && | ||
range == other.range; | ||
|
||
@override | ||
int get hashCode => uri.hashCode ^ range.hashCode; | ||
} | ||
|
||
class DiagnosticRelatedInformation { | ||
final Location location; | ||
|
||
final String message; | ||
|
||
const DiagnosticRelatedInformation(this.location, this.message); | ||
|
||
@override | ||
bool operator ==(Object other) => | ||
identical(this, other) || | ||
other is DiagnosticRelatedInformation && | ||
runtimeType == other.runtimeType && | ||
location == other.location && | ||
message == other.message; | ||
|
||
@override | ||
int get hashCode => location.hashCode ^ message.hashCode; | ||
} | ||
|
||
class Diagnostic { | ||
/// The range at which the message applies. | ||
final TextSpan range; | ||
|
||
/// The diagnostic's severity. To avoid interpretation mismatches when a | ||
/// server is used with different clients it is highly recommended that | ||
/// servers always provide a severity value. If omitted, it’s recommended | ||
/// for the client to interpret it as an Error severity. | ||
final DiagnosticSeverity severity; | ||
|
||
/// The diagnostic's code, which might appear in the user interface. | ||
final String? code; | ||
|
||
/// A human-readable string describing the source of this | ||
/// diagnostic, e.g. 'typescript' or 'super lint'. | ||
final String? source; | ||
|
||
/// The diagnostic's message. | ||
final String message; | ||
|
||
/// Additional metadata about the diagnostic. | ||
final List<DiagnosticTag>? tags; | ||
|
||
/// An array of related diagnostic information, e.g. when symbol-names within | ||
/// a scope collide all definitions can be marked via this property. | ||
final List<DiagnosticRelatedInformation>? relatedInformation; | ||
|
||
final dynamic data; | ||
|
||
const Diagnostic( | ||
this.range, | ||
this.message, { | ||
this.severity = DiagnosticSeverity.error, | ||
this.code, | ||
this.source, | ||
this.tags, | ||
this.relatedInformation, | ||
this.data, | ||
}); | ||
|
||
Diagnostic.error( | ||
this.range, | ||
this.message, { | ||
this.code, | ||
this.source, | ||
this.tags, | ||
this.relatedInformation, | ||
this.data, | ||
}) : severity = DiagnosticSeverity.error; | ||
|
||
Diagnostic.warning( | ||
this.range, | ||
this.message, { | ||
this.code, | ||
this.source, | ||
this.tags, | ||
this.relatedInformation, | ||
this.data, | ||
}) : severity = DiagnosticSeverity.warning; | ||
|
||
Diagnostic.information( | ||
this.range, | ||
this.message, { | ||
this.code, | ||
this.source, | ||
this.tags, | ||
this.relatedInformation, | ||
this.data, | ||
}) : severity = DiagnosticSeverity.information; | ||
|
||
Diagnostic.hint( | ||
this.range, | ||
this.message, { | ||
this.code, | ||
this.source, | ||
this.tags, | ||
this.relatedInformation, | ||
this.data, | ||
}) : severity = DiagnosticSeverity.hint; | ||
|
||
@override | ||
bool operator ==(Object other) => | ||
identical(this, other) || | ||
other is Diagnostic && | ||
runtimeType == other.runtimeType && | ||
range == other.range && | ||
severity == other.severity && | ||
code == other.code && | ||
source == other.source && | ||
message == other.message && | ||
tags == other.tags && | ||
relatedInformation == other.relatedInformation && | ||
data == other.data; | ||
|
||
@override | ||
int get hashCode => | ||
range.hashCode ^ | ||
severity.hashCode ^ | ||
code.hashCode ^ | ||
source.hashCode ^ | ||
message.hashCode ^ | ||
tags.hashCode ^ | ||
relatedInformation.hashCode ^ | ||
data.hashCode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import 'package:ying_shared/located_token.dart'; | ||
import 'package:ying_shared/languages/yang/type.dart'; | ||
import 'package:ying_shared/utils/stringify.dart'; | ||
|
||
abstract class Expression { | ||
@override | ||
String toString() => stringifyInstance("Expression"); | ||
} | ||
|
||
class IdentifierExpression extends Expression { | ||
final String value; | ||
|
||
IdentifierExpression(this.value); | ||
|
||
@override | ||
String toString() => stringifyInstance("IdentifierExpression", fields: { | ||
"value": value, | ||
}); | ||
} | ||
|
||
abstract class Statement { | ||
@override | ||
String toString() => stringifyInstance("Statement"); | ||
} | ||
|
||
class ExportStatement extends Statement { | ||
final Statement expression; | ||
|
||
ExportStatement(this.expression); | ||
|
||
@override | ||
String toString() => stringifyInstance("ExportExpression", fields: { | ||
"expression": expression, | ||
}); | ||
|
||
static (int, ExportStatement)? fromTokens( | ||
List<LocatedToken> locatedTokens, | ||
int currentPosition, | ||
) { | ||
return null; | ||
} | ||
} | ||
|
||
class TypeStatement extends Statement { | ||
Type identifier; | ||
|
||
Expression typeExpression; | ||
|
||
TypeStatement(this.identifier, this.typeExpression); | ||
|
||
@override | ||
String toString() => stringifyInstance("TypeStatement", fields: { | ||
"identifier": identifier, | ||
"typeExpression": typeExpression, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:ying_shared/languages/yang/type_argument.dart'; | ||
|
||
abstract class Identifier {} | ||
|
||
class UnresolvedIdentifier extends Identifier { | ||
final String base; | ||
final List<TypeArgument> typeArguments; | ||
|
||
UnresolvedIdentifier(this.base) : typeArguments = []; | ||
|
||
UnresolvedIdentifier.withTypeArguments(this.base, this.typeArguments); | ||
} |
Oops, something went wrong.