Compare commits

..

2 Commits

Author SHA1 Message Date
mae
73fd1dd90d fix/schema: fix string literals 2026-01-28 19:52:13 -06:00
mae
dc87bef1c2 feat/schema: additional literal types 2026-01-28 02:08:12 -06:00
12 changed files with 8651 additions and 1563 deletions

View File

@@ -2,6 +2,7 @@ package ast
import ( import (
"azalea/schema/token" "azalea/schema/token"
"azalea/schema/util"
"strconv" "strconv"
"strings" "strings"
) )
@@ -15,26 +16,45 @@ type Expr struct {
} }
type ValList []Val type ValList []Val
type Val struct { type Val struct {
string string string *string
number string rune *rune
name string int *int64
float *float64
imaginary *complex128
name *string
*Expr *Expr
} }
func NewExprList(expr any) (ExprList, error) {
return ExprList{expr.(Expr)}, nil
}
func NewStringVal(val *token.Token) (Val, error) { func NewStringVal(val *token.Token) (Val, error) {
return Val{string: string(val.Lit)}, nil s, err := strconv.Unquote(string(val.Lit))
return Val{string: &s}, err
}
func NewIStringVal(val *token.Token) (Val, error) {
s, err := util.InterpretString(string(val.Lit))
return Val{string: &s}, err
}
func NewRuneVal(val *token.Token) (Val, error) {
r := util.RuneValue(val.Lit)
return Val{rune: &r}, nil
}
func NewIntVal(val *token.Token) (Val, error) {
i, err := strconv.ParseInt(string(val.Lit), 0, 64)
return Val{int: &i}, err
} }
func NewNumberVal(val *token.Token) (Val, error) { func NewFloatVal(val *token.Token) (Val, error) {
return Val{number: string(val.Lit)}, nil f, err := strconv.ParseFloat(string(val.Lit), 64)
return Val{float: &f}, err
}
func NewComplexVal(val *token.Token) (Val, error) {
c, err := strconv.ParseComplex(string(val.Lit), 128)
return Val{imaginary: &c}, err
} }
func NewNameVal(val *token.Token) (Val, error) { func NewNameVal(val *token.Token) (Val, error) {
return Val{name: string(val.Lit)}, nil name := string(val.Lit)
return Val{name: &name}, nil
} }
func NewExprVal(val any) (Val, error) { func NewExprVal(val any) (Val, error) {
@@ -42,6 +62,10 @@ func NewExprVal(val any) (Val, error) {
return Val{Expr: &expr}, nil return Val{Expr: &expr}, nil
} }
func NewExprList(expr any) (ExprList, error) {
return ExprList{expr.(Expr)}, nil
}
func AppendExpr(exprList, expr any) (ExprList, error) { func AppendExpr(exprList, expr any) (ExprList, error) {
return append(exprList.(ExprList), expr.(Expr)), nil return append(exprList.(ExprList), expr.(Expr)), nil
} }
@@ -100,15 +124,23 @@ func (e Expr) String() string {
return sb.String() return sb.String()
} }
func (v *Val) String() string { func (v *Val) String() string {
if v.string != "" { if v.string != nil {
return v.string return *v.string
} }
if v.number != "" { if v.rune != nil {
num, _ := strconv.ParseInt(v.number, 0, 64) return string(*v.rune)
return strconv.FormatInt(num, 10)
} }
if v.name != "" { if v.int != nil {
return v.name return strconv.FormatInt(*v.int, 10)
}
if v.float != nil {
return strconv.FormatFloat(*v.float, 'g', -1, 64)
}
if v.imaginary != nil {
return strconv.FormatComplex(*v.imaginary, 'g', -1, 128)
}
if v.name != nil {
return *v.name
} }
if v.Expr != nil { if v.Expr != nil {
return v.Expr.String() return v.Expr.String()

View File

@@ -1,15 +1,42 @@
string: '`' {.} '`' | '"' {.} '"'; raw_string: '`' {.} '`';
interpreted_string: '"' {_byte_value | _little_u_value | _big_u_value | _escaped_char | ' ' - '!' | '#' - '[' | ']' - '\U0010FFFF'} '"';
_unicode_value: . | _little_u_value | _big_u_value | _escaped_char;
_byte_value: _octal_byte_value | _hex_byte_value;
_little_u_value: '\\' 'u' _hex_digit _hex_digit _hex_digit _hex_digit;
_big_u_value: '\\' 'U' _hex_digit _hex_digit _hex_digit _hex_digit _hex_digit _hex_digit _hex_digit _hex_digit;
_escaped_char: '\\' ('a' | 'b' | 'f' | 'n' | 'r' | 't' | 'v' | '\\' | '\'' | '"');
_octal_byte_value: '\\' _oct_digit _oct_digit _oct_digit;
_hex_byte_value: '\\' 'x' _hex_digit _hex_digit;
rune: '\'' (_unicode_value | _byte_value) '\'';
_bin_digit: '0' - '1'; _bin_digit: '0' - '1';
_bin_digits: _bin_digit {_bin_digit | '_'};
_oct_digit: _bin_digit | '2' - '7'; _oct_digit: _bin_digit | '2' - '7';
_oct_digits: _oct_digit {_oct_digit | '_'};
_dec_digit: _oct_digit | '8' - '9'; _dec_digit: _oct_digit | '8' - '9';
_dec_digits: _dec_digit {_dec_digit | '_'};
_hex_digit: _dec_digit | 'A' - 'F' | 'a' - 'f'; _hex_digit: _dec_digit | 'A' - 'F' | 'a' - 'f';
number: ['-' | '+'] '0' 'b' _bin_digit {_bin_digit | '_'} _hex_digits: _hex_digit {_hex_digit | '_'};
| ['-' | '+'] '0' 'o' _oct_digit {_oct_digit | '_'}
| ['-' | '+'] _dec_digit {_dec_digit | '_'}
| ['-' | '+'] '0' 'x' _hex_digit {_hex_digit | '_'};
_name_initial: 'A' - 'Z' | 'a' - 'z' | '_' | '~' | '!' | '@' | '#' | '$' | '%' | '^' | '&' | '*' | '-' | '_' | '+' | '=' | '?' | '/' | '.' | '\''; _int: ['-' | '+'] '0' ('b' | 'B') _bin_digits
| ['-' | '+'] '0' ('o' | 'O') _oct_digits
| ['-' | '+'] _dec_digits
| ['-' | '+'] '0' ('x' | 'X') _hex_digits;
int: _int;
_dec_exponent: ('e' | 'E') ['+' | '-'] _dec_digits;
_dec_float: ['-' | '+'] _dec_digits '.' [_dec_digits] [_dec_exponent]
| _dec_digits _dec_exponent
| '.' _dec_digits [_dec_exponent];
_hex_exponent: ('p' | 'P') ['+' | '-'] _dec_digits;
_hex_mantissa: ['_'] _hex_digits '.' _hex_digits | ['_'] _hex_digits | '.' _hex_digits;
_hex_float: ['-' | '+'] '0' ('x' | 'X') _hex_mantissa _hex_exponent;
_float: _dec_float | _hex_float;
float: _float;
imaginary: (_dec_digits | _int | _float) 'i';
_name_initial: 'A' - 'Z' | 'a' - 'z' | '_' | '~' | '!' | '@' | '#' | '$' | '%' | '^' | '&' | '*' | '-' | '_' | '+' | '=' | '?' | '/' | '.';
_name_char: _name_initial | _dec_digit; _name_char: _name_initial | _dec_digit;
name: _name_initial {_name_char}; name: _name_initial {_name_char};
@@ -32,8 +59,12 @@ ValList
| ValList Val <<ast.AppendVal($0, $1)>> | ValList Val <<ast.AppendVal($0, $1)>>
; ;
Val Val
: string <<ast.NewStringVal($T0)>> : raw_string <<ast.NewStringVal($T0)>>
| number <<ast.NewNumberVal($T0)>> | interpreted_string <<ast.NewIStringVal($T0)>>
| rune <<ast.NewRuneVal($T0)>>
| int <<ast.NewIntVal($T0)>>
| float <<ast.NewFloatVal($T0)>>
| imaginary <<ast.NewComplexVal($T0)>>
| name <<ast.NewNameVal($T0)>> | name <<ast.NewNameVal($T0)>>
| Expr <<ast.NewExprVal($0)>> | Expr <<ast.NewExprVal($0)>>
; ;

File diff suppressed because it is too large Load Diff

View File

@@ -11,8 +11,8 @@ import (
const ( const (
NoState = -1 NoState = -1
NumStates = 52 NumStates = 278
NumSymbols = 57 NumSymbols = 104
) )
type Lexer struct { type Lexer struct {
@@ -133,57 +133,104 @@ Lexer symbols:
1: '`' 1: '`'
2: '"' 2: '"'
3: '"' 3: '"'
4: '-' 4: '''
5: '+' 5: '''
6: '0' 6: 'i'
7: 'b' 7: '('
8: '_' 8: ')'
9: '-' 9: '.'
10: '+' 10: '\'
11: '0' 11: 'u'
12: 'o' 12: '\'
13: '_' 13: 'U'
14: '-' 14: '\'
15: '+' 15: 'a'
16: '_' 16: 'b'
17: '-' 17: 'f'
18: '+' 18: 'n'
19: '0' 19: 'r'
20: 'x' 20: 't'
21: '_' 21: 'v'
22: '(' 22: '\'
23: ')' 23: '''
24: '.' 24: '"'
25: '_' 25: '\'
26: '~' 26: '\'
27: '!' 27: 'x'
28: '@' 28: '_'
29: '#' 29: '_'
30: '$' 30: '_'
31: '%' 31: '_'
32: '^' 32: '-'
33: '&' 33: '+'
34: '*' 34: '0'
35: '-' 35: 'b'
36: '_' 36: 'B'
37: '+' 37: '-'
38: '=' 38: '+'
39: '?' 39: '0'
40: '/' 40: 'o'
41: '.' 41: 'O'
42: ''' 42: '-'
43: ' ' 43: '+'
44: '\t' 44: '-'
45: '\n' 45: '+'
46: '\r' 46: '0'
47: ';' 47: 'x'
48: '\n' 48: 'X'
49: '0'-'1' 49: 'e'
50: '2'-'7' 50: 'E'
51: '8'-'9' 51: '+'
52: 'A'-'F' 52: '-'
53: 'a'-'f' 53: '-'
54: 'A'-'Z' 54: '+'
55: 'a'-'z' 55: '.'
56: . 56: '.'
57: 'p'
58: 'P'
59: '+'
60: '-'
61: '_'
62: '.'
63: '_'
64: '.'
65: '-'
66: '+'
67: '0'
68: 'x'
69: 'X'
70: '_'
71: '~'
72: '!'
73: '@'
74: '#'
75: '$'
76: '%'
77: '^'
78: '&'
79: '*'
80: '-'
81: '_'
82: '+'
83: '='
84: '?'
85: '/'
86: '.'
87: ' '
88: '\t'
89: '\n'
90: '\r'
91: ';'
92: '\n'
93: ' '-'!'
94: '#'-'['
95: ']'-\U0010ffff
96: '0'-'1'
97: '2'-'7'
98: '8'-'9'
99: 'A'-'F'
100: 'a'-'f'
101: 'A'-'Z'
102: 'a'-'z'
103: .
*/ */

File diff suppressed because it is too large Load Diff

View File

@@ -16,8 +16,12 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
nil, // string nil, // raw_string
nil, // number nil, // interpreted_string
nil, // rune
nil, // int
nil, // float
nil, // imaginary
nil, // name nil, // name
shift(4), // ( shift(4), // (
nil, // ) nil, // )
@@ -29,8 +33,12 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
accept(true), // ␚ accept(true), // ␚
nil, // string nil, // raw_string
nil, // number nil, // interpreted_string
nil, // rune
nil, // int
nil, // float
nil, // imaginary
nil, // name nil, // name
nil, // ( nil, // (
nil, // ) nil, // )
@@ -42,8 +50,12 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
reduce(1), // ␚, reduce: Schema reduce(1), // ␚, reduce: Schema
nil, // string nil, // raw_string
nil, // number nil, // interpreted_string
nil, // rune
nil, // int
nil, // float
nil, // imaginary
nil, // name nil, // name
shift(4), // ( shift(4), // (
nil, // ) nil, // )
@@ -55,8 +67,12 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
reduce(2), // ␚, reduce: ExprList reduce(2), // ␚, reduce: ExprList
nil, // string nil, // raw_string
nil, // number nil, // interpreted_string
nil, // rune
nil, // int
nil, // float
nil, // imaginary
nil, // name nil, // name
reduce(2), // (, reduce: ExprList reduce(2), // (, reduce: ExprList
nil, // ) nil, // )
@@ -68,8 +84,12 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
nil, // string nil, // raw_string
nil, // number nil, // interpreted_string
nil, // rune
nil, // int
nil, // float
nil, // imaginary
shift(6), // name shift(6), // name
nil, // ( nil, // (
nil, // ) nil, // )
@@ -81,8 +101,12 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
reduce(3), // ␚, reduce: ExprList reduce(3), // ␚, reduce: ExprList
nil, // string nil, // raw_string
nil, // number nil, // interpreted_string
nil, // rune
nil, // int
nil, // float
nil, // imaginary
nil, // name nil, // name
reduce(3), // (, reduce: ExprList reduce(3), // (, reduce: ExprList
nil, // ) nil, // )
@@ -94,11 +118,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
shift(10), // string shift(10), // raw_string
shift(11), // number shift(11), // interpreted_string
shift(12), // name shift(12), // rune
shift(13), // ( shift(13), // int
shift(14), // ) shift(14), // float
shift(15), // imaginary
shift(16), // name
shift(17), // (
shift(18), // )
nil, // . nil, // .
}, },
}, },
@@ -107,10 +135,14 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
shift(10), // string shift(10), // raw_string
shift(11), // number shift(11), // interpreted_string
shift(12), // name shift(12), // rune
shift(13), // ( shift(13), // int
shift(14), // float
shift(15), // imaginary
shift(16), // name
shift(17), // (
nil, // ) nil, // )
nil, // . nil, // .
}, },
@@ -120,11 +152,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
reduce(9), // string, reduce: Val reduce(13), // raw_string, reduce: Val
reduce(9), // number, reduce: Val reduce(13), // interpreted_string, reduce: Val
reduce(9), // name, reduce: Val reduce(13), // rune, reduce: Val
reduce(9), // (, reduce: Val reduce(13), // int, reduce: Val
reduce(9), // ), reduce: Val reduce(13), // float, reduce: Val
reduce(13), // imaginary, reduce: Val
reduce(13), // name, reduce: Val
reduce(13), // (, reduce: Val
reduce(13), // ), reduce: Val
nil, // . nil, // .
}, },
}, },
@@ -133,11 +169,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
shift(19), // string shift(23), // raw_string
shift(20), // number shift(24), // interpreted_string
shift(21), // name shift(25), // rune
shift(22), // ( shift(26), // int
shift(23), // ) shift(27), // float
shift(28), // imaginary
shift(29), // name
shift(30), // (
shift(31), // )
nil, // . nil, // .
}, },
}, },
@@ -146,8 +186,12 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
reduce(6), // string, reduce: Val reduce(6), // raw_string, reduce: Val
reduce(6), // number, reduce: Val reduce(6), // interpreted_string, reduce: Val
reduce(6), // rune, reduce: Val
reduce(6), // int, reduce: Val
reduce(6), // float, reduce: Val
reduce(6), // imaginary, reduce: Val
reduce(6), // name, reduce: Val reduce(6), // name, reduce: Val
reduce(6), // (, reduce: Val reduce(6), // (, reduce: Val
reduce(6), // ), reduce: Val reduce(6), // ), reduce: Val
@@ -159,8 +203,12 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
reduce(7), // string, reduce: Val reduce(7), // raw_string, reduce: Val
reduce(7), // number, reduce: Val reduce(7), // interpreted_string, reduce: Val
reduce(7), // rune, reduce: Val
reduce(7), // int, reduce: Val
reduce(7), // float, reduce: Val
reduce(7), // imaginary, reduce: Val
reduce(7), // name, reduce: Val reduce(7), // name, reduce: Val
reduce(7), // (, reduce: Val reduce(7), // (, reduce: Val
reduce(7), // ), reduce: Val reduce(7), // ), reduce: Val
@@ -172,8 +220,12 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
reduce(8), // string, reduce: Val reduce(8), // raw_string, reduce: Val
reduce(8), // number, reduce: Val reduce(8), // interpreted_string, reduce: Val
reduce(8), // rune, reduce: Val
reduce(8), // int, reduce: Val
reduce(8), // float, reduce: Val
reduce(8), // imaginary, reduce: Val
reduce(8), // name, reduce: Val reduce(8), // name, reduce: Val
reduce(8), // (, reduce: Val reduce(8), // (, reduce: Val
reduce(8), // ), reduce: Val reduce(8), // ), reduce: Val
@@ -185,24 +237,32 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
nil, // string reduce(9), // raw_string, reduce: Val
nil, // number reduce(9), // interpreted_string, reduce: Val
shift(24), // name reduce(9), // rune, reduce: Val
nil, // ( reduce(9), // int, reduce: Val
nil, // ) reduce(9), // float, reduce: Val
shift(25), // . reduce(9), // imaginary, reduce: Val
reduce(9), // name, reduce: Val
reduce(9), // (, reduce: Val
reduce(9), // ), reduce: Val
nil, // .
}, },
}, },
actionRow{ // S14 actionRow{ // S14
canRecover: false, canRecover: false,
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
reduce(12), // ␚, reduce: Expr nil, // ␚
nil, // string reduce(10), // raw_string, reduce: Val
nil, // number reduce(10), // interpreted_string, reduce: Val
nil, // name reduce(10), // rune, reduce: Val
reduce(12), // (, reduce: Expr reduce(10), // int, reduce: Val
nil, // ) reduce(10), // float, reduce: Val
reduce(10), // imaginary, reduce: Val
reduce(10), // name, reduce: Val
reduce(10), // (, reduce: Val
reduce(10), // ), reduce: Val
nil, // . nil, // .
}, },
}, },
@@ -211,11 +271,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
shift(10), // string reduce(11), // raw_string, reduce: Val
shift(11), // number reduce(11), // interpreted_string, reduce: Val
shift(12), // name reduce(11), // rune, reduce: Val
shift(13), // ( reduce(11), // int, reduce: Val
shift(27), // ) reduce(11), // float, reduce: Val
reduce(11), // imaginary, reduce: Val
reduce(11), // name, reduce: Val
reduce(11), // (, reduce: Val
reduce(11), // ), reduce: Val
nil, // . nil, // .
}, },
}, },
@@ -224,11 +288,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
reduce(4), // string, reduce: ValList reduce(12), // raw_string, reduce: Val
reduce(4), // number, reduce: ValList reduce(12), // interpreted_string, reduce: Val
reduce(4), // name, reduce: ValList reduce(12), // rune, reduce: Val
reduce(4), // (, reduce: ValList reduce(12), // int, reduce: Val
reduce(4), // ), reduce: ValList reduce(12), // float, reduce: Val
reduce(12), // imaginary, reduce: Val
reduce(12), // name, reduce: Val
reduce(12), // (, reduce: Val
reduce(12), // ), reduce: Val
nil, // . nil, // .
}, },
}, },
@@ -237,24 +305,32 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
nil, // string nil, // raw_string
nil, // number nil, // interpreted_string
nil, // name nil, // rune
nil, // int
nil, // float
nil, // imaginary
shift(32), // name
nil, // ( nil, // (
reduce(9), // ), reduce: Val nil, // )
nil, // . shift(33), // .
}, },
}, },
actionRow{ // S18 actionRow{ // S18
canRecover: false, canRecover: false,
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ reduce(16), // ␚, reduce: Expr
nil, // string nil, // raw_string
nil, // number nil, // interpreted_string
nil, // rune
nil, // int
nil, // float
nil, // imaginary
nil, // name nil, // name
nil, // ( reduce(16), // (, reduce: Expr
shift(28), // ) nil, // )
nil, // . nil, // .
}, },
}, },
@@ -263,11 +339,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
nil, // string shift(10), // raw_string
nil, // number shift(11), // interpreted_string
nil, // name shift(12), // rune
nil, // ( shift(13), // int
reduce(6), // ), reduce: Val shift(14), // float
shift(15), // imaginary
shift(16), // name
shift(17), // (
shift(35), // )
nil, // . nil, // .
}, },
}, },
@@ -276,11 +356,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
nil, // string reduce(4), // raw_string, reduce: ValList
nil, // number reduce(4), // interpreted_string, reduce: ValList
nil, // name reduce(4), // rune, reduce: ValList
nil, // ( reduce(4), // int, reduce: ValList
reduce(7), // ), reduce: Val reduce(4), // float, reduce: ValList
reduce(4), // imaginary, reduce: ValList
reduce(4), // name, reduce: ValList
reduce(4), // (, reduce: ValList
reduce(4), // ), reduce: ValList
nil, // . nil, // .
}, },
}, },
@@ -289,11 +373,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
nil, // string nil, // raw_string
nil, // number nil, // interpreted_string
nil, // rune
nil, // int
nil, // float
nil, // imaginary
nil, // name nil, // name
nil, // ( nil, // (
reduce(8), // ), reduce: Val reduce(13), // ), reduce: Val
nil, // . nil, // .
}, },
}, },
@@ -302,24 +390,32 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
nil, // string nil, // raw_string
nil, // number nil, // interpreted_string
shift(29), // name nil, // rune
nil, // int
nil, // float
nil, // imaginary
nil, // name
nil, // ( nil, // (
nil, // ) shift(36), // )
shift(30), // . nil, // .
}, },
}, },
actionRow{ // S23 actionRow{ // S23
canRecover: false, canRecover: false,
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
reduce(11), // ␚, reduce: Expr nil, // ␚
nil, // string nil, // raw_string
nil, // number nil, // interpreted_string
nil, // rune
nil, // int
nil, // float
nil, // imaginary
nil, // name nil, // name
reduce(11), // (, reduce: Expr nil, // (
nil, // ) reduce(6), // ), reduce: Val
nil, // . nil, // .
}, },
}, },
@@ -328,11 +424,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
shift(10), // string nil, // raw_string
shift(11), // number nil, // interpreted_string
shift(12), // name nil, // rune
shift(13), // ( nil, // int
shift(32), // ) nil, // float
nil, // imaginary
nil, // name
nil, // (
reduce(7), // ), reduce: Val
nil, // . nil, // .
}, },
}, },
@@ -341,11 +441,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
shift(10), // string nil, // raw_string
shift(11), // number nil, // interpreted_string
shift(12), // name nil, // rune
shift(13), // ( nil, // int
nil, // ) nil, // float
nil, // imaginary
nil, // name
nil, // (
reduce(8), // ), reduce: Val
nil, // . nil, // .
}, },
}, },
@@ -354,11 +458,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
reduce(5), // string, reduce: ValList nil, // raw_string
reduce(5), // number, reduce: ValList nil, // interpreted_string
reduce(5), // name, reduce: ValList nil, // rune
reduce(5), // (, reduce: ValList nil, // int
reduce(5), // ), reduce: ValList nil, // float
nil, // imaginary
nil, // name
nil, // (
reduce(9), // ), reduce: Val
nil, // . nil, // .
}, },
}, },
@@ -366,12 +474,16 @@ var actionTab = actionTable{
canRecover: false, canRecover: false,
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
reduce(13), // ␚, reduce: Expr nil, // ␚
nil, // string nil, // raw_string
nil, // number nil, // interpreted_string
nil, // rune
nil, // int
nil, // float
nil, // imaginary
nil, // name nil, // name
reduce(13), // (, reduce: Expr nil, // (
nil, // ) reduce(10), // ), reduce: Val
nil, // . nil, // .
}, },
}, },
@@ -379,12 +491,16 @@ var actionTab = actionTable{
canRecover: false, canRecover: false,
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
reduce(10), // ␚, reduce: Expr nil, // ␚
nil, // string nil, // raw_string
nil, // number nil, // interpreted_string
nil, // rune
nil, // int
nil, // float
nil, // imaginary
nil, // name nil, // name
reduce(10), // (, reduce: Expr nil, // (
nil, // ) reduce(11), // ), reduce: Val
nil, // . nil, // .
}, },
}, },
@@ -393,11 +509,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
shift(10), // string nil, // raw_string
shift(11), // number nil, // interpreted_string
shift(12), // name nil, // rune
shift(13), // ( nil, // int
shift(35), // ) nil, // float
nil, // imaginary
nil, // name
nil, // (
reduce(12), // ), reduce: Val
nil, // . nil, // .
}, },
}, },
@@ -406,24 +526,32 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
shift(10), // string nil, // raw_string
shift(11), // number nil, // interpreted_string
shift(12), // name nil, // rune
shift(13), // ( nil, // int
nil, // float
nil, // imaginary
shift(37), // name
nil, // (
nil, // ) nil, // )
nil, // . shift(38), // .
}, },
}, },
actionRow{ // S31 actionRow{ // S31
canRecover: false, canRecover: false,
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ reduce(15), // ␚, reduce: Expr
shift(19), // string nil, // raw_string
shift(20), // number nil, // interpreted_string
shift(21), // name nil, // rune
shift(22), // ( nil, // int
shift(38), // ) nil, // float
nil, // imaginary
nil, // name
reduce(15), // (, reduce: Expr
nil, // )
nil, // . nil, // .
}, },
}, },
@@ -432,11 +560,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
reduce(12), // string, reduce: Expr shift(10), // raw_string
reduce(12), // number, reduce: Expr shift(11), // interpreted_string
reduce(12), // name, reduce: Expr shift(12), // rune
reduce(12), // (, reduce: Expr shift(13), // int
reduce(12), // ), reduce: Expr shift(14), // float
shift(15), // imaginary
shift(16), // name
shift(17), // (
shift(40), // )
nil, // . nil, // .
}, },
}, },
@@ -445,11 +577,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
shift(10), // string shift(10), // raw_string
shift(11), // number shift(11), // interpreted_string
shift(12), // name shift(12), // rune
shift(13), // ( shift(13), // int
shift(39), // ) shift(14), // float
shift(15), // imaginary
shift(16), // name
shift(17), // (
nil, // )
nil, // . nil, // .
}, },
}, },
@@ -458,11 +594,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
shift(19), // string reduce(5), // raw_string, reduce: ValList
shift(20), // number reduce(5), // interpreted_string, reduce: ValList
shift(21), // name reduce(5), // rune, reduce: ValList
shift(22), // ( reduce(5), // int, reduce: ValList
shift(41), // ) reduce(5), // float, reduce: ValList
reduce(5), // imaginary, reduce: ValList
reduce(5), // name, reduce: ValList
reduce(5), // (, reduce: ValList
reduce(5), // ), reduce: ValList
nil, // . nil, // .
}, },
}, },
@@ -470,12 +610,16 @@ var actionTab = actionTable{
canRecover: false, canRecover: false,
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ reduce(17), // ␚, reduce: Expr
nil, // string nil, // raw_string
nil, // number nil, // interpreted_string
nil, // rune
nil, // int
nil, // float
nil, // imaginary
nil, // name nil, // name
nil, // ( reduce(17), // (, reduce: Expr
reduce(12), // ), reduce: Expr nil, // )
nil, // . nil, // .
}, },
}, },
@@ -483,12 +627,16 @@ var actionTab = actionTable{
canRecover: false, canRecover: false,
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ reduce(14), // ␚, reduce: Expr
shift(10), // string nil, // raw_string
shift(11), // number nil, // interpreted_string
shift(12), // name nil, // rune
shift(13), // ( nil, // int
shift(42), // ) nil, // float
nil, // imaginary
nil, // name
reduce(14), // (, reduce: Expr
nil, // )
nil, // . nil, // .
}, },
}, },
@@ -497,10 +645,14 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
nil, // string shift(10), // raw_string
nil, // number shift(11), // interpreted_string
nil, // name shift(12), // rune
nil, // ( shift(13), // int
shift(14), // float
shift(15), // imaginary
shift(16), // name
shift(17), // (
shift(43), // ) shift(43), // )
nil, // . nil, // .
}, },
@@ -510,11 +662,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
reduce(11), // string, reduce: Expr shift(10), // raw_string
reduce(11), // number, reduce: Expr shift(11), // interpreted_string
reduce(11), // name, reduce: Expr shift(12), // rune
reduce(11), // (, reduce: Expr shift(13), // int
reduce(11), // ), reduce: Expr shift(14), // float
shift(15), // imaginary
shift(16), // name
shift(17), // (
nil, // )
nil, // . nil, // .
}, },
}, },
@@ -523,11 +679,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
reduce(13), // string, reduce: Expr shift(23), // raw_string
reduce(13), // number, reduce: Expr shift(24), // interpreted_string
reduce(13), // name, reduce: Expr shift(25), // rune
reduce(13), // (, reduce: Expr shift(26), // int
reduce(13), // ), reduce: Expr shift(27), // float
shift(28), // imaginary
shift(29), // name
shift(30), // (
shift(46), // )
nil, // . nil, // .
}, },
}, },
@@ -536,11 +696,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
nil, // string reduce(16), // raw_string, reduce: Expr
nil, // number reduce(16), // interpreted_string, reduce: Expr
nil, // name reduce(16), // rune, reduce: Expr
nil, // ( reduce(16), // int, reduce: Expr
shift(44), // ) reduce(16), // float, reduce: Expr
reduce(16), // imaginary, reduce: Expr
reduce(16), // name, reduce: Expr
reduce(16), // (, reduce: Expr
reduce(16), // ), reduce: Expr
nil, // . nil, // .
}, },
}, },
@@ -549,11 +713,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
nil, // string shift(10), // raw_string
nil, // number shift(11), // interpreted_string
nil, // name shift(12), // rune
nil, // ( shift(13), // int
reduce(11), // ), reduce: Expr shift(14), // float
shift(15), // imaginary
shift(16), // name
shift(17), // (
shift(47), // )
nil, // . nil, // .
}, },
}, },
@@ -562,11 +730,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
nil, // string shift(23), // raw_string
nil, // number shift(24), // interpreted_string
nil, // name shift(25), // rune
nil, // ( shift(26), // int
reduce(13), // ), reduce: Expr shift(27), // float
shift(28), // imaginary
shift(29), // name
shift(30), // (
shift(49), // )
nil, // . nil, // .
}, },
}, },
@@ -575,11 +747,15 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
reduce(10), // string, reduce: Expr nil, // raw_string
reduce(10), // number, reduce: Expr nil, // interpreted_string
reduce(10), // name, reduce: Expr nil, // rune
reduce(10), // (, reduce: Expr nil, // int
reduce(10), // ), reduce: Expr nil, // float
nil, // imaginary
nil, // name
nil, // (
reduce(16), // ), reduce: Expr
nil, // . nil, // .
}, },
}, },
@@ -588,11 +764,151 @@ var actionTab = actionTable{
actions: [numSymbols]action{ actions: [numSymbols]action{
nil, // INVALID nil, // INVALID
nil, // ␚ nil, // ␚
nil, // string shift(10), // raw_string
nil, // number shift(11), // interpreted_string
shift(12), // rune
shift(13), // int
shift(14), // float
shift(15), // imaginary
shift(16), // name
shift(17), // (
shift(50), // )
nil, // .
},
},
actionRow{ // S45
canRecover: false,
actions: [numSymbols]action{
nil, // INVALID
nil, // ␚
nil, // raw_string
nil, // interpreted_string
nil, // rune
nil, // int
nil, // float
nil, // imaginary
nil, // name nil, // name
nil, // ( nil, // (
reduce(10), // ), reduce: Expr shift(51), // )
nil, // .
},
},
actionRow{ // S46
canRecover: false,
actions: [numSymbols]action{
nil, // INVALID
nil, // ␚
reduce(15), // raw_string, reduce: Expr
reduce(15), // interpreted_string, reduce: Expr
reduce(15), // rune, reduce: Expr
reduce(15), // int, reduce: Expr
reduce(15), // float, reduce: Expr
reduce(15), // imaginary, reduce: Expr
reduce(15), // name, reduce: Expr
reduce(15), // (, reduce: Expr
reduce(15), // ), reduce: Expr
nil, // .
},
},
actionRow{ // S47
canRecover: false,
actions: [numSymbols]action{
nil, // INVALID
nil, // ␚
reduce(17), // raw_string, reduce: Expr
reduce(17), // interpreted_string, reduce: Expr
reduce(17), // rune, reduce: Expr
reduce(17), // int, reduce: Expr
reduce(17), // float, reduce: Expr
reduce(17), // imaginary, reduce: Expr
reduce(17), // name, reduce: Expr
reduce(17), // (, reduce: Expr
reduce(17), // ), reduce: Expr
nil, // .
},
},
actionRow{ // S48
canRecover: false,
actions: [numSymbols]action{
nil, // INVALID
nil, // ␚
nil, // raw_string
nil, // interpreted_string
nil, // rune
nil, // int
nil, // float
nil, // imaginary
nil, // name
nil, // (
shift(52), // )
nil, // .
},
},
actionRow{ // S49
canRecover: false,
actions: [numSymbols]action{
nil, // INVALID
nil, // ␚
nil, // raw_string
nil, // interpreted_string
nil, // rune
nil, // int
nil, // float
nil, // imaginary
nil, // name
nil, // (
reduce(15), // ), reduce: Expr
nil, // .
},
},
actionRow{ // S50
canRecover: false,
actions: [numSymbols]action{
nil, // INVALID
nil, // ␚
nil, // raw_string
nil, // interpreted_string
nil, // rune
nil, // int
nil, // float
nil, // imaginary
nil, // name
nil, // (
reduce(17), // ), reduce: Expr
nil, // .
},
},
actionRow{ // S51
canRecover: false,
actions: [numSymbols]action{
nil, // INVALID
nil, // ␚
reduce(14), // raw_string, reduce: Expr
reduce(14), // interpreted_string, reduce: Expr
reduce(14), // rune, reduce: Expr
reduce(14), // int, reduce: Expr
reduce(14), // float, reduce: Expr
reduce(14), // imaginary, reduce: Expr
reduce(14), // name, reduce: Expr
reduce(14), // (, reduce: Expr
reduce(14), // ), reduce: Expr
nil, // .
},
},
actionRow{ // S52
canRecover: false,
actions: [numSymbols]action{
nil, // INVALID
nil, // ␚
nil, // raw_string
nil, // interpreted_string
nil, // rune
nil, // int
nil, // float
nil, // imaginary
nil, // name
nil, // (
reduce(14), // ), reduce: Expr
nil, // . nil, // .
}, },
}, },

View File

@@ -70,8 +70,8 @@ var gotoTab = gotoTable{
-1, // S' -1, // S'
-1, // Schema -1, // Schema
-1, // ExprList -1, // ExprList
15, // ValList 19, // ValList
16, // Val 20, // Val
8, // Expr 8, // Expr
}, },
gotoRow{ // S8 gotoRow{ // S8
@@ -87,8 +87,8 @@ var gotoTab = gotoTable{
-1, // Schema -1, // Schema
-1, // ExprList -1, // ExprList
-1, // ValList -1, // ValList
18, // Val 22, // Val
17, // Expr 21, // Expr
}, },
gotoRow{ // S10 gotoRow{ // S10
-1, // S' -1, // S'
@@ -135,8 +135,8 @@ var gotoTab = gotoTable{
-1, // Schema -1, // Schema
-1, // ExprList -1, // ExprList
-1, // ValList -1, // ValList
26, // Val -1, // Val
8, // Expr -1, // Expr
}, },
gotoRow{ // S16 gotoRow{ // S16
-1, // S' -1, // S'
@@ -167,8 +167,8 @@ var gotoTab = gotoTable{
-1, // Schema -1, // Schema
-1, // ExprList -1, // ExprList
-1, // ValList -1, // ValList
-1, // Val 34, // Val
-1, // Expr 8, // Expr
}, },
gotoRow{ // S20 gotoRow{ // S20
-1, // S' -1, // S'
@@ -207,16 +207,16 @@ var gotoTab = gotoTable{
-1, // Schema -1, // Schema
-1, // ExprList -1, // ExprList
-1, // ValList -1, // ValList
31, // Val -1, // Val
8, // Expr -1, // Expr
}, },
gotoRow{ // S25 gotoRow{ // S25
-1, // S' -1, // S'
-1, // Schema -1, // Schema
-1, // ExprList -1, // ExprList
33, // ValList -1, // ValList
16, // Val -1, // Val
8, // Expr -1, // Expr
}, },
gotoRow{ // S26 gotoRow{ // S26
-1, // S' -1, // S'
@@ -247,26 +247,10 @@ var gotoTab = gotoTable{
-1, // Schema -1, // Schema
-1, // ExprList -1, // ExprList
-1, // ValList -1, // ValList
34, // Val -1, // Val
8, // Expr -1, // Expr
}, },
gotoRow{ // S30 gotoRow{ // S30
-1, // S'
-1, // Schema
-1, // ExprList
36, // ValList
16, // Val
8, // Expr
},
gotoRow{ // S31
-1, // S'
-1, // Schema
-1, // ExprList
-1, // ValList
37, // Val
17, // Expr
},
gotoRow{ // S32
-1, // S' -1, // S'
-1, // Schema -1, // Schema
-1, // ExprList -1, // ExprList
@@ -274,12 +258,28 @@ var gotoTab = gotoTable{
-1, // Val -1, // Val
-1, // Expr -1, // Expr
}, },
gotoRow{ // S33 gotoRow{ // S31
-1, // S' -1, // S'
-1, // Schema -1, // Schema
-1, // ExprList -1, // ExprList
-1, // ValList -1, // ValList
26, // Val -1, // Val
-1, // Expr
},
gotoRow{ // S32
-1, // S'
-1, // Schema
-1, // ExprList
-1, // ValList
39, // Val
8, // Expr
},
gotoRow{ // S33
-1, // S'
-1, // Schema
-1, // ExprList
41, // ValList
20, // Val
8, // Expr 8, // Expr
}, },
gotoRow{ // S34 gotoRow{ // S34
@@ -287,8 +287,8 @@ var gotoTab = gotoTable{
-1, // Schema -1, // Schema
-1, // ExprList -1, // ExprList
-1, // ValList -1, // ValList
40, // Val -1, // Val
17, // Expr -1, // Expr
}, },
gotoRow{ // S35 gotoRow{ // S35
-1, // S' -1, // S'
@@ -303,32 +303,32 @@ var gotoTab = gotoTable{
-1, // Schema -1, // Schema
-1, // ExprList -1, // ExprList
-1, // ValList -1, // ValList
26, // Val -1, // Val
8, // Expr -1, // Expr
}, },
gotoRow{ // S37 gotoRow{ // S37
-1, // S' -1, // S'
-1, // Schema -1, // Schema
-1, // ExprList -1, // ExprList
-1, // ValList -1, // ValList
-1, // Val 42, // Val
-1, // Expr 8, // Expr
}, },
gotoRow{ // S38 gotoRow{ // S38
-1, // S' -1, // S'
-1, // Schema -1, // Schema
-1, // ExprList -1, // ExprList
-1, // ValList 44, // ValList
-1, // Val 20, // Val
-1, // Expr 8, // Expr
}, },
gotoRow{ // S39 gotoRow{ // S39
-1, // S' -1, // S'
-1, // Schema -1, // Schema
-1, // ExprList -1, // ExprList
-1, // ValList -1, // ValList
-1, // Val 45, // Val
-1, // Expr 21, // Expr
}, },
gotoRow{ // S40 gotoRow{ // S40
-1, // S' -1, // S'
@@ -343,16 +343,16 @@ var gotoTab = gotoTable{
-1, // Schema -1, // Schema
-1, // ExprList -1, // ExprList
-1, // ValList -1, // ValList
-1, // Val 34, // Val
-1, // Expr 8, // Expr
}, },
gotoRow{ // S42 gotoRow{ // S42
-1, // S' -1, // S'
-1, // Schema -1, // Schema
-1, // ExprList -1, // ExprList
-1, // ValList -1, // ValList
-1, // Val 48, // Val
-1, // Expr 21, // Expr
}, },
gotoRow{ // S43 gotoRow{ // S43
-1, // S' -1, // S'
@@ -363,6 +363,70 @@ var gotoTab = gotoTable{
-1, // Expr -1, // Expr
}, },
gotoRow{ // S44 gotoRow{ // S44
-1, // S'
-1, // Schema
-1, // ExprList
-1, // ValList
34, // Val
8, // Expr
},
gotoRow{ // S45
-1, // S'
-1, // Schema
-1, // ExprList
-1, // ValList
-1, // Val
-1, // Expr
},
gotoRow{ // S46
-1, // S'
-1, // Schema
-1, // ExprList
-1, // ValList
-1, // Val
-1, // Expr
},
gotoRow{ // S47
-1, // S'
-1, // Schema
-1, // ExprList
-1, // ValList
-1, // Val
-1, // Expr
},
gotoRow{ // S48
-1, // S'
-1, // Schema
-1, // ExprList
-1, // ValList
-1, // Val
-1, // Expr
},
gotoRow{ // S49
-1, // S'
-1, // Schema
-1, // ExprList
-1, // ValList
-1, // Val
-1, // Expr
},
gotoRow{ // S50
-1, // S'
-1, // Schema
-1, // ExprList
-1, // ValList
-1, // Val
-1, // Expr
},
gotoRow{ // S51
-1, // S'
-1, // Schema
-1, // ExprList
-1, // ValList
-1, // Val
-1, // Expr
},
gotoRow{ // S52
-1, // S' -1, // S'
-1, // Schema -1, // Schema
-1, // ExprList -1, // ExprList

View File

@@ -11,9 +11,9 @@ import (
) )
const ( const (
numProductions = 14 numProductions = 18
numStates = 45 numStates = 53
numSymbols = 14 numSymbols = 18
) )
// Stack // Stack

View File

@@ -83,7 +83,7 @@ var productionsTable = ProdTab{
}, },
}, },
ProdTabEntry{ ProdTabEntry{
String: `Val : string << ast.NewStringVal(X[0].(*token.Token)) >>`, String: `Val : raw_string << ast.NewStringVal(X[0].(*token.Token)) >>`,
Id: "Val", Id: "Val",
NTType: 4, NTType: 4,
Index: 6, Index: 6,
@@ -93,20 +93,60 @@ var productionsTable = ProdTab{
}, },
}, },
ProdTabEntry{ ProdTabEntry{
String: `Val : number << ast.NewNumberVal(X[0].(*token.Token)) >>`, String: `Val : interpreted_string << ast.NewIStringVal(X[0].(*token.Token)) >>`,
Id: "Val", Id: "Val",
NTType: 4, NTType: 4,
Index: 7, Index: 7,
NumSymbols: 1, NumSymbols: 1,
ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) {
return ast.NewNumberVal(X[0].(*token.Token)) return ast.NewIStringVal(X[0].(*token.Token))
},
},
ProdTabEntry{
String: `Val : rune << ast.NewRuneVal(X[0].(*token.Token)) >>`,
Id: "Val",
NTType: 4,
Index: 8,
NumSymbols: 1,
ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) {
return ast.NewRuneVal(X[0].(*token.Token))
},
},
ProdTabEntry{
String: `Val : int << ast.NewIntVal(X[0].(*token.Token)) >>`,
Id: "Val",
NTType: 4,
Index: 9,
NumSymbols: 1,
ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) {
return ast.NewIntVal(X[0].(*token.Token))
},
},
ProdTabEntry{
String: `Val : float << ast.NewFloatVal(X[0].(*token.Token)) >>`,
Id: "Val",
NTType: 4,
Index: 10,
NumSymbols: 1,
ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) {
return ast.NewFloatVal(X[0].(*token.Token))
},
},
ProdTabEntry{
String: `Val : imaginary << ast.NewComplexVal(X[0].(*token.Token)) >>`,
Id: "Val",
NTType: 4,
Index: 11,
NumSymbols: 1,
ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) {
return ast.NewComplexVal(X[0].(*token.Token))
}, },
}, },
ProdTabEntry{ ProdTabEntry{
String: `Val : name << ast.NewNameVal(X[0].(*token.Token)) >>`, String: `Val : name << ast.NewNameVal(X[0].(*token.Token)) >>`,
Id: "Val", Id: "Val",
NTType: 4, NTType: 4,
Index: 8, Index: 12,
NumSymbols: 1, NumSymbols: 1,
ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) {
return ast.NewNameVal(X[0].(*token.Token)) return ast.NewNameVal(X[0].(*token.Token))
@@ -116,7 +156,7 @@ var productionsTable = ProdTab{
String: `Val : Expr << ast.NewExprVal(X[0]) >>`, String: `Val : Expr << ast.NewExprVal(X[0]) >>`,
Id: "Val", Id: "Val",
NTType: 4, NTType: 4,
Index: 9, Index: 13,
NumSymbols: 1, NumSymbols: 1,
ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) {
return ast.NewExprVal(X[0]) return ast.NewExprVal(X[0])
@@ -126,7 +166,7 @@ var productionsTable = ProdTab{
String: `Expr : "(" name Val Val ")" << ast.NewExpr(X[1].(*token.Token), X[2], X[3]) >>`, String: `Expr : "(" name Val Val ")" << ast.NewExpr(X[1].(*token.Token), X[2], X[3]) >>`,
Id: "Expr", Id: "Expr",
NTType: 5, NTType: 5,
Index: 10, Index: 14,
NumSymbols: 5, NumSymbols: 5,
ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) {
return ast.NewExpr(X[1].(*token.Token), X[2], X[3]) return ast.NewExpr(X[1].(*token.Token), X[2], X[3])
@@ -136,7 +176,7 @@ var productionsTable = ProdTab{
String: `Expr : "(" name Val ")" << ast.NewExpr(X[1].(*token.Token), X[2], nil) >>`, String: `Expr : "(" name Val ")" << ast.NewExpr(X[1].(*token.Token), X[2], nil) >>`,
Id: "Expr", Id: "Expr",
NTType: 5, NTType: 5,
Index: 11, Index: 15,
NumSymbols: 4, NumSymbols: 4,
ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) {
return ast.NewExpr(X[1].(*token.Token), X[2], nil) return ast.NewExpr(X[1].(*token.Token), X[2], nil)
@@ -146,7 +186,7 @@ var productionsTable = ProdTab{
String: `Expr : "(" name ")" << ast.NewExpr(X[1].(*token.Token), nil, nil) >>`, String: `Expr : "(" name ")" << ast.NewExpr(X[1].(*token.Token), nil, nil) >>`,
Id: "Expr", Id: "Expr",
NTType: 5, NTType: 5,
Index: 12, Index: 16,
NumSymbols: 3, NumSymbols: 3,
ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) {
return ast.NewExpr(X[1].(*token.Token), nil, nil) return ast.NewExpr(X[1].(*token.Token), nil, nil)
@@ -156,7 +196,7 @@ var productionsTable = ProdTab{
String: `Expr : "(" "." ValList ")" << ast.ListExpr(X[2]) >>`, String: `Expr : "(" "." ValList ")" << ast.ListExpr(X[2]) >>`,
Id: "Expr", Id: "Expr",
NTType: 5, NTType: 5,
Index: 13, Index: 17,
NumSymbols: 4, NumSymbols: 4,
ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) { ReduceFunc: func(X []Attrib, C interface{}) (Attrib, error) {
return ast.ListExpr(X[2]) return ast.ListExpr(X[2])

View File

@@ -6,13 +6,24 @@ import (
) )
func TestParser(t *testing.T) { func TestParser(t *testing.T) {
test := "(test)" + testSchema(t, "(test)\n ; test comment"+
"(test a)" + "(test a)\n"+
"(test a b)" + "(test a b)\n"+
"(test \"a\" \"b\")" + "(test \"a\" \"b\")\n"+
"(+ 0b1010 -0xDEAD_BEEF)" + "(+ 0b1010 -0xDEAD_BEEF)\n"+
"(. a b c d e f g)" + "(. a b c d e f g)\n"+
"(test (test1 \"hi\") (test2 \"hi 2\"))" + "(test (test1 \"hi\") (test2 \"hi 2\"))\n"+
"(test (. \"awa\" \"awawa\" \"awawawa\" \"awawawawa\"))" "(test (. \"awa\" `awawa` \"awawawa\" \"awawawawa\"))\n"+
fmt.Println(CreateSchema(test)) "(test \n `new\nline`)\n"+
"(test (. 0x0.1Fp1 '\\t' 2i '\\u6767' '\\U0001F600' '\\x23' '\\043'))\n")
}
func TestInterpretString(t *testing.T) {
testSchema(t, "(test \"\\\" \\\\v \\u6767 \\U0001F600 \\x23 \\043 \" `\\\\ \\t \\u6767 \\U0001F600 \\x23 \\043`)")
}
func testSchema(t *testing.T, test string) {
schema, err := CreateSchema(test)
if err != nil {
t.Fatal(err)
}
fmt.Println(schema)
} }

View File

@@ -138,8 +138,12 @@ var TokMap = TokenMap{
typeMap: []string{ typeMap: []string{
"INVALID", "INVALID",
"␚", "␚",
"string", "raw_string",
"number", "interpreted_string",
"rune",
"int",
"float",
"imaginary",
"name", "name",
"(", "(",
")", ")",
@@ -149,11 +153,15 @@ var TokMap = TokenMap{
idMap: map[string]Type{ idMap: map[string]Type{
"INVALID": 0, "INVALID": 0,
"␚": 1, "␚": 1,
"string": 2, "raw_string": 2,
"number": 3, "interpreted_string": 3,
"name": 4, "rune": 4,
"(": 5, "int": 5,
")": 6, "float": 6,
".": 7, "imaginary": 7,
"name": 8,
"(": 9,
")": 10,
".": 11,
}, },
} }

97
schema/util/util.go Normal file
View File

@@ -0,0 +1,97 @@
package util
import (
"errors"
"strconv"
"strings"
)
func InterpretString(in string) (string, error) {
in = in[1 : len(in)-1]
sb := strings.Builder{}
s := []rune(in)
for i := 0; i < len(s); {
r := s[i]
if r == '\\' {
if i == len(s)-1 {
return "", errors.New("illegal escape character")
}
switch s[i+1] {
case 'a':
sb.WriteRune('\a')
i += 2
break
case 'b':
sb.WriteRune('\b')
i += 2
break
case 'f':
sb.WriteRune('\f')
i += 2
break
case 'n':
sb.WriteRune('\n')
i += 2
break
case 'r':
sb.WriteRune('\r')
i += 2
break
case 't':
sb.WriteRune('\t')
i += 2
break
case 'v':
sb.WriteRune('\v')
i += 2
break
case '\\':
sb.WriteRune('\\')
i += 2
break
case '"':
sb.WriteRune('"')
i += 2
break
case 'u':
sub := s[i+2 : i+6]
n, err := strconv.ParseInt(string(sub), 16, 64)
if err != nil {
return "", err
}
sb.WriteRune(rune(n))
i += 6
case 'U':
sub := s[i+2 : i+10]
n, err := strconv.ParseInt(string(sub), 16, 64)
if err != nil {
return "", err
}
sb.WriteRune(rune(n))
i += 10
case '0', '1', '2', '3', '4', '5', '6', '7':
sub := s[i+1 : i+4]
n, err := strconv.ParseInt(string(sub), 8, 64)
if err != nil {
return "", err
}
sb.WriteRune(rune(n))
i += 4
case 'x':
sub := s[i+2 : i+4]
n, err := strconv.ParseInt(string(sub), 16, 64)
if err != nil {
return "", err
}
sb.WriteRune(rune(n))
i += 4
default:
return "", errors.New("could not parse escape character")
}
} else {
sb.WriteRune(r)
i++
}
}
return sb.String(), nil
}