Logs: freenode/#haskell
| 2020-10-27 12:47:31 | → | xff0x joins (~fox@2001:1a81:5219:2300:5d08:4351:f573:c6af) |
| 2020-10-27 12:47:35 | <Raito_Bezarius> | ha |
| 2020-10-27 12:48:05 | <dminuoso> | (Note that the first definition is already defined in megaparsec, I just included it for reference) |
| 2020-10-27 12:48:07 | <Raito_Bezarius> | well, I'll read more the docs until I understand why is it enough/trivial enough |
| 2020-10-27 12:48:13 | <Raito_Bezarius> | but like |
| 2020-10-27 12:48:20 | <dminuoso> | lexing and parsing are really the same thing. :) |
| 2020-10-27 12:48:20 | <Raito_Bezarius> | if I want to add a semicolon to a lexeme if only it's a certain lexeme |
| 2020-10-27 12:48:26 | <Raito_Bezarius> | I can just really chain lexeme & lexemeSemi ? |
| 2020-10-27 12:48:35 | <dminuoso> | Raito_Bezarius: Yes, that's why you use both lexeme and lexemeSemi |
| 2020-10-27 12:48:38 | <dminuoso> | For example: |
| 2020-10-27 12:48:55 | → | cfricke joins (~cfricke@unaffiliated/cfricke) |
| 2020-10-27 12:49:05 | × | kish quits (~oracle@unaffiliated/oracle) (Ping timeout: 240 seconds) |
| 2020-10-27 12:49:13 | <dminuoso> | say you have: |
| 2020-10-27 12:49:23 | <dminuoso> | lexemeSemi = p <* semi <* spc |
| 2020-10-27 12:49:23 | × | carlomagno quits (~cararell@148.87.23.7) (Remote host closed the connection) |
| 2020-10-27 12:49:26 | <dminuoso> | Where spc is your space consumer |
| 2020-10-27 12:49:28 | <dminuoso> | Then you can define |
| 2020-10-27 12:49:39 | <dminuoso> | err |
| 2020-10-27 12:49:42 | <dminuoso> | lexemeSemi p = p <* semi <* spc |
| 2020-10-27 12:49:53 | <dminuoso> | foo = lexemeSemi (string "foo") |
| 2020-10-27 12:50:00 | <dminuoso> | which would lex `foo;` plus leading whitespace |
| 2020-10-27 12:50:05 | <dminuoso> | (or trailing I guess) |
| 2020-10-27 12:50:09 | ← | PlasmaStrike parts (~mattplasm@38.73.141.198) ("ERC (IRC client for Emacs 28.0.50)") |
| 2020-10-27 12:50:10 | <Raito_Bezarius> | yes |
| 2020-10-27 12:50:17 | <Raito_Bezarius> | now if I give foo; can I still get foo; without error? |
| 2020-10-27 12:50:28 | <dminuoso> | "get foo; without error"? |
| 2020-10-27 12:50:29 | × | Zetagon quits (~leo@c151-177-52-233.bredband.comhem.se) (Ping timeout: 256 seconds) |
| 2020-10-27 12:50:31 | <Raito_Bezarius> | sorry |
| 2020-10-27 12:50:36 | <Raito_Bezarius> | if I give as input `foo;` |
| 2020-10-27 12:50:36 | × | lpy quits (~nyd@unaffiliated/elysian) (Quit: lpy) |
| 2020-10-27 12:50:41 | <Raito_Bezarius> | can I still make it so it lex to `foo;` |
| 2020-10-27 12:50:44 | <geekosaur> | I think Raito_Bezarius wants the opposite of what you're providing |
| 2020-10-27 12:50:50 | <Raito_Bezarius> | I want both |
| 2020-10-27 12:50:51 | → | PlasmaStrike joins (~mattplasm@38.73.141.198) |
| 2020-10-27 12:50:55 | × | thir quits (~thir@p200300f27f0b7e004c18ab60065ea01b.dip0.t-ipconnect.de) (Ping timeout: 240 seconds) |
| 2020-10-27 12:50:58 | <Raito_Bezarius> | I want semicolon to be automatically added when it's relevant |
| 2020-10-27 12:50:59 | <geekosaur> | insert a virtual semicolon after some lexemes, but allow it to be explicit as well |
| 2020-10-27 12:51:05 | <dminuoso> | ahh |
| 2020-10-27 12:51:11 | <Raito_Bezarius> | something like lexemeSemi (string "foo") <|> lexeme (string "foo;") or something like this |
| 2020-10-27 12:51:15 | <dminuoso> | Well, I'd just get rid of it in the parser |
| 2020-10-27 12:51:19 | <dminuoso> | or lexer |
| 2020-10-27 12:51:31 | <dminuoso> | I see |
| 2020-10-27 12:51:36 | <dminuoso> | You can make the semi optional |
| 2020-10-27 12:51:43 | <dminuoso> | lexemeSemi p = p <* optional semi <* spc |
| 2020-10-27 12:52:03 | <Raito_Bezarius> | but then, this separator won't always appear right? |
| 2020-10-27 12:52:12 | <dminuoso> | what do you mean by separator? |
| 2020-10-27 12:52:15 | <Raito_Bezarius> | the ; |
| 2020-10-27 12:52:18 | <Raito_Bezarius> | it will lex as foo or foo; |
| 2020-10-27 12:52:20 | <Raito_Bezarius> | right? |
| 2020-10-27 12:52:28 | <dminuoso> | Raito_Bezarius: What do you mean with "lex as"? |
| 2020-10-27 12:52:32 | <dminuoso> | It will *consume* both |
| 2020-10-27 12:52:57 | <Raito_Bezarius> | I mean, my grammar assumes that those semicolons always appear |
| 2020-10-27 12:53:32 | <Raito_Bezarius> | so the parser will expect semicolons for certain rules, but without automatically adding them explicitly, the rules will fail |
| 2020-10-27 12:53:43 | <dminuoso> | Im not quite sure what "adding" even means? |
| 2020-10-27 12:53:54 | <dminuoso> | We're in a parser, we dont generate a string, we consume it |
| 2020-10-27 12:53:56 | <Raito_Bezarius> | in this case, I'm looking at Julia |
| 2020-10-27 12:54:09 | <Raito_Bezarius> | if I have, `while foo end` |
| 2020-10-27 12:54:15 | → | carlomagno joins (~cararell@148.87.23.12) |
| 2020-10-27 12:54:23 | <Raito_Bezarius> | it should appear as `while foo end;` |
| 2020-10-27 12:54:29 | <dminuoso> | what do you mean by "appear"? |
| 2020-10-27 12:54:56 | <dminuoso> | A parser usually transforms `while foo end;` into some concrete or abstract syntax tree |
| 2020-10-27 12:55:02 | <Raito_Bezarius> | Yes |
| 2020-10-27 12:55:08 | <Raito_Bezarius> | Hm, maybe I am creating a XY problem or something |
| 2020-10-27 12:55:54 | → | Criggie1 joins (~Criggie@154.13.1.56) |
| 2020-10-27 12:56:16 | <Raito_Bezarius> | dminuoso: thanks for the ideas, I'll try to go for implementation first and expose the precise problem when I encounter it |
| 2020-10-27 12:56:19 | <Raito_Bezarius> | That was very helpful |
| 2020-10-27 12:56:20 | <geekosaur> | if you want to parse something and then prettyprint it, just have the prettyprinter always print the semicolons while rendering the AST back into text |
| 2020-10-27 12:56:34 | <Raito_Bezarius> | I'm not in the prettyprint phase though I plan to do so |
| 2020-10-27 12:56:42 | × | nbloomf quits (~nbloomf@2600:1700:ad14:3020:d1e5:1a77:fd52:7b88) (Quit: My MacBook has gone to sleep. ZZZzzz…) |
| 2020-10-27 12:56:46 | <Raito_Bezarius> | I was rather adapting a set of rules from a grammar into megaparsec parsing code |
| 2020-10-27 12:57:00 | <Raito_Bezarius> | and the set of rules expects semicolon because the lexical analysis suggests to automatically add them |
| 2020-10-27 12:57:02 | <dminuoso> | Raito_Bezarius: So this is where things can very very quickly become complicated. |
| 2020-10-27 12:57:16 | <dminuoso> | Do you need to preserve the exact input? |
| 2020-10-27 12:57:21 | <Raito_Bezarius> | No I do not need |
| 2020-10-27 12:57:34 | × | perry69420 quits (6ee39f85@110.227.159.133) (Ping timeout: 245 seconds) |
| 2020-10-27 12:57:39 | <Raito_Bezarius> | I didn't want to go for custom lexer code because I wanted to benefit from megaparsec source position stuff |
| 2020-10-27 12:57:48 | <dminuoso> | Raito_Bezarius: Okay. I think there may be some confusion here of what the output of a parser really is |
| 2020-10-27 12:57:58 | <Raito_Bezarius> | I want to output an AST right now |
| 2020-10-27 12:58:12 | <Raito_Bezarius> | I have an AST in terms of data |
| 2020-10-27 12:58:13 | <dminuoso> | Raito_Bezarius: Do you represent semicolons in that AST? |
| 2020-10-27 12:58:19 | <Raito_Bezarius> | No, so I can just discard them |
| 2020-10-27 12:58:32 | <Raito_Bezarius> | But I was afraid of stuff like ambiguous things in the grammar |
| 2020-10-27 13:00:59 | → | acarrico joins (~acarrico@dhcp-68-142-39-249.greenmountainaccess.net) |
| 2020-10-27 13:01:31 | → | djellemah joins (~djellemah@2601:5c2:100:96c:e008:b638:39fe:6a54) |
| 2020-10-27 13:03:45 | → | britva joins (~britva@31-10-157-156.cgn.dynamic.upc.ch) |
| 2020-10-27 13:04:27 | → | hyperisco joins (~hyperisco@d192-186-117-226.static.comm.cgocable.net) |
| 2020-10-27 13:05:09 | <Raito_Bezarius> | maybe stupid question, I'm trying to have "some digitChar" but I cannot because "Illegal equational constraint Token s ~ Char", should I just enable TypeFamilies or GADTs? |
| 2020-10-27 13:05:16 | <Raito_Bezarius> | or am I doing something wrong? |
| 2020-10-27 13:05:22 | <Raito_Bezarius> | integer = some digitChar <?> "an integer" |
| 2020-10-27 13:05:33 | → | nbloomf joins (~nbloomf@2600:1700:ad14:3020:d1e5:1a77:fd52:7b88) |
| 2020-10-27 13:06:08 | × | plutoniix quits (~q@175.176.222.7) (Quit: Leaving) |
| 2020-10-27 13:07:09 | <dminuoso> | Raito_Bezarius: What's the type signature of integer? |
| 2020-10-27 13:07:33 | <dminuoso> | Or.. that error mmm |
| 2020-10-27 13:07:36 | → | ClaudiusMaximus joins (~claude@198.123.199.146.dyn.plus.net) |
| 2020-10-27 13:07:36 | × | ClaudiusMaximus quits (~claude@198.123.199.146.dyn.plus.net) (Changing host) |
| 2020-10-27 13:07:36 | → | ClaudiusMaximus joins (~claude@unaffiliated/claudiusmaximus) |
| 2020-10-27 13:07:38 | <dminuoso> | Which ghc are you using? |
| 2020-10-27 13:07:52 | → | vacm joins (~vacwm@70.23.92.191) |
| 2020-10-27 13:07:53 | <Raito_Bezarius> | I want something like (MonadParsec m, …) => m [Char] |
| 2020-10-27 13:07:56 | <Raito_Bezarius> | GHC8 dminuoso |
All times are in UTC.