spark_transpiler

所属分类:云计算
开发工具:Python
文件大小:0KB
下载次数:0
上传日期:2023-08-18 23:13:08
上 传 者sh-1993
说明:  火花_发射器,,
(spark_transpiler,,)

文件列表:
assembler/ (0, 2023-11-28)
assembler/constants/ (0, 2023-11-28)
assembler/constants/assembler.js (317, 2023-11-28)
assembler/constants/internal.js (212, 2023-11-28)
assembler/index.js (1157, 2023-11-28)
assembler/sections/ (0, 2023-11-28)
assembler/sections/header.js (819, 2023-11-28)
assembler/sections/index.js (112, 2023-11-28)
assembler/sections/load/ (0, 2023-11-28)
assembler/sections/load/index.js (447, 2023-11-28)
assembler/sections/load/pagezero.js (997, 2023-11-28)
assembler/sections/load/text.js (1956, 2023-11-28)
assembler/sections/load_sub.js (1049, 2023-11-28)
assembler/test (256, 2023-11-28)
assembler/utils/ (0, 2023-11-28)
assembler/utils/binary.js (1060, 2023-11-28)
assembler/utils/common.js (94, 2023-11-28)
examples/ (0, 2023-11-28)
examples/include_example/ (0, 2023-11-28)
examples/include_example/components.spark (189, 2023-11-28)
examples/include_example/main.spark (49, 2023-11-28)
examples/include_example/main_frontend.spark (120, 2023-11-28)
examples/include_example/methods.spark (46, 2023-11-28)
examples/platforms.spark (47, 2023-11-28)
examples/print.spark (50, 2023-11-28)
examples/simple_website.spark (1894, 2023-11-28)
examples/sql.spark (767, 2023-11-28)
spark.bat (22, 2023-11-28)
spark.js (5103, 2023-11-28)
spark.py (20574, 2023-11-28)
spark.sh (266, 2023-11-28)
spark_test.py (18524, 2023-11-28)
src/ (0, 2023-11-28)
src/__init__.py (0, 2023-11-28)
src/constants.py (231, 2023-11-28)
src/file.py (3037, 2023-11-28)
src/generator.py (1853, 2023-11-28)
... ...

# Spark Transpiler ## What is it? This project defines a language, Spark, that is meant to be a very simple to use language, but also flexible. Somewhat of a combination between Python and JavaScript. I created this project to serve as a rapid prototyping language and system, so that I can try out ideas quickly without needing to setup a lot of boilerplate. To that end, it will eventually have a very powerful and extensive standard library, geared towards rapid prototyping of web apps. # Language Details ## Variables Variables are typeless, and can be defined like so: ``` variable_name = variable_name += ``` The following are examples of valid values for variables: | Name | Example | | ---| --- | | String | "Double quotes" 'single quotes' | | Integer | 1231523532 | | Floating Point | 154235.23543243 | | Boolean | true, false | The following operators exist for numeric variables: ``` variable ++ ``` The following operations can be performed on any statement: ``` + - / * ``` ## Conditionals Conditionals are of the format: ``` if else ``` Where a condition can be one of `>`, `<`, `=>`, `=<`, `==`, `!=` ## Loops A loop can have the following formats: ``` for array as item for map as key : item for ; ; while ``` ## Functions Function must be defined with the `function` keyword: ``` function foo() ``` They can take parameters: ``` function bar(a, b, c) ``` To call a function, arguments must be on new lines: ``` bar( 5 "string" 4.23432 ) ``` However a function that takes no arguments can be called on a single line: ``` bar() ``` Functions can return any statement: ``` function foo(bar) return bar ``` ## Classes Can extend other classes. Can contain functions inside them. Special function `constructor` for creating new instances. ``` class Name extends OtherClass function constructor(a,b,c) ``` Creating an instance of a method is done just like a function: ``` instance = Name( a b c ) ``` Chaining instances is done as normal: ``` class Class1 function hello() print( "hello" ) class Class2 function constructor() this.inst_of_class1 = Class1() inst_of_class2 = Class2() inst_of_class2.inst_of_class1.hello() ``` This code prints "hello" ## Arrays Arrays can be defined in the following way: ``` foo = [ "bar" baz [ "foo" ] ] ``` Accessing the contents of an array can be done as normal: ``` foo = [ "bar" ] bar = foo[0] ``` ## Maps Maps can be defined in the following way: ``` foo = { key: "value" } ``` ## JSX The system will properly parse JSX format as well: ``` foo =
"some text"
``` Note that this is basically syntactic sugar that does the same thing as making a new instance of a Component. ## Includes It is possible to include methods and classes from another file. Note that when doing so, you cannot define a backend function, then use it in frontend code in another file, or vice versa. `utils.spark`: ``` #backend class Foo function foo() function bar() ``` `main.spark`: ``` #utils Foo,bar inst = Foo() bar() ``` You can also import everything from a file simply by using its name with a hash `main.spark`: ``` #utils inst = utils.Foo() utils.bar() ``` # Standard Library ## Common These methods and classes are available to both backend and frontend: | Method | Description | Signature | | --- | --- | --- | | print | Prints text to the console | Can take in any number of params. Params must be castable to a string | ## Frontend These methods are available to the frontend code: | Method | Description | Signature | | --- | --- | --- | | Component.render | Renders a Component to the page | Takes in a single instance of a Component, or JSX tag | ### Component class The Component class represents a component and its children, and can be rendered to the page. The following methods are available: #### Constructor Signature: ``` Component( tag attributes children ) ``` | Param | Type | Description | | --- | --- | --- | | tag | string | The tag to render. Optional | | attributes | map | Attributes to attach to the element | | children | array | Children to render in the component. Can be strings, or other Components | If the constructor is called with only 2 parameters, these are expected to be the attributes and the children. This should only be done for classes that extend Component. #### Re-render The rerender method allows a component to rerender itself and all of its children, without rerendering the rest of the page Signature: ``` someComponent.rerender() ``` #### Extending Component can be extended in the following way: ``` class SomeElement extends Component function render() return
this.children
``` And can be incorporated into JSX: ``` foo =
"foo"
``` ### Style The Style object allows encoding of CSS and attaching it to a component #### Constructor Signature: ``` Style( { color: "#fff" } ) ``` ### Variable The Variable class allows storing of data across re-renders. #### Constructor Signature: ``` Variable( defaultValue ) ``` | Param | Type | Description | | --- | --- | --- | | defaultValue | any | The value to start the Variable with. Optional | #### Get Returns the current value of the Variable ``` foo = Variable( 0 ) bar = foo.get() ``` #### Set Sets the current value of the Variable ``` foo = Variable( 0 ) foo.set( 1 ) ``` ### Api The Api class on the frontend is used to call apis. #### post/get ``` result = Api.post( apiName apiParameters ) ``` | Param | Type | Description | | --- | --- | --- | | apiName | string | The name of the api to call | | apiParameters | any | The parameters to pass to the API method. Can be anything that can be turned into JSON | The result of this method will be whatever the API returned on the backend.** ### State The state object keeps track of app state across components. #### init The init method is called to hydrate the state with inital values. ``` State.init( { key: } ) ``` | Param | Type | Description | | --- | --- | --- | | initial value | map | The initial value of the app state | #### get The get method is called to fetch a value out of the state. ``` value = State.get( "path.to.desired.value" ) ``` | Param | Type | Description | | --- | --- | --- | | path | string | The path in the state tree to fetch | #### set The set method is called to update a piece of the state. ``` value = State.set( "path.to.desired.value" newValueToSet ) ``` | Param | Type | Description | | --- | --- | --- | | path | string | The path in the state tree to fetch | | value | any | The new value to set in the tree | ## Backend ### Table The Table class is used for defining and performing CRUD operations on database schemas. #### Constructor Signature: ``` Table( tableName fieldsList storageType ) ``` | Param | Type | Description | | --- | --- | --- | | tableName | string | The name of the database table | | fieldsList | array | An array of Field objects | | storageType | Table Storage Type | The type of storage to setup for this table. Optional, defaults to Table.SOURCE_FILE | The Field is an object with the following structure: ``` { name: "the name of the field" type: meta: } ``` Table field types: The following types exist for table Fields | Name | Description | | --- | --- | | STRING | Defines a field that stores strings | | INT | Defines a field that stores integers | Table meta types: The following meta entries exist for table Fields | Name | Description | | --- | --- | | AUTO | Indicates the field is an auto-increment field | Table storage types: | Name | Description | | --- | --- | | SOURCE_FILE | Uses a local file for data storage | | SOURCE_MYSQL | Attempts to use a MySql server for storage | #### load The load method is an instance method, and will perform a query on the database, returning all fields that match. ``` exampleTable = Table( "example" [ { name: "field1" type: Table.STRING } ] ) results = exampleTable.load( { field1: "foo" } ) ``` | Param | Type | Description | | --- | --- | --- | | search | map | A map with keys being the field to search and value being the value the field must contain. An empty map will return all rows. | #### insert The insert method is an instance method, and will insert a new row into the database ``` exampleTable = Table( "example" [ { name: "field1" type: Table.STRING } ] ) exampleTable.insert( { field1: "foo" } ) ``` | Param | Type | Description | | --- | --- | --- | | data | map | A map with keys being the field and value being the value to insert for that field | #### update The update method is an instance method, and will update all matching rows in the db ``` exampleTable = Table( "example" [ { name: "field1" type: Table.STRING } ] ) exampleTable.update( { field1: "foo" } { field1: "bar" } ) ``` | Param | Type | Description | | --- | --- | --- | | search | map | Similar to `load`, this map defines what rows should be updated. An empty map will update all rows | | data | map | Similar to `insert`, this map defines what fields to update and what data to update them with #### setConfig The setConfig method is meant for setting connection data for storage types that require connection info. For mysql the setConfig method should be called with an object containing the following: | Param | Description | | --- | --- | | host | The hostname or IP of the database | | user | The username of the database | | password | The password for the user | | database | The database to use | ### Api The Api class on the backend is used to define apis. #### post/get ``` Api.get( apiName function(parameters, RequestObject) return result ) ``` | Param | Type | Description | | --- | --- | --- | | apiName | string | The name of the api to call | | apiMethod | function | The function to call whenever the API is called. The result of this method is returned as the API result | The result of this method will be whatever the API returned on the backend. The RequestObject has the following methods available on it: #### setSession This method takes in any jsonifyable data and sets it as a session cookie on the frontend. ``` Api.get( apiName function(parameters, req) req.setSession( { id: 5 } ) ) ``` #### getSession This method will return any value stored in a session cookie from the frontend, or null if one does not exist. ``` Api.get( apiName function(parameters, req) sessionData = req.getSession() id = sessionData.id ) ```

近期下载者

相关文件


收藏者