-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.peg
71 lines (48 loc) · 1.31 KB
/
grammar.peg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package stock_parser
type StockCodeParser Peg {
pos int
peekPos int
}
Item <- Line* !.
Line <- FTStock / XLStock / Stock / OTHER
# Any other characters, to ignore
OTHER <- (.)
# Match stockcode
Stock <- (
# $BABA$, $BABA.US$
'$' Code (Suffix / Suffix?) '$' /
# $BABA.US $700.HK
'$' Code Suffix /
# BABA.US 700.HK
' '+ Code Suffix /
# $BABA
'$' USCode /
# (NYSE: A)
'(' ('NYSE' / 'NASDAQ') (':' / ':') SP* USCode ')' /
# (HK:2015) (US:BABA)
'(' Market ':' Code ')'
)
XLStock <- (
# $阿里巴巴(BABA)$ $中国平安(SH601318)$ $腾讯控股(00700)$ $百度集团-SW(09988)$ $恒生科技指数(HKHSTECH)$ $恒生指数(HKHSI)$ $CoinBase Global(COIN)$
'$' StockName '(' (CNMarket ACode / HKMarket HSCODE / USCode / HKCode / .USCode) ')' '$'
)
FTStock <- (
# $阿里巴巴(BABA.US)$ $腾讯控股(00700.HK)$ $歌尔股份(002241.SZ)$
'$' (StockName / StockName '-' Letter+) '(' Code '.' Market ')' '$'
)
StockName <- [^"()"]*
Code <- (USCode / HKCode / ACode)
USCode <- '.'?Letter+
HKCode <- Number+
ACode <- Number+
HSCODE <- ('HSTECH' / 'HSI')
Letter <- [A-Z]
Number <- [0-9]
Suffix <- '.' (Market / "O")
Market <- (CNMarket / HKMarket / USMarket / SGMarket)
CNMarket <- ('SH' / 'SZ')
HKMarket <- 'HK'
USMarket <- 'US'
SGMarket <- 'SG'
# Any spaces
SP <- " " / "\t"