We can convert files that are not one-command per lineto pliant standard by preprocessing them.

Message posted by maybe Boris Reitman on2005/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

This code doesn't work correctly for some reason, it goes into infinite loopentering my_custom_read function.

My plan is to extend the module meta by wrapping its present functionalityby 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,

Also, if I put this code outside of /pliant/languageI get an error that I am using modules out of scope. How can I work around it ?

Thanks,Boris

Message posted by hubert.tonneau on2005/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 ?

No.

> 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 apublic module, so what it exports is not public. I mean it deals with internal details that may change over time, so anyprogram using it should be blessed by me and part of the /pliant/languagestandard distribution.

> 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 (see /pliant/sample/parser.pli) 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 thePliant streams instead of the thin wrapper over Posix, so it would bringall you describe at once, but I'm not sure it's a good idea (kind of pandorabox) and that's why I've not done it yet.

Message posted by maybe Boris Reitman on2005/11/23 15:38:56

Thanks.

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 ?

If yes, how can I manage this constant value list, run throught it and deletethings from it, or prepend something to beginning ?

Boris

Message posted by hubert.tonneau on2005/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 inorder 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 definedseveral 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 areal list is that each definition is filtered with a module scope, so whenscanning the list, only entries that match the subset of selected modules bythe current module being compiled will be used.