|Newbie questions about Pliant
Filter for loading files
We can convert files that are not one-command per line
to pliant standard by preprocessing them.
|Message posted by maybe Boris Reitman on 2005/11/23 09:11:52
|This refers to an earlier discussion in the talk forum. I am trying
to apply a preprocessing filter before a module is sourced in and compiled.
I was thinking of overriding pliant_file_read_hook, like this
function my_custom_read handle buffer size -> red
arg Int handle ; arg Address buffer ; arg Int size ; arg Int red
console "NOW IN my_custom_read" eol
red := file_read handle buffer size
(gvar Function backup) executable := pliant_file_read_hook
pliant_file_read_hook := (the_function my_custom_read Int Address Int -> Int) executable
pliant_file_read_hook := backup executable
This code doesn't work correctly for some reason, it goes into infinite loop
entering my_custom_read function.
My plan is to extend the module meta by wrapping its present functionality
by setting pliant_file_read_hook before existing module processing,
and restoring it after.
Is this a good idea ?
Here are some applications of this,
- Can have multiline strings in the original source file.
- Can invert .page format to something like .php where code is embedded
in html and not vice versa. This can be convenient for graphic
designers, who want to make flashy pages with minimal code.
- Can open compressed files; Or network based urls.
So, am I on the right path, and why isn't above code working ?
The file "/borisreitman/dummy.pli" is this,
console "in dummy function"
Also, if I put this code outside of /pliant/language
I get an error that I am using modules out of scope. How can I work around it ?
|Message posted by hubert.tonneau on 2005/11/23 12:22:26
|> My plan is to extend the module meta by wrapping its present functionality
> by setting pliant_file_read_hook before existing module processing,
> and restoring it after.
> Is this a good idea ?
> Also, if I put this code outside of /pliant/language
> I get an error that I am using modules out of scope. How can I work around it ?
This is intended to warn you that /pliant/language/misc/hooks.pli is not a
public module, so what it exports is not public.
I mean it deals with internal details that may change over time, so any
program using it should be blessed by me and part of the /pliant/language
> Here are some applications of this,
> - Can have multiline strings in the original source file.
You can do that with properly extending the current parser.
> - Can invert .page format to something like .php where code is embedded
> in html and not vice versa. This can be convenient for graphic
> designers, who want to make flashy pages with minimal code.
Two solutions here:
. either you write a Pliant parser using Pliant parser machinery
it should be possible, and would be a very valuable contribution to write
a C parser working that way, so that at end we can submit various languages
using C like syntax to Pliant compiler engine
. or you write your parser using your machinery that will either build
expressions, or if you don't want to cope with Pliant compiler details,
just write a plain ascii list of strings following Pliant native
syntax (remind that LISP like encoding is valid Pliant native syntax)
and submit it to Pliant compiler
See function 'do_compile_dynamic_page' in /pliant/protocol/http/server.pli
for an example.
> - Can open compressed files; Or network based urls.
I might at some point use the hooks you tried to use in order to use the
Pliant streams instead of the thin wrapper over Posix, so it would bring
all you describe at once, but I'm not sure it's a good idea (kind of pandora
box) and that's why I've not done it yet.
|Message posted by maybe Boris Reitman on 2005/11/23 15:38:56
Running the sample parser.pli gives an error that '=' is unknown operator.
Also, why is the 'constant' keyword is used more than once on the same identifier name,
in the sample. Does it each time append to a list of tokens instead of overwriting ?
constant 'new_parser first_section' identifier_filter
constant 'new_parser first_section' comment_filter
constant 'new_parser first_section' space_filter
constant 'new_parser first_section' brackets_filter
constant 'new_parser first_section' equal_filter
constant 'new_parser first_section' eol_filter
If yes, how can I manage this constant value list, run throught it and delete
things from it, or prepend something to beginning ?
|Message posted by hubert.tonneau on 2005/11/23 16:04:40
|> Running the sample parser.pli gives an error that '=' is unknown operator.
Just replace the line with:
alias '==' '=' from "/pliant/language/basic/safe.pli"
'alias' meta has been enhanced at some point to provide better control in
order to reduce the unexpected side effect probability.
> Also, why is the 'constant' keyword is used more than once on the same identifier name,
> in the sample. Does it each time append to a list of tokens instead of overwriting ?
Just see 'new_parser first_section' as a list.
A Pliant identifier is an entry in the dictionary, and an entry can be defined
several times, so there is a list of definitions for each identifier.
The key advantage to keep it in the dictionary rather than storing it in a
real list is that each definition is filtered with a module scope, so when
scanning the list, only entries that match the subset of selected modules by
the current module being compiled will be used.
|Message posted by maybe Boris Reitman on 2005/11/27 06:43:21
|Here is a basic support for a multiline string,
Files can be browsed here, and examples are in the 't' subdirectory,