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

Change grammar source for Genero language and rename #6632

Merged
merged 4 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
[submodule "vendor/grammars/FreeMarker.tmbundle"]
path = vendor/grammars/FreeMarker.tmbundle
url = https://github.com/freemarker/FreeMarker.tmbundle
[submodule "vendor/grammars/GeneroFgl.tmbundle"]
path = vendor/grammars/GeneroFgl.tmbundle
url = https://github.com/FourjsGenero/GeneroFgl.tmbundle.git
[submodule "vendor/grammars/Handlebars"]
path = vendor/grammars/Handlebars
url = https://github.com/daaain/Handlebars
Expand Down Expand Up @@ -479,9 +482,6 @@
[submodule "vendor/grammars/gemini-vscode"]
path = vendor/grammars/gemini-vscode
url = https://github.com/printfn/gemini-vscode.git
[submodule "vendor/grammars/genero.tmbundle"]
path = vendor/grammars/genero.tmbundle
url = https://github.com/alienriver49/genero.tmbundle
[submodule "vendor/grammars/gettext.tmbundle"]
path = vendor/grammars/gettext.tmbundle
url = https://github.com/textmate/gettext.tmbundle
Expand Down
6 changes: 3 additions & 3 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ vendor/grammars/Elm/Syntaxes:
- text.html.mediawiki.elm-documentation
vendor/grammars/FreeMarker.tmbundle:
- text.html.ftl
vendor/grammars/GeneroFgl.tmbundle:
- source.genero-4gl
- source.genero-per
vendor/grammars/Handlebars:
- text.html.handlebars
vendor/grammars/IDL-Syntax:
Expand Down Expand Up @@ -389,9 +392,6 @@ vendor/grammars/gemfile-lock-tmlanguage:
- source.gemfile-lock
vendor/grammars/gemini-vscode:
- source.gemini
vendor/grammars/genero.tmbundle:
- source.genero
- source.genero-forms
vendor/grammars/gettext.tmbundle:
- source.po
vendor/grammars/gnuplot-tmbundle:
Expand Down
8 changes: 4 additions & 4 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2271,20 +2271,20 @@ Gemini:
wrap: true
tm_scope: source.gemini
language_id: 310828396
Genero:
Genero 4gl:
type: programming
color: "#63408e"
extensions:
- ".4gl"
tm_scope: source.genero
tm_scope: source.genero-4gl
ace_mode: text
language_id: 986054050
Genero Forms:
Genero per:
type: markup
color: "#d8df39"
extensions:
- ".per"
tm_scope: source.genero-forms
tm_scope: source.genero-per
ace_mode: text
language_id: 902995658
Genie:
Expand Down
183 changes: 183 additions & 0 deletions samples/Genero 4gl/books1.4gl
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
-- To test the sample:
--
-- $ sed -n 's/\#\# \(.*\)/\1/p' books1.4gl > library.sch
-- $ fglform -M ../"Genero Forms"/books1.per
-- $ mv ../"Genero Forms"/books1.42f .
-- $ fglcomp -M books1.4gl
-- $ fglrun books1.42m
--

SCHEMA library

PUBLIC TYPE t_book RECORD LIKE book.*
PUBLIC TYPE t_book_array DYNAMIC ARRAY OF t_book

PRIVATE CONSTANT ID_UNKNOWN = 100

MAIN

DEFINE books t_book_array
DEFINE brec t_book
DEFINE f_plot LIKE book.b_plot

CONNECT TO ":memory:+driver='dbmsqt'"

CALL create_tables()

OPEN FORM f1 FROM "books1"
DISPLAY FORM f1

CALL fill_book_array(books)

DIALOG ATTRIBUTES(UNBUFFERED)

DISPLAY ARRAY books TO sr1.*

BEFORE ROW
LET f_plot = books[ arr_curr() ].b_plot

ON ACTION nbrows ATTRIBUTES(TEXT="Row count")
MESSAGE SFMT("Number of books: %1",books.getLength())

ON INSERT
LET f_plot = NULL
INITIALIZE brec.* TO NULL
LET brec.b_author = ID_UNKNOWN
LET brec.b_pub_date = TODAY
LET brec.b_price = 0
CLEAR formonly.f_plot
INPUT brec.* FROM sr1[ scr_line() ].*
ATTRIBUTES(WITHOUT DEFAULTS);
IF NOT int_flag THEN
TRY
INSERT INTO book VALUES brec.*
LET brec.book_id = sqlca.sqlerrd[2]
LET books[ DIALOG.getCurrentRow("sr1") ] = brec
MESSAGE SFMT("New book record created (id=%1)",brec.book_id)
CATCH
ERROR "Could not insert new book row into database:", SQLERRMESSAGE
END TRY
END IF

ON DELETE
IF mbox_yn("Delete the current row?") THEN
TRY
DELETE FROM book WHERE book_id = books[arr_curr()].book_id
MESSAGE "Book record was deleted"
CATCH
ERROR "Could not delete the book row from database:", SQLERRMESSAGE
END TRY
END IF

END DISPLAY

INPUT BY NAME f_plot

ON ACTION clear_plot ATTRIBUTES(TEXT="Clear")
IF NOT mbox_yn("Are you sure you want to clear the plot summary?") THEN
CONTINUE DIALOG
END IF
LET f_plot = NULL
LET books[ arr_curr() ].b_plot = NULL
UPDATE book SET b_plot = NULL
WHERE book_id = books[ arr_curr() ].book_id

ON ACTION update_plot ATTRIBUTES(TEXT="Save")
LET books[ arr_curr() ].b_plot = f_plot
UPDATE book SET b_plot = f_plot
WHERE book_id = books[ arr_curr() ].book_id
MESSAGE SFMT("Plot summary saved (%1)",CURRENT HOUR TO SECOND)

END INPUT

ON ACTION close
ACCEPT DIALOG

END DIALOG

END MAIN

PRIVATE FUNCTION mbox_yn(question STRING) RETURNS BOOLEAN
DEFINE r BOOLEAN
MENU "Books" ATTRIBUTES(STYLE="dialog", COMMENT=question)
COMMAND "Yes" LET r = TRUE
COMMAND "No" LET r = FALSE
END MENU
RETURN r
END FUNCTION

FUNCTION fill_book_array(ba t_book_array)
RETURNS ()

DEFINE x INTEGER

DECLARE c1 CURSOR FOR
SELECT * FROM book ORDER BY b_title

LET x = 1
FOREACH c1 INTO ba[x].*
LET x = x + 1
END FOREACH
CALL ba.deleteElement(x)

END FUNCTION

FUNCTION init_authors(e ui.ComboBox)
RETURNS ()

DEFINE id LIKE author.auth_id
DEFINE name LIKE author.a_name

DECLARE c2 CURSOR FOR
SELECT auth_id, a_name FROM author ORDER BY a_name

FOREACH c2 INTO id, name
CALL e.addItem( id, name )
END FOREACH

END FUNCTION

FUNCTION create_tables()
RETURNS ()

CREATE TABLE author (
auth_id SERIAL NOT NULL PRIMARY KEY,
a_name VARCHAR(50)
);

CREATE TABLE book (
book_id SERIAL NOT NULL PRIMARY KEY,
b_title VARCHAR(100) NOT NULL,
b_author INTEGER NOT NULL REFERENCES author(auth_id),
b_isbn VARCHAR(20) NOT NULL UNIQUE,
b_pub_date DATE,
b_price DECIMAL(10,2),
b_plot VARCHAR(500)
);

INSERT INTO author VALUES ( 100, '?UNDEFINED?' );

INSERT INTO author VALUES ( 101, 'Stephen KING' );
INSERT INTO book VALUES ( 10101, 'The Talisman', 101, '978-0-670-69199-9', '1984-11-08', 15.60, NULL );
INSERT INTO book VALUES ( 10102, 'Doctor Sleep', 101, '978-1-4767-2765-3', '2013-09-24', 12.00, NULL );
INSERT INTO book VALUES ( 10103, 'The Long Walk', 101, '978-0-451-08754-6', '1979-07-11', 14.30, NULL );

INSERT INTO author VALUES ( 103, 'Dan Brown' );
INSERT INTO book VALUES ( 10301, 'Digital Fortress', 103, '0-312-18087-X', '1998-01-01', 10.20, NULL );
INSERT INTO book VALUES ( 10302, 'Angels & Demons', 103, '0-671-02735-2 ', '2000-04-01', 14.55, NULL );

-- For PostgreSQL
-- SELECT setval( pg_get_serial_sequence('author','auth_id'), 200 );
-- SELECT setval( pg_get_serial_sequence('book','book_id'), 20000 );

END FUNCTION

## author^auth_id^262^4^1^
## author^a_name^201^50^2^
## book^book_id^262^4^1^
## book^b_title^457^100^2^
## book^b_author^258^4^3^
## book^b_isbn^457^20^4^
## book^b_pub_date^7^4^5^
## book^b_price^5^2562^6^
## book^b_plot^201^500^7^
75 changes: 75 additions & 0 deletions samples/Genero 4gl/webserv1.4gl
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
-- Testing the web service:
--
-- Define FGLAPPSERVER to a free TCP port:
-- $ export FGLAPPSERVER=8089
--
-- Compile and start the server program:
-- $ fglcomp WebService.4gl
-- $ fglrun WebService.42m
--
-- Open a browser, and fetch the OpenAPI doc with:
--
-- http://localhost:8089/api?openapi.json
--

OPTIONS SHORT CIRCUIT

IMPORT com
IMPORT FGL webserv1_api

MAIN

DEFER INTERRUPT
CALL startServer()

END MAIN

PRIVATE FUNCTION startServer() RETURNS()
DEFINE returnCode INTEGER

CALL com.WebServiceEngine.RegisterRestService("webserv_api", "api")

DISPLAY "Server started"

CALL com.WebServiceEngine.Start()

LET int_flag = FALSE
WHILE TRUE
LET returnCode = com.WebServiceEngine.ProcessServices(-1)
CASE returnCode
WHEN 0
DISPLAY "Request processed."
WHEN -1
DISPLAY "Timeout reached."
WHEN -2
DISPLAY "Disconnected from application server."
# the application server has closed the connection
EXIT PROGRAM
WHEN -3
DISPLAY "Client connection lost."
WHEN -4
DISPLAY "Server interrupted with ctrl-c."
WHEN -9
DISPLAY "Unsupported operation."
WHEN -10
DISPLAY "Internal server error."
WHEN -23
DISPLAY "Deserialization error."
WHEN -35
DISPLAY "No such REST operation found."
WHEN -36
DISPLAY "Missing REST parameter."
OTHERWISE
DISPLAY SFMT("Unexpected server error: %1",returnCode)
EXIT WHILE
END CASE

IF int_flag THEN
EXIT WHILE
END IF

END WHILE

DISPLAY "Server stopped"

END FUNCTION
45 changes: 45 additions & 0 deletions samples/Genero 4gl/webserv1_api.4gl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
OPTIONS SHORT CIRCUIT

IMPORT com

PUBLIC TYPE UserAccount RECORD
id INTEGER,
name STRING,
dob DATE,
isActive BOOLEAN
END RECORD

PUBLIC DEFINE userError RECORD ATTRIBUTE(WSError = "User error")
message STRING
END RECORD

PUBLIC FUNCTION getNumberUsers()
ATTRIBUTES(WSGet,
WSPath = "/users/count",
WSDescription = "Returns a count of users.")
RETURNS INTEGER

DEFINE returnCount INTEGER
SELECT COUNT(*) INTO returnCount FROM UserAccounts
RETURN returnCount

END FUNCTION

PUBLIC FUNCTION createUser(newUser UserAccount)
ATTRIBUTES(WSPost,
WSPath = "/users",
WSDescription = "Create a user profile",
WSThrows = "400:@userError")
RETURNS STRING

DEFINE returnMessage STRING
TRY
INSERT INTO UserAccounts VALUES (newUser.*)
LET returnMessage = SFMT("Created user: %1", newUser.name)
CATCH
LET userError.message = SFMT("SQL error:%1 [%2]", sqlca.sqlcode, SQLERRMESSAGE)
CALL com.WebServiceEngine.SetRestError(400, userError)
END TRY
RETURN returnMessage

END FUNCTION
17 changes: 0 additions & 17 deletions samples/Genero Forms/FormProgram.per

This file was deleted.

Loading
Loading