2012-03-19 2 views
1

구문 분석 블록에서 변수 바인딩하는 방법 : 나는 ** 스크립트 오류를 ​​실행할 때난 그냥 파일의 목록을 그 내용이 파일의 이름을 인쇄 분석 한 후 반복 할

files: [%test1.txt %test2.txt] 
rule: [to "test" thru "test" copy x to "." (print x print file)] 
foreach file files [ 
    content: read file 
    parse [any rule] 
] 

를 : 파일에 값이 없음

파일 var 이름을 규칙 블록 프로그램의 컨텍스트에 바인드하려면 어떻게합니까?

답변

2

그냥 규칙을 바인드해야 각각의 반복 :

files: [%test1.txt %test2.txt] 
rule: [to "test" thru "test" copy x to "." (print x print file)] 
foreach file files [ 
    bind rule 'file 
    content: read file 
    parse content [any rule] 
] 
3

(말 그대로 규칙에 넣고 FOREACH는 적절한시기에 바인딩 할 수 있습니다) 이런 식으로 할 수도 있습니다 :

files: [%test1.txt %test2.txt] 
rule: [to "test" thru "test" copy x to "." (print x print file)] 
foreach file files compose/only/deep [ 
    content: read file 
    parse content [any (rule)] 
]