Skip to content

Commit

Permalink
feat: add monobase compiler module (#43)
Browse files Browse the repository at this point in the history
* feat: add compiler module and update server port

- Add initial compiler module with lexer and parser implementations
  - Implement comprehensive lexer with support for:
    - Keywords and identifiers
    - Numbers (decimal, hex, octal, binary, float)
    - Strings with escape sequences
    - Operators and delimiters
  - Add parser grammar for monoql language
  - Add token types and span tracking

- Change default server port from 3000 to 3456
  - Update port in documentation and examples
  - Add PORT environment variable support
  - Update default port constant

- Update project logo
  - Replace monocore_logo.png with monocore-thick-line-purple-gradient.svg

- Clean up documentation
  - Simplify AI agent capabilities section
  - Update code examples with new port

* refactor: expose compiler module

* fix: remove unecessary doc test
  • Loading branch information
appcypher authored Nov 21, 2024
1 parent f784830 commit da53a8b
Show file tree
Hide file tree
Showing 18 changed files with 2,547 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ private
# Build dirs
build/
monocore/build/
diff
pr.txt
22 changes: 9 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">
<a href="https://github.com/appcypher/monocore" target="_blank">
<img src="https://raw.githubusercontent.com/appcypher/monocore/main/assets/monocore_logo.png" alt="monocore logo" width="100"></img>
<img src="https://raw.githubusercontent.com/appcypher/monocore/main/assets/monocore-thick-line-purple-gradient.svg" alt="monocore logo" width="100"></img>
</a>

<h1 align="center">monocore</h1>
Expand Down Expand Up @@ -34,9 +34,9 @@ All while keeping your system safe through VM-level isolation.
monocore serve

# Your AI agent can now safely:
curl -X POST http://localhost:3000/up -d @sandbox.toml # Launch secure VMs
curl http://localhost:3000/status # Monitor execution
curl -X POST http://localhost:3000/down # Clean up when done
curl -X POST http://localhost:3456/up -d @sandbox.toml # Launch secure VMs
curl http://localhost:3456/status # Monitor execution
curl -X POST http://localhost:3456/down # Clean up when done
```

## Why monocore?
Expand Down Expand Up @@ -71,15 +71,11 @@ Develop and test locally with instant feedback, then deploy to production with c
2. **Start the sandbox server**

```sh
# Start the server on port 3000
monocore serve --port 3000
# Start the server on port 3456
monocore serve --port 3456
```

Your AI agent now has a secure execution environment for:
- Running untrusted code
- Generating visualizations
- Testing programs
- Executing system commands
Your AI agent now has a secure execution environment for its code execution needs!

3. **Define your sandboxes**

Expand Down Expand Up @@ -133,12 +129,12 @@ Develop and test locally with instant feedback, then deploy to production with c
Or via the REST API:
```sh
# Launch a sandbox
curl -X POST http://localhost:3000/up \
curl -X POST http://localhost:3456/up \
-H "Content-Type: application/json" \
-d @monocore.toml

# Check execution status
curl http://localhost:3000/status | jq '.services[] | {name, status, metrics}'
curl http://localhost:3456/status | jq '.services[] | {name, status, metrics}'
```

## Features in Action
Expand Down
9 changes: 9 additions & 0 deletions assets/monocore-thick-line-purple-gradient.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/monocore_logo.png
Binary file not shown.
6 changes: 6 additions & 0 deletions monobase/lib/compiler/ast.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//--------------------------------------------------------------------------------------------------
// Types
//--------------------------------------------------------------------------------------------------

/// Represents the Abstract Syntax Tree (AST) of a monoql program.
pub struct Ast {}
317 changes: 317 additions & 0 deletions monobase/lib/compiler/lexer/lexer.grammar
Original file line number Diff line number Diff line change
@@ -0,0 +1,317 @@

(*
* Lexer grammar for the monoql language.
*
* Keywords and certain letter-based operators are supported as identifiers and handled by the parser.
*)

(* COMMENTS *)

comment = (* ignored *)
| /--[^\r\n]*/

(* SPACES *)

spaces = (* ignored *)
| /\s*\\\r?\n\s*/
| /[ \t]+/

(* TERMINATORS *)

terminator =
| ";"

(* IDENTIFIER *)

plain_identifier =
| /[a-zA-Z_][a-zA-Z0-9_]*/

escaped_identifier =
| /`[a-zA-Z_][a-zA-Z0-9_]*`/

variable =
| /$[a-zA-Z_][a-zA-Z0-9_]*/

(* LITERALS *)

digit =
| /[0-9]/

bin_digit =
| "0"
| "1"

oct_digit =
| /[0-7]/

hex_digit =
| /[0-9a-fA-F]/
| /[a-f]/
| /[A-F]/

digit_part =
| digit ("_"? digit)*

exponent =
| ("e" | "E") ("+" | "-")? digit_part

fraction =
| "." digit_part

point_float =
| digit_part? fraction
| digit_part "."

exponent_float =
| (digit_part | point_float) exponent

dec_integer_lit =
| digit ("_"? digit)*

bin_integer_lit =
| "0b" bin_digit+ ("_"? bin_digit)*

oct_integer_lit =
| "0o" oct_digit+ ("_"? oct_digit)*

hex_integer_lit =
| "0x" hex_digit+ ("_"? hex_digit)*

float_lit =
| point_float
| exponent_float

string_char =
| <any source character except "\\" or newline or the quote>

string_escape_seq_char =
| "t"
| "n"
| "r"
| "'"
| "\""

string_escape_seq =
| "\\" string_escape_seq_char
| "\\" "x" hex_digit hex_digit
| "\\" "u" hex_digit hex_digit hex_digit hex_digit
| "\\" "U" hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit hex_digit

string_item =
| string_char
| string_escape_seq

string_lit =
| "'" string_item* "'"
| '"' string_item* '"'

regex_char =
| <any source character except newline or "/">

regex_escape_seq =
| "\\/"
| "\\" /./

regex_item =
| regex_char
| regex_escape_seq

regex_lit =
| "//" regex_item* "//" ("g" | "i" | "m" | "s" | "u" | "x")*

byte_string_lit =
| "b'" string_item* "'"
| 'b"' string_item* '"'

(* BLOCKS *)

module_block =
| <preceded and intiated by (kw_define spaces kw_module spaces identifier kw_with)> /[.]*?/ (?="end" | "END")

(* OPERATORS *)

op_paren_open =
| "("

op_paren_close =
| ")"

op_bracket_open =
| "["

op_bracket_close =
| "]"

op_brace_open =
| "{"

op_brace_close =
| "}"

op_comma =
| ","

op_scope =
| "::"

op_colon =
| ":"

op_assign_plus =
| "+="

op_assign_minus =
| "-="

op_assign_mul =
| "*="
| "×="

op_assign_div =
| "/="
| "÷="

op_assign_mod =
| "%="

op_assign_pow =
| "**="

op_assign_shl =
| "<<="

op_assign_shr =
| ">>="

op_assign_bit_and =
| "&="

op_assign_bit_or =
| "|="

op_assign_bit_xor =
| "^="

op_assign_bit_not =
| "~="

op_multi_arrow_right =
| "->>"

op_multi_arrow_left =
| "<<-"

op_arrow_right =
| "->"

op_arrow_left =
| "<-"

op_pow =
| "**"

op_plus =
| "+"

op_minus =
| "-"

op_mul_lexer =
| "×"

op_div =
| "/"
| "÷"

op_mod =
| "%"

op_match_lexer =
| "~"

op_not_match_lexer =
| "!~"

op_similarity =
| "<>"

op_and_lexer =
| "&&"

op_or_lexer =
| "||"

op_eq =
| "=="

op_is_lexer =
| "="

op_is_not_lexer =
| "!="

op_not_lexer =
| "!"

op_lte =
| "<="

op_gte =
| ">="

op_lt =
| "<"

op_gt =
| ">"

op_contains_lexer =
| "∋"

op_not_contains_lexer =
| "∌"

op_contains_none_lexer =
| "⊅"

op_contains_all_lexer =
| "⊇"

op_contains_any_lexer =
| "⊃"

op_safe_nav =
| "?."

op_null_coalesce =
| "?:"

op_shl =
| "<<"

op_shr =
| ">>"

op_bit_and =
| "&"

op_bit_or =
| "|"

op_bit_xor =
| "^"

op_star =
| "*"

op_dot =
| "."

op_range_incl =
| "..="

op_range =
| ".."

op_optional =
| "?"
Loading

0 comments on commit da53a8b

Please sign in to comment.