diff options
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java index 541a739..1d9244a 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java @@ -6,6 +6,7 @@ import org.zwobble.hobgoblin.compiler.output.lang.rust.ast.*; import java.io.IOException; import java.nio.file.Path; +import java.util.Set; import static org.zwobble.hobgoblin.compiler.output.CodeWriter.writeWithSeparator; @@ -353,10 +354,72 @@ public class RustWriter implements AutoCloseable { // == Identifiers == void writeIdentifier(RustIdentifier identifier) throws IOException { - // TODO: handle keywords + if (isRustKeyword(identifier)) { + this.writer.write("r#"); + } this.writer.write(identifier.value()); } + private static final Set<String> RUST_KEYWORDS = Set.of( + "_", + "abstract", + "as", + "async", + "await", + "become", + "box", + "break", + "const", + "continue", + "crate", + "do", + "dyn", + "else", + "enum", + "extern", + "false", + "final", + "fn", + "for", + "gen", + "if", + "impl", + "in", + "let", + "loop", + "macro", + "match", + "mod", + "move", + "mut", + "override", + "priv", + "pub", + "ref", + "return", + "self", + "Self", + "static", + "struct", + "super", + "trait", + "true", + "try", + "type", + "typeof", + "unsafe", + "unsized", + "use", + "virtual", + "where", + "while", + "yield" + ); + + private boolean isRustKeyword(RustIdentifier identifier) { + return RUST_KEYWORDS.contains(identifier.value()); + } + // == Doc comments == private void writeDocComment(DocComment docComment) throws IOException { |
