changed some names from (Y|y)arn to (W|w)ol
This commit is contained in:
parent
7238986fa1
commit
aeb74a2d43
|
@ -10,10 +10,10 @@ signal node_completed(node)
|
|||
signal running
|
||||
signal finished
|
||||
|
||||
const YarnCompiler = preload("res://addons/Wol/core/compiler/compiler.gd")
|
||||
const YarnDialogue = preload("res://addons/Wol/core/dialogue.gd")
|
||||
const WolCompiler = preload("res://addons/Wol/core/compiler/compiler.gd")
|
||||
const WolDialogue = preload("res://addons/Wol/core/dialogue.gd")
|
||||
|
||||
export(String, FILE, "*.yarn") var path setget set_path
|
||||
export(String, FILE, "*.wol") var path setget set_path
|
||||
export(String) var start_node = "Start"
|
||||
export(bool) var auto_start = false
|
||||
export(NodePath) var variable_storage_path
|
||||
|
@ -44,7 +44,7 @@ func init_dialogue():
|
|||
if dialogue != null:
|
||||
existing_state = dialogue._visitedNodeCount
|
||||
|
||||
dialogue = YarnDialogue.new(variable_storage)
|
||||
dialogue = WolDialogue.new(variable_storage)
|
||||
|
||||
# FIXME: Remove these lines
|
||||
if existing_state:
|
||||
|
@ -64,20 +64,20 @@ func set_path(_path):
|
|||
file.open(_path, File.READ)
|
||||
var source = file.get_as_text()
|
||||
file.close()
|
||||
program = YarnCompiler.compile_string(source, _path)
|
||||
program = WolCompiler.compile_string(source, _path)
|
||||
path = _path
|
||||
|
||||
func _handle_line(line):
|
||||
call_deferred('emit_signal', 'line', line)
|
||||
return YarnGlobals.HandlerState.PauseExecution
|
||||
return WolGlobals.HandlerState.PauseExecution
|
||||
|
||||
func _handle_command(command):
|
||||
call_deferred('emit_signal', 'command', command)
|
||||
return YarnGlobals.HandlerState.PauseExecution
|
||||
return WolGlobals.HandlerState.PauseExecution
|
||||
|
||||
func _handle_options(options):
|
||||
emit_signal('options', options)
|
||||
return YarnGlobals.HandlerState.PauseExecution
|
||||
return WolGlobals.HandlerState.PauseExecution
|
||||
|
||||
func _handle_dialogue_complete():
|
||||
emit_signal('finished')
|
||||
|
@ -98,7 +98,7 @@ func _handle_node_start(node):
|
|||
func _handle_node_complete(node):
|
||||
emit_signal('node_completed', node)
|
||||
running = false
|
||||
return YarnGlobals.HandlerState.ContinueExecution
|
||||
return WolGlobals.HandlerState.ContinueExecution
|
||||
|
||||
func select_option(id):
|
||||
dialogue.get_vm().set_selected_option(id)
|
|
@ -75,16 +75,16 @@ enum TokenType {
|
|||
#7 '#'
|
||||
TagMarker,
|
||||
|
||||
#8 Command syntax ("<<foo>>")
|
||||
#8 Command syntax ('<<foo>>')
|
||||
BeginCommand, EndCommand,
|
||||
|
||||
#10 Variables ("$foo")
|
||||
#10 Variables ('$foo')
|
||||
Variable,
|
||||
|
||||
#11 Shortcut syntax ("->")
|
||||
#11 Shortcut syntax ('->')
|
||||
ShortcutOption,
|
||||
|
||||
#12 Option syntax ("[[Let's go here|Destination]]")
|
||||
#12 Option syntax ('[[Let's go here|Destination]]')
|
||||
OptionStart, # [[
|
||||
OptionDelimit, # |
|
||||
OptionEnd, # ]]
|
||||
|
@ -152,7 +152,7 @@ enum ExpressionType{
|
|||
}
|
||||
|
||||
|
||||
enum StatementTypes{
|
||||
enum StatementTypes j{
|
||||
CustomCommand,
|
||||
ShortcutOptionGroup,
|
||||
Block,
|
||||
|
@ -167,7 +167,7 @@ enum ValueType{
|
|||
Str,
|
||||
Boolean,
|
||||
Variable,
|
||||
Nullean#null lel
|
||||
Nullean
|
||||
}
|
||||
|
||||
func defaultValue(type):
|
||||
|
@ -177,16 +177,14 @@ static func token_type_name(value:int)->String:
|
|||
for key in TokenType.keys():
|
||||
if TokenType[key] == value:
|
||||
return key
|
||||
return "NOTVALID"
|
||||
return 'NOTVALID'
|
||||
|
||||
static func merge_dir(target, patch):
|
||||
for key in patch:
|
||||
target[key] = patch[key]
|
||||
|
||||
|
||||
#same as top one woops
|
||||
func token_name(type)->String:
|
||||
var string : String = ""
|
||||
var string : String = ''
|
||||
|
||||
for key in TokenType.keys():
|
||||
if TokenType[key] == type:
|
||||
|
@ -195,40 +193,40 @@ func token_name(type)->String:
|
|||
|
||||
func bytecode_name(bytecode):
|
||||
return [
|
||||
"Label",
|
||||
"JumpTo",
|
||||
"Jump",
|
||||
"RunLine",
|
||||
"RunCommand",
|
||||
"AddOption",
|
||||
"ShowOptions",
|
||||
"PushString",
|
||||
"PushNumber",
|
||||
"PushBool",
|
||||
"PushNull",
|
||||
"JumpIfFalse",
|
||||
"Pop",
|
||||
"CallFunc",
|
||||
"PushVariable",
|
||||
"StoreVariable",
|
||||
"Stop",
|
||||
"RunNode"
|
||||
'Label',
|
||||
'JumpTo',
|
||||
'Jump',
|
||||
'RunLine',
|
||||
'RunCommand',
|
||||
'AddOption',
|
||||
'ShowOptions',
|
||||
'PushString',
|
||||
'PushNumber',
|
||||
'PushBool',
|
||||
'PushNull',
|
||||
'JumpIfFalse',
|
||||
'Pop',
|
||||
'CallFunc',
|
||||
'PushVariable',
|
||||
'StoreVariable',
|
||||
'Stop',
|
||||
'RunNode'
|
||||
][bytecode]
|
||||
|
||||
#combine all the programs in the provided array
|
||||
static func combine_programs(programs : Array = []):
|
||||
var YarnProgram = load("res://addons/Wol/core/program/program.gd")
|
||||
static func combine_programs(programs = []):
|
||||
var WolProgram = load('res://addons/Wol/core/program/program.gd')
|
||||
if programs.size() == 0:
|
||||
printerr("no programs to combine - you failure")
|
||||
printerr('no programs to combine - you failure')
|
||||
return
|
||||
var p = YarnProgram.new()
|
||||
var p = WolProgram.new()
|
||||
|
||||
for program in programs:
|
||||
for nodeKey in program.yarnNodes.keys():
|
||||
if p.yarnNodes.has(nodeKey):
|
||||
printerr("Program with duplicate node names %s "% nodeKey)
|
||||
for nodeKey in program.wolNodes.keys():
|
||||
if p.wolNodes.has(nodeKey):
|
||||
printerr('Program with duplicate node names %s '% nodeKey)
|
||||
return
|
||||
p.yarnNodes[nodeKey] = program.yarnNodes[nodeKey]
|
||||
p.wolNodes[nodeKey] = program.wolNodes[nodeKey]
|
||||
|
||||
return p
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
extends Object
|
||||
|
||||
const Lexer = preload("res://addons/Wol/core/compiler/lexer.gd")
|
||||
const LineInfo = preload("res://addons/Wol/core/program/yarn_line.gd")
|
||||
const YarnNode = preload("res://addons/Wol/core/program/yarn_node.gd")
|
||||
const LineInfo = preload("res://addons/Wol/core/program/wol_line.gd")
|
||||
const WolNode = preload("res://addons/Wol/core/program/wol_node.gd")
|
||||
const Instruction = preload("res://addons/Wol/core/program/instruction.gd")
|
||||
const YarnProgram = preload("res://addons/Wol/core/program/program.gd")
|
||||
const WolProgram = preload("res://addons/Wol/core/program/program.gd")
|
||||
const Operand = preload("res://addons/Wol/core/program/operand.gd")
|
||||
|
||||
|
||||
|
@ -23,7 +23,7 @@ var _errors : int
|
|||
var _lastError : int
|
||||
|
||||
#-----Class vars
|
||||
var _currentNode : YarnNode
|
||||
var _currentNode : WolNode
|
||||
var _rawText : bool
|
||||
var _fileName : String
|
||||
var _containsImplicitStringTags : bool
|
||||
|
@ -32,10 +32,10 @@ var _labelCount : int = 0
|
|||
#<String, LineInfo>
|
||||
var _stringTable : Dictionary = {}
|
||||
var _stringCount : int = 0
|
||||
#<int, YarnGlobals.TokenType>
|
||||
#<int, WolGlobals.TokenType>
|
||||
var _tokens : Dictionary = {}
|
||||
|
||||
static func compile_string(source: String, filename: String) -> YarnProgram:
|
||||
static func compile_string(source: String, filename: String) -> WolProgram:
|
||||
var Parser = load("res://addons/Wol/core/compiler/parser.gd")
|
||||
var Compiler = load("res://addons/Wol/core/compiler/compiler.gd")
|
||||
|
||||
|
@ -107,23 +107,23 @@ static func compile_string(source: String, filename: String) -> YarnProgram:
|
|||
|
||||
#--- End parsing nodes---
|
||||
|
||||
var program = YarnProgram.new()
|
||||
var program = WolProgram.new()
|
||||
|
||||
#compile nodes
|
||||
for node in parsedNodes:
|
||||
compiler.compile_node(program, node)
|
||||
|
||||
for key in compiler._stringTable:
|
||||
program.yarnStrings[key] = compiler._stringTable[key]
|
||||
program.wolStrings[key] = compiler._stringTable[key]
|
||||
|
||||
return program
|
||||
|
||||
func compile_node(program:YarnProgram,parsedNode)->void:
|
||||
if program.yarnNodes.has(parsedNode.name):
|
||||
func compile_node(program:WolProgram,parsedNode)->void:
|
||||
if program.wolNodes.has(parsedNode.name):
|
||||
emit_error(DUPLICATE_NODES_IN_PROGRAM)
|
||||
printerr("Duplicate node in program: %s" % parsedNode.name)
|
||||
else:
|
||||
var nodeCompiled : YarnNode = YarnNode.new()
|
||||
var nodeCompiled : WolNode = WolNode.new()
|
||||
|
||||
nodeCompiled.nodeName = parsedNode.name
|
||||
nodeCompiled.tags = parsedNode.tags
|
||||
|
@ -135,7 +135,7 @@ func compile_node(program:YarnProgram,parsedNode)->void:
|
|||
else:
|
||||
#compile node
|
||||
var startLabel : String = register_label()
|
||||
emit(YarnGlobals.ByteCode.Label,nodeCompiled,[Operand.new(startLabel)])
|
||||
emit(WolGlobals.ByteCode.Label,nodeCompiled,[Operand.new(startLabel)])
|
||||
|
||||
for statement in parsedNode.statements:
|
||||
generate_statement(nodeCompiled,statement)
|
||||
|
@ -146,19 +146,19 @@ func compile_node(program:YarnProgram,parsedNode)->void:
|
|||
|
||||
var danglingOptions = false
|
||||
for instruction in nodeCompiled.instructions :
|
||||
if instruction.operation == YarnGlobals.ByteCode.AddOption:
|
||||
if instruction.operation == WolGlobals.ByteCode.AddOption:
|
||||
danglingOptions = true
|
||||
if instruction.operation == YarnGlobals.ByteCode.ShowOptions:
|
||||
if instruction.operation == WolGlobals.ByteCode.ShowOptions:
|
||||
danglingOptions = false
|
||||
|
||||
if danglingOptions:
|
||||
emit(YarnGlobals.ByteCode.ShowOptions, nodeCompiled)
|
||||
emit(YarnGlobals.ByteCode.RunNode, nodeCompiled)
|
||||
emit(WolGlobals.ByteCode.ShowOptions, nodeCompiled)
|
||||
emit(WolGlobals.ByteCode.RunNode, nodeCompiled)
|
||||
else:
|
||||
emit(YarnGlobals.ByteCode.Stop, nodeCompiled)
|
||||
emit(WolGlobals.ByteCode.Stop, nodeCompiled)
|
||||
|
||||
|
||||
program.yarnNodes[nodeCompiled.nodeName] = nodeCompiled
|
||||
program.wolNodes[nodeCompiled.nodeName] = nodeCompiled
|
||||
|
||||
func register_string(text:String,nodeName:String,id:String="",lineNumber:int=-1,tags:Array=[])->String:
|
||||
var lineIdUsed : String
|
||||
|
@ -189,7 +189,7 @@ func register_label(comment:String="")->String:
|
|||
_labelCount+=1
|
||||
return "L%s%s" %[ _labelCount , comment]
|
||||
|
||||
func emit(bytecode,node:YarnNode=_currentNode,operands:Array=[]):
|
||||
func emit(bytecode,node:WolNode=_currentNode,operands:Array=[]):
|
||||
var instruction : Instruction = Instruction.new(null)
|
||||
instruction.operation = bytecode
|
||||
instruction.operands = operands
|
||||
|
@ -199,7 +199,7 @@ func emit(bytecode,node:YarnNode=_currentNode,operands:Array=[]):
|
|||
printerr("trying to emit to null node with byteCode: %s" % bytecode)
|
||||
return;
|
||||
node.instructions.append(instruction)
|
||||
if bytecode == YarnGlobals.ByteCode.Label :
|
||||
if bytecode == WolGlobals.ByteCode.Label :
|
||||
#add to label table
|
||||
node.labels[instruction.operands[0].value] = node.instructions.size()-1
|
||||
|
||||
|
@ -217,19 +217,19 @@ func generate_header():
|
|||
func generate_statement(node,statement):
|
||||
# print("generating statement")
|
||||
match statement.type:
|
||||
YarnGlobals.StatementTypes.CustomCommand:
|
||||
WolGlobals.StatementTypes.CustomCommand:
|
||||
generate_custom_command(node,statement.customCommand)
|
||||
YarnGlobals.StatementTypes.ShortcutOptionGroup:
|
||||
WolGlobals.StatementTypes.ShortcutOptionGroup:
|
||||
generate_shortcut_group(node,statement.shortcutOptionGroup)
|
||||
YarnGlobals.StatementTypes.Block:
|
||||
WolGlobals.StatementTypes.Block:
|
||||
generate_block(node,statement.block.statements)
|
||||
YarnGlobals.StatementTypes.IfStatement:
|
||||
WolGlobals.StatementTypes.IfStatement:
|
||||
generate_if(node,statement.ifStatement)
|
||||
YarnGlobals.StatementTypes.OptionStatement:
|
||||
WolGlobals.StatementTypes.OptionStatement:
|
||||
generate_option(node,statement.optionStatement)
|
||||
YarnGlobals.StatementTypes.AssignmentStatement:
|
||||
WolGlobals.StatementTypes.AssignmentStatement:
|
||||
generate_assignment(node,statement.assignment)
|
||||
YarnGlobals.StatementTypes.Line:
|
||||
WolGlobals.StatementTypes.Line:
|
||||
generate_line(node,statement,statement.line)
|
||||
_:
|
||||
emit_error(ERR_COMPILATION_FAILED)
|
||||
|
@ -244,15 +244,15 @@ func generate_custom_command(node,command):
|
|||
else:
|
||||
var commandString = command.clientCommand
|
||||
if commandString == "stop":
|
||||
emit(YarnGlobals.ByteCode.Stop,node)
|
||||
emit(WolGlobals.ByteCode.Stop,node)
|
||||
else :
|
||||
emit(YarnGlobals.ByteCode.RunCommand,node,[Operand.new(commandString)])
|
||||
emit(WolGlobals.ByteCode.RunCommand,node,[Operand.new(commandString)])
|
||||
|
||||
#compile instructions for linetags and use them
|
||||
# \#line:number
|
||||
func generate_line(node,statement,line:String):
|
||||
var num : String = register_string(line,node.nodeName,"",statement.lineNumber,[]);
|
||||
emit(YarnGlobals.ByteCode.RunLine,node,[Operand.new(num)])
|
||||
emit(WolGlobals.ByteCode.RunLine,node,[Operand.new(num)])
|
||||
|
||||
func generate_shortcut_group(node,shortcutGroup):
|
||||
# print("generating shortcutoptopn group")
|
||||
|
@ -271,37 +271,37 @@ func generate_shortcut_group(node,shortcutGroup):
|
|||
if option.condition != null :
|
||||
endofClause = register_label("conditional_%s"%optionCount)
|
||||
generate_expression(node,option.condition)
|
||||
emit(YarnGlobals.ByteCode.JumpIfFalse,node,[Operand.new(endofClause)])
|
||||
emit(WolGlobals.ByteCode.JumpIfFalse,node,[Operand.new(endofClause)])
|
||||
|
||||
var labelLineId : String = ""#no tag TODO: ADD TAG SUPPORT
|
||||
var labelStringId : String = register_string(option.label,node.nodeName,
|
||||
labelLineId,option.lineNumber,[])
|
||||
|
||||
emit(YarnGlobals.ByteCode.AddOption,node,[Operand.new(labelStringId),Operand.new(opDestination)])
|
||||
emit(WolGlobals.ByteCode.AddOption,node,[Operand.new(labelStringId),Operand.new(opDestination)])
|
||||
|
||||
if option.condition != null :
|
||||
emit(YarnGlobals.ByteCode.Label,node,[Operand.new(endofClause)])
|
||||
emit(YarnGlobals.ByteCode.Pop,node)
|
||||
emit(WolGlobals.ByteCode.Label,node,[Operand.new(endofClause)])
|
||||
emit(WolGlobals.ByteCode.Pop,node)
|
||||
|
||||
optionCount+=1
|
||||
|
||||
emit(YarnGlobals.ByteCode.ShowOptions,node)
|
||||
emit(YarnGlobals.ByteCode.Jump,node)
|
||||
emit(WolGlobals.ByteCode.ShowOptions,node)
|
||||
emit(WolGlobals.ByteCode.Jump,node)
|
||||
|
||||
optionCount = 0
|
||||
|
||||
for option in shortcutGroup.options:
|
||||
emit(YarnGlobals.ByteCode.Label,node,[Operand.new(labels[optionCount])])
|
||||
emit(WolGlobals.ByteCode.Label,node,[Operand.new(labels[optionCount])])
|
||||
|
||||
if option.node != null :
|
||||
generate_block(node,option.node.statements)
|
||||
emit(YarnGlobals.ByteCode.JumpTo,node,[Operand.new(end)])
|
||||
emit(WolGlobals.ByteCode.JumpTo,node,[Operand.new(end)])
|
||||
optionCount+=1
|
||||
|
||||
#end of option group
|
||||
emit(YarnGlobals.ByteCode.Label,node,[Operand.new(end)])
|
||||
emit(WolGlobals.ByteCode.Label,node,[Operand.new(end)])
|
||||
#clean up
|
||||
emit(YarnGlobals.ByteCode.Pop,node)
|
||||
emit(WolGlobals.ByteCode.Pop,node)
|
||||
|
||||
|
||||
|
||||
|
@ -325,19 +325,19 @@ func generate_if(node,ifStatement):
|
|||
|
||||
if clause.expression!=null:
|
||||
generate_expression(node,clause.expression)
|
||||
emit(YarnGlobals.ByteCode.JumpIfFalse,node,[Operand.new(endClause)])
|
||||
emit(WolGlobals.ByteCode.JumpIfFalse,node,[Operand.new(endClause)])
|
||||
|
||||
generate_block(node,clause.statements)
|
||||
emit(YarnGlobals.ByteCode.JumpTo,node,[Operand.new(endif)])
|
||||
emit(WolGlobals.ByteCode.JumpTo,node,[Operand.new(endif)])
|
||||
|
||||
if clause.expression!=null:
|
||||
emit(YarnGlobals.ByteCode.Label,node,[Operand.new(endClause)])
|
||||
emit(WolGlobals.ByteCode.Label,node,[Operand.new(endClause)])
|
||||
|
||||
if clause.expression!=null:
|
||||
emit(YarnGlobals.ByteCode.Pop)
|
||||
emit(WolGlobals.ByteCode.Pop)
|
||||
|
||||
|
||||
emit(YarnGlobals.ByteCode.Label,node,[Operand.new(endif)])
|
||||
emit(WolGlobals.ByteCode.Label,node,[Operand.new(endif)])
|
||||
|
||||
|
||||
#compile instructions for options
|
||||
|
@ -347,25 +347,25 @@ func generate_option(node,option):
|
|||
|
||||
if option.label == null || option.label.empty():
|
||||
#jump to another node
|
||||
emit(YarnGlobals.ByteCode.RunNode,node,[Operand.new(destination)])
|
||||
emit(WolGlobals.ByteCode.RunNode,node,[Operand.new(destination)])
|
||||
else :
|
||||
var lineID : String = ""#tags not supported TODO: ADD TAG SUPPORT
|
||||
var stringID = register_string(option.label,node.nodeName,lineID,option.lineNumber,[])
|
||||
|
||||
emit(YarnGlobals.ByteCode.AddOption,node,[Operand.new(stringID),Operand.new(destination)])
|
||||
emit(WolGlobals.ByteCode.AddOption,node,[Operand.new(stringID),Operand.new(destination)])
|
||||
|
||||
|
||||
#compile instructions for assigning values
|
||||
func generate_assignment(node,assignment):
|
||||
# print("generating assign")
|
||||
#assignment
|
||||
if assignment.operation == YarnGlobals.TokenType.EqualToOrAssign:
|
||||
if assignment.operation == WolGlobals.TokenType.EqualToOrAssign:
|
||||
#evaluate the expression to a value for the stack
|
||||
generate_expression(node,assignment.value)
|
||||
else :
|
||||
#this is combined op
|
||||
#get value of var
|
||||
emit(YarnGlobals.ByteCode.PushVariable,node,[assignment.destination])
|
||||
emit(WolGlobals.ByteCode.PushVariable,node,[assignment.destination])
|
||||
|
||||
#evaluate the expression and push value to stack
|
||||
generate_expression(node,assignment.value)
|
||||
|
@ -373,27 +373,27 @@ func generate_assignment(node,assignment):
|
|||
#stack contains oldvalue and result
|
||||
|
||||
match assignment.operation:
|
||||
YarnGlobals.TokenType.AddAssign:
|
||||
emit(YarnGlobals.ByteCode.CallFunc,node,
|
||||
[Operand.new(YarnGlobals.token_type_name(YarnGlobals.TokenType.Add))])
|
||||
YarnGlobals.TokenType.MinusAssign:
|
||||
emit(YarnGlobals.ByteCode.CallFunc,node,
|
||||
[Operand.new(YarnGlobals.token_type_name(YarnGlobals.TokenType.Minus))])
|
||||
YarnGlobals.TokenType.MultiplyAssign:
|
||||
emit(YarnGlobals.ByteCode.CallFunc,node,
|
||||
[Operand.new(YarnGlobals.token_type_name(YarnGlobals.TokenType.MultiplyAssign))])
|
||||
YarnGlobals.TokenType.DivideAssign:
|
||||
emit(YarnGlobals.ByteCode.CallFunc,node,
|
||||
[Operand.new(YarnGlobals.token_type_name(YarnGlobals.TokenType.DivideAssign))])
|
||||
WolGlobals.TokenType.AddAssign:
|
||||
emit(WolGlobals.ByteCode.CallFunc,node,
|
||||
[Operand.new(WolGlobals.token_type_name(WolGlobals.TokenType.Add))])
|
||||
WolGlobals.TokenType.MinusAssign:
|
||||
emit(WolGlobals.ByteCode.CallFunc,node,
|
||||
[Operand.new(WolGlobals.token_type_name(WolGlobals.TokenType.Minus))])
|
||||
WolGlobals.TokenType.MultiplyAssign:
|
||||
emit(WolGlobals.ByteCode.CallFunc,node,
|
||||
[Operand.new(WolGlobals.token_type_name(WolGlobals.TokenType.MultiplyAssign))])
|
||||
WolGlobals.TokenType.DivideAssign:
|
||||
emit(WolGlobals.ByteCode.CallFunc,node,
|
||||
[Operand.new(WolGlobals.token_type_name(WolGlobals.TokenType.DivideAssign))])
|
||||
_:
|
||||
printerr("Unable to generate assignment")
|
||||
|
||||
#stack contains destination value
|
||||
#store the top of the stack in variable
|
||||
emit(YarnGlobals.ByteCode.StoreVariable,node,[Operand.new(assignment.destination)])
|
||||
emit(WolGlobals.ByteCode.StoreVariable,node,[Operand.new(assignment.destination)])
|
||||
|
||||
#clean stack
|
||||
emit(YarnGlobals.ByteCode.Pop,node)
|
||||
emit(WolGlobals.ByteCode.Pop,node)
|
||||
|
||||
|
||||
#compile expression instructions
|
||||
|
@ -401,18 +401,18 @@ func generate_expression(node,expression):
|
|||
# print("generating expression")
|
||||
#expression = value || func call
|
||||
match expression.type:
|
||||
YarnGlobals.ExpressionType.Value:
|
||||
WolGlobals.ExpressionType.Value:
|
||||
generate_value(node,expression.value)
|
||||
YarnGlobals.ExpressionType.FunctionCall:
|
||||
WolGlobals.ExpressionType.FunctionCall:
|
||||
#eval all parameters
|
||||
for param in expression.params:
|
||||
generate_expression(node,param)
|
||||
|
||||
#put the num of of params to stack
|
||||
emit(YarnGlobals.ByteCode.PushNumber,node,[Operand.new(expression.params.size())])
|
||||
emit(WolGlobals.ByteCode.PushNumber,node,[Operand.new(expression.params.size())])
|
||||
|
||||
#call function
|
||||
emit(YarnGlobals.ByteCode.CallFunc,node,[Operand.new(expression.function)])
|
||||
emit(WolGlobals.ByteCode.CallFunc,node,[Operand.new(expression.function)])
|
||||
_:
|
||||
printerr("no expression")
|
||||
|
||||
|
@ -421,18 +421,18 @@ func generate_value(node,value):
|
|||
# print("generating value")
|
||||
#push value to stack
|
||||
match value.value.type:
|
||||
YarnGlobals.ValueType.Number:
|
||||
emit(YarnGlobals.ByteCode.PushNumber,node,[Operand.new(value.value.as_number())])
|
||||
YarnGlobals.ValueType.Str:
|
||||
WolGlobals.ValueType.Number:
|
||||
emit(WolGlobals.ByteCode.PushNumber,node,[Operand.new(value.value.as_number())])
|
||||
WolGlobals.ValueType.Str:
|
||||
var id : String = register_string(value.value.as_string(),
|
||||
node.nodeName,"",value.lineNumber,[])
|
||||
emit(YarnGlobals.ByteCode.PushString,node,[Operand.new(id)])
|
||||
YarnGlobals.ValueType.Boolean:
|
||||
emit(YarnGlobals.ByteCode.PushBool,node,[Operand.new(value.value.as_bool())])
|
||||
YarnGlobals.ValueType.Variable:
|
||||
emit(YarnGlobals.ByteCode.PushVariable,node,[Operand.new(value.value.variable)])
|
||||
YarnGlobals.ValueType.Nullean:
|
||||
emit(YarnGlobals.ByteCode.PushNull,node)
|
||||
emit(WolGlobals.ByteCode.PushString,node,[Operand.new(id)])
|
||||
WolGlobals.ValueType.Boolean:
|
||||
emit(WolGlobals.ByteCode.PushBool,node,[Operand.new(value.value.as_bool())])
|
||||
WolGlobals.ValueType.Variable:
|
||||
emit(WolGlobals.ByteCode.PushVariable,node,[Operand.new(value.value.variable)])
|
||||
WolGlobals.ValueType.Nullean:
|
||||
emit(WolGlobals.ByteCode.PushNull,node)
|
||||
_:
|
||||
printerr("Unrecognized valuenode type: %s" % value.value.type)
|
||||
|
||||
|
@ -458,6 +458,6 @@ static func print_tokens(tokens:Array=[]):
|
|||
var list : PoolStringArray = []
|
||||
list.append("\n")
|
||||
for token in tokens:
|
||||
list.append("%s (%s line %s)\n"%[YarnGlobals.token_type_name(token.type),token.value,token.lineNumber])
|
||||
list.append("%s (%s line %s)\n"%[WolGlobals.token_type_name(token.type),token.value,token.lineNumber])
|
||||
print("TOKENS:")
|
||||
print(list.join(""))
|
||||
|
|
|
@ -33,50 +33,50 @@ func _init():
|
|||
|
||||
func create_states():
|
||||
var patterns : Dictionary = {}
|
||||
patterns[YarnGlobals.TokenType.Text] = ".*"
|
||||
patterns[WolGlobals.TokenType.Text] = ".*"
|
||||
|
||||
patterns[YarnGlobals.TokenType.Number] = "\\-?[0-9]+(\\.[0-9+])?"
|
||||
patterns[YarnGlobals.TokenType.Str] = "\"([^\"\\\\]*(?:\\.[^\"\\\\]*)*)\""
|
||||
patterns[YarnGlobals.TokenType.TagMarker] = "\\#"
|
||||
patterns[YarnGlobals.TokenType.LeftParen] = "\\("
|
||||
patterns[YarnGlobals.TokenType.RightParen] = "\\)"
|
||||
patterns[YarnGlobals.TokenType.EqualTo] = "(==|is(?!\\w)|eq(?!\\w))"
|
||||
patterns[YarnGlobals.TokenType.EqualToOrAssign] = "(=|to(?!\\w))"
|
||||
patterns[YarnGlobals.TokenType.NotEqualTo] = "(\\!=|neq(?!\\w))"
|
||||
patterns[YarnGlobals.TokenType.GreaterThanOrEqualTo] = "(\\>=|gte(?!\\w))"
|
||||
patterns[YarnGlobals.TokenType.GreaterThan] = "(\\>|gt(?!\\w))"
|
||||
patterns[YarnGlobals.TokenType.LessThanOrEqualTo] = "(\\<=|lte(?!\\w))"
|
||||
patterns[YarnGlobals.TokenType.LessThan] = "(\\<|lt(?!\\w))"
|
||||
patterns[YarnGlobals.TokenType.AddAssign] = "\\+="
|
||||
patterns[YarnGlobals.TokenType.MinusAssign] = "\\-="
|
||||
patterns[YarnGlobals.TokenType.MultiplyAssign] = "\\*="
|
||||
patterns[YarnGlobals.TokenType.DivideAssign] = "\\/="
|
||||
patterns[YarnGlobals.TokenType.Add] = "\\+"
|
||||
patterns[YarnGlobals.TokenType.Minus] = "\\-"
|
||||
patterns[YarnGlobals.TokenType.Multiply] = "\\*"
|
||||
patterns[YarnGlobals.TokenType.Divide] = "\\/"
|
||||
patterns[YarnGlobals.TokenType.Modulo] = "\\%"
|
||||
patterns[YarnGlobals.TokenType.And] = "(\\&\\&|and(?!\\w))"
|
||||
patterns[YarnGlobals.TokenType.Or] = "(\\|\\||or(?!\\w))"
|
||||
patterns[YarnGlobals.TokenType.Xor] = "(\\^|xor(?!\\w))"
|
||||
patterns[YarnGlobals.TokenType.Not] = "(\\!|not(?!\\w))"
|
||||
patterns[YarnGlobals.TokenType.Variable] = "\\$([A-Za-z0-9_\\.])+"
|
||||
patterns[YarnGlobals.TokenType.Comma] = "\\,"
|
||||
patterns[YarnGlobals.TokenType.TrueToken] = "true(?!\\w)"
|
||||
patterns[YarnGlobals.TokenType.FalseToken] = "false(?!\\w)"
|
||||
patterns[YarnGlobals.TokenType.NullToken] = "null(?!\\w)"
|
||||
patterns[YarnGlobals.TokenType.BeginCommand] = "\\<\\<"
|
||||
patterns[YarnGlobals.TokenType.EndCommand] = "\\>\\>"
|
||||
patterns[YarnGlobals.TokenType.OptionStart] = "\\[\\["
|
||||
patterns[YarnGlobals.TokenType.OptionEnd] = "\\]\\]"
|
||||
patterns[YarnGlobals.TokenType.OptionDelimit] = "\\|"
|
||||
patterns[YarnGlobals.TokenType.Identifier] = "[a-zA-Z0-9_:\\.]+"
|
||||
patterns[YarnGlobals.TokenType.IfToken] = "if(?!\\w)"
|
||||
patterns[YarnGlobals.TokenType.ElseToken] = "else(?!\\w)"
|
||||
patterns[YarnGlobals.TokenType.ElseIf] = "elseif(?!\\w)"
|
||||
patterns[YarnGlobals.TokenType.EndIf] = "endif(?!\\w)"
|
||||
patterns[YarnGlobals.TokenType.Set] = "set(?!\\w)"
|
||||
patterns[YarnGlobals.TokenType.ShortcutOption] = "\\-\\>\\s*"
|
||||
patterns[WolGlobals.TokenType.Number] = "\\-?[0-9]+(\\.[0-9+])?"
|
||||
patterns[WolGlobals.TokenType.Str] = "\"([^\"\\\\]*(?:\\.[^\"\\\\]*)*)\""
|
||||
patterns[WolGlobals.TokenType.TagMarker] = "\\#"
|
||||
patterns[WolGlobals.TokenType.LeftParen] = "\\("
|
||||
patterns[WolGlobals.TokenType.RightParen] = "\\)"
|
||||
patterns[WolGlobals.TokenType.EqualTo] = "(==|is(?!\\w)|eq(?!\\w))"
|
||||
patterns[WolGlobals.TokenType.EqualToOrAssign] = "(=|to(?!\\w))"
|
||||
patterns[WolGlobals.TokenType.NotEqualTo] = "(\\!=|neq(?!\\w))"
|
||||
patterns[WolGlobals.TokenType.GreaterThanOrEqualTo] = "(\\>=|gte(?!\\w))"
|
||||
patterns[WolGlobals.TokenType.GreaterThan] = "(\\>|gt(?!\\w))"
|
||||
patterns[WolGlobals.TokenType.LessThanOrEqualTo] = "(\\<=|lte(?!\\w))"
|
||||
patterns[WolGlobals.TokenType.LessThan] = "(\\<|lt(?!\\w))"
|
||||
patterns[WolGlobals.TokenType.AddAssign] = "\\+="
|
||||
patterns[WolGlobals.TokenType.MinusAssign] = "\\-="
|
||||
patterns[WolGlobals.TokenType.MultiplyAssign] = "\\*="
|
||||
patterns[WolGlobals.TokenType.DivideAssign] = "\\/="
|
||||
patterns[WolGlobals.TokenType.Add] = "\\+"
|
||||
patterns[WolGlobals.TokenType.Minus] = "\\-"
|
||||
patterns[WolGlobals.TokenType.Multiply] = "\\*"
|
||||
patterns[WolGlobals.TokenType.Divide] = "\\/"
|
||||
patterns[WolGlobals.TokenType.Modulo] = "\\%"
|
||||
patterns[WolGlobals.TokenType.And] = "(\\&\\&|and(?!\\w))"
|
||||
patterns[WolGlobals.TokenType.Or] = "(\\|\\||or(?!\\w))"
|
||||
patterns[WolGlobals.TokenType.Xor] = "(\\^|xor(?!\\w))"
|
||||
patterns[WolGlobals.TokenType.Not] = "(\\!|not(?!\\w))"
|
||||
patterns[WolGlobals.TokenType.Variable] = "\\$([A-Za-z0-9_\\.])+"
|
||||
patterns[WolGlobals.TokenType.Comma] = "\\,"
|
||||
patterns[WolGlobals.TokenType.TrueToken] = "true(?!\\w)"
|
||||
patterns[WolGlobals.TokenType.FalseToken] = "false(?!\\w)"
|
||||
patterns[WolGlobals.TokenType.NullToken] = "null(?!\\w)"
|
||||
patterns[WolGlobals.TokenType.BeginCommand] = "\\<\\<"
|
||||
patterns[WolGlobals.TokenType.EndCommand] = "\\>\\>"
|
||||
patterns[WolGlobals.TokenType.OptionStart] = "\\[\\["
|
||||
patterns[WolGlobals.TokenType.OptionEnd] = "\\]\\]"
|
||||
patterns[WolGlobals.TokenType.OptionDelimit] = "\\|"
|
||||
patterns[WolGlobals.TokenType.Identifier] = "[a-zA-Z0-9_:\\.]+"
|
||||
patterns[WolGlobals.TokenType.IfToken] = "if(?!\\w)"
|
||||
patterns[WolGlobals.TokenType.ElseToken] = "else(?!\\w)"
|
||||
patterns[WolGlobals.TokenType.ElseIf] = "elseif(?!\\w)"
|
||||
patterns[WolGlobals.TokenType.EndIf] = "endif(?!\\w)"
|
||||
patterns[WolGlobals.TokenType.Set] = "set(?!\\w)"
|
||||
patterns[WolGlobals.TokenType.ShortcutOption] = "\\-\\>\\s*"
|
||||
|
||||
#compound states
|
||||
var shortcut_option : String= SHORTCUT + DASH + OPTION
|
||||
|
@ -87,84 +87,84 @@ func create_states():
|
|||
_states = {}
|
||||
|
||||
_states[BASE] = LexerState.new(patterns)
|
||||
_states[BASE].add_transition(YarnGlobals.TokenType.BeginCommand,COMMAND,true)
|
||||
_states[BASE].add_transition(YarnGlobals.TokenType.OptionStart,LINK,true)
|
||||
_states[BASE].add_transition(YarnGlobals.TokenType.ShortcutOption,shortcut_option)
|
||||
_states[BASE].add_transition(YarnGlobals.TokenType.TagMarker,TAG,true)
|
||||
_states[BASE].add_text_rule(YarnGlobals.TokenType.Text)
|
||||
_states[BASE].add_transition(WolGlobals.TokenType.BeginCommand,COMMAND,true)
|
||||
_states[BASE].add_transition(WolGlobals.TokenType.OptionStart,LINK,true)
|
||||
_states[BASE].add_transition(WolGlobals.TokenType.ShortcutOption,shortcut_option)
|
||||
_states[BASE].add_transition(WolGlobals.TokenType.TagMarker,TAG,true)
|
||||
_states[BASE].add_text_rule(WolGlobals.TokenType.Text)
|
||||
|
||||
_states[TAG] = LexerState.new(patterns)
|
||||
_states[TAG].add_transition(YarnGlobals.TokenType.Identifier,BASE)
|
||||
_states[TAG].add_transition(WolGlobals.TokenType.Identifier,BASE)
|
||||
|
||||
_states[shortcut_option] = LexerState.new(patterns)
|
||||
_states[shortcut_option].track_indent = true
|
||||
_states[shortcut_option].add_transition(YarnGlobals.TokenType.BeginCommand,EXPRESSION,true)
|
||||
_states[shortcut_option].add_transition(YarnGlobals.TokenType.TagMarker,shortcut_option_tag,true)
|
||||
_states[shortcut_option].add_text_rule(YarnGlobals.TokenType.Text,BASE)
|
||||
_states[shortcut_option].add_transition(WolGlobals.TokenType.BeginCommand,EXPRESSION,true)
|
||||
_states[shortcut_option].add_transition(WolGlobals.TokenType.TagMarker,shortcut_option_tag,true)
|
||||
_states[shortcut_option].add_text_rule(WolGlobals.TokenType.Text,BASE)
|
||||
|
||||
_states[shortcut_option_tag] = LexerState.new(patterns)
|
||||
_states[shortcut_option_tag].add_transition(YarnGlobals.TokenType.Identifier,shortcut_option)
|
||||
_states[shortcut_option_tag].add_transition(WolGlobals.TokenType.Identifier,shortcut_option)
|
||||
|
||||
_states[COMMAND] = LexerState.new(patterns)
|
||||
_states[COMMAND].add_transition(YarnGlobals.TokenType.IfToken,EXPRESSION)
|
||||
_states[COMMAND].add_transition(YarnGlobals.TokenType.ElseToken)
|
||||
_states[COMMAND].add_transition(YarnGlobals.TokenType.ElseIf,EXPRESSION)
|
||||
_states[COMMAND].add_transition(YarnGlobals.TokenType.EndIf)
|
||||
_states[COMMAND].add_transition(YarnGlobals.TokenType.Set,ASSIGNMENT)
|
||||
_states[COMMAND].add_transition(YarnGlobals.TokenType.EndCommand,BASE,true)
|
||||
_states[COMMAND].add_transition(YarnGlobals.TokenType.Identifier,command_or_expression)
|
||||
_states[COMMAND].add_text_rule(YarnGlobals.TokenType.Text)
|
||||
_states[COMMAND].add_transition(WolGlobals.TokenType.IfToken,EXPRESSION)
|
||||
_states[COMMAND].add_transition(WolGlobals.TokenType.ElseToken)
|
||||
_states[COMMAND].add_transition(WolGlobals.TokenType.ElseIf,EXPRESSION)
|
||||
_states[COMMAND].add_transition(WolGlobals.TokenType.EndIf)
|
||||
_states[COMMAND].add_transition(WolGlobals.TokenType.Set,ASSIGNMENT)
|
||||
_states[COMMAND].add_transition(WolGlobals.TokenType.EndCommand,BASE,true)
|
||||
_states[COMMAND].add_transition(WolGlobals.TokenType.Identifier,command_or_expression)
|
||||
_states[COMMAND].add_text_rule(WolGlobals.TokenType.Text)
|
||||
|
||||
_states[command_or_expression] = LexerState.new(patterns)
|
||||
_states[command_or_expression].add_transition(YarnGlobals.TokenType.LeftParen,EXPRESSION)
|
||||
_states[command_or_expression].add_transition(YarnGlobals.TokenType.EndCommand,BASE,true)
|
||||
_states[command_or_expression].add_text_rule(YarnGlobals.TokenType.Text)
|
||||
_states[command_or_expression].add_transition(WolGlobals.TokenType.LeftParen,EXPRESSION)
|
||||
_states[command_or_expression].add_transition(WolGlobals.TokenType.EndCommand,BASE,true)
|
||||
_states[command_or_expression].add_text_rule(WolGlobals.TokenType.Text)
|
||||
|
||||
_states[ASSIGNMENT] = LexerState.new(patterns)
|
||||
_states[ASSIGNMENT].add_transition(YarnGlobals.TokenType.Variable)
|
||||
_states[ASSIGNMENT].add_transition(YarnGlobals.TokenType.EqualToOrAssign, EXPRESSION)
|
||||
_states[ASSIGNMENT].add_transition(YarnGlobals.TokenType.AddAssign, EXPRESSION)
|
||||
_states[ASSIGNMENT].add_transition(YarnGlobals.TokenType.MinusAssign, EXPRESSION)
|
||||
_states[ASSIGNMENT].add_transition(YarnGlobals.TokenType.MultiplyAssign, EXPRESSION)
|
||||
_states[ASSIGNMENT].add_transition(YarnGlobals.TokenType.DivideAssign, EXPRESSION)
|
||||
_states[ASSIGNMENT].add_transition(WolGlobals.TokenType.Variable)
|
||||
_states[ASSIGNMENT].add_transition(WolGlobals.TokenType.EqualToOrAssign, EXPRESSION)
|
||||
_states[ASSIGNMENT].add_transition(WolGlobals.TokenType.AddAssign, EXPRESSION)
|
||||
_states[ASSIGNMENT].add_transition(WolGlobals.TokenType.MinusAssign, EXPRESSION)
|
||||
_states[ASSIGNMENT].add_transition(WolGlobals.TokenType.MultiplyAssign, EXPRESSION)
|
||||
_states[ASSIGNMENT].add_transition(WolGlobals.TokenType.DivideAssign, EXPRESSION)
|
||||
|
||||
_states[EXPRESSION] = LexerState.new(patterns)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.EndCommand, BASE)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.Number)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.Str)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.LeftParen)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.RightParen)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.EqualTo)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.EqualToOrAssign)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.NotEqualTo)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.GreaterThanOrEqualTo)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.GreaterThan)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.LessThanOrEqualTo)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.LessThan)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.Add)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.Minus)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.Multiply)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.Divide)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.Modulo)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.And)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.Or)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.Xor)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.Not)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.Variable)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.Comma)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.TrueToken)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.FalseToken)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.NullToken)
|
||||
_states[EXPRESSION].add_transition(YarnGlobals.TokenType.Identifier)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.EndCommand, BASE)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.Number)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.Str)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.LeftParen)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.RightParen)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.EqualTo)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.EqualToOrAssign)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.NotEqualTo)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.GreaterThanOrEqualTo)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.GreaterThan)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.LessThanOrEqualTo)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.LessThan)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.Add)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.Minus)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.Multiply)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.Divide)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.Modulo)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.And)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.Or)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.Xor)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.Not)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.Variable)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.Comma)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.TrueToken)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.FalseToken)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.NullToken)
|
||||
_states[EXPRESSION].add_transition(WolGlobals.TokenType.Identifier)
|
||||
|
||||
_states[LINK] = LexerState.new(patterns)
|
||||
_states[LINK].add_transition(YarnGlobals.TokenType.OptionEnd, BASE, true)
|
||||
_states[LINK].add_transition(YarnGlobals.TokenType.OptionDelimit, link_destination, true)
|
||||
_states[LINK].add_text_rule(YarnGlobals.TokenType.Text)
|
||||
_states[LINK].add_transition(WolGlobals.TokenType.OptionEnd, BASE, true)
|
||||
_states[LINK].add_transition(WolGlobals.TokenType.OptionDelimit, link_destination, true)
|
||||
_states[LINK].add_text_rule(WolGlobals.TokenType.Text)
|
||||
|
||||
_states[link_destination] = LexerState.new(patterns)
|
||||
_states[link_destination].add_transition(YarnGlobals.TokenType.Identifier)
|
||||
_states[link_destination].add_transition(YarnGlobals.TokenType.OptionEnd, BASE)
|
||||
_states[link_destination].add_transition(WolGlobals.TokenType.Identifier)
|
||||
_states[link_destination].add_transition(WolGlobals.TokenType.OptionEnd, BASE)
|
||||
|
||||
_defaultState = _states[BASE]
|
||||
|
||||
|
@ -192,7 +192,7 @@ func tokenize(text:String)->Array:
|
|||
tokens+=tokenize_line(line,lineNumber)
|
||||
lineNumber+=1
|
||||
|
||||
var endOfInput : Token = Token.new(YarnGlobals.TokenType.EndOfInput,_currentState,lineNumber,0)
|
||||
var endOfInput : Token = Token.new(WolGlobals.TokenType.EndOfInput,_currentState,lineNumber,0)
|
||||
tokens.append(endOfInput)
|
||||
|
||||
# print(tokens)
|
||||
|
@ -212,7 +212,7 @@ func tokenize_line(line:String, lineNumber : int)->Array:
|
|||
#we add an indenation token to record indent level
|
||||
_indentStack.push_front(IntBoolPair.new(indentation,true))
|
||||
|
||||
var indent : Token = Token.new(YarnGlobals.TokenType.Indent,_currentState,lineNumber,prevIndentation.key)
|
||||
var indent : Token = Token.new(WolGlobals.TokenType.Indent,_currentState,lineNumber,prevIndentation.key)
|
||||
indent.value = "%*s" % [indentation - prevIndentation.key,""]
|
||||
|
||||
_shouldTrackIndent = false
|
||||
|
@ -224,7 +224,7 @@ func tokenize_line(line:String, lineNumber : int)->Array:
|
|||
while indentation < _indentStack.front().key:
|
||||
var top : IntBoolPair = _indentStack.pop_front()
|
||||
if top.value:
|
||||
var deIndent : Token = Token.new(YarnGlobals.TokenType.Dedent,_currentState,lineNumber,0)
|
||||
var deIndent : Token = Token.new(WolGlobals.TokenType.Dedent,_currentState,lineNumber,0)
|
||||
tokenStack.push_front(deIndent)
|
||||
|
||||
|
||||
|
@ -251,22 +251,22 @@ func tokenize_line(line:String, lineNumber : int)->Array:
|
|||
|
||||
var tokenText : String
|
||||
|
||||
if rule.tokenType == YarnGlobals.TokenType.Text:
|
||||
if rule.tokenType == WolGlobals.TokenType.Text:
|
||||
#if this is text then we back up to the most recent
|
||||
#delimiting token and treat everything from there as text.
|
||||
|
||||
var startIndex : int = indentation
|
||||
|
||||
if tokenStack.size() > 0 :
|
||||
while tokenStack.front().type == YarnGlobals.TokenType.Identifier:
|
||||
while tokenStack.front().type == WolGlobals.TokenType.Identifier:
|
||||
tokenStack.pop_front()
|
||||
|
||||
var startDelimitToken : Token = tokenStack.front()
|
||||
startIndex = startDelimitToken.column
|
||||
|
||||
if startDelimitToken.type == YarnGlobals.TokenType.Indent:
|
||||
if startDelimitToken.type == WolGlobals.TokenType.Indent:
|
||||
startIndex += startDelimitToken.value.length()
|
||||
if startDelimitToken.type == YarnGlobals.TokenType.Dedent:
|
||||
if startDelimitToken.type == WolGlobals.TokenType.Dedent:
|
||||
startIndex = indentation
|
||||
#
|
||||
|
||||
|
@ -281,7 +281,7 @@ func tokenize_line(line:String, lineNumber : int)->Array:
|
|||
column += tokenText.length()
|
||||
|
||||
#pre-proccess string
|
||||
if rule.tokenType == YarnGlobals.TokenType.Str:
|
||||
if rule.tokenType == WolGlobals.TokenType.Str:
|
||||
tokenText = tokenText.substr(1,tokenText.length() - 2)
|
||||
tokenText = tokenText.replace("\\\\", "\\")
|
||||
tokenText = tokenText.replace("\\\"","\"")
|
||||
|
@ -356,7 +356,7 @@ class Token:
|
|||
self.value = value
|
||||
|
||||
func _to_string():
|
||||
return "%s (%s) at %s:%s (state: %s)" % [YarnGlobals.token_type_name(type),value,lineNumber,column,lexerState]
|
||||
return "%s (%s) at %s:%s (state: %s)" % [WolGlobals.token_type_name(type),value,lineNumber,column,lexerState]
|
||||
|
||||
|
||||
class LexerState:
|
||||
|
@ -416,7 +416,7 @@ class Rule:
|
|||
self.delimitsText = delimitsText
|
||||
|
||||
func _to_string():
|
||||
return "[Rule : %s - %s]" % [YarnGlobals.token_type_name(tokenType),regex]
|
||||
return "[Rule : %s - %s]" % [WolGlobals.token_type_name(tokenType),regex]
|
||||
|
||||
class IntBoolPair:
|
||||
var key : int
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
extends Object
|
||||
|
||||
const YarnGlobals = preload("res://addons/Wol/autoloads/execution_states.gd")
|
||||
const WolGlobals = preload("res://addons/Wol/autoloads/execution_states.gd")
|
||||
const Lexer = preload("res://addons/Wol/core/compiler/lexer.gd")
|
||||
|
||||
|
||||
|
@ -14,8 +14,8 @@ enum Associativity {
|
|||
Left,Right,None
|
||||
}
|
||||
|
||||
func parse_node()->YarnNode:
|
||||
return YarnNode.new("Start",null,self)
|
||||
func parse_node()->WolNode:
|
||||
return WolNode.new("Start",null,self)
|
||||
|
||||
func next_symbol_is(validTypes:Array)->bool:
|
||||
var type = self._tokens.front().type
|
||||
|
@ -37,7 +37,7 @@ func expect_symbol(tokenTypes:Array = [])->Lexer.Token:
|
|||
var size = tokenTypes.size()
|
||||
|
||||
if size == 0:
|
||||
if t.type == YarnGlobals.TokenType.EndOfInput:
|
||||
if t.type == WolGlobals.TokenType.EndOfInput:
|
||||
printerr("unexpected end of input")
|
||||
return null
|
||||
return t
|
||||
|
@ -75,11 +75,11 @@ class ParseNode:
|
|||
func tags_to_string(indentLevel : int)->String:
|
||||
return "%s" % "TAGS<tags_to_string>NOTIMPLEMENTED"
|
||||
|
||||
func get_node_parent()->YarnNode:
|
||||
func get_node_parent()->WolNode:
|
||||
var node = self
|
||||
while node != null:
|
||||
if node.has_method("yarn_node"):
|
||||
return node as YarnNode
|
||||
if node.has_method("wol_node"):
|
||||
return node as WolNode
|
||||
node = node.parent
|
||||
return null
|
||||
|
||||
|
@ -90,8 +90,8 @@ class ParseNode:
|
|||
func set_parent(parent):
|
||||
self.parent = parent
|
||||
|
||||
#this is a Yarn Node - contains all the text
|
||||
class YarnNode extends ParseNode:
|
||||
#this is a Wol Node - contains all the text
|
||||
class WolNode extends ParseNode:
|
||||
|
||||
var name : String
|
||||
var source : String
|
||||
|
@ -103,11 +103,11 @@ class YarnNode extends ParseNode:
|
|||
|
||||
self.name = name
|
||||
while (parser.tokens().size() > 0 &&
|
||||
!parser.next_symbol_is([YarnGlobals.TokenType.Dedent,YarnGlobals.TokenType.EndOfInput])):
|
||||
!parser.next_symbol_is([WolGlobals.TokenType.Dedent,WolGlobals.TokenType.EndOfInput])):
|
||||
statements.append(Statement.new(self,parser))
|
||||
#print(statements.size())
|
||||
|
||||
func yarn_node():
|
||||
func wol_node():
|
||||
pass
|
||||
|
||||
func tree_string(indentLevel : int)->String:
|
||||
|
@ -127,7 +127,7 @@ class Header extends ParseNode:
|
|||
|
||||
|
||||
class Statement extends ParseNode:
|
||||
var Type = YarnGlobals.StatementTypes
|
||||
var Type = WolGlobals.StatementTypes
|
||||
|
||||
var type : int
|
||||
var block : Block
|
||||
|
@ -158,8 +158,8 @@ class Statement extends ParseNode:
|
|||
elif CustomCommand.can_parse(parser):
|
||||
customCommand = CustomCommand.new(self,parser)
|
||||
type = Type.CustomCommand
|
||||
elif parser.next_symbol_is([YarnGlobals.TokenType.Text]):
|
||||
line = parser.expect_symbol([YarnGlobals.TokenType.Text]).value
|
||||
elif parser.next_symbol_is([WolGlobals.TokenType.Text]):
|
||||
line = parser.expect_symbol([WolGlobals.TokenType.Text]).value
|
||||
type = Type.Line
|
||||
else:
|
||||
printerr("expected a statement but got %s instead. (probably an inbalanced if statement)" % parser.tokens().front()._to_string())
|
||||
|
@ -167,9 +167,9 @@ class Statement extends ParseNode:
|
|||
|
||||
var tags : Array = []
|
||||
|
||||
while parser.next_symbol_is([YarnGlobals.TokenType.TagMarker]):
|
||||
parser.expect_symbol([YarnGlobals.TokenType.TagMarker])
|
||||
var tag : String = parser.expect_symbol([YarnGlobals.TokenType.Identifier]).value
|
||||
while parser.next_symbol_is([WolGlobals.TokenType.TagMarker]):
|
||||
parser.expect_symbol([WolGlobals.TokenType.TagMarker])
|
||||
var tag : String = parser.expect_symbol([WolGlobals.TokenType.Identifier]).value
|
||||
tags.append(tag)
|
||||
|
||||
if(tags.size()>0):
|
||||
|
@ -213,20 +213,20 @@ class CustomCommand extends ParseNode:
|
|||
var clientCommand : String
|
||||
|
||||
func _init(parent:ParseNode,parser).(parent,parser):
|
||||
parser.expect_symbol([YarnGlobals.TokenType.BeginCommand])
|
||||
parser.expect_symbol([WolGlobals.TokenType.BeginCommand])
|
||||
|
||||
var commandTokens = []
|
||||
commandTokens.append(parser.expect_symbol())
|
||||
|
||||
while !parser.next_symbol_is([YarnGlobals.TokenType.EndCommand]):
|
||||
while !parser.next_symbol_is([WolGlobals.TokenType.EndCommand]):
|
||||
commandTokens.append(parser.expect_symbol())
|
||||
|
||||
parser.expect_symbol([YarnGlobals.TokenType.EndCommand])
|
||||
parser.expect_symbol([WolGlobals.TokenType.EndCommand])
|
||||
|
||||
#if first token is identifier and second is leftt parenthesis
|
||||
#evaluate as function
|
||||
if (commandTokens.size() > 1 && commandTokens[0].type == YarnGlobals.TokenType.Identifier
|
||||
&& commandTokens[1].type == YarnGlobals.TokenType.LeftParen):
|
||||
if (commandTokens.size() > 1 && commandTokens[0].type == WolGlobals.TokenType.Identifier
|
||||
&& commandTokens[1].type == WolGlobals.TokenType.LeftParen):
|
||||
var p = get_script().new(commandTokens,parser.library)
|
||||
var expression : ExpressionNode = ExpressionNode.parse(self,p)
|
||||
type = Type.Expression
|
||||
|
@ -245,8 +245,8 @@ class CustomCommand extends ParseNode:
|
|||
return ""
|
||||
|
||||
static func can_parse(parser)->bool:
|
||||
return (parser.next_symbols_are([YarnGlobals.TokenType.BeginCommand,YarnGlobals.TokenType.Text])
|
||||
|| parser.next_symbols_are([YarnGlobals.TokenType.BeginCommand,YarnGlobals.TokenType.Identifier]))
|
||||
return (parser.next_symbols_are([WolGlobals.TokenType.BeginCommand,WolGlobals.TokenType.Text])
|
||||
|| parser.next_symbols_are([WolGlobals.TokenType.BeginCommand,WolGlobals.TokenType.Identifier]))
|
||||
|
||||
|
||||
|
||||
|
@ -264,7 +264,7 @@ class ShortcutOptionGroup extends ParseNode:
|
|||
var sIndex : int = 1
|
||||
options.append(ShortCutOption.new(sIndex, self, parser))
|
||||
sIndex+=1
|
||||
while parser.next_symbol_is([YarnGlobals.TokenType.ShortcutOption]):
|
||||
while parser.next_symbol_is([WolGlobals.TokenType.ShortcutOption]):
|
||||
options.append(ShortCutOption.new(sIndex, self, parser))
|
||||
sIndex+=1
|
||||
|
||||
|
@ -282,43 +282,43 @@ class ShortcutOptionGroup extends ParseNode:
|
|||
return info.join("")
|
||||
|
||||
static func can_parse(parser)->bool:
|
||||
return parser.next_symbol_is([YarnGlobals.TokenType.ShortcutOption])
|
||||
return parser.next_symbol_is([WolGlobals.TokenType.ShortcutOption])
|
||||
pass
|
||||
|
||||
class ShortCutOption extends ParseNode:
|
||||
|
||||
var label : String
|
||||
var condition : ExpressionNode
|
||||
var node : YarnNode
|
||||
var node : WolNode
|
||||
|
||||
func _init(index:int, parent:ParseNode, parser).(parent,parser):
|
||||
parser.expect_symbol([YarnGlobals.TokenType.ShortcutOption])
|
||||
label = parser.expect_symbol([YarnGlobals.TokenType.Text]).value
|
||||
parser.expect_symbol([WolGlobals.TokenType.ShortcutOption])
|
||||
label = parser.expect_symbol([WolGlobals.TokenType.Text]).value
|
||||
|
||||
# parse the conditional << if $x >> when it exists
|
||||
|
||||
var tags : Array = []#string
|
||||
while( parser.next_symbols_are([YarnGlobals.TokenType.BeginCommand,YarnGlobals.TokenType.IfToken])
|
||||
|| parser.next_symbol_is([YarnGlobals.TokenType.TagMarker])):
|
||||
while( parser.next_symbols_are([WolGlobals.TokenType.BeginCommand,WolGlobals.TokenType.IfToken])
|
||||
|| parser.next_symbol_is([WolGlobals.TokenType.TagMarker])):
|
||||
|
||||
if parser.next_symbols_are([YarnGlobals.TokenType.BeginCommand, YarnGlobals.TokenType.IfToken]):
|
||||
parser.expect_symbol([YarnGlobals.TokenType.BeginCommand])
|
||||
parser.expect_symbol([YarnGlobals.TokenType.IfToken])
|
||||
if parser.next_symbols_are([WolGlobals.TokenType.BeginCommand, WolGlobals.TokenType.IfToken]):
|
||||
parser.expect_symbol([WolGlobals.TokenType.BeginCommand])
|
||||
parser.expect_symbol([WolGlobals.TokenType.IfToken])
|
||||
condition = ExpressionNode.parse(self,parser)
|
||||
parser.expect_symbol([YarnGlobals.TokenType.EndCommand])
|
||||
elif parser.next_symbol_is([YarnGlobals.TokenType.TagMarker]):
|
||||
parser.expect_symbol([YarnGlobals.TokenType.TagMarker])
|
||||
var tag : String = parser.expect_symbol([YarnGlobals.TokenType.Identifier]).value;
|
||||
parser.expect_symbol([WolGlobals.TokenType.EndCommand])
|
||||
elif parser.next_symbol_is([WolGlobals.TokenType.TagMarker]):
|
||||
parser.expect_symbol([WolGlobals.TokenType.TagMarker])
|
||||
var tag : String = parser.expect_symbol([WolGlobals.TokenType.Identifier]).value;
|
||||
tags.append(tag)
|
||||
|
||||
|
||||
self.tags = tags
|
||||
# parse remaining statements
|
||||
|
||||
if parser.next_symbol_is([YarnGlobals.TokenType.Indent]):
|
||||
parser.expect_symbol([YarnGlobals.TokenType.Indent])
|
||||
node = YarnNode.new("%s.%s" %[self.get_node_parent().name ,index], self,parser)
|
||||
parser.expect_symbol([YarnGlobals.TokenType.Dedent])
|
||||
if parser.next_symbol_is([WolGlobals.TokenType.Indent]):
|
||||
parser.expect_symbol([WolGlobals.TokenType.Indent])
|
||||
node = WolNode.new("%s.%s" %[self.get_node_parent().name ,index], self,parser)
|
||||
parser.expect_symbol([WolGlobals.TokenType.Dedent])
|
||||
|
||||
|
||||
func tree_string(indentLevel : int)->String:
|
||||
|
@ -346,15 +346,15 @@ class Block extends ParseNode:
|
|||
|
||||
func _init(parent:ParseNode, parser).(parent,parser):
|
||||
#read indent
|
||||
parser.expect_symbol([YarnGlobals.TokenType.Indent])
|
||||
parser.expect_symbol([WolGlobals.TokenType.Indent])
|
||||
|
||||
#keep reading statements until we hit a dedent
|
||||
while !parser.next_symbol_is([YarnGlobals.TokenType.Dedent]):
|
||||
while !parser.next_symbol_is([WolGlobals.TokenType.Dedent]):
|
||||
#parse all statements including nested blocks
|
||||
statements.append(Statement.new(self,parser))
|
||||
|
||||
#clean up dedent
|
||||
parser.expect_symbol([YarnGlobals.TokenType.Dedent])
|
||||
parser.expect_symbol([WolGlobals.TokenType.Dedent])
|
||||
|
||||
|
||||
func tree_string(indentLevel : int)->String:
|
||||
|
@ -370,7 +370,7 @@ class Block extends ParseNode:
|
|||
return info.join("")
|
||||
|
||||
static func can_parse(parser)->bool:
|
||||
return parser.next_symbol_is([YarnGlobals.TokenType.Indent])
|
||||
return parser.next_symbol_is([WolGlobals.TokenType.Indent])
|
||||
|
||||
#Option Statements are links to other nodes
|
||||
class OptionStatement extends ParseNode:
|
||||
|
@ -383,20 +383,20 @@ class OptionStatement extends ParseNode:
|
|||
var strings : Array = []#string
|
||||
|
||||
#parse [[LABEL
|
||||
parser.expect_symbol([YarnGlobals.TokenType.OptionStart])
|
||||
strings.append(parser.expect_symbol([YarnGlobals.TokenType.Text]).value)
|
||||
parser.expect_symbol([WolGlobals.TokenType.OptionStart])
|
||||
strings.append(parser.expect_symbol([WolGlobals.TokenType.Text]).value)
|
||||
|
||||
#if there is a | get the next string
|
||||
if parser.next_symbol_is([YarnGlobals.TokenType.OptionDelimit]):
|
||||
parser.expect_symbol([YarnGlobals.TokenType.OptionDelimit])
|
||||
var t = parser.expect_symbol([YarnGlobals.TokenType.Text,YarnGlobals.TokenType.Identifier])
|
||||
if parser.next_symbol_is([WolGlobals.TokenType.OptionDelimit]):
|
||||
parser.expect_symbol([WolGlobals.TokenType.OptionDelimit])
|
||||
var t = parser.expect_symbol([WolGlobals.TokenType.Text,WolGlobals.TokenType.Identifier])
|
||||
#print("Token %s"%t.value)
|
||||
strings.append(t.value as String)
|
||||
|
||||
label = strings[0] if strings.size() > 1 else ""
|
||||
destination = strings[1] if strings.size() > 1 else strings[0]
|
||||
|
||||
parser.expect_symbol([YarnGlobals.TokenType.OptionEnd])
|
||||
parser.expect_symbol([WolGlobals.TokenType.OptionEnd])
|
||||
|
||||
func tree_string(indentLevel : int)->String:
|
||||
if label != null:
|
||||
|
@ -405,7 +405,7 @@ class OptionStatement extends ParseNode:
|
|||
return tab(indentLevel,"Option: -> %s"%destination)
|
||||
|
||||
static func can_parse(parser)->bool:
|
||||
return parser.next_symbol_is([YarnGlobals.TokenType.OptionStart])
|
||||
return parser.next_symbol_is([WolGlobals.TokenType.OptionStart])
|
||||
|
||||
class IfStatement extends ParseNode:
|
||||
|
||||
|
@ -416,80 +416,80 @@ class IfStatement extends ParseNode:
|
|||
#<<if Expression>>
|
||||
var prime : Clause = Clause.new()
|
||||
|
||||
parser.expect_symbol([YarnGlobals.TokenType.BeginCommand])
|
||||
parser.expect_symbol([YarnGlobals.TokenType.IfToken])
|
||||
parser.expect_symbol([WolGlobals.TokenType.BeginCommand])
|
||||
parser.expect_symbol([WolGlobals.TokenType.IfToken])
|
||||
prime.expression = ExpressionNode.parse(self,parser)
|
||||
parser.expect_symbol([YarnGlobals.TokenType.EndCommand])
|
||||
parser.expect_symbol([WolGlobals.TokenType.EndCommand])
|
||||
|
||||
#read statements until 'endif' or 'else' or 'else if'
|
||||
var statements : Array = []#statement
|
||||
while (!parser.next_symbols_are([YarnGlobals.TokenType.BeginCommand, YarnGlobals.TokenType.EndIf])
|
||||
&& !parser.next_symbols_are([YarnGlobals.TokenType.BeginCommand, YarnGlobals.TokenType.ElseToken])
|
||||
&& !parser.next_symbols_are([YarnGlobals.TokenType.BeginCommand, YarnGlobals.TokenType.ElseIf])):
|
||||
while (!parser.next_symbols_are([WolGlobals.TokenType.BeginCommand, WolGlobals.TokenType.EndIf])
|
||||
&& !parser.next_symbols_are([WolGlobals.TokenType.BeginCommand, WolGlobals.TokenType.ElseToken])
|
||||
&& !parser.next_symbols_are([WolGlobals.TokenType.BeginCommand, WolGlobals.TokenType.ElseIf])):
|
||||
|
||||
statements.append(Statement.new(self,parser))
|
||||
|
||||
#ignore dedent
|
||||
while parser.next_symbol_is([YarnGlobals.TokenType.Dedent]):
|
||||
parser.expect_symbol([YarnGlobals.TokenType.Dedent])
|
||||
while parser.next_symbol_is([WolGlobals.TokenType.Dedent]):
|
||||
parser.expect_symbol([WolGlobals.TokenType.Dedent])
|
||||
|
||||
|
||||
prime.statements = statements
|
||||
clauses.append(prime)
|
||||
|
||||
#handle all else if
|
||||
while parser.next_symbols_are([YarnGlobals.TokenType.BeginCommand,YarnGlobals.TokenType.ElseIf]):
|
||||
while parser.next_symbols_are([WolGlobals.TokenType.BeginCommand,WolGlobals.TokenType.ElseIf]):
|
||||
var clauseElif : Clause = Clause.new()
|
||||
|
||||
#parse condition syntax
|
||||
parser.expect_symbol([YarnGlobals.TokenType.BeginCommand])
|
||||
parser.expect_symbol([YarnGlobals.TokenType.ElseIf])
|
||||
parser.expect_symbol([WolGlobals.TokenType.BeginCommand])
|
||||
parser.expect_symbol([WolGlobals.TokenType.ElseIf])
|
||||
clauseElif.expression = ExpressionNode.parse(self,parser)
|
||||
parser.expect_symbol([YarnGlobals.TokenType.EndCommand])
|
||||
parser.expect_symbol([WolGlobals.TokenType.EndCommand])
|
||||
|
||||
|
||||
var elifStatements : Array = []#statement
|
||||
while (!parser.next_symbols_are([YarnGlobals.TokenType.BeginCommand, YarnGlobals.TokenType.EndIf])
|
||||
&& !parser.next_symbols_are([YarnGlobals.TokenType.BeginCommand, YarnGlobals.TokenType.ElseToken])
|
||||
&& !parser.next_symbols_are([YarnGlobals.TokenType.BeginCommand, YarnGlobals.TokenType.ElseIf])):
|
||||
while (!parser.next_symbols_are([WolGlobals.TokenType.BeginCommand, WolGlobals.TokenType.EndIf])
|
||||
&& !parser.next_symbols_are([WolGlobals.TokenType.BeginCommand, WolGlobals.TokenType.ElseToken])
|
||||
&& !parser.next_symbols_are([WolGlobals.TokenType.BeginCommand, WolGlobals.TokenType.ElseIf])):
|
||||
|
||||
elifStatements.append(Statement.new(self,parser))
|
||||
|
||||
#ignore dedent
|
||||
while parser.next_symbol_is([YarnGlobals.TokenType.Dedent]):
|
||||
parser.expect_symbol([YarnGlobals.TokenType.Dedent])
|
||||
while parser.next_symbol_is([WolGlobals.TokenType.Dedent]):
|
||||
parser.expect_symbol([WolGlobals.TokenType.Dedent])
|
||||
|
||||
|
||||
clauseElif.statements = statements
|
||||
clauses.append(clauseElif)
|
||||
|
||||
#handle else if exists
|
||||
if (parser.next_symbols_are([YarnGlobals.TokenType.BeginCommand,
|
||||
YarnGlobals.TokenType.ElseToken,YarnGlobals.TokenType.EndCommand])):
|
||||
if (parser.next_symbols_are([WolGlobals.TokenType.BeginCommand,
|
||||
WolGlobals.TokenType.ElseToken,WolGlobals.TokenType.EndCommand])):
|
||||
|
||||
#expect no expression - just <<else>>
|
||||
parser.expect_symbol([YarnGlobals.TokenType.BeginCommand])
|
||||
parser.expect_symbol([YarnGlobals.TokenType.ElseToken])
|
||||
parser.expect_symbol([YarnGlobals.TokenType.EndCommand])
|
||||
parser.expect_symbol([WolGlobals.TokenType.BeginCommand])
|
||||
parser.expect_symbol([WolGlobals.TokenType.ElseToken])
|
||||
parser.expect_symbol([WolGlobals.TokenType.EndCommand])
|
||||
|
||||
#parse until hit endif
|
||||
var clauseElse : Clause = Clause.new()
|
||||
var elStatements : Array = []#statement
|
||||
while !parser.next_symbols_are([YarnGlobals.TokenType.BeginCommand,YarnGlobals.TokenType.EndIf]):
|
||||
while !parser.next_symbols_are([WolGlobals.TokenType.BeginCommand,WolGlobals.TokenType.EndIf]):
|
||||
elStatements.append(Statement.new(self,parser))
|
||||
|
||||
clauseElse.statements = elStatements
|
||||
clauses.append(clauseElse)
|
||||
|
||||
#ignore dedent
|
||||
while parser.next_symbol_is([YarnGlobals.TokenType.Dedent]):
|
||||
parser.expect_symbol([YarnGlobals.TokenType.Dedent])
|
||||
while parser.next_symbol_is([WolGlobals.TokenType.Dedent]):
|
||||
parser.expect_symbol([WolGlobals.TokenType.Dedent])
|
||||
|
||||
|
||||
#finish
|
||||
parser.expect_symbol([YarnGlobals.TokenType.BeginCommand])
|
||||
parser.expect_symbol([YarnGlobals.TokenType.EndIf])
|
||||
parser.expect_symbol([YarnGlobals.TokenType.EndCommand])
|
||||
parser.expect_symbol([WolGlobals.TokenType.BeginCommand])
|
||||
parser.expect_symbol([WolGlobals.TokenType.EndIf])
|
||||
parser.expect_symbol([WolGlobals.TokenType.EndCommand])
|
||||
|
||||
|
||||
func tree_string(indentLevel : int)->String:
|
||||
|
@ -509,7 +509,7 @@ class IfStatement extends ParseNode:
|
|||
return info.join("")
|
||||
|
||||
static func can_parse(parser)->bool:
|
||||
return parser.next_symbols_are([YarnGlobals.TokenType.BeginCommand,YarnGlobals.TokenType.IfToken])
|
||||
return parser.next_symbols_are([WolGlobals.TokenType.BeginCommand,WolGlobals.TokenType.IfToken])
|
||||
pass
|
||||
|
||||
class ValueNode extends ParseNode:
|
||||
|
@ -521,26 +521,26 @@ class ValueNode extends ParseNode:
|
|||
|
||||
var t : Lexer.Token = token
|
||||
if t == null :
|
||||
parser.expect_symbol([YarnGlobals.TokenType.Number,
|
||||
YarnGlobals.TokenType.Variable,YarnGlobals.TokenType.Str])
|
||||
parser.expect_symbol([WolGlobals.TokenType.Number,
|
||||
WolGlobals.TokenType.Variable,WolGlobals.TokenType.Str])
|
||||
use_token(t)
|
||||
|
||||
#store value depending on type
|
||||
func use_token(t:Lexer.Token):
|
||||
match t.type:
|
||||
YarnGlobals.TokenType.Number:
|
||||
WolGlobals.TokenType.Number:
|
||||
value = Value.new(float(t.value))
|
||||
YarnGlobals.TokenType.Str:
|
||||
WolGlobals.TokenType.Str:
|
||||
value = Value.new(t.value)
|
||||
YarnGlobals.TokenType.FalseToken:
|
||||
WolGlobals.TokenType.FalseToken:
|
||||
value = Value.new(false)
|
||||
YarnGlobals.TokenType.TrueToken:
|
||||
WolGlobals.TokenType.TrueToken:
|
||||
value = Value.new(true)
|
||||
YarnGlobals.TokenType.Variable:
|
||||
WolGlobals.TokenType.Variable:
|
||||
value = Value.new(null)
|
||||
value.type = YarnGlobals.ValueType.Variable
|
||||
value.type = WolGlobals.ValueType.Variable
|
||||
value.variable = t.value
|
||||
YarnGlobals.TokenType.NullToken:
|
||||
WolGlobals.TokenType.NullToken:
|
||||
value = Value.new(null)
|
||||
_:
|
||||
printerr("%s, Invalid token type" % t.name)
|
||||
|
@ -564,20 +564,20 @@ class ExpressionNode extends ParseNode:
|
|||
|
||||
#no function - means value
|
||||
if value!=null:
|
||||
self.type = YarnGlobals.ExpressionType.Value
|
||||
self.type = WolGlobals.ExpressionType.Value
|
||||
self.value = value
|
||||
else:#function
|
||||
|
||||
self.type = YarnGlobals.ExpressionType.FunctionCall
|
||||
self.type = WolGlobals.ExpressionType.FunctionCall
|
||||
self.function = function
|
||||
self.params = params
|
||||
|
||||
func tree_string(indentLevel : int)->String:
|
||||
var info : PoolStringArray = []
|
||||
match type:
|
||||
YarnGlobals.ExpressionType.Value:
|
||||
WolGlobals.ExpressionType.Value:
|
||||
return value.tree_string(indentLevel)
|
||||
YarnGlobals.ExpressionType.FunctionCall:
|
||||
WolGlobals.ExpressionType.FunctionCall:
|
||||
info.append(tab(indentLevel,"Func[%s - params(%s)]:{"%[function,params.size()]))
|
||||
for param in params:
|
||||
#print("----> %s paramSize:%s"%[(function) , params.size()])
|
||||
|
@ -599,16 +599,16 @@ class ExpressionNode extends ParseNode:
|
|||
var funcStack : Array = []#token
|
||||
|
||||
var validTypes : Array = [
|
||||
YarnGlobals.TokenType.Number,
|
||||
YarnGlobals.TokenType.Variable,
|
||||
YarnGlobals.TokenType.Str,
|
||||
YarnGlobals.TokenType.LeftParen,
|
||||
YarnGlobals.TokenType.RightParen,
|
||||
YarnGlobals.TokenType.Identifier,
|
||||
YarnGlobals.TokenType.Comma,
|
||||
YarnGlobals.TokenType.TrueToken,
|
||||
YarnGlobals.TokenType.FalseToken,
|
||||
YarnGlobals.TokenType.NullToken
|
||||
WolGlobals.TokenType.Number,
|
||||
WolGlobals.TokenType.Variable,
|
||||
WolGlobals.TokenType.Str,
|
||||
WolGlobals.TokenType.LeftParen,
|
||||
WolGlobals.TokenType.RightParen,
|
||||
WolGlobals.TokenType.Identifier,
|
||||
WolGlobals.TokenType.Comma,
|
||||
WolGlobals.TokenType.TrueToken,
|
||||
WolGlobals.TokenType.FalseToken,
|
||||
WolGlobals.TokenType.NullToken
|
||||
]
|
||||
validTypes+=Operator.op_types()
|
||||
validTypes.invert()
|
||||
|
@ -619,26 +619,26 @@ class ExpressionNode extends ParseNode:
|
|||
while parser.tokens().size() > 0 && parser.next_symbol_is(validTypes):
|
||||
var next = parser.expect_symbol(validTypes) #lexer.Token
|
||||
|
||||
if( next.type == YarnGlobals.TokenType.Variable ||
|
||||
next.type == YarnGlobals.TokenType.Number ||
|
||||
next.type == YarnGlobals.TokenType.Str ||
|
||||
next.type == YarnGlobals.TokenType.TrueToken ||
|
||||
next.type == YarnGlobals.TokenType.FalseToken ||
|
||||
next.type == YarnGlobals.TokenType.NullToken ):
|
||||
if( next.type == WolGlobals.TokenType.Variable ||
|
||||
next.type == WolGlobals.TokenType.Number ||
|
||||
next.type == WolGlobals.TokenType.Str ||
|
||||
next.type == WolGlobals.TokenType.TrueToken ||
|
||||
next.type == WolGlobals.TokenType.FalseToken ||
|
||||
next.type == WolGlobals.TokenType.NullToken ):
|
||||
|
||||
#output primitives
|
||||
rpn.append(next)
|
||||
elif next.type == YarnGlobals.TokenType.Identifier:
|
||||
elif next.type == WolGlobals.TokenType.Identifier:
|
||||
opStack.push_back(next)
|
||||
funcStack.push_back(next)
|
||||
|
||||
#next token is parent - left
|
||||
next = parser.expect_symbol([YarnGlobals.TokenType.LeftParen])
|
||||
next = parser.expect_symbol([WolGlobals.TokenType.LeftParen])
|
||||
opStack.push_back(next)
|
||||
elif next.type == YarnGlobals.TokenType.Comma:
|
||||
elif next.type == WolGlobals.TokenType.Comma:
|
||||
|
||||
#resolve sub expression before moving on
|
||||
while opStack.back().type != YarnGlobals.TokenType.LeftParen:
|
||||
while opStack.back().type != WolGlobals.TokenType.LeftParen:
|
||||
var p = opStack.pop_back()
|
||||
if p == null:
|
||||
printerr("unbalanced parenthesis %s " % next.name)
|
||||
|
@ -648,8 +648,8 @@ class ExpressionNode extends ParseNode:
|
|||
|
||||
#next token in opStack left paren
|
||||
# next parser token not allowed to be right paren or comma
|
||||
if parser.next_symbol_is([YarnGlobals.TokenType.RightParen,
|
||||
YarnGlobals.TokenType.Comma]):
|
||||
if parser.next_symbol_is([WolGlobals.TokenType.RightParen,
|
||||
WolGlobals.TokenType.Comma]):
|
||||
printerr("Expected Expression : %s" % parser.tokens().front().name)
|
||||
|
||||
#find the closest function on stack
|
||||
|
@ -668,17 +668,17 @@ class ExpressionNode extends ParseNode:
|
|||
#is only unary when the last token was a left paren,
|
||||
#an operator, or its the first token.
|
||||
|
||||
if (next.type == YarnGlobals.TokenType.Minus):
|
||||
if (next.type == WolGlobals.TokenType.Minus):
|
||||
if (last == null ||
|
||||
last.type == YarnGlobals.TokenType.LeftParen ||
|
||||
last.type == WolGlobals.TokenType.LeftParen ||
|
||||
Operator.is_op(last.type)):
|
||||
#unary minus
|
||||
next.type = YarnGlobals.TokenType.UnaryMinus
|
||||
next.type = WolGlobals.TokenType.UnaryMinus
|
||||
|
||||
#cannot assign inside expression
|
||||
# x = a is the same as x == a
|
||||
if next.type == YarnGlobals.TokenType.EqualToOrAssign:
|
||||
next.type = YarnGlobals.TokenType.EqualTo
|
||||
if next.type == WolGlobals.TokenType.EqualToOrAssign:
|
||||
next.type = WolGlobals.TokenType.EqualTo
|
||||
|
||||
|
||||
#operator precedence
|
||||
|
@ -688,25 +688,25 @@ class ExpressionNode extends ParseNode:
|
|||
|
||||
opStack.push_back(next)
|
||||
|
||||
elif next.type == YarnGlobals.TokenType.LeftParen:
|
||||
elif next.type == WolGlobals.TokenType.LeftParen:
|
||||
#entered parenthesis sub expression
|
||||
opStack.push_back(next)
|
||||
elif next.type == YarnGlobals.TokenType.RightParen:
|
||||
elif next.type == WolGlobals.TokenType.RightParen:
|
||||
#leaving sub expression
|
||||
# resolve order of operations
|
||||
while opStack.back().type != YarnGlobals.TokenType.LeftParen:
|
||||
while opStack.back().type != WolGlobals.TokenType.LeftParen:
|
||||
rpn.append(opStack.pop_back())
|
||||
if opStack.back() == null:
|
||||
printerr("Unbalanced parenthasis #RightParen. Parser.ExpressionNode")
|
||||
|
||||
|
||||
opStack.pop_back()
|
||||
if opStack.back().type == YarnGlobals.TokenType.Identifier:
|
||||
if opStack.back().type == WolGlobals.TokenType.Identifier:
|
||||
#function call
|
||||
#last token == left paren this == no params
|
||||
#else
|
||||
#we have more than 1 param
|
||||
if last.type != YarnGlobals.TokenType.LeftParen:
|
||||
if last.type != WolGlobals.TokenType.LeftParen:
|
||||
funcStack.back().paramCount+=1
|
||||
|
||||
rpn.append(opStack.pop_back())
|
||||
|
@ -735,7 +735,7 @@ class ExpressionNode extends ParseNode:
|
|||
var info : OperatorInfo = Operator.op_info(next.type)
|
||||
|
||||
if evalStack.size() < info.arguments:
|
||||
printerr("Error parsing : Not enough arguments for %s [ got %s expected - was %s]"%[YarnGlobals.token_type_name(next.type),evalStack.size(),info.arguments])
|
||||
printerr("Error parsing : Not enough arguments for %s [ got %s expected - was %s]"%[WolGlobals.token_type_name(next.type),evalStack.size(),info.arguments])
|
||||
|
||||
var params : Array = []#ExpressionNode
|
||||
for i in range(info.arguments):
|
||||
|
@ -749,7 +749,7 @@ class ExpressionNode extends ParseNode:
|
|||
|
||||
evalStack.append(expression)
|
||||
|
||||
elif next.type == YarnGlobals.TokenType.Identifier:
|
||||
elif next.type == WolGlobals.TokenType.Identifier:
|
||||
#function call
|
||||
|
||||
var function : String = next.value
|
||||
|
@ -785,8 +785,8 @@ class ExpressionNode extends ParseNode:
|
|||
static func get_func_name(type)->String:
|
||||
var string : String = ""
|
||||
|
||||
for key in YarnGlobals.TokenType.keys():
|
||||
if YarnGlobals.TokenType[key] == type:
|
||||
for key in WolGlobals.TokenType.keys():
|
||||
if WolGlobals.TokenType[key] == type:
|
||||
return key
|
||||
return string
|
||||
|
||||
|
@ -822,35 +822,35 @@ class Assignment extends ParseNode:
|
|||
var operation
|
||||
|
||||
func _init(parent:ParseNode,parser).(parent,parser):
|
||||
parser.expect_symbol([YarnGlobals.TokenType.BeginCommand])
|
||||
parser.expect_symbol([YarnGlobals.TokenType.Set])
|
||||
destination = parser.expect_symbol([YarnGlobals.TokenType.Variable]).value
|
||||
parser.expect_symbol([WolGlobals.TokenType.BeginCommand])
|
||||
parser.expect_symbol([WolGlobals.TokenType.Set])
|
||||
destination = parser.expect_symbol([WolGlobals.TokenType.Variable]).value
|
||||
operation = parser.expect_symbol(Assignment.valid_ops()).type
|
||||
value = ExpressionNode.parse(self,parser)
|
||||
parser.expect_symbol([YarnGlobals.TokenType.EndCommand])
|
||||
parser.expect_symbol([WolGlobals.TokenType.EndCommand])
|
||||
|
||||
func tree_string(indentLevel : int)->String:
|
||||
var info : PoolStringArray = []
|
||||
info.append(tab(indentLevel,"set:"))
|
||||
info.append(tab(indentLevel+1,destination))
|
||||
info.append(tab(indentLevel+1,YarnGlobals.token_type_name(operation)))
|
||||
info.append(tab(indentLevel+1,WolGlobals.token_type_name(operation)))
|
||||
info.append(value.tree_string(indentLevel+1))
|
||||
return info.join("")
|
||||
|
||||
|
||||
static func can_parse(parser)->bool:
|
||||
return parser.next_symbols_are([
|
||||
YarnGlobals.TokenType.BeginCommand,
|
||||
YarnGlobals.TokenType.Set
|
||||
WolGlobals.TokenType.BeginCommand,
|
||||
WolGlobals.TokenType.Set
|
||||
])
|
||||
|
||||
static func valid_ops()->Array:
|
||||
return [
|
||||
YarnGlobals.TokenType.EqualToOrAssign,
|
||||
YarnGlobals.TokenType.AddAssign,
|
||||
YarnGlobals.TokenType.MinusAssign,
|
||||
YarnGlobals.TokenType.DivideAssign,
|
||||
YarnGlobals.TokenType.MultiplyAssign
|
||||
WolGlobals.TokenType.EqualToOrAssign,
|
||||
WolGlobals.TokenType.AddAssign,
|
||||
WolGlobals.TokenType.MinusAssign,
|
||||
WolGlobals.TokenType.DivideAssign,
|
||||
WolGlobals.TokenType.MultiplyAssign
|
||||
]
|
||||
|
||||
class Operator extends ParseNode:
|
||||
|
@ -875,7 +875,7 @@ class Operator extends ParseNode:
|
|||
|
||||
#determine associativity and operands
|
||||
# each operand has
|
||||
var TokenType = YarnGlobals.TokenType
|
||||
var TokenType = WolGlobals.TokenType
|
||||
|
||||
match op:
|
||||
TokenType.Not, TokenType.UnaryMinus:
|
||||
|
@ -903,27 +903,27 @@ class Operator extends ParseNode:
|
|||
|
||||
static func op_types()->Array:
|
||||
return [
|
||||
YarnGlobals.TokenType.Not,
|
||||
YarnGlobals.TokenType.UnaryMinus,
|
||||
WolGlobals.TokenType.Not,
|
||||
WolGlobals.TokenType.UnaryMinus,
|
||||
|
||||
YarnGlobals.TokenType.Add,
|
||||
YarnGlobals.TokenType.Minus,
|
||||
YarnGlobals.TokenType.Divide,
|
||||
YarnGlobals.TokenType.Multiply,
|
||||
YarnGlobals.TokenType.Modulo,
|
||||
WolGlobals.TokenType.Add,
|
||||
WolGlobals.TokenType.Minus,
|
||||
WolGlobals.TokenType.Divide,
|
||||
WolGlobals.TokenType.Multiply,
|
||||
WolGlobals.TokenType.Modulo,
|
||||
|
||||
YarnGlobals.TokenType.EqualToOrAssign,
|
||||
YarnGlobals.TokenType.EqualTo,
|
||||
YarnGlobals.TokenType.GreaterThan,
|
||||
YarnGlobals.TokenType.GreaterThanOrEqualTo,
|
||||
YarnGlobals.TokenType.LessThan,
|
||||
YarnGlobals.TokenType.LessThanOrEqualTo,
|
||||
YarnGlobals.TokenType.NotEqualTo,
|
||||
WolGlobals.TokenType.EqualToOrAssign,
|
||||
WolGlobals.TokenType.EqualTo,
|
||||
WolGlobals.TokenType.GreaterThan,
|
||||
WolGlobals.TokenType.GreaterThanOrEqualTo,
|
||||
WolGlobals.TokenType.LessThan,
|
||||
WolGlobals.TokenType.LessThanOrEqualTo,
|
||||
WolGlobals.TokenType.NotEqualTo,
|
||||
|
||||
YarnGlobals.TokenType.And,
|
||||
YarnGlobals.TokenType.Or,
|
||||
WolGlobals.TokenType.And,
|
||||
WolGlobals.TokenType.Or,
|
||||
|
||||
YarnGlobals.TokenType.Xor
|
||||
WolGlobals.TokenType.Xor
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@ const FMF_PLACEHOLDE = "<VALUE PLACEHOLDER>"
|
|||
|
||||
const StandardLibrary = preload("res://addons/Wol/core/libraries/standard.gd")
|
||||
const VirtualMachine = preload("res://addons/Wol/core/virtual_machine.gd")
|
||||
const YarnLibrary = preload("res://addons/Wol/core/library.gd")
|
||||
const WolLibrary = preload("res://addons/Wol/core/library.gd")
|
||||
const Value = preload("res://addons/Wol/core/value.gd")
|
||||
const YarnProgram = preload("res://addons/Wol/core/program/program.gd")
|
||||
const WolProgram = preload("res://addons/Wol/core/program/program.gd")
|
||||
|
||||
var _variableStorage
|
||||
|
||||
|
@ -26,7 +26,7 @@ var executionComplete : bool
|
|||
func _init(variableStorage):
|
||||
_variableStorage = variableStorage
|
||||
_vm = VirtualMachine.new(self)
|
||||
library = YarnLibrary.new()
|
||||
library = WolLibrary.new()
|
||||
_debugLog = funcref(self, "dlog")
|
||||
_errLog = funcref(self, "elog")
|
||||
executionComplete = false
|
||||
|
@ -49,7 +49,7 @@ func elog(message:String):
|
|||
print("YARN_ERROR : %s" % message)
|
||||
|
||||
func is_active():
|
||||
return get_exec_state() != YarnGlobals.ExecutionState.Stopped
|
||||
return get_exec_state() != WolGlobals.ExecutionState.Stopped
|
||||
|
||||
#gets the current execution state of the virtual machine
|
||||
func get_exec_state():
|
||||
|
@ -62,7 +62,7 @@ func set_node(name:String = DEFAULT_START):
|
|||
_vm.set_node(name)
|
||||
|
||||
func resume():
|
||||
if _vm.executionState == YarnGlobals.ExecutionState.Running:
|
||||
if _vm.executionState == WolGlobals.ExecutionState.Running:
|
||||
print('BLOCKED')
|
||||
return
|
||||
_vm.resume()
|
||||
|
@ -74,7 +74,7 @@ func stop():
|
|||
_vm.stop()
|
||||
|
||||
func get_all_nodes():
|
||||
return _program.yarnNodes.keys()
|
||||
return _program.wolNodes.keys()
|
||||
|
||||
func current_node():
|
||||
return _vm.get_current()
|
||||
|
@ -116,7 +116,7 @@ func is_node_visited(node = _vm.current_node_name()):
|
|||
|
||||
func node_visit_count(node = _vm.current_node_name()):
|
||||
if node is Value:
|
||||
node = _program.yarnStrings[node.value()].text
|
||||
node = _program.wolStrings[node.value()].text
|
||||
|
||||
var visitCount : int = 0
|
||||
if _visitedNodeCount.has(node):
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
extends Object
|
||||
|
||||
const LineInfo = preload("res://addons/Wol/core/program/yarn_line.gd")
|
||||
const LineInfo = preload("res://addons/Wol/core/program/wol_line.gd")
|
||||
|
||||
var id : String
|
||||
var substitutions : Array = []#String
|
||||
|
|
|
@ -12,7 +12,7 @@ func get_function(name:String)->FunctionInfo:
|
|||
return null
|
||||
|
||||
func import_library(other)->void:
|
||||
YarnGlobals.merge_dir(functions,other.functions)
|
||||
WolGlobals.merge_dir(functions,other.functions)
|
||||
|
||||
func register_function(name: String, paramCount: int, function: FuncRef, returnsValue: bool):
|
||||
var functionInfo: FunctionInfo = FunctionInfo.new(name, paramCount, function, returnsValue)
|
||||
|
|
|
@ -14,4 +14,4 @@ func dump(program,library)->String:
|
|||
return "InstructionInformation:NotImplemented"
|
||||
|
||||
func _to_string():
|
||||
return YarnGlobals.bytecode_name(operation) + ':' + operands as String
|
||||
return WolGlobals.bytecode_name(operation) + ':' + operands as String
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
extends Node
|
||||
|
||||
var programName : String
|
||||
var yarnStrings : Dictionary = {}
|
||||
var yarnNodes : Dictionary = {}
|
||||
var wolStrings : Dictionary = {}
|
||||
var wolNodes : Dictionary = {}
|
||||
|
||||
func get_node_tags(name:String)->Array:
|
||||
return yarnNodes[name].tags
|
||||
return wolNodes[name].tags
|
||||
|
||||
func get_yarn_string(key:String)->String:
|
||||
return yarnStrings[key]
|
||||
func get_wol_string(key:String)->String:
|
||||
return wolStrings[key]
|
||||
|
||||
func get_node_text(name:String)->String:
|
||||
var key = yarnNodes[name].sourceId
|
||||
return get_yarn_string(key)
|
||||
var key = wolNodes[name].sourceId
|
||||
return get_wol_string(key)
|
||||
|
||||
#possible support for line tags
|
||||
func get_untagged_strings()->Dictionary:
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
extends Object
|
||||
|
||||
const YarnGlobals = preload("res://addons/Wol/autoloads/execution_states.gd")
|
||||
const WolGlobals = preload("res://addons/Wol/autoloads/execution_states.gd")
|
||||
|
||||
const NULL_STRING : String = "null"
|
||||
const FALSE_STRING : String= "false"
|
||||
const TRUE_STRING : String = "true"
|
||||
const NANI : String = "NaN"
|
||||
|
||||
var type : int = YarnGlobals.ValueType.Nullean
|
||||
var type : int = WolGlobals.ValueType.Nullean
|
||||
var number : float = 0
|
||||
var string : String = ""
|
||||
var variable : String = ""
|
||||
|
@ -16,7 +16,7 @@ var boolean : bool = false
|
|||
|
||||
func _init(value = NANI):
|
||||
if typeof(value) == TYPE_OBJECT && value.get_script() == self.get_script():
|
||||
if value.type == YarnGlobals.ValueType.Variable:
|
||||
if value.type == WolGlobals.ValueType.Variable:
|
||||
self.type = value.type
|
||||
self.variable = value.variable
|
||||
else:
|
||||
|
@ -24,23 +24,23 @@ func _init(value = NANI):
|
|||
|
||||
func value():
|
||||
match type:
|
||||
YarnGlobals.ValueType.Number:
|
||||
WolGlobals.ValueType.Number:
|
||||
return number
|
||||
YarnGlobals.ValueType.Str:
|
||||
WolGlobals.ValueType.Str:
|
||||
return string
|
||||
YarnGlobals.ValueType.Boolean:
|
||||
WolGlobals.ValueType.Boolean:
|
||||
return boolean
|
||||
YarnGlobals.ValueType.Variable:
|
||||
WolGlobals.ValueType.Variable:
|
||||
return variable
|
||||
return null
|
||||
|
||||
func as_bool():
|
||||
match type:
|
||||
YarnGlobals.ValueType.Number:
|
||||
WolGlobals.ValueType.Number:
|
||||
return number != 0
|
||||
YarnGlobals.ValueType.Str:
|
||||
WolGlobals.ValueType.Str:
|
||||
return !string.empty()
|
||||
YarnGlobals.ValueType.Boolean:
|
||||
WolGlobals.ValueType.Boolean:
|
||||
return boolean
|
||||
return false
|
||||
|
||||
|
@ -49,37 +49,37 @@ func as_string():
|
|||
|
||||
func as_number():
|
||||
match type:
|
||||
YarnGlobals.ValueType.Number:
|
||||
WolGlobals.ValueType.Number:
|
||||
return number
|
||||
YarnGlobals.ValueType.Str:
|
||||
WolGlobals.ValueType.Str:
|
||||
return float(string)
|
||||
YarnGlobals.ValueType.Boolean:
|
||||
WolGlobals.ValueType.Boolean:
|
||||
return 0.0 if !boolean else 1.0
|
||||
return .0
|
||||
|
||||
func set_value(value):
|
||||
if value == null || (typeof(value) == TYPE_STRING && value == NANI):
|
||||
type = YarnGlobals.ValueType.Nullean
|
||||
type = WolGlobals.ValueType.Nullean
|
||||
return
|
||||
|
||||
match typeof(value):
|
||||
TYPE_INT,TYPE_REAL:
|
||||
type = YarnGlobals.ValueType.Number
|
||||
type = WolGlobals.ValueType.Number
|
||||
number = value
|
||||
TYPE_STRING:
|
||||
type = YarnGlobals.ValueType.Str
|
||||
type = WolGlobals.ValueType.Str
|
||||
string = value
|
||||
TYPE_BOOL:
|
||||
type = YarnGlobals.ValueType.Boolean
|
||||
type = WolGlobals.ValueType.Boolean
|
||||
boolean = value
|
||||
|
||||
#operations >>
|
||||
|
||||
#addition
|
||||
func add(other):
|
||||
if self.type == YarnGlobals.ValueType.Str || other.type == YarnGlobals.ValueType.Str:
|
||||
if self.type == WolGlobals.ValueType.Str || other.type == WolGlobals.ValueType.Str:
|
||||
return get_script().new("%s%s"%[self.value(),other.value()])
|
||||
if self.type == YarnGlobals.ValueType.Number && other.type == YarnGlobals.ValueType.Number:
|
||||
if self.type == WolGlobals.ValueType.Number && other.type == WolGlobals.ValueType.Number:
|
||||
return get_script().new(self.number + other.number)
|
||||
return null
|
||||
|
||||
|
@ -92,56 +92,56 @@ func equals(other)->bool:
|
|||
|
||||
#subtract
|
||||
func sub(other):
|
||||
if self.type == YarnGlobals.ValueType.Str || other.type == YarnGlobals.ValueType.Str:
|
||||
if self.type == WolGlobals.ValueType.Str || other.type == WolGlobals.ValueType.Str:
|
||||
return get_script().new(str(value()).replace(str(other.value()),""))
|
||||
if self.type == YarnGlobals.ValueType.Number && other.type == YarnGlobals.ValueType.Number:
|
||||
if self.type == WolGlobals.ValueType.Number && other.type == WolGlobals.ValueType.Number:
|
||||
return get_script().new(self.number - other.number)
|
||||
return null
|
||||
|
||||
#multiply
|
||||
func mult(other):
|
||||
if self.type == YarnGlobals.ValueType.Number && other.type == YarnGlobals.ValueType.Number:
|
||||
if self.type == WolGlobals.ValueType.Number && other.type == WolGlobals.ValueType.Number:
|
||||
return get_script().new(self.number * other.number)
|
||||
return null
|
||||
|
||||
#division
|
||||
func div(other):
|
||||
if self.type == YarnGlobals.ValueType.Number && other.type == YarnGlobals.ValueType.Number:
|
||||
if self.type == WolGlobals.ValueType.Number && other.type == WolGlobals.ValueType.Number:
|
||||
return get_script().new(self.number / other.number)
|
||||
return null
|
||||
|
||||
#modulus
|
||||
func mod(other):
|
||||
if self.type == YarnGlobals.ValueType.Number && other.type == YarnGlobals.ValueType.Number:
|
||||
if self.type == WolGlobals.ValueType.Number && other.type == WolGlobals.ValueType.Number:
|
||||
return get_script().new(self.number % other.number)
|
||||
return null
|
||||
|
||||
func negative():
|
||||
if self.type == YarnGlobals.ValueType.Number:
|
||||
if self.type == WolGlobals.ValueType.Number:
|
||||
return get_script().new(-self.number)
|
||||
return null
|
||||
|
||||
#greater than other
|
||||
func greater(other)->bool:
|
||||
if self.type == YarnGlobals.ValueType.Number && other.type == YarnGlobals.ValueType.Number:
|
||||
if self.type == WolGlobals.ValueType.Number && other.type == WolGlobals.ValueType.Number:
|
||||
return self.number > other.number
|
||||
return false
|
||||
|
||||
#less than other
|
||||
func less(other)->bool:
|
||||
if self.type == YarnGlobals.ValueType.Number && other.type == YarnGlobals.ValueType.Number:
|
||||
if self.type == WolGlobals.ValueType.Number && other.type == WolGlobals.ValueType.Number:
|
||||
return self.number < other.number
|
||||
return false
|
||||
|
||||
#greater than or equal to other
|
||||
func geq(other)->bool:
|
||||
if self.type == YarnGlobals.ValueType.Number && other.type == YarnGlobals.ValueType.Number:
|
||||
if self.type == WolGlobals.ValueType.Number && other.type == WolGlobals.ValueType.Number:
|
||||
return self.number > other.number || self.equals(other)
|
||||
return false
|
||||
|
||||
#lesser than or equal to other
|
||||
func leq(other)->bool:
|
||||
if self.type == YarnGlobals.ValueType.Number && other.type == YarnGlobals.ValueType.Number:
|
||||
if self.type == WolGlobals.ValueType.Number && other.type == WolGlobals.ValueType.Number:
|
||||
return self.number < other.number || self.equals(other)
|
||||
return false
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
extends Node
|
||||
var YarnGlobals = load("res://addons/Wol/autoloads/execution_states.gd")
|
||||
var WolGlobals = load("res://addons/Wol/autoloads/execution_states.gd")
|
||||
|
||||
var FunctionInfo = load("res://addons/Wol/core/function_info.gd")
|
||||
var Value = load("res://addons/Wol/core/value.gd")
|
||||
var YarnProgram = load("res://addons/Wol/core/program/program.gd")
|
||||
var YarnNode = load("res://addons/Wol/core/program/yarn_node.gd")
|
||||
var WolProgram = load("res://addons/Wol/core/program/program.gd")
|
||||
var WolNode = load("res://addons/Wol/core/program/wol_node.gd")
|
||||
var Instruction = load("res://addons/Wol/core/program/instruction.gd")
|
||||
var Line = load("res://addons/Wol/core/dialogue/line.gd")
|
||||
var Command = load("res://addons/Wol/core/dialogue/command.gd")
|
||||
|
@ -28,7 +28,7 @@ var _state
|
|||
|
||||
var _currentNode
|
||||
|
||||
var executionState = YarnGlobals.ExecutionState.Stopped
|
||||
var executionState = WolGlobals.ExecutionState.Stopped
|
||||
|
||||
var string_table = {}
|
||||
|
||||
|
@ -44,19 +44,19 @@ func set_program(program):
|
|||
#return true if successeful false if no node
|
||||
#of that name found
|
||||
func set_node(name:String)->bool:
|
||||
if _program == null || _program.yarnNodes.size() == 0:
|
||||
if _program == null || _program.wolNodes.size() == 0:
|
||||
printerr("Could not load %s : no nodes loaded" % name)
|
||||
return false
|
||||
|
||||
if !_program.yarnNodes.has(name):
|
||||
executionState = YarnGlobals.ExecutionState.Stopped
|
||||
if !_program.wolNodes.has(name):
|
||||
executionState = WolGlobals.ExecutionState.Stopped
|
||||
reset()
|
||||
printerr("No node named %s has been loaded" % name)
|
||||
return false
|
||||
|
||||
_dialogue.dlog("Running node %s" % name)
|
||||
|
||||
_currentNode = _program.yarnNodes[name]
|
||||
_currentNode = _program.wolNodes[name]
|
||||
reset()
|
||||
_state.currentNodeName = name
|
||||
nodeStartHandler.call_func(name)
|
||||
|
@ -70,11 +70,11 @@ func current_node():
|
|||
return _currentNode
|
||||
|
||||
func pause():
|
||||
executionState = YarnGlobals.ExecutionState.Suspended
|
||||
executionState = WolGlobals.ExecutionState.Suspended
|
||||
|
||||
#stop exectuion
|
||||
func stop():
|
||||
executionState = YarnGlobals.ExecutionState.Stopped
|
||||
executionState = WolGlobals.ExecutionState.Stopped
|
||||
reset()
|
||||
_currentNode = null
|
||||
|
||||
|
@ -82,7 +82,7 @@ func stop():
|
|||
#resume execution if waiting for result
|
||||
#return false if error
|
||||
func set_selected_option(id):
|
||||
if executionState != YarnGlobals.ExecutionState.WaitingForOption:
|
||||
if executionState != WolGlobals.ExecutionState.WaitingForOption:
|
||||
printerr("Unable to select option when dialogue not waiting for option")
|
||||
return false
|
||||
|
||||
|
@ -95,7 +95,7 @@ func set_selected_option(id):
|
|||
_state.currentOptions.clear()
|
||||
|
||||
#no longer waiting for option
|
||||
executionState = YarnGlobals.ExecutionState.Suspended
|
||||
executionState = WolGlobals.ExecutionState.Suspended
|
||||
|
||||
return true
|
||||
|
||||
|
@ -110,7 +110,7 @@ func resume()->bool:
|
|||
if _currentNode == null :
|
||||
printerr("Cannot run dialogue with no node selected")
|
||||
return false
|
||||
if executionState == YarnGlobals.ExecutionState.WaitingForOption:
|
||||
if executionState == WolGlobals.ExecutionState.WaitingForOption:
|
||||
printerr("Cannot run while waiting for option")
|
||||
return false
|
||||
|
||||
|
@ -133,10 +133,10 @@ func resume()->bool:
|
|||
return false
|
||||
|
||||
|
||||
executionState = YarnGlobals.ExecutionState.Running
|
||||
executionState = WolGlobals.ExecutionState.Running
|
||||
|
||||
#execute instruction until something cool happens
|
||||
while executionState == YarnGlobals.ExecutionState.Running:
|
||||
while executionState == WolGlobals.ExecutionState.Running:
|
||||
var currentInstruction = _currentNode.instructions[_state.programCounter]
|
||||
|
||||
run_instruction(currentInstruction)
|
||||
|
@ -144,7 +144,7 @@ func resume()->bool:
|
|||
|
||||
if _state.programCounter >= _currentNode.instructions.size():
|
||||
nodeCompleteHandler.call_func(_currentNode.nodeName)
|
||||
executionState = YarnGlobals.ExecutionState.Stopped
|
||||
executionState = WolGlobals.ExecutionState.Stopped
|
||||
reset()
|
||||
dialogueCompleteHandler.call_func()
|
||||
_dialogue.dlog("Run Complete")
|
||||
|
@ -159,18 +159,18 @@ func find_label_instruction(label:String)->int:
|
|||
|
||||
func run_instruction(instruction)->bool:
|
||||
match instruction.operation:
|
||||
YarnGlobals.ByteCode.Label:
|
||||
WolGlobals.ByteCode.Label:
|
||||
#do nothing woooo!
|
||||
pass
|
||||
YarnGlobals.ByteCode.JumpTo:
|
||||
WolGlobals.ByteCode.JumpTo:
|
||||
#jump to named label
|
||||
_state .programCounter = find_label_instruction(instruction.operands[0].value)-1
|
||||
YarnGlobals.ByteCode.RunLine:
|
||||
WolGlobals.ByteCode.RunLine:
|
||||
#look up string from string table
|
||||
#pass it to client as line
|
||||
var key = instruction.operands[0].value
|
||||
|
||||
var line = Line.new(key, _program.yarnStrings[key])
|
||||
var line = Line.new(key, _program.wolStrings[key])
|
||||
|
||||
#the second operand is the expression count
|
||||
# of format function
|
||||
|
@ -180,11 +180,11 @@ func run_instruction(instruction)->bool:
|
|||
var pause : int = lineHandler.call_func(line)
|
||||
|
||||
|
||||
if pause == YarnGlobals.HandlerState.PauseExecution:
|
||||
executionState = YarnGlobals.ExecutionState.Suspended
|
||||
if pause == WolGlobals.HandlerState.PauseExecution:
|
||||
executionState = WolGlobals.ExecutionState.Suspended
|
||||
|
||||
|
||||
YarnGlobals.ByteCode.RunCommand:
|
||||
WolGlobals.ByteCode.RunCommand:
|
||||
var commandText : String = instruction.operands[0].value
|
||||
|
||||
if instruction.operands.size() > 1:
|
||||
|
@ -193,37 +193,37 @@ func run_instruction(instruction)->bool:
|
|||
var command = Command.new(commandText)
|
||||
|
||||
var pause = commandHandler.call_func(command) as int
|
||||
if pause == YarnGlobals.HandlerState.PauseExecution:
|
||||
executionState = YarnGlobals.ExecutionState.Suspended
|
||||
if pause == WolGlobals.HandlerState.PauseExecution:
|
||||
executionState = WolGlobals.ExecutionState.Suspended
|
||||
|
||||
|
||||
YarnGlobals.ByteCode.PushString:
|
||||
WolGlobals.ByteCode.PushString:
|
||||
#push String var to stack
|
||||
_state.push_value(instruction.operands[0].value)
|
||||
YarnGlobals.ByteCode.PushNumber:
|
||||
WolGlobals.ByteCode.PushNumber:
|
||||
#push number to stack
|
||||
_state.push_value(instruction.operands[0].value)
|
||||
YarnGlobals.ByteCode.PushBool:
|
||||
WolGlobals.ByteCode.PushBool:
|
||||
#push boolean to stack
|
||||
_state.push_value(instruction.operands[0].value)
|
||||
|
||||
YarnGlobals.ByteCode.PushNull:
|
||||
WolGlobals.ByteCode.PushNull:
|
||||
#push null t
|
||||
_state.push_value(NULL_VALUE)
|
||||
|
||||
YarnGlobals.ByteCode.JumpIfFalse:
|
||||
WolGlobals.ByteCode.JumpIfFalse:
|
||||
#jump to named label if value of stack top is false
|
||||
if !_state.peek_value().as_bool():
|
||||
_state.programCounter = find_label_instruction(instruction.operands[0].value)-1
|
||||
|
||||
YarnGlobals.ByteCode.Jump:
|
||||
WolGlobals.ByteCode.Jump:
|
||||
#jump to label whose name is on the stack
|
||||
var dest : String = _state.peek_value().as_string()
|
||||
_state.programCounter = find_label_instruction(dest)-1
|
||||
YarnGlobals.ByteCode.Pop:
|
||||
WolGlobals.ByteCode.Pop:
|
||||
#pop value from stack
|
||||
_state.pop_value()
|
||||
YarnGlobals.ByteCode.CallFunc:
|
||||
WolGlobals.ByteCode.CallFunc:
|
||||
#call function with params on stack
|
||||
#push any return value to stack
|
||||
var functionName : String = instruction.operands[0].value
|
||||
|
@ -259,25 +259,25 @@ func run_instruction(instruction)->bool:
|
|||
_state.push_value(result)
|
||||
pass
|
||||
|
||||
YarnGlobals.ByteCode.PushVariable:
|
||||
WolGlobals.ByteCode.PushVariable:
|
||||
#get content of variable and push to stack
|
||||
var name : String = instruction.operands[0].value
|
||||
var loaded = _dialogue._variableStorage.get_value(name)
|
||||
_state.push_value(loaded)
|
||||
YarnGlobals.ByteCode.StoreVariable:
|
||||
WolGlobals.ByteCode.StoreVariable:
|
||||
#store top stack value to variable
|
||||
var top = _state.peek_value()
|
||||
var destination : String = instruction.operands[0].value
|
||||
_dialogue._variableStorage.set_value(destination,top)
|
||||
|
||||
YarnGlobals.ByteCode.Stop:
|
||||
WolGlobals.ByteCode.Stop:
|
||||
#stop execution and repost it
|
||||
nodeCompleteHandler.call_func(_currentNode.nodeName)
|
||||
dialogueCompleteHandler.call_func()
|
||||
executionState = YarnGlobals.ExecutionState.Stopped
|
||||
executionState = WolGlobals.ExecutionState.Stopped
|
||||
reset()
|
||||
|
||||
YarnGlobals.ByteCode.RunNode:
|
||||
WolGlobals.ByteCode.RunNode:
|
||||
#run a node
|
||||
var name : String
|
||||
|
||||
|
@ -290,24 +290,24 @@ func run_instruction(instruction)->bool:
|
|||
var pause = nodeCompleteHandler.call_func(_currentNode.nodeName)
|
||||
set_node(name)
|
||||
_state.programCounter-=1
|
||||
if pause == YarnGlobals.HandlerState.PauseExecution:
|
||||
executionState = YarnGlobals.ExecutionState.Suspended
|
||||
if pause == WolGlobals.HandlerState.PauseExecution:
|
||||
executionState = WolGlobals.ExecutionState.Suspended
|
||||
|
||||
YarnGlobals.ByteCode.AddOption:
|
||||
WolGlobals.ByteCode.AddOption:
|
||||
# add an option to current state
|
||||
var key = instruction.operands[0].value
|
||||
|
||||
var line = Line.new(key, _program.yarnStrings[key])
|
||||
var line = Line.new(key, _program.wolStrings[key])
|
||||
|
||||
if instruction.operands.size() > 2:
|
||||
pass #formated text options
|
||||
|
||||
# line to show and node name
|
||||
_state.currentOptions.append(SimpleEntry.new(line,instruction.operands[1].value))
|
||||
YarnGlobals.ByteCode.ShowOptions:
|
||||
WolGlobals.ByteCode.ShowOptions:
|
||||
#show options - stop if none
|
||||
if _state.currentOptions.size() == 0:
|
||||
executionState = YarnGlobals.ExecutionState.Stopped
|
||||
executionState = WolGlobals.ExecutionState.Stopped
|
||||
reset()
|
||||
dialogueCompleteHandler.call_func()
|
||||
return false
|
||||
|
@ -319,7 +319,7 @@ func run_instruction(instruction)->bool:
|
|||
choices.append(Option.new(option.key, optionIndex, option.value))
|
||||
|
||||
#we cant continue until option chosen
|
||||
executionState = YarnGlobals.ExecutionState.WaitingForOption
|
||||
executionState = WolGlobals.ExecutionState.WaitingForOption
|
||||
|
||||
#pass the options to the client
|
||||
#delegate for them to call
|
||||
|
@ -329,7 +329,7 @@ func run_instruction(instruction)->bool:
|
|||
pass
|
||||
_:
|
||||
#bytecode messed up woopsise
|
||||
executionState = YarnGlobals.ExecutionState.Stopped
|
||||
executionState = WolGlobals.ExecutionState.Stopped
|
||||
reset()
|
||||
printerr("Unknown Bytecode %s "%instruction.operation)
|
||||
return false
|
||||
|
|
|
@ -3,18 +3,18 @@ extends EditorPlugin
|
|||
|
||||
func _enter_tree():
|
||||
add_autoload_singleton(
|
||||
'YarnGlobals',
|
||||
'WolGlobals',
|
||||
'res://addons/Wol/autoloads/execution_states.gd'
|
||||
)
|
||||
|
||||
add_custom_type(
|
||||
'Wol',
|
||||
'Node',
|
||||
load('res://addons/Wol/yarn_runner.gd'),
|
||||
load('res://addons/Wol/Wol.gd'),
|
||||
load('res://addons/Wol/assets/icon.png')
|
||||
)
|
||||
|
||||
|
||||
func _exit_tree():
|
||||
remove_autoload_singleton('YarnGlobals')
|
||||
remove_autoload_singleton('WolGlobals')
|
||||
remove_custom_type('Wol')
|
||||
|
|
|
@ -15,7 +15,7 @@ config/icon="res://icon.png"
|
|||
|
||||
[autoload]
|
||||
|
||||
YarnGlobals="*res://addons/Wol/autoloads/execution_states.gd"
|
||||
WolGlobals="*res://addons/Wol/autoloads/execution_states.gd"
|
||||
|
||||
[editor_plugins]
|
||||
|
||||
|
|
Reference in a new issue