@ -118,10 +118,11 @@ A major limitation, and thus an adjustment when coming to nimf from many other l
Variables can be named anything you like with the following exceptions:
- A variable, or a word for that matter, cannot dontain only digits (ex. `23`) as the interpreter will treat this as an integer
- A variable, or a word for that matter, cannot contain only digits (ex. `23`) as the interpreter will treat this as an integer
- A variable or word name cannot take the form of a decimal, hexidecimal, octal, or binary number. Using numbers in a var name or word is fine, so long as they do not match the established patterns for these number forms
- A variable or word name cannot contain whitespace
As a convention, not enforced at a code level, can create private words by using the following variable/word naming scheme: _module-name_.private._name_. For example: `url.private.port` would be part of the `url` module and is intended to only be used internally so is marked private, it is then given the name `port`. Using `private` in this way excludes any variables and words containing `.private.` from the word listing provided with the word `words`. In reality you can still call private words if you like, but private is one way a developer can provide intent to other developers.
As a convention, not enforced at a code level, private words can be created by using the following variable/word naming scheme: _module-name_.private._name_. For example: `url.private.port` would be part of the `url` module and is intended to only be used internally so is marked private, it is then given the name `port`. Using `private` in this way excludes any variables and words containing `.private.` from the word listing provided with the word `words`. In reality you can still call private words if you like, but private is one way a developer can provide intent to other developers.
panic(fmt.Sprintf("Invalid word name while eating word definition on line %d in %s",line,file))
handleParseError(fmt.Errorf("Invalid word name while eating word definition"),line,file,nameTok.String())
return
}
name:=nameTok.String()
def:=make([]token,0,10)
@ -156,7 +164,8 @@ ParseLoop:
for{
t,err:=r.Read()
iferr!=nil{
panic(fmt.Sprintf("End of input file reached before close of word definition %q in file %s",name,nameTok.file))
handleParseError(fmt.Errorf("End of input file reached before close of word definition %q",name),nameTok.line,nameTok.file,"")
return
}
ift.tokType==stringType||t.tokType==intType{
def=append(def,t)
@ -165,20 +174,23 @@ ParseLoop:
case";":
breakParseLoop
case"inline":
panic(fmt.Sprintf("Error while parsing word definition %q. Found an %q directive on line %d of %s. Cannot inline from within a word",name,"inline",t.line,t.file))
handleParseError(fmt.Errorf("Error while parsing word definition %q. Cannot inline from within a word definition",name),t.line,t.file,"inline")
return
case"if":
ifTok++
def=append(def,t)
case"else":
elseTok++
ifelseTok>ifTok{
panic(fmt.Sprintf("Error while parsing word definition %q on line %d of %s. Cannot use 'else' before a similarly nested 'if'",name,t.line,t.file))
handleParseError(fmt.Errorf("Error while parsing word definition %q. Cannot use 'else' before a similarly nested 'if'",name),t.line,t.file,"else")
return
}
def=append(def,t)
case"then":
thenTok++
ifthenTok>ifTok{
panic(fmt.Sprintf("Error while parsing word definition %q on line %d of %s. Cannot use 'then' before a similarly nested 'if'",name,t.line,t.file))
handleParseError(fmt.Errorf("Error while parsing word definition %q. Cannot use 'then' before a similarly nested 'if'",name),t.line,t.file,"then")
return
}
def=append(def,t)
case"do":
@ -187,18 +199,21 @@ ParseLoop:
case"loop":
loopTok++
ifloopTok>doTok{
panic(fmt.Sprintf("Error while parsing word definition %q on line %d of %s. Cannot use 'loop' before a similarly nested 'do'",name,t.line,t.file))
handleParseError(fmt.Errorf("Error while parsing word definition %q. Cannot use 'loop' before a similarly nested 'do'",name),t.line,t.file,"loop")
return
}
def=append(def,t)
case":":
panic(fmt.Sprintf("Error while parsing word definition %q on line %d of %s. Cannot use ':' to create a word within a word definition",name,t.line,t.file))
handleParseError(fmt.Errorf("Error while parsing word definition %q. Cannot use ':' to create a word within a word definition",name),t.line,t.file,":")
return
default:
def=append(def,t)
}
}
}
ifdoTok!=loopTok||ifTok!=thenTok{
panic(fmt.Sprintf("The word definition for %q found on line %d of %s contains an unbalanced conrol structures",name,nameTok.line,nameTok.file))
handleParseError(fmt.Errorf("The word definition for %q contains an unbalanced conrol structure",name),nameTok.line,nameTok.file,"")