]> git.ozlabs.org Git - ccan/blob - ccan/ccan_tokenizer/number_constant.guppy
tdb2: allow transaction to nest.
[ccan] / ccan / ccan_tokenizer / number_constant.guppy
1 /*
2 guppy is a pattern-matching language by Joey Adams that's not implemented or formalized yet.
3 See http://www.funsitelots.com/pub/guppy.g for a near self-definition
4
5 This is a guppy representation of integer and floating point formatting in C.
6 It is based on http://c0x.coding-guidelines.com/6.4.4.1.html and http://c0x.coding-guidelines.com/6.4.4.2.html
7 */
8
9 number_constant: [
10         integer_constant()
11         floating_constant()
12 ]
13
14 integer_constant: [
15         ([1-9] [0-9]*)           //decimal
16         (0 [0-7]*)               //octal
17         (0 [X x] [0-9 A-F a-f]*) //hexadecimal
18 ]
19
20 integer_suffix: [
21         ([U u] [L l]*0..2)
22         ([L l]*1..2 [U u]*0..1)
23 ]
24
25 floating_constant: [
26         decimal_floating_constant()
27         hexadecimal_floating_constant()
28 ]
29
30 decimal_floating_constant: [
31         ([0-9]* '.' [0-9]+ exponent_part()*0..1 floating_suffix())
32         ([0-9]+ '.' exponent_part()*0..1 floating_suffix())
33         ([0-9]+ exponent_part() floating_suffix())
34 ]
35
36 exponent_part:
37         ([E e] ['+' '-']*0..1 [0-9]+)
38
39 hexadecimal_floating_constant:
40         (0 [X x] [
41                 [0-9 A-F a-f]* '.' [0-9 A-F a-f]+
42                 [0-9 A-F a-f]+ '.'
43                 [0-9 A-F a-f]+
44         ] [P p] ['+' '-']*0..1 [0-9]+ floating_suffix())
45
46 floating_suffix: [F L f l]*0..1
47
48 scan_number:
49 (
50         [
51                 (0 [X x] [0-9 A-F a-f '.']*)
52                 (0 [B b] [0-1] [0-9 '.']*)
53                 ([0-9 '.']*)
54         ]
55         ( [E P e p] ['+' '-']*0..1 [0-9]* )*0..1
56         [0-9 A-Z a-z '.' '_' '$']*
57 )
58
59 /*
60 Notes:
61
62 A numeric constant can begin with any of:
63         0-9 '.'
64 and can contain any of:
65         0-9 a-f e f l p u x '.' '+' '-'
66 along with capital equivalents.
67
68 If scanning finds something starting with a '.' but no decimal digit after it, it is the '.' operator and not a number.
69
70 */