Closed Matthew-Mosior closed 4 months ago
@gallais
I'm still very new to understanding the internals, but I took a crack at it (could be completely off base with this) and looks like a contributing piece of this issue stems from blockComment
:
blockComment : Lexer
blockComment = is '{' <+> is '-' <+> many (is '-') <+> (eof <|> toEndComment 1)
and the fact that it calls (eof <|> toEndComment 1)
given
||| `toEndComment` is the default state and it will munch through
||| the input until we detect a special character (a dash, an
||| opening brace, or a double quote) and then switch to the
||| appropriate state.
toEndComment : (k : Nat) -> Recognise (k /= 0)
toEndComment Z = empty
toEndComment (S k)
= some (pred (\c => c /= '-' && c /= '{' && c /= '"'))
<+> (eof <|> toEndComment (S k))
<|> is '{' <+> singleBrace k
<|> is '-' <+> singleDash k
<|> stringLit <+> toEndComment (S k)
where toEndComment
will munch until it detects a special character, of which }
is not one of them?
Please see https://github.com/idris-lang/Idris2/blob/main/src/Parser/Lexer/Source.idr for these functions.
Also,
||| After reading a single brace, we may either finish reading an
||| opening delimiter or ignore it (e.g. it could be an implicit
||| binder).
singleBrace : (k : Nat) -> Lexer
singleBrace k
= is '-' <+> many (is '-') -- opening delimiter
<+> (eof <|> singleDash (S k)) -- `singleDash` handles the {----} special case
-- `eof` handles the file ending with {---
<|> toEndComment (S k) -- not a valid comment
states singleDash handles the {----} special case
but
||| After reading a single dash, we may either find another one,
||| meaning we may have started reading a line comment, or find
||| a closing brace meaning we have found a closing delimiter.
singleDash : (k : Nat) -> Lexer
singleDash k
= is '-' <+> doubleDash k -- comment or closing delimiter
<|> is '}' <+> toEndComment k -- closing delimiter
<|> toEndComment (S k) -- not a valid comment
doesn't cover non -
characters?
After trying to allow for characters other than -
within a self-closing multiline comment (i.e. {-abcd-}
), I found a test that shows an example of named arguments that take on this form:
-- When binding arguments on LHS or listing arguments to
-- a function on RHS
-- unnamed arguments always take priority over named,
-- i.e they are bound/applied first,
-- regardless of their relative positions to named ones
testOrder1 : (a : String) -> (a : String) -> String
testOrder1 {a = a2} {-snd-} a1 {-fst-} = a1 ++ a2
Namely, {-snd-}
and {-fst-}
.
Thus, this feature may not be feasible to implement.
This code can be found in tests/idris2/basic049/Fld.idr
.
Isn't the main problem that many (is '-')
eats up all the dashes and then we're only seeing }
instead -}
? Of course we can't just fix that in the toplevel blockComment
, we also need to
handle it appropriately once it's nested inside an existing {- ... -}
block.
@gallais I meant to look into this awhile ago, it appears now that this is no longer an issue.
Preface
Please see this repo for full, complete code (an .ipkg-based project):
https://github.com/Matthew-Mosior/Pac-Man-Clone
Problem
When trying to use the exported top-level constant,
topborder
, from thesrc/Map/TopBorder.idr
file, insrc/Main.idr
, it cannot be found (undefined name).Steps to Reproduce
Clone https://github.com/ECburx/Idris2GL and install following direction in the README.
Clone https://github.com/Matthew-Mosior/Pac-Man-Clone.
You may also refer to the following minified code snippets below:
src/Map/TopBorder.idr
src/Main.idr
Expected Behavior
The program type checks and compiles using
idris2 --build pacman-clone.ipkg
Observed Behavior
Fix
This code can be made to work, (big thanks to @stefan-hoeck for helping) by removing the multi-line comments in
src/Map/TopBorder.idr
.