Skip to content

Commit

Permalink
Ohm indentation and gen class test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattmart42 committed May 2, 2024
1 parent c5b0348 commit a129b9d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 46 deletions.
18 changes: 9 additions & 9 deletions src/MODE.ohm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MODE {
Program = Stmt+
Program = Stmt+
Stmt = VarDecl
| Assignment
| FunDecl
Expand Down Expand Up @@ -30,8 +30,8 @@ MODE {
ClassDef = class id "{" Field* "}" ";"
Field = id ":" Type ";"
FunDecl = func id Params (":" Type)? Block
Params = "(" ListOf<Param, ","> ")"
Param = id ":" Type
Params = "(" ListOf<Param, ","> ")"
Param = id ":" Type

Type = Type "[" "]" --arr
| types --primitive
Expand Down Expand Up @@ -62,13 +62,13 @@ MODE {

relop = "<=" | "<" | "==" | "!=" | ">=" | ">"
int = digit+
float = digit+ ("." digit+) (("E" | "e") ("+" | "-")? digit+)?
string = "\"" char* "\""
char = ~"\\" ~"\"" any --normalchars
| "\\" ("'" | "\"" | "n" | "\\") --escape
| "\\u{" hex? hex? hex? hex? hex? hex? "}" --hex
float = digit+ ("." digit+) (("E" | "e") ("+" | "-")? digit+)?
string = "\"" char* "\""
char = ~"\\" ~"\"" any --normalchars
| "\\" ("'" | "\"" | "n" | "\\") --escape
| "\\u{" hex? hex? hex? hex? hex? hex? "}" --hex
| "%{"id"}" --stringinterpolation
hex = hexDigit
hex = hexDigit
mut = ~"==" "=" | "++" | "--"

print = "print" ~idchar
Expand Down
68 changes: 33 additions & 35 deletions test/compiler.test.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
import * as assert from "assert/strict";
import assert from "node:assert/strict"
import compile from "../src/compiler.js"

describe("Sample Test", () => {
it("should test that true === true", () => {
assert.equal;(true, true);
});
});

// import assert from "node:assert/strict"
// import compile from "../src/compiler.js"
const sampleProgram = "print(0);"

// const sampleProgram = "print(0);"

// describe("The compiler", () => {
// it("throws when the output type is missing", done => {
// assert.throws(() => compile(sampleProgram), /Unknown output type/)
// done()
// })
// it("throws when the output type is unknown", done => {
// assert.throws(() => compile(sampleProgram, "no such type"), /Unknown output type/)
// done()
// })
// it("accepts the parsed option", done => {
// const compiled = compile(sampleProgram, "parsed")
// assert(compiled.startsWith("Syntax is ok"))
// done()
// })
// it("accepts the analyzed option", done => {
// const compiled = compile(sampleProgram, "analyzed")
// assert(compiled.kind === "Program")
// done()
// })
// it("accepts the optimized option", done => {
// const compiled = compile(sampleProgram, "optimized")
// assert(compiled.kind === "Program")
// done()
// })
// it("generates js code when given the js option", done => {
// const compiled = compile(sampleProgram, "js")
// assert(compiled.startsWith("console.log(0)"))
// done()
// })
// })
describe("The compiler", () => {
it("throws when the output type is missing", done => {
assert.throws(() => compile(sampleProgram), /Unknown output type/)
done()
})
it("throws when the output type is unknown", done => {
assert.throws(() => compile(sampleProgram, "no such type"), /Unknown output type/)
done()
})
it("accepts the parsed option", done => {
const compiled = compile(sampleProgram, "parsed")
assert(compiled.startsWith("Syntax is ok"))
done()
})
it("accepts the analyzed option", done => {
const compiled = compile(sampleProgram, "analyzed")
assert(compiled.kind === "Program")
done()
})
it("accepts the optimized option", done => {
const compiled = compile(sampleProgram, "optimized")
assert(compiled.kind === "Program")
done()
})
it("generates js code when given the js option", done => {
const compiled = compile(sampleProgram, "js")
assert(compiled.startsWith("console.log(0)"))
done()
})
})
4 changes: 2 additions & 2 deletions test/generator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ const fixtures = [
this["x_1"] = x_1;
}
}
let x_3 = new S_1(3);
console.log((x_3["x_2"]));
let x_2 = new S(3);
console.log((x_2["x_1"]));
`,
},
{
Expand Down

0 comments on commit a129b9d

Please sign in to comment.