-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Core PureScript migration #281
Comments
@min-nguyen I’ll start implementing a new parser (in PureScript) that will accept our existing examples. I won’t bother building a syntax tree until the PureScript prototype starts coming together. |
Ooh okay, I thought I was doing that, sure. Is there anything for me to do in the meanwhile? As in, are the other tasks from #279 on standby for now? |
Sorry, I probably wasn’t clear. You can go ahead with #279 without a parser (i.e. without having a way of turning strings into syntax trees). You can just create syntax trees directly for testing purposes, e.g.: Cons(Nat(5), Cons(Nat(6), Nil))) will be a PureScript program whose value represents a Fluid expression (or in this case, value). The #279 task is to define all the datatypes for expressing examples like the above, and enough of an interpreter to evaluate them. This “migrate parser” task is (conveniently) independent of what you’re doing. I’ll start just by writing a parser in PureScript that accepts all our existing Fluid examples (without creating a syntax tree for them). Then as the PureScript implementation comes together, and we have a rich enough language to represent the old Fluid examples, we can extend the new parser to build a parse tree in the new implementation. Let me know if any of this doesn’t make sense... |
Here’s the old TypeScript number parser (from before the Nearley port): // JSON grammar for numbers, https://tools.ietf.org/html/rfc7159.html#section-6.
// I’m assuming (but haven’t checked that) DIGIT is defined as
const DIGIT: Parser<string> = range(“0”, “9”)
// decimal-point = %x2E ; .
const decimal_point = ch(“.”)
// digit1-9 = %x31-39 ; 1-9
const digit1to9: Parser<string> = range(“1”, “9”)
// e = %x65 / %x45 ; e E
const e: Parser<string> = choice([ch("e"), ch("E")])
// minus = %x2D ; -
const minus: Parser<string> = ch(“-”)
// plus = %x2B ; +
const plus: Parser<string> = ch(“+”)
// zero = %x30 ; 0
const zero: Parser<string> = ch(“0”)
// exp = e [ minus / plus ] 1*DIGIT
const exp: Parser<string> = withJoin(sequence([e, optional(choice([minus, plus]), () => ""), withJoin(repeat1(DIGIT))]))
// frac = decimal-point 1*DIGIT
const frac = withJoin(sequence([decimal_point, withJoin(repeat1(DIGIT))]))
// int = zero / ( digit1-9 *DIGIT )
const int: Parser<string> = choice([zero, withJoin(sequence([digit1to9, withJoin(repeat(DIGIT))]))])
// number = [ minus ] int [ frac ] [ exp ]
const numberʹ: Parser<string> =
withJoin(sequence([optional(minus, () => ""), int, optional(frac, () => ""), optional(exp, () => "")]) |
@min-nguyen I’ve made some progress on the parser. I’ve also played around with some ideas for using modules and imports to reduce our reliance on prefixing schemes like |
Root task to capture migration of the following components to PureScript:
Still to do:
flatten.fld
lookup.fld
mergeSort.fld
(drop for now)typematch.fld
prelude.fld
Float
form forExpr
,Expl
andVal
Float
log
atInt -> Float
/
atInt + Float -> Int + Float -> Float
pow
atInt + Float -> Int + Float -> Float
graphics.fld
moduleopenDatasetAs
background.fld
Float
overloadgrouped-bar-chart.fld
sum
needs to curry(+)
Pattern mismatch: no branch for Viewport
– distinguish missing branch from data type mismatchViewport is not a constructor of List
– fix use ofconcat
toconcat2
line-chart.fld
Pattern mismatch: no branch for Nil
– add (error-raising)Nil
cases tolookup
,head
,tail
Can’t take head of empty list
tickEvery 5
produces-20
2 * 10 ** m
isInfinity
– oops,**
for integers implemented as/
Join undefined
– missingStr
case forRawExpr
String
overloadstacked-bar-chart.fld
eval_fwd
andeval_bwd
rulesdefine– problematic: will make variables in scope when it looks like they aren’tjoin
-like operation on variables such thatx join “_” = x
(:)
pattern
parser which builds constructor patterns for infix operatorsexpr_
parser:binaryOp
should build a (partial) constructor if operator is infix constructor– not needed till Backtick syntax for infix function names #305BinaryApp
rule foreval
to work with constructors as well as primitives?(:)
needs to have a value; usezipWith
exampleDone/dropped:
yarn add –dev purescript spago
movespago.dhall
to workspace root?purescript-parsing
dependencyTest.Parse
module with basic test that reads a filefluid/example/parser-wip.fld
purescript-spec
test frameworklet rec
syntax to list of mutually recursive functionscloseDefs
to build environment extension for list of mutually recursive functionscloseDefs_fwd
eval
to applycloseDefs
at each stepeval_fwd
arithmetic.fld
compose.fld
compose
defined in same filecompose
toprelude.fld
successfulParse
,parseWithImports
,openWithImports
loadModule
let
definitions into an environmentfactorial.fld
filter.fld
foldr_sumSquares.fld
length
lexicalScoping.fld
intToStr
let
parsing (More consistent let/letrec syntax #229)match..as
Bool
map.fld
normalise.fld
test caseControl.Lazy
and explicit fixpoint for recursive grammarsimpleExpr
let
appChain
+
gets parsed as part of integer literal?use backtick– see Backtick syntax for infix function names #305div
notation?div
to preludepattern-match.fld
reverse.fld
zipWith.fld
The text was updated successfully, but these errors were encountered: