World: r3wp
[Parse] Discussion of PARSE dialect
older newer | first last |
Oldes 30-Jul-2010 [5069] | 0:00:00.968 for chunk 512 |
BrianH 30-Jul-2010 [5070x3] | Oldes, did you notice that I wrote READ/part, not READ ? |
And loading from the resulting string, not the file? | |
If you are reading from a hard drive there is no point to using a chunk size of less than 4096. For floppies, 512 will do. | |
Oldes 30-Jul-2010 [5073x3] | load-first-block2: func[file /local port buffer result tmp ][ port: open/direct file buffer: copy "" result: none chunks: 0 until [ chunks: chunks + 1 if any [ chunks > 10 none? tmp: copy/part port 512 ] [close port return none] insert tail buffer tmp not error? try [result: first load/next buffer] ] close port result ] |
is faster... a little bit... 0:00:00.859 | |
But we are in "parse" topic so we were making parse solution. | |
BrianH 30-Jul-2010 [5076] | LOAD parses. |
Oldes 30-Jul-2010 [5077x3] | ok.. the precise topic is: Parse (Discussing of PARSE dialect)... anyway.. I started as well asking why not to use load/next. |
btw.. the second function is not complete as it does not check for block but any rebol value. | |
Btw... what would be best way to get the last block of the file without loading complete file? | |
Steeve 30-Jul-2010 [5080] | impossible |
BrianH 30-Jul-2010 [5081x2] | Your solution is similar to what I suggested, but is missing a couple speedups: - Getting an estimate of how many characters the value would take on the high end, and using that as the initial read part. - Chunk value reflecting hard disk sector value (the OS may load in 4096 byte blocks) |
Last block... OPEN/seek perhaps, then SKIP ? | |
Anton 31-Jul-2010 [5083x3] | BrianH, finding out the size that is sure to encompass the desired block in all my input files requires prescanning the entirety of all of the files at least once. That's a good optimization for my specific case, but I want to make the function general enough that it can be used in other situations where the data may not be so consistent, and the desired block may not be always near the beginning or end. |
So I'm going to persist with PARSE. | |
Steeve, do you mean to say that it's impossible to get the last block without loading the complete file? | |
Pekr 31-Jul-2010 [5086x2] | what about using something like open/seek at port ((size? file) - chunk-size) chunk-size? |
http://www.rebol.com/article/0199.html | |
Anton 31-Jul-2010 [5088] | Getting chunks in reverse, from the end of the file towards the start, is not hard. It's the parse rule to go with it that's difficult. But first I want to figure out the parse rule that goes forward. |
rjshanley 4-Aug-2010 [5089] | I'm using REBOL to control a test by using the Parse dialect to check information returned from the test environment. From other looking around, it seems that the best approach would be to implement a Telnet scheme to handle the input/response give and take with the test environment, but I can't find an implementation I've been able to tweak. So.....my question is, has anyone had success with loading a Telnet client as a dll/shared library and getting Telnet functionality that way? |
BrianH 4-Aug-2010 [5090x2] | Check rebol.org - I recall the existence of a telnet scheme. But isn't telnet mostly just unadorned TCP? |
http://www.rebol.org/view-script.r?script=telnet-client.r | |
rjshanley 4-Aug-2010 [5092] | Thanks for the recommendation. |
BrianH 4-Aug-2010 [5093] | Apparently the actual scheme is here (bad form on the script submission): http://www.reboltech.com/library/scripts/telnet.r |
Henrik 4-Aug-2010 [5094] | I've used Frank Sievertsens telnet.r script from rebol.org. It works well for my needs. |
BrianH 4-Aug-2010 [5095x2] | Not anymore, as it references a script from a site that doesn't exist anymore. |
Never mind, it is here: http://www.rebol.org/view-script.r?script=telnet.r | |
Henrik 4-Aug-2010 [5097] | I've got it locally, if rebol.org fails. |
rjshanley 4-Aug-2010 [5098] | Thanks all, I'll give those another shot. |
BrianH 4-Aug-2010 [5099] | And come back here if you need help with the parsing part :) |
rjshanley 4-Aug-2010 [5100] | What would have been the correct place to post? |
BrianH 4-Aug-2010 [5101] | Networking |
rjshanley 4-Aug-2010 [5102] | Thanks. I posted here because it was a Tcl/Expect-like capability someone might have implemented already. |
BrianH 4-Aug-2010 [5103] | It's OK. We all use the "I'm New" group on occasion, even when we have been here for years :) Group purism is for redirecting flame wars. |
Gregg 4-Aug-2010 [5104] | I think Expect in REBOL would be very cool. We could call it Rexpect ('ree-speckt). :-) |
Maxim 4-Aug-2010 [5105] | sort of like an assert mixed in with a default ? |
BrianH 4-Aug-2010 [5106x2] | Expect is a TCL thing which handles interaction with external programs through their human-oriented UIs. |
There's even versions of expect that handle GUIs, but that is likely out of scope here. Character UIs would be sufficient. It's sor of like screen scraping for mainframe interaction. | |
Anton 11-Aug-2010 [5108] | By the way, I got that chunky-load-first-block parse working the other day. |
RobertS 20-Aug-2010 [5109] | Why would the R3 error with parse "a b c" ["a" "b" "c"] as compared to 2.7.7 not be a severe bug in CodeCure ? |
Henrik 20-Aug-2010 [5110] | because the R3 behavior is correct. you are not parsing spaces in the above example. |
Gregg 20-Aug-2010 [5111] | Should the docs say that a block! rule implies /all? |
JoshF 1-Sep-2010 [5112] | Hi! Quick question about parsing REBOL code itself... I'm putting together an entry for a contest which is line-constrained (no more than 250 SLOC), so I want to crush my code down as much as possible while still having something that actually looks like code (I know about using the compression, but I want something that looks like a program). I'm starting with Carl's REBOL parser from the cookbook, but it seems to skip the colons for initializers ("x: x + 1" -> [x x + 1]). Here's my current hack of his parser: tokens: copy [] parse read %contest-entry.r blk-rule: [ some [ str: newline | #";" [thru newline | to end] new: (probe copy/part str new) | [#"[" | #"("] (append tokens str/1) blk-rule | [#"]" | #")"] (append tokens str/1) break | skip (set [value new] load/next str append tokens :value) :new ] ] Any ideas why it might be skipping the vital ":" character? Thanks very much! |
Anton 1-Sep-2010 [5113] | What version of Rebol are you using? Seems to work ok for me in R2. What's the input which fails? |
Gregg 1-Sep-2010 [5114] | Works for me too. |
JoshF 1-Sep-2010 [5115] | Hi! Thanks for taking a look at the code. I went over it again, it seems that part of the problem was in the fact that the parsed objects weren't transliterated into strings as I had expected. I.e. if you look at the output of the code snippet above, it seems OK, but examination of the types of the data in the tokens array turn up things that don't convert to strings too well without help. I've puzzled over Carl's pretty printer, and I _think_ I understand why now... Either way, I was able to modify it to give me the kind of output I wanted. To repay you for your kind attention, I will post my code here, but in crushed form, so it doesn't take up too much space... ; - ) REBOL [ Title: "REBOL Compressor" ] emit-space: func [ pos ] [ append out pick [ #" " "" ] found? not any [ find "[(" last out find ")]" first pos ] ] emit: func [ from to ] [ emit-space from word: copy/part from to long: ( length? out ) + length? word if 80 < long [ append lines out out: copy "" ] append out copy/part from to ] lines: copy [ ] clean-script: func [ Returns new script text with standard spacing. script "Original Script text" /local str new ] [ out: append clear copy script newline parse script blk-rule: [ some [ str: some [ newline ] ( ) | #";" [ thru newline | to end ] new: ( ) | [ #"[" | #"(" ] ( emit str 1 ) blk-rule | [ #"]" | #")" ] ( emit str 1 ) break | skip ( set [ value new ] load/next str emit str new ) :new ] ] append lines out remove lines/1 print [ length? lines "lines." ] lines ] write/lines %crushed.r clean-script read %c.r print read %crushed.r Thanks! |
Gregg 2-Sep-2010 [5116] | If you note that load/next is used when values are parsed, you can see why values aren't strings. MOLD can be your friend as FORM (and PRINT) will hide datatype details from you. e.g. >> print first [x] x >> print first [x:] x >> print first ['x] x >> print first [:x] x |
Maxim 2-Sep-2010 [5117] | which is why its a good habit to use use probe instead of print in most cases where you trace data |
Anton 2-Sep-2010 [5118] | JoshF, if this script stands alone then I would make these changes: - Add as locals to EMIT: WORD and LONG. - Add to CLEAN-SCRIPT's locals: LINES, OUT, EMIT-SPACE, EMIT, BLK-RULE, VALUE - Move into CLEAN-SCRIPT's body: 1 lines: copy [] 2 The EMIT-SPACE function 3 The EMIT function - Change this line: out: append clear copy script newline to: out: copy "" (There's no point copying the string SCRIPT when the next thing you do is CLEAR it.) - Remove this line: remove lines/1 (There seems no point in initializing OUT with a single newline char if it is only to be removed ultimately.) After, that, you should have only one word, CLEAN-SCRIPT, defined globally, referring to a function with no side-effects. |
older newer | first last |