OSDN Git Service

Adds grammar for dianzhu
[dianzhuhui/script.git] / lib / dianzhu.citrus
1 # 標点の文法(点注会)
2
3 grammar Dianzhu
4   rule sentence_seq
5     ( sentence+ )
6   end
7   rule sentence
8     (((phrase ':' quotation) | quotation | phrase_seq )+ fullstop)
9   end
10
11   # 引用はネストしない
12   rule quotation
13     ( '「' phrase_seq '」' )
14   end
15
16   # 説解用
17   rule sentence_part
18     ( sentence_seq? (phrase_seq punctuation)? )
19   end
20 #  rule phrase_seq
21 #    ( phrase (punctuation phrase)* )
22 #  end 
23
24   rule phrase_seq
25     ( phrases | phrase )
26   end
27   rule phrases
28     ( phrase punctuation seq:(phrases | phrase) ) {
29       phrase.value + punctuation.value + seq.value
30     }
31   end
32
33 #  rule phrase
34 #    ( word+ )
35 #  end
36   rule phrase
37     ( words | word )
38   end
39   rule words
40     ( word seq:(words | word) ) { word.value + seq.value }
41   end
42
43   rule word
44    ( object | text )
45   end
46   rule object
47     ('[' command ':' text ']') {
48         command.value + "{" + text + "}"
49     }
50   end
51   rule command
52      ( book | chapter | person | fanqie | rime_group )
53   end
54   rule book
55     'bk' { "\book" }
56   end
57   rule chapter
58     'ch' { "\chap" }
59   end
60   rule person
61     'p' { "\pers" }
62   end
63
64   # terminals
65   rule text
66     /[^《》〈〉【】「」。,、:;?!\[\]:a-z]+/u  # TODO: 半角を除く \W
67   end
68   rule punctuation
69     /[,、:;]/u
70   end
71   rule fullstop
72     /[。]/u
73   end
74 end