Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Unified Diff: pkg/analysis_server/tool/spec/codegen_tools.dart

Issue 863883004: Support code generation for other languages (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove setter Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/tool/spec/codegen_tools.dart
diff --git a/pkg/analysis_server/tool/spec/codegen_tools.dart b/pkg/analysis_server/tool/spec/codegen_tools.dart
index 898f4b777c2d34ae46b43e583015308181872dcf..bbd243c28d59944fcbb771c684427f0007029920 100644
--- a/pkg/analysis_server/tool/spec/codegen_tools.dart
+++ b/pkg/analysis_server/tool/spec/codegen_tools.dart
@@ -57,6 +57,12 @@ class CodeGenerator {
_CodeGeneratorState _state;
/**
+ * Settings that specialize code generation behavior for a given
+ * programming language.
+ */
+ CodeGeneratorSettings codeGeneratorSettings;
+
+ /**
* Measure the width of the current indentation level.
*/
int get indentWidth => _state.nextIndent.length;
@@ -82,16 +88,28 @@ class CodeGenerator {
* If [javadocStyle] is true, then the output is compatable with Javadoc,
* which understands certain HTML constructs.
*/
- void docComment(List<dom.Node> docs, {int width: 79, bool javadocStyle:
- false}) {
+ void docComment(List<dom.Node> docs) {
if (containsOnlyWhitespace(docs)) {
return;
}
- writeln('/**');
- indentBy(' * ', () {
+ writeln(codeGeneratorSettings.docCommentStartMarker);
+ var width = codeGeneratorSettings.commentLineLength;
+ var javadocStyle = codeGeneratorSettings.languageName == 'java';
+ indentBy(codeGeneratorSettings.docCommentLineLeader, () {
write(nodesToText(docs, width - _state.indent.length, javadocStyle));
});
- writeln(' */');
+ writeln(codeGeneratorSettings.docCommentEndMarker);
+ }
+
+ void lineComment(List<dom.Node> docs) {
+ if (containsOnlyWhitespace(docs)) {
+ return;
+ }
+ write(codeGeneratorSettings.lineCommentLineLeader);
+ var width = codeGeneratorSettings.commentLineLength;
+ indentBy(codeGeneratorSettings.lineCommentLineLeader, () {
+ write(nodesToText(docs, width - _state.indent.length, false));
+ });
}
/**
@@ -126,7 +144,7 @@ class CodeGenerator {
void outputHeader({bool javaStyle: false}) {
String header;
- if (javaStyle) {
+ if (codeGeneratorSettings.languageName == 'java') {
header = '''
/*
* Copyright (c) 2014, the Dart project authors.
@@ -144,6 +162,16 @@ class CodeGenerator {
* This file has been automatically generated. Please do not edit it manually.
* To regenerate the file, use the script "pkg/analysis_server/tool/spec/generate_files".
*/''';
+ } else if (codeGeneratorSettings.languageName == 'python') {
+ header = '''
+# Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+# for details. All rights reserved. Use of this source code is governed by a
+# BSD-style license that can be found in the LICENSE file.
+#
+# This file has been automatically generated. Please do not edit it manually.
+# To regenerate the file, use the script
+# "pkg/analysis_server/tool/spec/generate_files".
+''';
} else {
header = '''
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
@@ -398,6 +426,47 @@ abstract class HtmlCodeGenerator {
}
/**
+ * Controls several settings of [CodeGenerator].
+ *
+ * The default settings are valid for generating Java and Dart code.
+ */
+class CodeGeneratorSettings {
+ /**
+ * Name of the language being generated. Lowercase.
+ */
+ String languageName;
+
+ /**
+ * Marker used in line comments.
+ */
+ String lineCommentLineLeader;
+
+ /**
+ * Start marker for doc comments.
+ */
+ String docCommentStartMarker;
+
+ /**
+ * Line leader for body lines in doc comments.
+ */
+ String docCommentLineLeader;
+
+ /**
+ * End marker for doc comments.
+ */
+ String docCommentEndMarker;
+
+ /**
+ * Line length for doc comment lines.
+ */
+ int commentLineLength;
+
+ CodeGeneratorSettings({this.languageName: 'java', this.lineCommentLineLeader: '// ',
+ this.docCommentStartMarker: '/**', this.docCommentLineLeader: ' * ',
+ this.docCommentEndMarker: ' */', this.commentLineLength: 79});
+}
+
+/**
* State used by [CodeGenerator].
*/
class _CodeGeneratorState {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698