Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BrightScript support written by a LLM #986

Open
1 task done
walt93 opened this issue Jul 2, 2024 · 0 comments
Open
1 task done

BrightScript support written by a LLM #986

walt93 opened this issue Jul 2, 2024 · 0 comments
Labels
language A request to add a language extension

Comments

@walt93
Copy link

walt93 commented Jul 2, 2024

Check for existing issues

  • Completed

Language

BrightScript

Tree Sitter parser link

No response

Language server link

No response

Misc notes

Multi-turn prompt for LLM:

  1. Do you know the tree-sitter format from Github?
  2. Do you know the Brightscript language by Roku?
  3. Can you generate a tree-sitter specifcation for Brightscript?

Response: (this likely needs further promptgramming and/or someone with actual domain knowledge of tree-sitter)

// tree-sitter-brightscript/grammar.js
module.exports = grammar({
  name: 'brightscript',

  extras: $ => [
    /\s/, // whitespace
    $.comment
  ],

  rules: {
    source_file: $ => repeat($._statement),

    _statement: $ => choice(
      $.assignment_statement,
      $.if_statement,
      $.while_statement,
      $.for_statement,
      $.function_declaration,
      $.return_statement,
      $.expression_statement
    ),

    assignment_statement: $ => seq(
      field('left', $.identifier),
      '=',
      field('right', $.expression),
      '\n'
    ),

    if_statement: $ => seq(
      'if',
      field('condition', $.expression),
      'then',
      repeat($._statement),
      optional(seq('else', repeat($._statement))),
      'end if'
    ),

    while_statement: $ => seq(
      'while',
      field('condition', $.expression),
      repeat($._statement),
      'end while'
    ),

    for_statement: $ => seq(
      'for',
      field('variable', $.identifier),
      '=',
      field('start', $.expression),
      'to',
      field('end', $.expression),
      optional(seq('step', field('step', $.expression))),
      repeat($._statement),
      'end for'
    ),

    function_declaration: $ => seq(
      'function',
      field('name', $.identifier),
      '(',
      optional($.parameter_list),
      ')',
      repeat($._statement),
      'end function'
    ),

    parameter_list: $ => commaSep1($.identifier),

    return_statement: $ => seq(
      'return',
      optional($.expression),
      '\n'
    ),

    expression_statement: $ => seq(
      $.expression,
      '\n'
    ),

    expression: $ => choice(
      $.identifier,
      $.number,
      $.string,
      $.binary_expression,
      $.function_call
    ),

    binary_expression: $ => prec.left(seq(
      field('left', $.expression),
      field('operator', choice('+', '-', '*', '/', '>', '<', '>=', '<=', '=', '<>')),
      field('right', $.expression)
    )),

    function_call: $ => seq(
      field('function', $.identifier),
      '(',
      optional($.argument_list),
      ')'
    ),

    argument_list: $ => commaSep1($.expression),

    identifier: $ => /[a-zA-Z_][a-zA-Z0-9_]*/,

    number: $ => /\d+(\.\d+)?/,

    string: $ => /"[^"]*"/,

    comment: $ => token(seq("'", /.*/))
  }
});

function commaSep1(rule) {
  return seq(rule, repeat(seq(',', rule)));
}

@walt93 walt93 added the language A request to add a language extension label Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language A request to add a language extension
Projects
None yet
Development

No branches or pull requests

1 participant