Revision 459:f04ba52ddf4b, 1.9 KB
(checked in by Andreas Gassner <ag@…>, 7 years ago)

Started the ANTLR conversion of the parser

Line  

1  grammar UL4; 

2  

3  options 

4  { 

5  output=AST; 

6  language=Java; 

7  ASTLabelType=CommonTree; 

8  } 

9  

10  @header 

11  { 

12  package com.livinglogic.ul4; 

13  } 

14  

15  NONE : 'None'; 

16  

17  TRUE : 'True'; 

18  

19  FALSE : 'False'; 

20  

21  NAME : ('a'..'z''A'..'Z''_') ('a'..'z''A'..'Z''0'..'9''_')* 

22  ; 

23  

24  fragment 

25  DIGIT : '0'..'9' 

26  ; 

27  

28  fragment 

29  BIN_DIGIT 

30  : ('0''1') 

31  ; 

32  fragment 

33  OCT_DIGIT 

34  : '0'..'7' 

35  ; 

36  

37  fragment 

38  HEX_DIGIT : ('0'..'9''a'..'f''A'..'F') 

39  ; 

40  

41  INT : DIGIT+ 

42   '0' ('b''B') BIN_DIGIT+ 

43   '0' ('o''O') OCT_DIGIT+ 

44   '0' ('x''X') HEX_DIGIT+ 

45  ; 

46  

47  FLOAT 

48  : DIGIT+ '.' DIGIT* EXPONENT? 

49   '.' DIGIT+ EXPONENT? 

50   DIGIT+ EXPONENT 

51  ; 

52  

53  fragment 

54  TIME : DIGIT DIGIT ':' DIGIT DIGIT (':' DIGIT DIGIT('.' DIGIT DIGIT DIGIT DIGIT DIGIT DIGIT)?)?; 

55  

56  DATE : '@' DIGIT DIGIT DIGIT DIGIT '' DIGIT DIGIT '' DIGIT DIGIT 'T' TIME?; 

57  

58  COLOR : '#' HEX_DIGIT HEX_DIGIT HEX_DIGIT 

59   '#' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT 

60   '#' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT 

61   '#' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT 

62  ; 

63  

64  WS : ( ' ' 

65   '\t' 

66   '\r' 

67   '\n' 

68  ) {$channel=HIDDEN;} 

69  ; 

70  

71  STRING 

72  : '"' ( ESC_SEQ  ~('\\''"') )* '"' 

73   '\'' ( ESC_SEQ  ~('\\''\'') )* '\'' 

74  ; 

75  

76  fragment 

77  EXPONENT : ('e''E') ('+''')? DIGIT+ ; 

78  

79  fragment 

80  ESC_SEQ 

81  : '\\' ('a''b''e''t''n''f''r''\"''\'''\\') 

82   UNICODE1_ESC 

83   UNICODE2_ESC 

84   UNICODE4_ESC 

85  ; 

86  

87  fragment 

88  UNICODE1_ESC 

89  : '\\' 'x' HEX_DIGIT HEX_DIGIT 

90  ; 

91  

92  fragment 

93  UNICODE2_ESC 

94  : '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT 

95  ; 

96  

97  fragment 

98  UNICODE4_ESC 

99  : '\\' 'U' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT 

100  ; 

101  

102  parse : atom; 

103  

104  atom 

105  : NONE 

106   FALSE 

107   TRUE 

108   NAME 

109   INT 

110   STRING 

111   DATE 

112   COLOR 

113  ; 

114  

115  expr : atom  list; 

116  

117  list : '[' (expr ',')* ']' 

118   '[' (expr ',')* expr ']' 

119  ; 
