Permalink
Browse files

Fixed specification of extensible parser.

  • Loading branch information...
1 parent 8ac8840 commit 1fd1b05a3ae7ea788d1fb02dd72f6d28a60957c6 nineties committed Mar 14, 2013
View
@@ -1,7 +1,7 @@
#!/usr/bin/amber -m
# Copyright (C) 2012 nineties
#
-# $Id: hyperlisp.ab 2013-03-06 22:56:40 nineties $
+# $Id: hyperlisp.ab 2013-03-14 20:44:04 nineties $
# Reference
# Masahiko Sato and Masami Hagiya: HyperLisp, Algorithmic Languages
@@ -19,5 +19,5 @@ open HyperLisp
# Switch to the HyperLisp interpreter.
-(eval, Parser::statement, Parser::comment)
- = (HyperLisp::hl_eval, HyperLisp::Parser::hl_expr, HyperLisp::Parser::hl_comment)
+(eval, Syntax::statement, Syntax::comment)
+ = (HyperLisp::hl_eval, HyperLisp::Syntax::hl_expr, HyperLisp::Syntax::hl_comment)
@@ -1,6 +1,6 @@
# Copyright (C) 2012 nineties
#
-# $Id: hyperlisp/symbol.ab 2013-03-09 01:01:10 nineties $
+# $Id: hyperlisp/symbol.ab 2013-03-14 20:45:49 nineties $
# Reference
# Masahiko Sato and Masami Hagiya: HyperLisp, Algorithmic Languages
@@ -10,7 +10,6 @@
import core
module HyperLisp {
- module Parser {
# Metaliteral
hl_metaliteral ::= nospace( ([A-Z][A-Za-z0-9]*) )
{ `Meta{!$input.to_sym} }
@@ -22,7 +21,6 @@ module HyperLisp {
{ `Eq{!$0, !$2} }
| "." hl_expr
{ `Whole{!$1} }
- }
# Rename variables to avoid name conflict.
rename(sym): ("hyperlisp_" + sym).to_sym
@@ -220,16 +218,14 @@ module HyperLisp {
## Function definition
- module Parser {
# The symbol '#' is used for start symbol of comments in
# Amber's default syntax.
- hl_comment: C_style_comment
+ Syntax::hl_comment: Syntax::C_style_comment
hl_expr ::= <<multiline>>
"#" hl_literal hl_simple_expr "=" hl_expr ";"
{ cons_list([\Meta{Delta}, $1,
cons_list([\Meta{Lambda}, $2, $4])]) }
- }
# Extend eval and apply
eval_define(x): {
@@ -249,12 +245,10 @@ module HyperLisp {
| x@Snoc -> snoc(macro(x.car), macro(x.cdr))
| x -> x
- module Parser {
# lambda-abstraction and label-expression is just a syntax sugar.
# Therefore, they should be translated to sexp before evaluation.
- hl_expr_old: hl_expr
+ hl_expr_old: Syntax::hl_expr
hl_expr_macro ::= hl_expr_old { macro($0) }
- hl_expr = hl_expr_macro
- }
+ Syntax::hl_expr = Syntax::hl_expr_macro
}
@@ -1,6 +1,6 @@
# Copyright (C) 2012 nineties
#
-# $Id: hyperlisp/symbol.ab 2013-03-06 00:00:29 nineties $
+# $Id: hyperlisp/symbol.ab 2013-03-14 20:40:38 nineties $
# Reference
# Masahiko Sato and Masami Hagiya: HyperLisp, Algorithmic Languages
@@ -46,13 +46,11 @@ module HyperLisp {
(s.size == 1) ? zero : s[1..-1].to_sym
}
- module Parser {
# Extend Syntax
#
# A literal is a nonempty sequence of lowercase letters
hl_literal ::= nospace( [a-z]+ ) { $input.to_sym }
hl_simple_expr ::= hl_literal
- }
# Use Amber's default pretty-printer
}
@@ -1,6 +1,6 @@
# Copyright (C) 2012 nineties
#
-# $Id: hyperlisp/syntax.ab 2013-03-08 17:44:35 nineties $
+# $Id: hyperlisp/syntax.ab 2013-03-14 20:40:46 nineties $
# Reference
# Masahiko Sato and Masami Hagiya: HyperLisp, Algorithmic Languages
@@ -10,7 +10,6 @@
import core
module HyperLisp {
- module Parser {
# Basic syntax
hl_simple_expr
::= "(" hl_expr "." hl_expr ")" { cons($1, $3) }
@@ -37,7 +36,6 @@ module HyperLisp {
::= hl_secondary_expr ":" hl_secondary_expr
{ cons_list([$0, $2]) }
| hl_secondary_expr
- }
# Pretty printing
is_cons_list
View
@@ -1,10 +1,8 @@
-BeginModule{Qualified{Std, Parser}}
-
-Assign{comment, shell_style_comment}
+Assign{Qualified{Syntax,comment}, Qualified{Syntax,shell_style_comment}}
# Copyright (C) 2010 nineties
#
-# $Id: syntax.ab 2013-03-08 17:41:41 nineties $
+# $Id: syntax.ab 2013-03-14 20:36:48 nineties $
# Syntax definition of the Amber language.
# This file will be loaded first.
@@ -220,7 +218,7 @@ pattern ::= quote_expr
term ::= primary_expr
## enable use of quotation expressions for following definitions.
-Assign{expr, quote_expr}
+Assign{Qualified{Syntax,expr}, Qualified{Syntax,quote_expr}}
prefix_expr
::= "+" quote_expr { `UnaryPlus{!node1} }
@@ -310,7 +308,7 @@ assign_expr
| pattern ">>=" assign_expr { `ShiftRAssign{!node0, !node2} }
| multi_lambda_expr
-Assign{expr, assign_expr}
+Assign{Syntax::expr, Syntax::assign_expr}
### Statements
package ::= string
@@ -371,8 +369,6 @@ ReserveSymbol{not, and, or, when, open, if, else, case, of,
throw, try, catch, seq, scope
}
-EndModule{} # Std::Parser
-
## Syntax Sugars
+x => `uplus(!x)
-x => `uminus(!x)
@@ -403,16 +399,16 @@ x is not y => `(not identical(!x, !y))
x[args...] => `Apply{at, !Std::cons(x, args)}
x[args...] = e => `Apply{store, !Std::cons(x, Std::append(args, [e]))}
-module Std::Parser {
+module Syntax {
### Extend primary_expr so as to enable use $... to refer nodes
# of syntax-tree only in parser_action.
module Action {
- primary_expr ::= "$" decimal { ("node" + node1).to_sym }
- | "$input" { \input_text(parser,begin,end) }
+ primary_expr ::= "$" decimal { ("node" + node1).to_sym }
+ | "$input" { \input_text(parser,begin,end) }
}
# FIXME: This is temporary dirty hack.
- primary_expr_act : primary_expr | Action::primary_expr
+ primary_expr_act : primary_expr | Action::Syntax::primary_expr
parser_action_old: parser_action
parser_action = parser -> {
save_primary_expr: primary_expr
@@ -424,7 +420,7 @@ module Std::Parser {
### Syntax definitions which are effective only in shell-mode.
module Shell {
- primary_expr ::= "%" nospace(decimal) { `shell_outputs[!$1] }
- | "%" { `shell_outputs[0] }
+ primary_expr ::= "%" nospace(decimal) { `shell_outputs[!$1] }
+ | "%" { `shell_outputs[0] }
}
}
View
@@ -1,15 +1,13 @@
# Copyright (C) 2012 nineties
#
-# $Id: table.ab 2013-03-05 04:44:39 nineties $
+# $Id: table.ab 2013-03-14 20:38:14 nineties $
module Std {
- module Parser {
- table_entry ::= expr "=>" expr { ($0, $2) }
- postfix_expr
- ::= <<multiline>> "Table" "{" delimited(table_entry, ",") "}"
- { `Table::from_list(!$2) }
- }
-
each(tbl@Table): tbl.entries.each
reverse_each(tbl@Table): tbl.entries.reverse_each
}
+
+table_entry ::= expr "=>" expr { ($0, $2) }
+postfix_expr
+ ::= <<multiline>> "Table" "{" delimited(table_entry, ",") "}"
+ { `Table::from_list(!$2) }
View
@@ -1,29 +1,25 @@
# Copyright (C) 2013 nineties
#
-# $Id: oop.ab 2013-03-05 05:41:52 nineties $
+# $Id: oop.ab 2013-03-14 16:48:06 nineties $
# Prototype-based Object-Oriented Programming
-module Std {
- module Parser {
- object_slot ::= symbol ":" expr { ($0, $2) }
- object_slots
- ::= <<multiline>> "{" delimited(object_slot, ",") "}" { $1 }
- | <<multiline>> "{" aligned(object_slot) "}" { $1 }
+object_slot ::= symbol ":" expr { ($0, $2) }
+object_slots
+ ::= <<multiline>> "{" delimited(object_slot, ",") "}" { $1 }
+ | <<multiline>> "{" aligned(object_slot) "}" { $1 }
- object_creation
- ::= <<multiline>> "make" symbol object_slots { `MakeSlots{!$1, !$2} }
+object_creation
+ ::= <<multiline>> "make" symbol object_slots { `MakeSlots{!$1, !$2} }
- prefix_expr ::= object_creation
- }
+prefix_expr ::= object_creation
- MakeSlots{head, fields} => {
- obj: gensym()
- inits: map(((x,v)) -> `set_slot(!obj, \!x, !v), fields)
- `{
- DefineVariable{!obj, MakeObject{\!head, []}}
- Seq{!inits}
- !obj
- }
+MakeSlots{head, fields} => {
+ obj: gensym()
+ inits: map(((x,v)) -> `set_slot(!obj, \!x, !v), fields)
+ `{
+ DefineVariable{!obj, MakeObject{\!head, []}}
+ Seq{!inits}
+ !obj
}
}
View
@@ -1,6 +1,6 @@
# Copyright (C) 2010 nineties
#
-# $Id: printf.ab 2013-03-08 17:42:20 nineties $
+# $Id: printf.ab 2013-03-14 20:37:59 nineties $
module Std {
module Printf {
@@ -32,27 +32,25 @@ module Std {
}
}
- module Parser {
- ### Format string
- # XXX: Not good implementation (should not define new syntax)
+}
- format_string_element
- ::= "%" [sSdXobpf] { $input }
- | "%" . { throw `SyntaxError{!LOCATION,
- "Invalid format string", !($0 + $1)}
- }
- | nospace( [^%\""]+ ) { $input.unescape }
-
- format_string
- ::= nospace( ('"' format_string_element* '"') ) { $0[1] }
+### Format string
+# XXX: Not good implementation (should not define new syntax)
- postfix_expr
- ::= "printf" "(" format_string ("," expr)* ")"
- { Printf::compile_printf(\stdout, $2, map(x->x[1], $3)) }
- | "printf" "(" expr "," format_string ("," expr)* ")"
- { Printf::compile_printf($2, $4, map(x->x[1], $5)) }
- | "format" "(" format_string ("," expr)* ")"
- { Printf::compile_format($2, map(x->x[1], $3))}
- }
-
-}
+format_string_element
+ ::= "%" [sSdXobpf] { $input }
+ | "%" . { throw `SyntaxError{!LOCATION,
+ "Invalid format string", !($0 + $1)}
+ }
+ | nospace( [^%\""]+ ) { $input.unescape }
+
+format_string
+ ::= nospace( ('"' format_string_element* '"') ) { $0[1] }
+
+postfix_expr
+ ::= "printf" "(" format_string ("," expr)* ")"
+ { Std::Printf::compile_printf(\stdout, $2, map(x->x[1], $3)) }
+ | "printf" "(" expr "," format_string ("," expr)* ")"
+ { Std::Printf::compile_printf($2, $4, map(x->x[1], $5)) }
+ | "format" "(" format_string ("," expr)* ")"
+ { Std::Printf::compile_format($2, map(x->x[1], $3))}
View
@@ -1,6 +1,6 @@
# Copyright (C) 2012 nineties
#
-# $Id: UnitTest.ab 2013-03-05 04:32:29 nineties $
+# $Id: UnitTest.ab 2013-03-14 20:37:40 nineties $
#USAGE :
#
@@ -10,13 +10,11 @@
# }
# }
-module Parser {
- statement
- ::= "test" string block { `UnitTestTarget{!$1, !$2} }
- | string ":" test_code { `UnitTestItem{!$0, !$2} }
- ReserveSymbol{test}
- test_code ::= expr
-}
+statement
+ ::= "test" string block { `UnitTestTarget{!$1, !$2} }
+ | string ":" test_code { `UnitTestItem{!$0, !$2} }
+ReserveSymbol{test}
+test_code ::= expr
UnitTestTarget{target, tests} => `{
printf("=== tests of %s ===\n\n", !target)
View
@@ -2,7 +2,7 @@
; rowl - 1st generation
; Copyright (C) 2010 nineties
;
-; $Id: rowl1-compile.rlc 2013-03-09 00:50:53 nineties $
+; $Id: rowl1-compile.rlc 2013-03-13 23:08:17 nineties $
;
(import "rlvm-compile")
@@ -1036,9 +1036,9 @@
(fun load_module_variable (sym node) (
(var v (car (field_get node 1)))
- (if (== v uninitialized) (do
+ (if (== v uninitialized)
(throw (undefined_var current_loc sym))
- ))
+ )
(return v)
))
View
@@ -2,7 +2,7 @@
; rowl - 1st generation
; Copyright (C) 2010 nineties
;
-; $Id: rowl1-node.rlc 2013-03-08 06:55:09 nineties $
+; $Id: rowl1-node.rlc 2013-03-09 12:33:05 nineties $
;
(import "rlvm-compile")
@@ -22,7 +22,7 @@
(export fun type_error (loc required actual) (
(return (make_object3 (to_sym "TypeError") loc
(make_object1 (to_sym "expected") required)
- (make_object1 (to_sym "actual") actual)
+ (make_object1 (to_sym "value") actual)
))
))
Oops, something went wrong.

0 comments on commit 1fd1b05

Please sign in to comment.