2009-09-22 8 views
0

이 (Sunanda의 제안 How can I parse [a/b] ? syntax error in Rebol? 덕분에) 잘 작동 :REBOL 구문 분석 규칙은

attribute: copy [] 
class: copy [] 
definition-rule: compose/deep [some [set class word! 'is 'defined 'by 
[some [copy attribute to (to-lit-word "/") thru (to-lit-word "/") ]] 
copy attribute to end]] 
parse [Customer is defined by First Name/Last Name/Email] definition-rule 

하지만 지금 (출력 클래스 추가) 일부 APPEND 지침을 추가해야하고 그렇지 않습니다 더 이상 작동 : 여기

attribute: copy [] 
class: copy [] 
definition-rule: compose/deep [some [set class word! (append output class) 'is 'defined 'by 
[some [copy attribute to (to-lit-word "/") thru (to-lit-word "/") ]] 
copy attribute to end]] 
parse [Customer is defined by First Name/Last Name/Email] definition-rule 
+0

자, 다시 Sunanda가 대답하는지 봅시다. 튜토리얼에서 질문하는 이유를 이해할 수는 없지만 잘못된 답변을 준비하고 있습니다. –

+0

REBOL에 대한 질문이있는 포럼에서 REBOL에 대한 질문에 답변하게되어 기쁩니다 (답변을 알고있는 경우). REBOL 커뮤니티의 Stackoverflow 활용은 지금까지는 아주 적습니다. 주로 RebolTutorial에서 질문하고 여러 사람들 (주로 지금까지)이 응답했습니다. 이것이 누군가에게 문제가된다면, Reboltutorial은 REBOL 관련 포럼 중 하나 인 Q & A 지원으로 전환 할 수 있습니다. – Sunanda

답변

1

문제는 괄호에있는 모든 식을 먹고있는 구성이다. (to-lit-word "/")을 먹는 것이 좋지만 구문 방언을 위해 의도 된 것이므로 (추가 출력 클래스)을 심각하게 먹는 것을 원하지 않습니다.

attribute: copy [] 
class: copy [] 
output: copy "" 
fs: to-lit-word "/" ;; define a forward slash lit-word 

definition-rule: [ 
    some [set class word! (append output class) 'is 'defined 'by [ 
     some [copy attribute to fs thru fs] 
    ] 
    copy attribute to end] 
    ] 

parse [Customer is defined by First Name/Last Name/Email] definition-rule 
== true 

내가 완전히 확실하지 않다 ... 는 구문 분석 규칙의 외부 조명 단어를 작업을 수행하여를 구성 제거 :

아마 영리한 방법이있다, 그러나 이것은 작동합니다

attribute: copy [] 
attributes: copy [] 
class: copy [] 
output: copy "" 
fs: to-lit-word "/" ;; define a forward slash lit-word 

definition-rule: [ 
    some [set class word! (append output class) 'is 'defined 'by [ 
     some [copy attribute to fs thru fs (append/only attributes attribute)] 
    ] 
    copy attribute to end (append/only attributes attribute)] 
    ] 

parse [Customer is defined by First Name/Last Name/Email] definition-rule 

print ["==" class mold attributes] 

== Customer [[First Name] [Last Name] [Email]] 
+0

고마워, 내가이 일을 위해 두 번째 예제를 필요 : 속성 : 복사 [] 클래스 : [] FS를 복사에 조명 단어 "/" 출력 : 복사 "" 정의 규칙 : [ 일부 [클래스 단어 세트! (출력 부속 속성 추가)] 일부 [복사 속성을 fs ~ fs (출력 결합 속성 추가; "]" 복사 속성 추가 출력 속성 추가)] ] [고객이 성/이름/전자 메일로 정의 됨] 정의 규칙 프로브 출력 –

0

은 읽을 수 없습니다 나는 승, 코멘트 코드를 재 게시 : 당신이이 코드를 수행하려고하지만, 당신이 마지막에 속성 세트를 추출 할 것은,이 변화를 고려 정확하게하고 싶었던 모자는 다음과 같습니다.

attribute: copy [] 
class: copy [] 
fs: to-lit-word "/" 
output: copy "" 


definition-rule: [ 
    some [set class word! (append output join class "|") 'is 'defined 'by [ 
     some [copy attribute to fs thru fs (append output join attribute ";")] 
    ] 
    copy attribute to end (append output attribute)] 
] 

parse [Customer is defined by First Name/Last Name/Email] definition-rule 
probe output