r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Parse] Discussion of PARSE dialect

Volker
1-Nov-2005
[626]
if implies a then, and we have none.
Graham
1-Nov-2005
[627x2]
away-rule: [
	'away set .. [
		'from ... |
		'every set day word! 

  if ( either day = to-word pick system/locale/days current-date/weekday 
  [
			repend away-days [ current-date current-date ]
			true
			][
			false
		   )

		) |
		break

	]
	( reason: copy "" )
	opt ...
]
oops .. close
BrianH
1-Nov-2005
[629x3]
Then is everything after the if clause. Parse already has control 
flow.
Here is a rewording of the proposal. Any problems?
I would like an IF clause in parse, that would work like this:
- Syntax: if (test)

- Behavior: The paren is executed like any other paren in parse, 
but the return value of that paren is checked, treated like the condition 
argument to the if native. A false or none value would cause the 
parse to fail as if it had failed to find some syntactic element 
- otherwise the parse should continue. Failure should trigger any 
normal backtracking and advancement to the next alternate, just like 
failure of a syntactic match would at that point.


This clause would allow parse flow to be directed by semantic criteria 
as well as syntatic, allowing parse to handle a greater range of 
grammars. An if clause would be sufficient to make parse into a predicated 
parser, similar in capabilities to ANTLR.
Volker
1-Nov-2005
[632x3]
to me it sounds like "do somewhing", not just continue.
more like verify or assure.
assert
, although more like debugging.
Graham
1-Nov-2005
[635]
It means I can do this

if ( clause ) |
break

I guess to exit the rule.
Pekr
1-Nov-2005
[636]
BrianH: then Rambo-it! :-)
BrianH
1-Nov-2005
[637]
The control flow of parse is more like that of Prolog or Icon than 
it is like Pascal. "Then" is a Pascal thing.
Ladislav
1-Nov-2005
[638x3]
the new wording looks better
Graham: you can do even if (not clause)
which might do what you wanted for if (clause) | break
Graham
1-Nov-2005
[641]
I think 'or should be an alternative to | ( off topic )
BrianH
1-Nov-2005
[642]
Should the keyword be named TEST? I chose IF because it was less 
likely to be used for variables in existing code, and it corresponds 
to the equivalent concept in the different semantic model. Plus, 
that's how they say it in other predicated parsers.
Graham
1-Nov-2005
[643x2]
conditionally
saw that in one forth book.
BrianH
1-Nov-2005
[645]
If there are no other comments or suggestions, I'll submit it as 
worded above.
Volker
1-Nov-2005
[646]
I am ok with that. after thinking about prolog&icon withthe if too.
Graham
1-Nov-2005
[647]
Go.
Ladislav
1-Nov-2005
[648]
yes
BrianH
1-Nov-2005
[649x3]
I didn't do a really useful example, just one to demonstrate the 
current way of faking the behavior.
Example:  [if (test) | ...]
Fix:  [(unless test [dummy: [end skip]]) dummy | ...]
On a (slightly) different note, has anyone tried to implement incremental 
parsing with parse? Last time I tried something like continuations, 
but there must be a better way...
For instance, can you put a wait in a parse paren?
Volker
1-Nov-2005
[652x2]
Interesting idea. I guess that would work. but not with async.
for small things i would just reparse the whole thing.
BrianH
1-Nov-2005
[654]
See, this is why I wanted that if clause. It's so easy to mess up 
the workaround.
Fix:  [(dummy: unless test [[end skip]]) dummy | ...]
Volker
1-Nov-2005
[655]
what i would like is in incremental parse as base for multitasking.
BrianH
1-Nov-2005
[656x2]
I was thinking about parsing data larger than available memory, or 
coming over a slow link.
Something like do/next for parse.
Volker
1-Nov-2005
[658x2]
Or beeing interactive, where the next things depend on what you reply.
but i know no good way with parse only.
BrianH
1-Nov-2005
[660x4]
f: open/direct file
a: copy/part f 4096

parse a [some [rule1 | rule2 | b: if (if a: copy/part f 4096 [b: 
join b a]) :b]]
With the IF workaround applied, if you can.
Well, I submitted the entry when you all said it was OK (I forgot 
to mention). Now we get to see how it all turns out. I like RAMBO 
much more than feedback - more public.
Later all!
Graham
1-Nov-2005
[664]
Keep us informed on the outcome :)
Gabriele
1-Nov-2005
[665]
btw, my compile-rules.r implements IF (i don't recall if exactly 
as noted above, but i think so, or very close). i had a rep with 
this and other things too.
Ladislav
1-Nov-2005
[666]
http://www.compkarori.com/vanilla/display/TO, THRU And NOT PARSE Rules 
implements IF too, but using IF [...] instead of IF (...) , which 
is the only difference as far as I can tell
BrianH
1-Nov-2005
[667]
Gabriele, I recall that it didn't work the same, but have no way 
of checking that right now because I couldn't find your compile-rules.r 
on rebol.org and you didn't provide a link just now.
Gabriele
1-Nov-2005
[668x4]
it's different, as i made it as:
| 'if set val1 paren!                        ; NEW: apply rule only 
if condition is true
            element

      | 'either set val1 paren!                    ; NEW: choose rule based 
      on condition
            element
            element
i think there are pros and cons to both approachs.
i admit i haven't used if and either much though, what i used a lot 
was DO.
BrianH
1-Nov-2005
[672]
I prefer the continue-if-true version. I particularly like that there 
is a workaround now that the backtrack-through-paren bug has been 
fixed since I first suggested an IF clause.
Ladislav
1-Nov-2005
[673]
BrianH: see the above link, it is an IF as you proposed, except that 
it uses a block instead of paren!, because that was simpler to implement, 
but it doesn't matter much, can be transformed
Graham
4-Nov-2005
[674x2]
How do get parse out ^?
>> caret: charset [ #"\^" ]
** Syntax Error: Missing " at caret: charset [ #"\^" ]
** Where: halt-view
** Near: caret: charset #"a"