jmeaster30 / ocean

A C-like programming language (get it like sea-like like an ocean lol)
GNU General Public License v3.0
0 stars 0 forks source link

Annotations Overhaul #101

Open jmeaster30 opened 6 months ago

jmeaster30 commented 6 months ago

I would like to have the annotation parser be part of the phase 1 parser so that we can have better parsing of annotations.

For example, it would improve functionality around online annotations for function parameters and even individual statement macros (like the hydro macros).

It would probably allow hydro macros to be specifically in expressions (which is phase 2 parsing I guess). The main issue with having a hydro macros is then all the hydro keywords have to become ocean keywords :(

TODO:

Unanswered Questions:

jmeaster30 commented 4 months ago

This might be easier cause I made a thing that let's parser phase 1 send a whole ast node to parser phase 2 instead of just a list of tokens

jmeaster30 commented 4 months ago

Actually I have an idea for annotations there are going to be 3 kinds

  1. Basic annotation has no extra options for configuring
    @Trace
  2. Inline annotation with options (note the multilines)
    @Operator(
    symbol: +,
    precedence: 10,
    order: infix
    )

    Or

    @Operator(+, 10, infix)
  3. Block annotation
    @@ Documentation
    This function does really neat stuff
    @@
jmeaster30 commented 4 months ago

Declaring an annotation:

@Annotation(
      name: Trace,
      scope: function
)
function trace_annotation(function_name: string, target_function: func(auto Arguments...)->(auto Returns...), annotation_parameters: AnnotationParameters, arguments: Arguments) -> (result: Returns...) { }
jmeaster30 commented 4 months ago

For parameters in declaring an annotation it could be nice to just make a struct that holds the parameters:

union OperatorOrder {
    Prefix,
    Postfix,
    Infix,
}

pack OperatorParameters {
    symbol: string,
    precedence: u32,
    order: OperatorOrder
}

@Annotation (
    name: "Operator",
    scope: function,
    parameters: OperatorParameters
)
Blah blah blah
jmeaster30 commented 4 months ago

Ordering of things will be as follows as a result

This does make me think that the symbol table should be built into the ast so we can easily do multiple passes to get everything checked semantically

jmeaster30 commented 3 months ago

Moved the parser to phase 1. Block annotations would still need to be parsed a little bit

jmeaster30 commented 3 months ago

Renaming cause I want to have a central place to track the annotation overhaul stuff