On Tue, Jun 14, 2011 at 01:04:20PM -0700, BGB wrote:
> On 6/14/2011 12:14 PM, Michael FIG wrote:
> >Hi,
> >
> >John Nilsson<[email protected]>  writes:
> >
> >>So my fix is to make the separation a hidden thing, which means the
> >>program needs to be represented in something that allows such hidden
> >>things (and I don't think Unicode control characters is the way to go
> >>here).
> >Why not crib a hack from JavaDoc and make your nested syntax embedded in
> >comments in the host language?
> >
> 
> or, like in my languages (generally for other things):
> use a keyword...
> 
> reusing prior example:
> 
> public int totalAmmount(InvoiceNo invoceNo)
> {
>   return SQLExpr {
>     SELECT SUM(ammount) FROM Invoices WHERE invoiceNo = :InvoiceNo;
>   }
> }
> 
>
Well you can embed languages easily using fact that in any sane language 
parenthness match 
unless you areb inside string.
You could get pretty strong preprocessor in few lines like my preprocessor 
which I attach.

It has one command 
register(name,command)  
which replaces all subsequent occurences of name(args){properly parenthized 
text} 
by output of command with args given and text pasted as input.
-- 

Big to little endian conversion error
$reg={"register"=>true}
def subp(s,i,l,r)
        return ["",i] if s[i,1]!=l
        o=""
        pc=0
        begin
                pc+=1 if s[i,1]==l
                pc-=1 if s[i,1]==r
                if s[i,1]=='"'
                        while s[i+1,1]!='"' && s[i,1]!='\\'
                                o<<s[i,1]
                                i+=1 
                        end
                        i+=1
                end
                o<<s[i,1]
                i+=1
        end while pc>0
        [process(o[1,o.size-2]),i]
end
def process(s)
        o=""
        i=0
        while i<s.size
                ch=false
                $reg.each{|name,command| 
                        if name==s[i,name.size] && !(s[i+name.size]=~/\w/)
                                i+=name.size
                                args,i=subp(s,i,"(",")")
                                text,i=subp(s,i,"{","}")
                                if name=="register"
                                        word,program=args.split(",")
                                        $reg[word]=program
                                else
                                        File.open("tmp1","w"){|f| f.puts(text)}
                                        `#{command} #{args} <tmp1 >tmp2`
                                        
o<<process(File.new("tmp2").lines.to_a*"")
                                end
                                ch=true
                                break
                        end
                }
                if !ch
                        o<<s[i,1]
                        i+=1
                end
        end
        o
end
puts process(File.new(ARGV[0]).lines.to_a*"")
_______________________________________________
fonc mailing list
[email protected]
http://vpri.org/mailman/listinfo/fonc

Reply via email to