Skip to content

Commit

Permalink
[syntax] use "@cicada-lang/partech" to implement new syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Jul 29, 2023
1 parent 5bf7890 commit a71a5b9
Show file tree
Hide file tree
Showing 28 changed files with 264 additions and 200 deletions.
6 changes: 4 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[syntax] use "@cicada-lang/partech" to implement new syntax
`"head" let` instead of `(let head)`

`Node` with optionally named port

- `NetRenderer` show free port names
`defnode` instead of `defcons` and `defelim`

`NetRenderer` -- format to simple text representation of graph

Expand All @@ -12,6 +12,8 @@ change the `render` command to simple `run` command

[maybe] quit using `ActiveEdge`

`NetRenderer` show free port names

# the paper

phase space and monoid -- understand the model theory of linear logic
Expand Down
15 changes: 7 additions & 8 deletions docs/notes/design-of-new-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ defrule add1 add
end
```

`defn` is a short hand for simple `defrule`,
to define rules that works like a function.
`defru` is a short hand for simple `defrule`.

```inet
defn zero add end
defru zero add end
defn add1 add add add1 end
defru add1 add add add1 end
```

```inet
Expand Down Expand Up @@ -111,12 +110,12 @@ defrule cons append
return-(append)
end
defn null append end
defru null append end
# the syntax for `let` and `get` is yet to be designed.
# I use `<...>` and description for work-in-progress syntax design.
defn cons append
defru cons append
<let head> append <get head> cons
end
Expand Down Expand Up @@ -158,13 +157,13 @@ defrule diff diff_open
(diff)-left return-(diff_open)
end
defn diff diff_append
defru diff diff_append
<let diff_list end start>
<get end> <get diff_list>
diff_open <get start> diff
end
defn diff diff_open
defru diff diff_open
<let list end start>
<get list> <get end> connect
<get start>
Expand Down
38 changes: 21 additions & 17 deletions docs/tests/diff-list.inet
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
(defcons sole 0 1)
defcons sole 0 1 end

(defcons null 0 1)
(defcons cons 2 1)
defcons null 0 1 end
defcons cons 2 1 end

(defcons diff 2 1)
defcons diff 2 1 end

(defelim diff-append 2 1)
defelim diff_append 2 1 end

(defrule (diff diff-append)
(let diff-list end start)
end diff-list diff-open start diff)
defru diff diff_append
(let start) (let fin) (let diff_list)
fin diff_list diff_open start diff
end

(defelim diff-open 2 1)
defelim diff_open 2 1 end

(defrule (diff diff-open)
(let list end start)
list end connect
start)
defru diff diff_open
(let start) (let fin) (let list)
list fin connect
start
end

(defnet one-two-soles
defnet one_two_soles
wire sole cons diff
wire sole cons sole cons diff
diff-append)
diff_append
end

(defnet two-two-soles
defnet two_two_soles
wire sole cons sole cons diff
wire sole cons sole cons diff
diff-append)
diff_append
end
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ cons#8
diff#9 -- cons#8 [label="0-2"]
cons#8
diff#9
diff-append#10 -- diff#3 [label="1-2"]
diff_append#10 -- diff#3 [label="1-2"]
diff#3
diff-append#10
diff_append#10
cons#2 -- diff#3 [label="1-1"]
diff#3
cons#2
cons#6 -- diff#9 [label="1-1"]
diff#9
cons#6
diff-append#10 -- diff#9 [label="0-2" color=red]
diff_append#10 -- diff#9 [label="0-2" color=red]
diff#9
diff-append#10
diff-append#10(2) -- diff-append#10
diff-append#10
diff-append#10(2)
diff_append#10
diff_append#10(2) -- diff_append#10
diff_append#10
diff_append#10(2)
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ cons#24
diff#25 -- cons#24 [label="0-2"]
cons#24
diff#25
diff-append#26 -- diff#19 [label="1-2"]
diff_append#26 -- diff#19 [label="1-2"]
diff#19
diff-append#26
diff_append#26
cons#16 -- diff#19 [label="1-1"]
diff#19
cons#16
cons#22 -- diff#25 [label="1-1"]
diff#25
cons#22
diff-append#26 -- diff#25 [label="0-2" color=red]
diff_append#26 -- diff#25 [label="0-2" color=red]
diff#25
diff-append#26
diff-append#26(2) -- diff-append#26
diff-append#26
diff-append#26(2)
diff_append#26
diff_append#26(2) -- diff_append#26
diff_append#26
diff_append#26(2)
17 changes: 9 additions & 8 deletions docs/tests/list.inet
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
(defcons sole 0 1)
defcons sole 0 1 end

(defcons null 0 1)
defcons null 0 1 end

(defcons cons 2 1)
defcons cons 2 1 end

(defelim append 2 1)
defelim append 2 1 end

(defrule (null append))
defru null append end

(defrule (cons append) (let head) append head cons)
defru cons append (let head) append head cons end

(defnet six-soles
defnet six_soles
null sole cons sole cons sole cons
null sole cons sole cons sole cons
append)
append
end
File renamed without changes.
File renamed without changes.
20 changes: 11 additions & 9 deletions docs/tests/nat.inet
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
(defcons zero 0 1)
defcons zero 0 1 end

(defcons add1 1 1)
defcons add1 1 1 end

(defelim add 2 1)
defelim add 2 1 end

(defrule (zero add))
defru zero add end

(defrule (add1 add) add add1)
defru add1 add add add1 end

(defnet two
defnet two
zero add1
zero add1
add)
add
end

(defnet four
two two add)
defnet four
two two add
end
33 changes: 0 additions & 33 deletions docs/todo/diff-list.inet

This file was deleted.

29 changes: 23 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"typescript": "^5.1.6"
},
"dependencies": {
"@cicada-lang/sexp": "^0.0.36",
"@cicada-lang/partech": "^0.2.5",
"@xieyuheng/command-line": "^0.0.10",
"@xieyuheng/ty": "^0.1.22"
},
Expand Down
4 changes: 2 additions & 2 deletions src/console/commands/RenderCommand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ParsingError } from "@cicada-lang/sexp/lib/errors"
import { ParsingError } from "@cicada-lang/partech/lib/errors"
import { Command, CommandRunner } from "@xieyuheng/command-line"
import ty from "@xieyuheng/ty"
import fs from "fs"
Expand Down Expand Up @@ -68,7 +68,7 @@ export class RenderCommand extends Command<Args, Opts> {
}
} catch (error) {
if (error instanceof ParsingError) {
const report = error.span.report(text)
const report = error.report(text)
console.error(report)
}

Expand Down
2 changes: 1 addition & 1 deletion src/lang/errors/ParsingError.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { ParsingError } from "@cicada-lang/sexp/lib/errors"
export { ParsingError } from "@cicada-lang/partech/lib/errors"
2 changes: 1 addition & 1 deletion src/lang/span/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { Span } from "@cicada-lang/sexp/lib/span"
export { Span } from "@cicada-lang/partech/lib/span"
24 changes: 0 additions & 24 deletions src/lang/syntax/Parser.ts

This file was deleted.

10 changes: 10 additions & 0 deletions src/lang/syntax/grammars/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as pt from "@cicada-lang/partech"

export const zero_or_more = pt.grammars.zero_or_more
export const one_or_more = pt.grammars.one_or_more
export const optional = pt.grammars.optional
export const dashline = pt.grammars.dashline

export * from "./name"
export * from "./stmt"
export * from "./word"
Loading

0 comments on commit a71a5b9

Please sign in to comment.