Skip to content

Instantly share code, notes, and snippets.

@duchainer
Last active September 25, 2021 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duchainer/dd4f04fb6a320cbeaf3fddf926bd28f3 to your computer and use it in GitHub Desktop.
Save duchainer/dd4f04fb6a320cbeaf3fddf926bd28f3 to your computer and use it in GitHub Desktop.
WIP Godot scene parser in Smalltalk Compiler-Compiler (SmaCC) in glamorous toolkit
Start
: Section+
;
Section
: Header ContentParam*
;
Header
: <leftBracket> <name> HeaderParam* <rightBracket>
;
<leftBracket> : \[ ;
<rightBracket>: \] ;
# no prefix number
# \w is letter, number or underscore
<name>
: ( [a-zA-Z] | _ ) \w*
;
<whitespace>: \s+ ;
# Key=Value
HeaderParam
: Key <equal> Value
;
Key : <name> ;
<equal> : \= ;
Value
: <name>
| <number>
| <string>
| FunctionCall
;
#All number literals
<number> : <integer> | <floatnumber>;
# Integer literals
<decimalinteger> : [1-9] [0-9]* | 0 ;
<integer> : <decimalinteger>;
#Float literals
<pointfloat> : ([0-9]+ \. [0-9]*) | (\. [0-9]+) ;
<exponentfloat> : ([0-9]+ | <pointfloat>) (e | E) (\+|\-)? [0-9]+ ;
<floatnumber> : <pointfloat> | <exponentfloat> ;
<string>
: \" [^\"]* \"
;
FunctionCall
: <name> <leftBrace> Value? <rightBrace>
;
<leftBrace>
: \(
;
<rightBrace>
: \)
;
ContentParam
: Key <equal> Value
;
[gd_scene load_steps=2 format=2]
[ext_resource path="res://icon.png" type="texture" id=1]
[node name="Node2D" type="Node2D"]
[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 )
@duchainer
Copy link
Author

Just managed to fix the FunctionCall scanning by removing all references to , so now these are correctly implied by SmaCC. 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment