Add literal string constants (#19)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
In addition, for the sake of Haskell code generation, this PR adds static typing with Statix. Resolves #5. Co-authored-by: Glen Whitney <glen@studioinfinity.org> Reviewed-on: #19 Co-Authored-By: Glen Whitney <glen@nobody@nowhere.net> Co-Committed-By: Glen Whitney <glen@nobody@nowhere.net>
This commit is contained in:
parent
c516ed6d7f
commit
2772fd0c5c
16 changed files with 386 additions and 34 deletions
|
@ -13,13 +13,25 @@ rules
|
|||
|
||||
js: Stream() -> $[Stdio]
|
||||
js: Int(x) -> x
|
||||
js: LitString(x) -> <javaLitString>x
|
||||
js: Sum(x,y) -> $[[x] + [y]]
|
||||
js: Gets(x, y) -> $[[x].gets([y])]
|
||||
js: To(x, y) -> $[to([x],[y])]
|
||||
js: Terminate(x) -> x
|
||||
js: Sequence(l) -> <join(|";\n")>l
|
||||
|
||||
/* Characters we need to escape in Javascript string constants */
|
||||
Jscape: ['\t' | cs ] -> ['\', 't' | cs ]
|
||||
/* I think I can just use ASCII constants for characters... */
|
||||
Jscape: [ 0 | cs ] -> ['\', '0' | cs ]
|
||||
Jscape: [ 8 | cs ] -> ['\', 'b' | cs ] // Backspace
|
||||
Jscape: [ 11 | cs ] -> ['\', 'v' | cs ] // Vertical tab
|
||||
Jscape: [ 12 | cs ] -> ['\', 'f' | cs ] // Form feed
|
||||
|
||||
strategies
|
||||
javaLitString = un-single-quote
|
||||
; string-as-chars(escape-chars(Escape <+ Jscape))
|
||||
; single-quote
|
||||
|
||||
javascript = bottomup(try(js))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue