diff --git a/Numscript.g4 b/Numscript.g4 index 793d2d9..4ea640b 100644 --- a/Numscript.g4 +++ b/Numscript.g4 @@ -60,7 +60,8 @@ valueExpr: | left = valueExpr op = ('+' | '-') right = valueExpr # infixExpr; functionCallArgs: valueExpr ( COMMA valueExpr)*; -functionCall: IDENTIFIER LPARENS functionCallArgs? RPARENS; +functionCall: + fnName = (OVERDRAFT | IDENTIFIER) LPARENS functionCallArgs? RPARENS; varOrigin: EQ functionCall; varDeclaration: diff --git a/internal/analysis/check.go b/internal/analysis/check.go index 38ef771..eeb4717 100644 --- a/internal/analysis/check.go +++ b/internal/analysis/check.go @@ -55,6 +55,7 @@ const FnSetTxMeta = "set_tx_meta" const FnSetAccountMeta = "set_account_meta" const FnVarOriginMeta = "meta" const FnVarOriginBalance = "balance" +const FnVarOriginOverdraft = "overdraft" var Builtins = map[string]FnCallResolution{ FnSetTxMeta: StatementFnCallResolution{ @@ -75,6 +76,11 @@ var Builtins = map[string]FnCallResolution{ Return: TypeMonetary, Docs: "fetch account balance", }, + FnVarOriginOverdraft: VarOriginFnCallResolution{ + Params: []string{TypeAccount, TypeAsset}, + Return: TypeMonetary, + Docs: "get absolute amount of the overdraft of an account. Returns zero if balance is not negative", + }, } type Diagnostic struct { diff --git a/internal/cmd/run.go b/internal/cmd/run.go index b4f52b4..d7ba612 100644 --- a/internal/cmd/run.go +++ b/internal/cmd/run.go @@ -26,6 +26,8 @@ var runRawOpt string var runStdinFlag bool var runOutFormatOpt string +var overdraftFeatureFlag bool + type inputOpts struct { Script string `json:"script"` Variables map[string]string `json:"variables"` @@ -115,10 +117,15 @@ func run(path string) { os.Exit(1) } + featureFlags := map[string]struct{}{} + if overdraftFeatureFlag { + featureFlags[interpreter.ExperimentalOverdraftFunctionFeatureFlag] = struct{}{} + } + result, err := interpreter.RunProgram(context.Background(), parseResult.Value, opt.Variables, interpreter.StaticStore{ Balances: opt.Balances, Meta: opt.Meta, - }, nil) + }, featureFlags) if err != nil { rng := err.GetRange() @@ -192,6 +199,9 @@ func getRunCmd() *cobra.Command { cmd.Flags().StringVarP(&runRawOpt, "raw", "r", "", "Raw json input containing script, variables, balances, metadata") cmd.Flags().BoolVar(&runStdinFlag, "stdin", false, "Take input from stdin (same format as the --raw option)") + // Feature flag + cmd.Flags().BoolVar(&overdraftFeatureFlag, interpreter.ExperimentalOverdraftFunctionFeatureFlag, false, "feature flag to enable the overdraft() function") + // Output options cmd.Flags().StringVar(&runOutFormatOpt, "output-format", OutputFormatPretty, "Set the output format. Available options: pretty, json.") diff --git a/internal/interpreter/interpreter.go b/internal/interpreter/interpreter.go index 989b303..78382a4 100644 --- a/internal/interpreter/interpreter.go +++ b/internal/interpreter/interpreter.go @@ -140,6 +140,13 @@ func (s *programState) handleOrigin(type_ string, fnCall parser.FnCall) (Value, } return *monetary, nil + case analysis.FnVarOriginOverdraft: + monetary, err := overdraft(s, fnCall.Range, args) + if err != nil { + return nil, err + } + return *monetary, nil + default: return nil, UnboundFunctionErr{Name: fnCall.Caller.Name} } @@ -170,6 +177,10 @@ func (s *programState) parseVars(varDeclrs []parser.VarDeclaration, rawVars map[ return nil } +type FeatureFlag = string + +const ExperimentalOverdraftFunctionFeatureFlag FeatureFlag = "experimental-overdraft-function" + func RunProgram( ctx context.Context, program parser.Program, @@ -189,6 +200,10 @@ func RunProgram( ctx: ctx, } + if _, ok := featureFlags[ExperimentalOverdraftFunctionFeatureFlag]; ok { + st.OverdraftFunctionFeatureFlag = true + } + err := st.parseVars(program.Vars, vars) if err != nil { return nil, err @@ -245,6 +260,8 @@ type programState struct { CachedBalances Balances CurrentBalanceQuery BalanceQuery + + OverdraftFunctionFeatureFlag bool } func (st *programState) pushSender(name string, monetary *big.Int) { @@ -778,6 +795,22 @@ func meta( return value, nil } +// Utility function to get the balance +func getBalance( + s *programState, + account string, + asset string, +) (*big.Int, InterpreterError) { + s.batchQuery(account, asset) + fetchBalanceErr := s.runBalancesQuery() + if fetchBalanceErr != nil { + return nil, QueryBalanceError{WrappedError: fetchBalanceErr} + } + balance := s.getCachedBalance(account, asset) + return balance, nil + +} + func balance( s *programState, r parser.Range, @@ -793,13 +826,12 @@ func balance( } // body - s.batchQuery(*account, *asset) - fetchBalanceErr := s.runBalancesQuery() - if fetchBalanceErr != nil { - return nil, QueryBalanceError{WrappedError: fetchBalanceErr} + + balance, err := getBalance(s, *account, *asset) + if err != nil { + return nil, err } - balance := s.getCachedBalance(*account, *asset) if balance.Cmp(big.NewInt(0)) == -1 { return nil, NegativeBalanceError{ Account: *account, @@ -816,6 +848,44 @@ func balance( return &m, nil } +func overdraft( + s *programState, + r parser.Range, + args []Value, +) (*Monetary, InterpreterError) { + if !s.OverdraftFunctionFeatureFlag { + return nil, ExperimentalFeature{FlagName: ExperimentalOverdraftFunctionFeatureFlag} + } + + // TODO more precise args range location + p := NewArgsParser(args) + account := parseArg(p, r, expectAccount) + asset := parseArg(p, r, expectAsset) + err := p.parse() + if err != nil { + return nil, err + } + + balance_, err := getBalance(s, *account, *asset) + if err != nil { + return nil, err + } + + balanceIsPositive := balance_.Cmp(big.NewInt(0)) == 1 + if balanceIsPositive { + return &Monetary{ + Amount: NewMonetaryInt(0), + Asset: Asset(*asset), + }, nil + } + + overdraft := new(big.Int).Neg(balance_) + return &Monetary{ + Amount: MonetaryInt(*overdraft), + Asset: Asset(*asset), + }, nil +} + func setTxMeta(st *programState, r parser.Range, args []Value) InterpreterError { p := NewArgsParser(args) key := parseArg(p, r, expectString) diff --git a/internal/interpreter/interpreter_error.go b/internal/interpreter/interpreter_error.go index 168df11..c819f1a 100644 --- a/internal/interpreter/interpreter_error.go +++ b/internal/interpreter/interpreter_error.go @@ -184,3 +184,12 @@ type QueryMetadataError struct { func (e QueryMetadataError) Error() string { return e.WrappedError.Error() } + +type ExperimentalFeature struct { + parser.Range + FlagName string +} + +func (e ExperimentalFeature) Error() string { + return fmt.Sprintf("this feature is experimental. You need the '%s' feature flag to enable it", e.FlagName) +} diff --git a/internal/interpreter/interpreter_test.go b/internal/interpreter/interpreter_test.go index 7d068dc..8a200fb 100644 --- a/internal/interpreter/interpreter_test.go +++ b/internal/interpreter/interpreter_test.go @@ -82,16 +82,50 @@ func (c *TestCase) setBalance(account string, asset string, amount int64) { } func test(t *testing.T, testCase TestCase) { + testWithFeatureFlag(t, testCase, "") +} + +// A version of test() which tests code under a feature flag +// if the feature flag is the empty string, it behaves as test() +// otherwise, it tests the program under that feature flag and also tests that +// the same script, without the flag, yields the ExperimentalFeature{} error +func testWithFeatureFlag(t *testing.T, testCase TestCase, flagName string) { t.Parallel() prog := testCase.program require.NotNil(t, prog) - execResult, err := machine.RunProgram(context.Background(), *prog, testCase.vars, machine.StaticStore{ - testCase.balances, - testCase.meta, - }, nil) + featureFlags := map[string]struct{}{} + if flagName != "" { + featureFlags[flagName] = struct{}{} + + _, err := machine.RunProgram( + context.Background(), + *prog, + testCase.vars, + machine.StaticStore{ + testCase.balances, + testCase.meta, + }, + nil, + ) + + require.Equal(t, machine.ExperimentalFeature{ + FlagName: flagName, + }, removeRange(err)) + } + + execResult, err := machine.RunProgram( + context.Background(), + *prog, + testCase.vars, + machine.StaticStore{ + testCase.balances, + testCase.meta, + }, + featureFlags, + ) expected := testCase.expected if expected.Error != nil { @@ -3266,6 +3300,117 @@ func TestSaveFromAccount(t *testing.T) { }) } +func TestOverdraftFunctionWhenNegative(t *testing.T) { + script := ` + vars { monetary $amt = overdraft(@acc, EUR/2) } + + send $amt ( + source = @world + destination = @dest + ) + + ` + + tc := NewTestCase() + tc.compile(t, script) + + tc.setBalance("acc", "EUR/2", -100) + tc.expected = CaseResult{ + Postings: []Posting{ + { + Asset: "EUR/2", + Amount: big.NewInt(100), + Source: "world", + Destination: "dest", + }, + }, + Error: nil, + } + testWithFeatureFlag(t, tc, machine.ExperimentalOverdraftFunctionFeatureFlag) +} + +func TestOverdraftFunctionWhenZero(t *testing.T) { + script := ` + vars { monetary $amt = overdraft(@acc, EUR/2) } + + send $amt ( + source = @world + destination = @dest + ) + + ` + + tc := NewTestCase() + tc.compile(t, script) + + tc.expected = CaseResult{ + Postings: []Posting{ + // zero posting is omitted + }, + Error: nil, + } + testWithFeatureFlag(t, tc, machine.ExperimentalOverdraftFunctionFeatureFlag) +} + +func TestOverdraftFunctionWhenPositive(t *testing.T) { + script := ` + vars { monetary $amt = overdraft(@acc, EUR/2) } + + send $amt ( + source = @world + destination = @dest + ) + ` + + tc := NewTestCase() + tc.compile(t, script) + + tc.setBalance("acc", "EUR/2", 100) + + tc.expected = CaseResult{ + Postings: []Posting{ + // zero posting is omitted + }, + Error: nil, + } + testWithFeatureFlag(t, tc, machine.ExperimentalOverdraftFunctionFeatureFlag) +} + +func TestOverdraftFunctionUseCaseRemoveDebt(t *testing.T) { + script := ` + vars { monetary $amt = overdraft(@user:001, USD/2) } + + + // we have at most 1000 USD/2 to remove user:001's debt + send [USD/2 1000] ( + source = @world + destination = { + // but we send at most what we need to cancel the debt + max $amt to @user:001 + remaining kept + } + ) + ` + + tc := NewTestCase() + tc.compile(t, script) + + tc.setBalance("user:001", "USD/2", -100) + + tc.expected = CaseResult{ + Postings: []Posting{ + machine.Posting{ + Asset: "USD/2", + Amount: big.NewInt(100), + Source: "world", + Destination: "user:001", + }, + }, + Error: nil, + } + testWithFeatureFlag(t, tc, machine.ExperimentalOverdraftFunctionFeatureFlag) +} + func TestAddMonetariesSameCurrency(t *testing.T) { script := ` send [COIN 1] + [COIN 2] ( diff --git a/internal/parser/antlr/Numscript.interp b/internal/parser/antlr/Numscript.interp index 8dc2e94..56d0de5 100644 --- a/internal/parser/antlr/Numscript.interp +++ b/internal/parser/antlr/Numscript.interp @@ -101,4 +101,4 @@ statement atn: -[4, 1, 37, 217, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 3, 1, 46, 8, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 56, 8, 2, 1, 2, 1, 2, 1, 2, 5, 2, 61, 8, 2, 10, 2, 12, 2, 64, 9, 2, 1, 3, 1, 3, 1, 3, 5, 3, 69, 8, 3, 10, 3, 12, 3, 72, 9, 3, 1, 4, 1, 4, 1, 4, 3, 4, 77, 8, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 3, 6, 87, 8, 6, 1, 7, 1, 7, 1, 7, 5, 7, 92, 8, 7, 10, 7, 12, 7, 95, 9, 7, 1, 7, 1, 7, 1, 8, 3, 8, 100, 8, 8, 1, 8, 5, 8, 103, 8, 8, 10, 8, 12, 8, 106, 9, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 3, 10, 118, 8, 10, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 4, 11, 135, 8, 11, 11, 11, 12, 11, 136, 1, 11, 1, 11, 1, 11, 1, 11, 5, 11, 143, 8, 11, 10, 11, 12, 11, 146, 9, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 3, 11, 154, 8, 11, 1, 12, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 3, 13, 163, 8, 13, 1, 14, 1, 14, 1, 14, 1, 14, 1, 15, 1, 15, 1, 15, 4, 15, 172, 8, 15, 11, 15, 12, 15, 173, 1, 15, 1, 15, 1, 15, 1, 15, 5, 15, 180, 8, 15, 10, 15, 12, 15, 183, 9, 15, 1, 15, 1, 15, 1, 15, 1, 15, 3, 15, 189, 8, 15, 1, 16, 1, 16, 1, 16, 1, 17, 1, 17, 3, 17, 196, 8, 17, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 3, 18, 215, 8, 18, 1, 18, 0, 1, 4, 19, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 0, 1, 2, 0, 1, 1, 29, 29, 228, 0, 38, 1, 0, 0, 0, 2, 45, 1, 0, 0, 0, 4, 55, 1, 0, 0, 0, 6, 65, 1, 0, 0, 0, 8, 73, 1, 0, 0, 0, 10, 80, 1, 0, 0, 0, 12, 83, 1, 0, 0, 0, 14, 88, 1, 0, 0, 0, 16, 99, 1, 0, 0, 0, 18, 109, 1, 0, 0, 0, 20, 117, 1, 0, 0, 0, 22, 153, 1, 0, 0, 0, 24, 155, 1, 0, 0, 0, 26, 162, 1, 0, 0, 0, 28, 164, 1, 0, 0, 0, 30, 188, 1, 0, 0, 0, 32, 190, 1, 0, 0, 0, 34, 195, 1, 0, 0, 0, 36, 214, 1, 0, 0, 0, 38, 39, 5, 22, 0, 0, 39, 40, 3, 4, 2, 0, 40, 41, 3, 4, 2, 0, 41, 42, 5, 23, 0, 0, 42, 1, 1, 0, 0, 0, 43, 46, 5, 30, 0, 0, 44, 46, 5, 31, 0, 0, 45, 43, 1, 0, 0, 0, 45, 44, 1, 0, 0, 0, 46, 3, 1, 0, 0, 0, 47, 48, 6, 2, -1, 0, 48, 56, 5, 35, 0, 0, 49, 56, 5, 37, 0, 0, 50, 56, 5, 32, 0, 0, 51, 56, 5, 36, 0, 0, 52, 56, 5, 34, 0, 0, 53, 56, 3, 0, 0, 0, 54, 56, 3, 2, 1, 0, 55, 47, 1, 0, 0, 0, 55, 49, 1, 0, 0, 0, 55, 50, 1, 0, 0, 0, 55, 51, 1, 0, 0, 0, 55, 52, 1, 0, 0, 0, 55, 53, 1, 0, 0, 0, 55, 54, 1, 0, 0, 0, 56, 62, 1, 0, 0, 0, 57, 58, 10, 1, 0, 0, 58, 59, 7, 0, 0, 0, 59, 61, 3, 4, 2, 2, 60, 57, 1, 0, 0, 0, 61, 64, 1, 0, 0, 0, 62, 60, 1, 0, 0, 0, 62, 63, 1, 0, 0, 0, 63, 5, 1, 0, 0, 0, 64, 62, 1, 0, 0, 0, 65, 70, 3, 4, 2, 0, 66, 67, 5, 26, 0, 0, 67, 69, 3, 4, 2, 0, 68, 66, 1, 0, 0, 0, 69, 72, 1, 0, 0, 0, 70, 68, 1, 0, 0, 0, 70, 71, 1, 0, 0, 0, 71, 7, 1, 0, 0, 0, 72, 70, 1, 0, 0, 0, 73, 74, 5, 33, 0, 0, 74, 76, 5, 20, 0, 0, 75, 77, 3, 6, 3, 0, 76, 75, 1, 0, 0, 0, 76, 77, 1, 0, 0, 0, 77, 78, 1, 0, 0, 0, 78, 79, 5, 21, 0, 0, 79, 9, 1, 0, 0, 0, 80, 81, 5, 27, 0, 0, 81, 82, 3, 8, 4, 0, 82, 11, 1, 0, 0, 0, 83, 84, 5, 33, 0, 0, 84, 86, 5, 35, 0, 0, 85, 87, 3, 10, 5, 0, 86, 85, 1, 0, 0, 0, 86, 87, 1, 0, 0, 0, 87, 13, 1, 0, 0, 0, 88, 89, 5, 6, 0, 0, 89, 93, 5, 24, 0, 0, 90, 92, 3, 12, 6, 0, 91, 90, 1, 0, 0, 0, 92, 95, 1, 0, 0, 0, 93, 91, 1, 0, 0, 0, 93, 94, 1, 0, 0, 0, 94, 96, 1, 0, 0, 0, 95, 93, 1, 0, 0, 0, 96, 97, 5, 25, 0, 0, 97, 15, 1, 0, 0, 0, 98, 100, 3, 14, 7, 0, 99, 98, 1, 0, 0, 0, 99, 100, 1, 0, 0, 0, 100, 104, 1, 0, 0, 0, 101, 103, 3, 36, 18, 0, 102, 101, 1, 0, 0, 0, 103, 106, 1, 0, 0, 0, 104, 102, 1, 0, 0, 0, 104, 105, 1, 0, 0, 0, 105, 107, 1, 0, 0, 0, 106, 104, 1, 0, 0, 0, 107, 108, 5, 0, 0, 1, 108, 17, 1, 0, 0, 0, 109, 110, 5, 22, 0, 0, 110, 111, 3, 4, 2, 0, 111, 112, 5, 28, 0, 0, 112, 113, 5, 23, 0, 0, 113, 19, 1, 0, 0, 0, 114, 118, 3, 2, 1, 0, 115, 118, 5, 35, 0, 0, 116, 118, 5, 14, 0, 0, 117, 114, 1, 0, 0, 0, 117, 115, 1, 0, 0, 0, 117, 116, 1, 0, 0, 0, 118, 21, 1, 0, 0, 0, 119, 120, 3, 4, 2, 0, 120, 121, 5, 15, 0, 0, 121, 122, 5, 16, 0, 0, 122, 123, 5, 17, 0, 0, 123, 154, 1, 0, 0, 0, 124, 125, 3, 4, 2, 0, 125, 126, 5, 15, 0, 0, 126, 127, 5, 17, 0, 0, 127, 128, 5, 12, 0, 0, 128, 129, 5, 13, 0, 0, 129, 130, 3, 4, 2, 0, 130, 154, 1, 0, 0, 0, 131, 154, 3, 4, 2, 0, 132, 134, 5, 24, 0, 0, 133, 135, 3, 24, 12, 0, 134, 133, 1, 0, 0, 0, 135, 136, 1, 0, 0, 0, 136, 134, 1, 0, 0, 0, 136, 137, 1, 0, 0, 0, 137, 138, 1, 0, 0, 0, 138, 139, 5, 25, 0, 0, 139, 154, 1, 0, 0, 0, 140, 144, 5, 24, 0, 0, 141, 143, 3, 22, 11, 0, 142, 141, 1, 0, 0, 0, 143, 146, 1, 0, 0, 0, 144, 142, 1, 0, 0, 0, 144, 145, 1, 0, 0, 0, 145, 147, 1, 0, 0, 0, 146, 144, 1, 0, 0, 0, 147, 154, 5, 25, 0, 0, 148, 149, 5, 7, 0, 0, 149, 150, 3, 4, 2, 0, 150, 151, 5, 11, 0, 0, 151, 152, 3, 22, 11, 0, 152, 154, 1, 0, 0, 0, 153, 119, 1, 0, 0, 0, 153, 124, 1, 0, 0, 0, 153, 131, 1, 0, 0, 0, 153, 132, 1, 0, 0, 0, 153, 140, 1, 0, 0, 0, 153, 148, 1, 0, 0, 0, 154, 23, 1, 0, 0, 0, 155, 156, 3, 20, 10, 0, 156, 157, 5, 11, 0, 0, 157, 158, 3, 22, 11, 0, 158, 25, 1, 0, 0, 0, 159, 160, 5, 13, 0, 0, 160, 163, 3, 30, 15, 0, 161, 163, 5, 18, 0, 0, 162, 159, 1, 0, 0, 0, 162, 161, 1, 0, 0, 0, 163, 27, 1, 0, 0, 0, 164, 165, 5, 7, 0, 0, 165, 166, 3, 4, 2, 0, 166, 167, 3, 26, 13, 0, 167, 29, 1, 0, 0, 0, 168, 189, 3, 4, 2, 0, 169, 171, 5, 24, 0, 0, 170, 172, 3, 32, 16, 0, 171, 170, 1, 0, 0, 0, 172, 173, 1, 0, 0, 0, 173, 171, 1, 0, 0, 0, 173, 174, 1, 0, 0, 0, 174, 175, 1, 0, 0, 0, 175, 176, 5, 25, 0, 0, 176, 189, 1, 0, 0, 0, 177, 181, 5, 24, 0, 0, 178, 180, 3, 28, 14, 0, 179, 178, 1, 0, 0, 0, 180, 183, 1, 0, 0, 0, 181, 179, 1, 0, 0, 0, 181, 182, 1, 0, 0, 0, 182, 184, 1, 0, 0, 0, 183, 181, 1, 0, 0, 0, 184, 185, 5, 14, 0, 0, 185, 186, 3, 26, 13, 0, 186, 187, 5, 25, 0, 0, 187, 189, 1, 0, 0, 0, 188, 168, 1, 0, 0, 0, 188, 169, 1, 0, 0, 0, 188, 177, 1, 0, 0, 0, 189, 31, 1, 0, 0, 0, 190, 191, 3, 20, 10, 0, 191, 192, 3, 26, 13, 0, 192, 33, 1, 0, 0, 0, 193, 196, 3, 4, 2, 0, 194, 196, 3, 18, 9, 0, 195, 193, 1, 0, 0, 0, 195, 194, 1, 0, 0, 0, 196, 35, 1, 0, 0, 0, 197, 198, 5, 10, 0, 0, 198, 199, 3, 34, 17, 0, 199, 200, 5, 20, 0, 0, 200, 201, 5, 8, 0, 0, 201, 202, 5, 27, 0, 0, 202, 203, 3, 22, 11, 0, 203, 204, 5, 9, 0, 0, 204, 205, 5, 27, 0, 0, 205, 206, 3, 30, 15, 0, 206, 207, 5, 21, 0, 0, 207, 215, 1, 0, 0, 0, 208, 209, 5, 19, 0, 0, 209, 210, 3, 34, 17, 0, 210, 211, 5, 11, 0, 0, 211, 212, 3, 4, 2, 0, 212, 215, 1, 0, 0, 0, 213, 215, 3, 8, 4, 0, 214, 197, 1, 0, 0, 0, 214, 208, 1, 0, 0, 0, 214, 213, 1, 0, 0, 0, 215, 37, 1, 0, 0, 0, 19, 45, 55, 62, 70, 76, 86, 93, 99, 104, 117, 136, 144, 153, 162, 173, 181, 188, 195, 214] \ No newline at end of file +[4, 1, 37, 217, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 3, 1, 46, 8, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 56, 8, 2, 1, 2, 1, 2, 1, 2, 5, 2, 61, 8, 2, 10, 2, 12, 2, 64, 9, 2, 1, 3, 1, 3, 1, 3, 5, 3, 69, 8, 3, 10, 3, 12, 3, 72, 9, 3, 1, 4, 1, 4, 1, 4, 3, 4, 77, 8, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 3, 6, 87, 8, 6, 1, 7, 1, 7, 1, 7, 5, 7, 92, 8, 7, 10, 7, 12, 7, 95, 9, 7, 1, 7, 1, 7, 1, 8, 3, 8, 100, 8, 8, 1, 8, 5, 8, 103, 8, 8, 10, 8, 12, 8, 106, 9, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 3, 10, 118, 8, 10, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 4, 11, 135, 8, 11, 11, 11, 12, 11, 136, 1, 11, 1, 11, 1, 11, 1, 11, 5, 11, 143, 8, 11, 10, 11, 12, 11, 146, 9, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 3, 11, 154, 8, 11, 1, 12, 1, 12, 1, 12, 1, 12, 1, 13, 1, 13, 1, 13, 3, 13, 163, 8, 13, 1, 14, 1, 14, 1, 14, 1, 14, 1, 15, 1, 15, 1, 15, 4, 15, 172, 8, 15, 11, 15, 12, 15, 173, 1, 15, 1, 15, 1, 15, 1, 15, 5, 15, 180, 8, 15, 10, 15, 12, 15, 183, 9, 15, 1, 15, 1, 15, 1, 15, 1, 15, 3, 15, 189, 8, 15, 1, 16, 1, 16, 1, 16, 1, 17, 1, 17, 3, 17, 196, 8, 17, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 3, 18, 215, 8, 18, 1, 18, 0, 1, 4, 19, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 0, 2, 2, 0, 1, 1, 29, 29, 2, 0, 17, 17, 33, 33, 228, 0, 38, 1, 0, 0, 0, 2, 45, 1, 0, 0, 0, 4, 55, 1, 0, 0, 0, 6, 65, 1, 0, 0, 0, 8, 73, 1, 0, 0, 0, 10, 80, 1, 0, 0, 0, 12, 83, 1, 0, 0, 0, 14, 88, 1, 0, 0, 0, 16, 99, 1, 0, 0, 0, 18, 109, 1, 0, 0, 0, 20, 117, 1, 0, 0, 0, 22, 153, 1, 0, 0, 0, 24, 155, 1, 0, 0, 0, 26, 162, 1, 0, 0, 0, 28, 164, 1, 0, 0, 0, 30, 188, 1, 0, 0, 0, 32, 190, 1, 0, 0, 0, 34, 195, 1, 0, 0, 0, 36, 214, 1, 0, 0, 0, 38, 39, 5, 22, 0, 0, 39, 40, 3, 4, 2, 0, 40, 41, 3, 4, 2, 0, 41, 42, 5, 23, 0, 0, 42, 1, 1, 0, 0, 0, 43, 46, 5, 30, 0, 0, 44, 46, 5, 31, 0, 0, 45, 43, 1, 0, 0, 0, 45, 44, 1, 0, 0, 0, 46, 3, 1, 0, 0, 0, 47, 48, 6, 2, -1, 0, 48, 56, 5, 35, 0, 0, 49, 56, 5, 37, 0, 0, 50, 56, 5, 32, 0, 0, 51, 56, 5, 36, 0, 0, 52, 56, 5, 34, 0, 0, 53, 56, 3, 0, 0, 0, 54, 56, 3, 2, 1, 0, 55, 47, 1, 0, 0, 0, 55, 49, 1, 0, 0, 0, 55, 50, 1, 0, 0, 0, 55, 51, 1, 0, 0, 0, 55, 52, 1, 0, 0, 0, 55, 53, 1, 0, 0, 0, 55, 54, 1, 0, 0, 0, 56, 62, 1, 0, 0, 0, 57, 58, 10, 1, 0, 0, 58, 59, 7, 0, 0, 0, 59, 61, 3, 4, 2, 2, 60, 57, 1, 0, 0, 0, 61, 64, 1, 0, 0, 0, 62, 60, 1, 0, 0, 0, 62, 63, 1, 0, 0, 0, 63, 5, 1, 0, 0, 0, 64, 62, 1, 0, 0, 0, 65, 70, 3, 4, 2, 0, 66, 67, 5, 26, 0, 0, 67, 69, 3, 4, 2, 0, 68, 66, 1, 0, 0, 0, 69, 72, 1, 0, 0, 0, 70, 68, 1, 0, 0, 0, 70, 71, 1, 0, 0, 0, 71, 7, 1, 0, 0, 0, 72, 70, 1, 0, 0, 0, 73, 74, 7, 1, 0, 0, 74, 76, 5, 20, 0, 0, 75, 77, 3, 6, 3, 0, 76, 75, 1, 0, 0, 0, 76, 77, 1, 0, 0, 0, 77, 78, 1, 0, 0, 0, 78, 79, 5, 21, 0, 0, 79, 9, 1, 0, 0, 0, 80, 81, 5, 27, 0, 0, 81, 82, 3, 8, 4, 0, 82, 11, 1, 0, 0, 0, 83, 84, 5, 33, 0, 0, 84, 86, 5, 35, 0, 0, 85, 87, 3, 10, 5, 0, 86, 85, 1, 0, 0, 0, 86, 87, 1, 0, 0, 0, 87, 13, 1, 0, 0, 0, 88, 89, 5, 6, 0, 0, 89, 93, 5, 24, 0, 0, 90, 92, 3, 12, 6, 0, 91, 90, 1, 0, 0, 0, 92, 95, 1, 0, 0, 0, 93, 91, 1, 0, 0, 0, 93, 94, 1, 0, 0, 0, 94, 96, 1, 0, 0, 0, 95, 93, 1, 0, 0, 0, 96, 97, 5, 25, 0, 0, 97, 15, 1, 0, 0, 0, 98, 100, 3, 14, 7, 0, 99, 98, 1, 0, 0, 0, 99, 100, 1, 0, 0, 0, 100, 104, 1, 0, 0, 0, 101, 103, 3, 36, 18, 0, 102, 101, 1, 0, 0, 0, 103, 106, 1, 0, 0, 0, 104, 102, 1, 0, 0, 0, 104, 105, 1, 0, 0, 0, 105, 107, 1, 0, 0, 0, 106, 104, 1, 0, 0, 0, 107, 108, 5, 0, 0, 1, 108, 17, 1, 0, 0, 0, 109, 110, 5, 22, 0, 0, 110, 111, 3, 4, 2, 0, 111, 112, 5, 28, 0, 0, 112, 113, 5, 23, 0, 0, 113, 19, 1, 0, 0, 0, 114, 118, 3, 2, 1, 0, 115, 118, 5, 35, 0, 0, 116, 118, 5, 14, 0, 0, 117, 114, 1, 0, 0, 0, 117, 115, 1, 0, 0, 0, 117, 116, 1, 0, 0, 0, 118, 21, 1, 0, 0, 0, 119, 120, 3, 4, 2, 0, 120, 121, 5, 15, 0, 0, 121, 122, 5, 16, 0, 0, 122, 123, 5, 17, 0, 0, 123, 154, 1, 0, 0, 0, 124, 125, 3, 4, 2, 0, 125, 126, 5, 15, 0, 0, 126, 127, 5, 17, 0, 0, 127, 128, 5, 12, 0, 0, 128, 129, 5, 13, 0, 0, 129, 130, 3, 4, 2, 0, 130, 154, 1, 0, 0, 0, 131, 154, 3, 4, 2, 0, 132, 134, 5, 24, 0, 0, 133, 135, 3, 24, 12, 0, 134, 133, 1, 0, 0, 0, 135, 136, 1, 0, 0, 0, 136, 134, 1, 0, 0, 0, 136, 137, 1, 0, 0, 0, 137, 138, 1, 0, 0, 0, 138, 139, 5, 25, 0, 0, 139, 154, 1, 0, 0, 0, 140, 144, 5, 24, 0, 0, 141, 143, 3, 22, 11, 0, 142, 141, 1, 0, 0, 0, 143, 146, 1, 0, 0, 0, 144, 142, 1, 0, 0, 0, 144, 145, 1, 0, 0, 0, 145, 147, 1, 0, 0, 0, 146, 144, 1, 0, 0, 0, 147, 154, 5, 25, 0, 0, 148, 149, 5, 7, 0, 0, 149, 150, 3, 4, 2, 0, 150, 151, 5, 11, 0, 0, 151, 152, 3, 22, 11, 0, 152, 154, 1, 0, 0, 0, 153, 119, 1, 0, 0, 0, 153, 124, 1, 0, 0, 0, 153, 131, 1, 0, 0, 0, 153, 132, 1, 0, 0, 0, 153, 140, 1, 0, 0, 0, 153, 148, 1, 0, 0, 0, 154, 23, 1, 0, 0, 0, 155, 156, 3, 20, 10, 0, 156, 157, 5, 11, 0, 0, 157, 158, 3, 22, 11, 0, 158, 25, 1, 0, 0, 0, 159, 160, 5, 13, 0, 0, 160, 163, 3, 30, 15, 0, 161, 163, 5, 18, 0, 0, 162, 159, 1, 0, 0, 0, 162, 161, 1, 0, 0, 0, 163, 27, 1, 0, 0, 0, 164, 165, 5, 7, 0, 0, 165, 166, 3, 4, 2, 0, 166, 167, 3, 26, 13, 0, 167, 29, 1, 0, 0, 0, 168, 189, 3, 4, 2, 0, 169, 171, 5, 24, 0, 0, 170, 172, 3, 32, 16, 0, 171, 170, 1, 0, 0, 0, 172, 173, 1, 0, 0, 0, 173, 171, 1, 0, 0, 0, 173, 174, 1, 0, 0, 0, 174, 175, 1, 0, 0, 0, 175, 176, 5, 25, 0, 0, 176, 189, 1, 0, 0, 0, 177, 181, 5, 24, 0, 0, 178, 180, 3, 28, 14, 0, 179, 178, 1, 0, 0, 0, 180, 183, 1, 0, 0, 0, 181, 179, 1, 0, 0, 0, 181, 182, 1, 0, 0, 0, 182, 184, 1, 0, 0, 0, 183, 181, 1, 0, 0, 0, 184, 185, 5, 14, 0, 0, 185, 186, 3, 26, 13, 0, 186, 187, 5, 25, 0, 0, 187, 189, 1, 0, 0, 0, 188, 168, 1, 0, 0, 0, 188, 169, 1, 0, 0, 0, 188, 177, 1, 0, 0, 0, 189, 31, 1, 0, 0, 0, 190, 191, 3, 20, 10, 0, 191, 192, 3, 26, 13, 0, 192, 33, 1, 0, 0, 0, 193, 196, 3, 4, 2, 0, 194, 196, 3, 18, 9, 0, 195, 193, 1, 0, 0, 0, 195, 194, 1, 0, 0, 0, 196, 35, 1, 0, 0, 0, 197, 198, 5, 10, 0, 0, 198, 199, 3, 34, 17, 0, 199, 200, 5, 20, 0, 0, 200, 201, 5, 8, 0, 0, 201, 202, 5, 27, 0, 0, 202, 203, 3, 22, 11, 0, 203, 204, 5, 9, 0, 0, 204, 205, 5, 27, 0, 0, 205, 206, 3, 30, 15, 0, 206, 207, 5, 21, 0, 0, 207, 215, 1, 0, 0, 0, 208, 209, 5, 19, 0, 0, 209, 210, 3, 34, 17, 0, 210, 211, 5, 11, 0, 0, 211, 212, 3, 4, 2, 0, 212, 215, 1, 0, 0, 0, 213, 215, 3, 8, 4, 0, 214, 197, 1, 0, 0, 0, 214, 208, 1, 0, 0, 0, 214, 213, 1, 0, 0, 0, 215, 37, 1, 0, 0, 0, 19, 45, 55, 62, 70, 76, 86, 93, 99, 104, 117, 136, 144, 153, 162, 173, 181, 188, 195, 214] \ No newline at end of file diff --git a/internal/parser/antlr/numscript_parser.go b/internal/parser/antlr/numscript_parser.go index 4fefc7b..542cd8b 100644 --- a/internal/parser/antlr/numscript_parser.go +++ b/internal/parser/antlr/numscript_parser.go @@ -77,76 +77,76 @@ func numscriptParserInit() { 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 1, 18, 3, 18, 215, 8, 18, 1, 18, 0, 1, 4, 19, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, - 0, 1, 2, 0, 1, 1, 29, 29, 228, 0, 38, 1, 0, 0, 0, 2, 45, 1, 0, 0, 0, 4, - 55, 1, 0, 0, 0, 6, 65, 1, 0, 0, 0, 8, 73, 1, 0, 0, 0, 10, 80, 1, 0, 0, - 0, 12, 83, 1, 0, 0, 0, 14, 88, 1, 0, 0, 0, 16, 99, 1, 0, 0, 0, 18, 109, - 1, 0, 0, 0, 20, 117, 1, 0, 0, 0, 22, 153, 1, 0, 0, 0, 24, 155, 1, 0, 0, - 0, 26, 162, 1, 0, 0, 0, 28, 164, 1, 0, 0, 0, 30, 188, 1, 0, 0, 0, 32, 190, - 1, 0, 0, 0, 34, 195, 1, 0, 0, 0, 36, 214, 1, 0, 0, 0, 38, 39, 5, 22, 0, - 0, 39, 40, 3, 4, 2, 0, 40, 41, 3, 4, 2, 0, 41, 42, 5, 23, 0, 0, 42, 1, - 1, 0, 0, 0, 43, 46, 5, 30, 0, 0, 44, 46, 5, 31, 0, 0, 45, 43, 1, 0, 0, - 0, 45, 44, 1, 0, 0, 0, 46, 3, 1, 0, 0, 0, 47, 48, 6, 2, -1, 0, 48, 56, - 5, 35, 0, 0, 49, 56, 5, 37, 0, 0, 50, 56, 5, 32, 0, 0, 51, 56, 5, 36, 0, - 0, 52, 56, 5, 34, 0, 0, 53, 56, 3, 0, 0, 0, 54, 56, 3, 2, 1, 0, 55, 47, - 1, 0, 0, 0, 55, 49, 1, 0, 0, 0, 55, 50, 1, 0, 0, 0, 55, 51, 1, 0, 0, 0, - 55, 52, 1, 0, 0, 0, 55, 53, 1, 0, 0, 0, 55, 54, 1, 0, 0, 0, 56, 62, 1, - 0, 0, 0, 57, 58, 10, 1, 0, 0, 58, 59, 7, 0, 0, 0, 59, 61, 3, 4, 2, 2, 60, - 57, 1, 0, 0, 0, 61, 64, 1, 0, 0, 0, 62, 60, 1, 0, 0, 0, 62, 63, 1, 0, 0, - 0, 63, 5, 1, 0, 0, 0, 64, 62, 1, 0, 0, 0, 65, 70, 3, 4, 2, 0, 66, 67, 5, - 26, 0, 0, 67, 69, 3, 4, 2, 0, 68, 66, 1, 0, 0, 0, 69, 72, 1, 0, 0, 0, 70, - 68, 1, 0, 0, 0, 70, 71, 1, 0, 0, 0, 71, 7, 1, 0, 0, 0, 72, 70, 1, 0, 0, - 0, 73, 74, 5, 33, 0, 0, 74, 76, 5, 20, 0, 0, 75, 77, 3, 6, 3, 0, 76, 75, - 1, 0, 0, 0, 76, 77, 1, 0, 0, 0, 77, 78, 1, 0, 0, 0, 78, 79, 5, 21, 0, 0, - 79, 9, 1, 0, 0, 0, 80, 81, 5, 27, 0, 0, 81, 82, 3, 8, 4, 0, 82, 11, 1, - 0, 0, 0, 83, 84, 5, 33, 0, 0, 84, 86, 5, 35, 0, 0, 85, 87, 3, 10, 5, 0, - 86, 85, 1, 0, 0, 0, 86, 87, 1, 0, 0, 0, 87, 13, 1, 0, 0, 0, 88, 89, 5, - 6, 0, 0, 89, 93, 5, 24, 0, 0, 90, 92, 3, 12, 6, 0, 91, 90, 1, 0, 0, 0, - 92, 95, 1, 0, 0, 0, 93, 91, 1, 0, 0, 0, 93, 94, 1, 0, 0, 0, 94, 96, 1, - 0, 0, 0, 95, 93, 1, 0, 0, 0, 96, 97, 5, 25, 0, 0, 97, 15, 1, 0, 0, 0, 98, - 100, 3, 14, 7, 0, 99, 98, 1, 0, 0, 0, 99, 100, 1, 0, 0, 0, 100, 104, 1, - 0, 0, 0, 101, 103, 3, 36, 18, 0, 102, 101, 1, 0, 0, 0, 103, 106, 1, 0, - 0, 0, 104, 102, 1, 0, 0, 0, 104, 105, 1, 0, 0, 0, 105, 107, 1, 0, 0, 0, - 106, 104, 1, 0, 0, 0, 107, 108, 5, 0, 0, 1, 108, 17, 1, 0, 0, 0, 109, 110, - 5, 22, 0, 0, 110, 111, 3, 4, 2, 0, 111, 112, 5, 28, 0, 0, 112, 113, 5, - 23, 0, 0, 113, 19, 1, 0, 0, 0, 114, 118, 3, 2, 1, 0, 115, 118, 5, 35, 0, - 0, 116, 118, 5, 14, 0, 0, 117, 114, 1, 0, 0, 0, 117, 115, 1, 0, 0, 0, 117, - 116, 1, 0, 0, 0, 118, 21, 1, 0, 0, 0, 119, 120, 3, 4, 2, 0, 120, 121, 5, - 15, 0, 0, 121, 122, 5, 16, 0, 0, 122, 123, 5, 17, 0, 0, 123, 154, 1, 0, - 0, 0, 124, 125, 3, 4, 2, 0, 125, 126, 5, 15, 0, 0, 126, 127, 5, 17, 0, - 0, 127, 128, 5, 12, 0, 0, 128, 129, 5, 13, 0, 0, 129, 130, 3, 4, 2, 0, - 130, 154, 1, 0, 0, 0, 131, 154, 3, 4, 2, 0, 132, 134, 5, 24, 0, 0, 133, - 135, 3, 24, 12, 0, 134, 133, 1, 0, 0, 0, 135, 136, 1, 0, 0, 0, 136, 134, - 1, 0, 0, 0, 136, 137, 1, 0, 0, 0, 137, 138, 1, 0, 0, 0, 138, 139, 5, 25, - 0, 0, 139, 154, 1, 0, 0, 0, 140, 144, 5, 24, 0, 0, 141, 143, 3, 22, 11, - 0, 142, 141, 1, 0, 0, 0, 143, 146, 1, 0, 0, 0, 144, 142, 1, 0, 0, 0, 144, - 145, 1, 0, 0, 0, 145, 147, 1, 0, 0, 0, 146, 144, 1, 0, 0, 0, 147, 154, - 5, 25, 0, 0, 148, 149, 5, 7, 0, 0, 149, 150, 3, 4, 2, 0, 150, 151, 5, 11, - 0, 0, 151, 152, 3, 22, 11, 0, 152, 154, 1, 0, 0, 0, 153, 119, 1, 0, 0, - 0, 153, 124, 1, 0, 0, 0, 153, 131, 1, 0, 0, 0, 153, 132, 1, 0, 0, 0, 153, - 140, 1, 0, 0, 0, 153, 148, 1, 0, 0, 0, 154, 23, 1, 0, 0, 0, 155, 156, 3, - 20, 10, 0, 156, 157, 5, 11, 0, 0, 157, 158, 3, 22, 11, 0, 158, 25, 1, 0, - 0, 0, 159, 160, 5, 13, 0, 0, 160, 163, 3, 30, 15, 0, 161, 163, 5, 18, 0, - 0, 162, 159, 1, 0, 0, 0, 162, 161, 1, 0, 0, 0, 163, 27, 1, 0, 0, 0, 164, - 165, 5, 7, 0, 0, 165, 166, 3, 4, 2, 0, 166, 167, 3, 26, 13, 0, 167, 29, - 1, 0, 0, 0, 168, 189, 3, 4, 2, 0, 169, 171, 5, 24, 0, 0, 170, 172, 3, 32, - 16, 0, 171, 170, 1, 0, 0, 0, 172, 173, 1, 0, 0, 0, 173, 171, 1, 0, 0, 0, - 173, 174, 1, 0, 0, 0, 174, 175, 1, 0, 0, 0, 175, 176, 5, 25, 0, 0, 176, - 189, 1, 0, 0, 0, 177, 181, 5, 24, 0, 0, 178, 180, 3, 28, 14, 0, 179, 178, - 1, 0, 0, 0, 180, 183, 1, 0, 0, 0, 181, 179, 1, 0, 0, 0, 181, 182, 1, 0, - 0, 0, 182, 184, 1, 0, 0, 0, 183, 181, 1, 0, 0, 0, 184, 185, 5, 14, 0, 0, - 185, 186, 3, 26, 13, 0, 186, 187, 5, 25, 0, 0, 187, 189, 1, 0, 0, 0, 188, - 168, 1, 0, 0, 0, 188, 169, 1, 0, 0, 0, 188, 177, 1, 0, 0, 0, 189, 31, 1, - 0, 0, 0, 190, 191, 3, 20, 10, 0, 191, 192, 3, 26, 13, 0, 192, 33, 1, 0, - 0, 0, 193, 196, 3, 4, 2, 0, 194, 196, 3, 18, 9, 0, 195, 193, 1, 0, 0, 0, - 195, 194, 1, 0, 0, 0, 196, 35, 1, 0, 0, 0, 197, 198, 5, 10, 0, 0, 198, - 199, 3, 34, 17, 0, 199, 200, 5, 20, 0, 0, 200, 201, 5, 8, 0, 0, 201, 202, - 5, 27, 0, 0, 202, 203, 3, 22, 11, 0, 203, 204, 5, 9, 0, 0, 204, 205, 5, - 27, 0, 0, 205, 206, 3, 30, 15, 0, 206, 207, 5, 21, 0, 0, 207, 215, 1, 0, - 0, 0, 208, 209, 5, 19, 0, 0, 209, 210, 3, 34, 17, 0, 210, 211, 5, 11, 0, - 0, 211, 212, 3, 4, 2, 0, 212, 215, 1, 0, 0, 0, 213, 215, 3, 8, 4, 0, 214, - 197, 1, 0, 0, 0, 214, 208, 1, 0, 0, 0, 214, 213, 1, 0, 0, 0, 215, 37, 1, - 0, 0, 0, 19, 45, 55, 62, 70, 76, 86, 93, 99, 104, 117, 136, 144, 153, 162, - 173, 181, 188, 195, 214, + 0, 2, 2, 0, 1, 1, 29, 29, 2, 0, 17, 17, 33, 33, 228, 0, 38, 1, 0, 0, 0, + 2, 45, 1, 0, 0, 0, 4, 55, 1, 0, 0, 0, 6, 65, 1, 0, 0, 0, 8, 73, 1, 0, 0, + 0, 10, 80, 1, 0, 0, 0, 12, 83, 1, 0, 0, 0, 14, 88, 1, 0, 0, 0, 16, 99, + 1, 0, 0, 0, 18, 109, 1, 0, 0, 0, 20, 117, 1, 0, 0, 0, 22, 153, 1, 0, 0, + 0, 24, 155, 1, 0, 0, 0, 26, 162, 1, 0, 0, 0, 28, 164, 1, 0, 0, 0, 30, 188, + 1, 0, 0, 0, 32, 190, 1, 0, 0, 0, 34, 195, 1, 0, 0, 0, 36, 214, 1, 0, 0, + 0, 38, 39, 5, 22, 0, 0, 39, 40, 3, 4, 2, 0, 40, 41, 3, 4, 2, 0, 41, 42, + 5, 23, 0, 0, 42, 1, 1, 0, 0, 0, 43, 46, 5, 30, 0, 0, 44, 46, 5, 31, 0, + 0, 45, 43, 1, 0, 0, 0, 45, 44, 1, 0, 0, 0, 46, 3, 1, 0, 0, 0, 47, 48, 6, + 2, -1, 0, 48, 56, 5, 35, 0, 0, 49, 56, 5, 37, 0, 0, 50, 56, 5, 32, 0, 0, + 51, 56, 5, 36, 0, 0, 52, 56, 5, 34, 0, 0, 53, 56, 3, 0, 0, 0, 54, 56, 3, + 2, 1, 0, 55, 47, 1, 0, 0, 0, 55, 49, 1, 0, 0, 0, 55, 50, 1, 0, 0, 0, 55, + 51, 1, 0, 0, 0, 55, 52, 1, 0, 0, 0, 55, 53, 1, 0, 0, 0, 55, 54, 1, 0, 0, + 0, 56, 62, 1, 0, 0, 0, 57, 58, 10, 1, 0, 0, 58, 59, 7, 0, 0, 0, 59, 61, + 3, 4, 2, 2, 60, 57, 1, 0, 0, 0, 61, 64, 1, 0, 0, 0, 62, 60, 1, 0, 0, 0, + 62, 63, 1, 0, 0, 0, 63, 5, 1, 0, 0, 0, 64, 62, 1, 0, 0, 0, 65, 70, 3, 4, + 2, 0, 66, 67, 5, 26, 0, 0, 67, 69, 3, 4, 2, 0, 68, 66, 1, 0, 0, 0, 69, + 72, 1, 0, 0, 0, 70, 68, 1, 0, 0, 0, 70, 71, 1, 0, 0, 0, 71, 7, 1, 0, 0, + 0, 72, 70, 1, 0, 0, 0, 73, 74, 7, 1, 0, 0, 74, 76, 5, 20, 0, 0, 75, 77, + 3, 6, 3, 0, 76, 75, 1, 0, 0, 0, 76, 77, 1, 0, 0, 0, 77, 78, 1, 0, 0, 0, + 78, 79, 5, 21, 0, 0, 79, 9, 1, 0, 0, 0, 80, 81, 5, 27, 0, 0, 81, 82, 3, + 8, 4, 0, 82, 11, 1, 0, 0, 0, 83, 84, 5, 33, 0, 0, 84, 86, 5, 35, 0, 0, + 85, 87, 3, 10, 5, 0, 86, 85, 1, 0, 0, 0, 86, 87, 1, 0, 0, 0, 87, 13, 1, + 0, 0, 0, 88, 89, 5, 6, 0, 0, 89, 93, 5, 24, 0, 0, 90, 92, 3, 12, 6, 0, + 91, 90, 1, 0, 0, 0, 92, 95, 1, 0, 0, 0, 93, 91, 1, 0, 0, 0, 93, 94, 1, + 0, 0, 0, 94, 96, 1, 0, 0, 0, 95, 93, 1, 0, 0, 0, 96, 97, 5, 25, 0, 0, 97, + 15, 1, 0, 0, 0, 98, 100, 3, 14, 7, 0, 99, 98, 1, 0, 0, 0, 99, 100, 1, 0, + 0, 0, 100, 104, 1, 0, 0, 0, 101, 103, 3, 36, 18, 0, 102, 101, 1, 0, 0, + 0, 103, 106, 1, 0, 0, 0, 104, 102, 1, 0, 0, 0, 104, 105, 1, 0, 0, 0, 105, + 107, 1, 0, 0, 0, 106, 104, 1, 0, 0, 0, 107, 108, 5, 0, 0, 1, 108, 17, 1, + 0, 0, 0, 109, 110, 5, 22, 0, 0, 110, 111, 3, 4, 2, 0, 111, 112, 5, 28, + 0, 0, 112, 113, 5, 23, 0, 0, 113, 19, 1, 0, 0, 0, 114, 118, 3, 2, 1, 0, + 115, 118, 5, 35, 0, 0, 116, 118, 5, 14, 0, 0, 117, 114, 1, 0, 0, 0, 117, + 115, 1, 0, 0, 0, 117, 116, 1, 0, 0, 0, 118, 21, 1, 0, 0, 0, 119, 120, 3, + 4, 2, 0, 120, 121, 5, 15, 0, 0, 121, 122, 5, 16, 0, 0, 122, 123, 5, 17, + 0, 0, 123, 154, 1, 0, 0, 0, 124, 125, 3, 4, 2, 0, 125, 126, 5, 15, 0, 0, + 126, 127, 5, 17, 0, 0, 127, 128, 5, 12, 0, 0, 128, 129, 5, 13, 0, 0, 129, + 130, 3, 4, 2, 0, 130, 154, 1, 0, 0, 0, 131, 154, 3, 4, 2, 0, 132, 134, + 5, 24, 0, 0, 133, 135, 3, 24, 12, 0, 134, 133, 1, 0, 0, 0, 135, 136, 1, + 0, 0, 0, 136, 134, 1, 0, 0, 0, 136, 137, 1, 0, 0, 0, 137, 138, 1, 0, 0, + 0, 138, 139, 5, 25, 0, 0, 139, 154, 1, 0, 0, 0, 140, 144, 5, 24, 0, 0, + 141, 143, 3, 22, 11, 0, 142, 141, 1, 0, 0, 0, 143, 146, 1, 0, 0, 0, 144, + 142, 1, 0, 0, 0, 144, 145, 1, 0, 0, 0, 145, 147, 1, 0, 0, 0, 146, 144, + 1, 0, 0, 0, 147, 154, 5, 25, 0, 0, 148, 149, 5, 7, 0, 0, 149, 150, 3, 4, + 2, 0, 150, 151, 5, 11, 0, 0, 151, 152, 3, 22, 11, 0, 152, 154, 1, 0, 0, + 0, 153, 119, 1, 0, 0, 0, 153, 124, 1, 0, 0, 0, 153, 131, 1, 0, 0, 0, 153, + 132, 1, 0, 0, 0, 153, 140, 1, 0, 0, 0, 153, 148, 1, 0, 0, 0, 154, 23, 1, + 0, 0, 0, 155, 156, 3, 20, 10, 0, 156, 157, 5, 11, 0, 0, 157, 158, 3, 22, + 11, 0, 158, 25, 1, 0, 0, 0, 159, 160, 5, 13, 0, 0, 160, 163, 3, 30, 15, + 0, 161, 163, 5, 18, 0, 0, 162, 159, 1, 0, 0, 0, 162, 161, 1, 0, 0, 0, 163, + 27, 1, 0, 0, 0, 164, 165, 5, 7, 0, 0, 165, 166, 3, 4, 2, 0, 166, 167, 3, + 26, 13, 0, 167, 29, 1, 0, 0, 0, 168, 189, 3, 4, 2, 0, 169, 171, 5, 24, + 0, 0, 170, 172, 3, 32, 16, 0, 171, 170, 1, 0, 0, 0, 172, 173, 1, 0, 0, + 0, 173, 171, 1, 0, 0, 0, 173, 174, 1, 0, 0, 0, 174, 175, 1, 0, 0, 0, 175, + 176, 5, 25, 0, 0, 176, 189, 1, 0, 0, 0, 177, 181, 5, 24, 0, 0, 178, 180, + 3, 28, 14, 0, 179, 178, 1, 0, 0, 0, 180, 183, 1, 0, 0, 0, 181, 179, 1, + 0, 0, 0, 181, 182, 1, 0, 0, 0, 182, 184, 1, 0, 0, 0, 183, 181, 1, 0, 0, + 0, 184, 185, 5, 14, 0, 0, 185, 186, 3, 26, 13, 0, 186, 187, 5, 25, 0, 0, + 187, 189, 1, 0, 0, 0, 188, 168, 1, 0, 0, 0, 188, 169, 1, 0, 0, 0, 188, + 177, 1, 0, 0, 0, 189, 31, 1, 0, 0, 0, 190, 191, 3, 20, 10, 0, 191, 192, + 3, 26, 13, 0, 192, 33, 1, 0, 0, 0, 193, 196, 3, 4, 2, 0, 194, 196, 3, 18, + 9, 0, 195, 193, 1, 0, 0, 0, 195, 194, 1, 0, 0, 0, 196, 35, 1, 0, 0, 0, + 197, 198, 5, 10, 0, 0, 198, 199, 3, 34, 17, 0, 199, 200, 5, 20, 0, 0, 200, + 201, 5, 8, 0, 0, 201, 202, 5, 27, 0, 0, 202, 203, 3, 22, 11, 0, 203, 204, + 5, 9, 0, 0, 204, 205, 5, 27, 0, 0, 205, 206, 3, 30, 15, 0, 206, 207, 5, + 21, 0, 0, 207, 215, 1, 0, 0, 0, 208, 209, 5, 19, 0, 0, 209, 210, 3, 34, + 17, 0, 210, 211, 5, 11, 0, 0, 211, 212, 3, 4, 2, 0, 212, 215, 1, 0, 0, + 0, 213, 215, 3, 8, 4, 0, 214, 197, 1, 0, 0, 0, 214, 208, 1, 0, 0, 0, 214, + 213, 1, 0, 0, 0, 215, 37, 1, 0, 0, 0, 19, 45, 55, 62, 70, 76, 86, 93, 99, + 104, 117, 136, 144, 153, 162, 173, 181, 188, 195, 214, } deserializer := antlr.NewATNDeserializer(nil) staticData.atn = deserializer.Deserialize(staticData.serializedATN) @@ -1385,10 +1385,17 @@ type IFunctionCallContext interface { // GetParser returns the parser. GetParser() antlr.Parser + // GetFnName returns the fnName token. + GetFnName() antlr.Token + + // SetFnName sets the fnName token. + SetFnName(antlr.Token) + // Getter signatures - IDENTIFIER() antlr.TerminalNode LPARENS() antlr.TerminalNode RPARENS() antlr.TerminalNode + OVERDRAFT() antlr.TerminalNode + IDENTIFIER() antlr.TerminalNode FunctionCallArgs() IFunctionCallArgsContext // IsFunctionCallContext differentiates from other interfaces. @@ -1398,6 +1405,7 @@ type IFunctionCallContext interface { type FunctionCallContext struct { antlr.BaseParserRuleContext parser antlr.Parser + fnName antlr.Token } func NewEmptyFunctionCallContext() *FunctionCallContext { @@ -1427,9 +1435,9 @@ func NewFunctionCallContext(parser antlr.Parser, parent antlr.ParserRuleContext, func (s *FunctionCallContext) GetParser() antlr.Parser { return s.parser } -func (s *FunctionCallContext) IDENTIFIER() antlr.TerminalNode { - return s.GetToken(NumscriptParserIDENTIFIER, 0) -} +func (s *FunctionCallContext) GetFnName() antlr.Token { return s.fnName } + +func (s *FunctionCallContext) SetFnName(v antlr.Token) { s.fnName = v } func (s *FunctionCallContext) LPARENS() antlr.TerminalNode { return s.GetToken(NumscriptParserLPARENS, 0) @@ -1439,6 +1447,14 @@ func (s *FunctionCallContext) RPARENS() antlr.TerminalNode { return s.GetToken(NumscriptParserRPARENS, 0) } +func (s *FunctionCallContext) OVERDRAFT() antlr.TerminalNode { + return s.GetToken(NumscriptParserOVERDRAFT, 0) +} + +func (s *FunctionCallContext) IDENTIFIER() antlr.TerminalNode { + return s.GetToken(NumscriptParserIDENTIFIER, 0) +} + func (s *FunctionCallContext) FunctionCallArgs() IFunctionCallArgsContext { var t antlr.RuleContext for _, ctx := range s.GetChildren() { @@ -1483,10 +1499,20 @@ func (p *NumscriptParser) FunctionCall() (localctx IFunctionCallContext) { p.EnterOuterAlt(localctx, 1) { p.SetState(73) - p.Match(NumscriptParserIDENTIFIER) - if p.HasError() { - // Recognition error - abort rule - goto errorExit + + var _lt = p.GetTokenStream().LT(1) + + localctx.(*FunctionCallContext).fnName = _lt + + _la = p.GetTokenStream().LA(1) + + if !(_la == NumscriptParserOVERDRAFT || _la == NumscriptParserIDENTIFIER) { + var _ri = p.GetErrorHandler().RecoverInline(p) + + localctx.(*FunctionCallContext).fnName = _ri + } else { + p.GetErrorHandler().ReportMatch(p) + p.Consume() } } { @@ -2164,7 +2190,7 @@ func (p *NumscriptParser) Program() (localctx IProgramContext) { } _la = p.GetTokenStream().LA(1) - for (int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&8590459904) != 0 { + for (int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&8590590976) != 0 { { p.SetState(101) p.Statement() @@ -4889,7 +4915,7 @@ func (p *NumscriptParser) Statement() (localctx IStatementContext) { p.valueExpr(0) } - case NumscriptParserIDENTIFIER: + case NumscriptParserOVERDRAFT, NumscriptParserIDENTIFIER: localctx = NewFnCallStatementContext(p, localctx) p.EnterOuterAlt(localctx, 3) { diff --git a/internal/parser/parser.go b/internal/parser/parser.go index 35c4baa..a29677b 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -508,7 +508,7 @@ func parseFnCall(fnCallCtx parser.IFunctionCallContext) *FnCall { return nil } - ident := fnCallCtx.IDENTIFIER() + ident := fnCallCtx.GetFnName() if ident == nil { return nil } @@ -518,8 +518,8 @@ func parseFnCall(fnCallCtx parser.IFunctionCallContext) *FnCall { return &FnCall{ Range: ctxToRange(fnCallCtx), Caller: &FnCallIdentifier{ - Range: tokenToRange(ident.GetSymbol()), - Name: ident.GetSymbol().GetText(), + Range: tokenToRange(ident), + Name: ident.GetText(), }, Args: parseFnArgs(allArgs), }